WFC Service Client Calls Instancing and concurrency - concurrency

Thanks in advance for your help.
I read several articles about concurrency, Instancing and thread safety, but I confess that I still have doubts.
In fact, the information in the articles is sometimes contradictory.
I have a simple WFC service that, receives a date period (StartDate and EndDate).
The service has to search for files that contain a date in their name within the period defined by StartDate and EndDate.
The founded files will then be Zipped and Uploaded to a Server.
After many tests I never noticed any problem with the service's operation.
But before using the service in a production environment, I need to make sure that the service code is secure, in order to ensure that multiple
simultaneous requests from clients don't affect the data integrity of other requests.
I posted a code snippet, and I have added comments/questions to the code.
Please note that I've set the service Instancing To PerCall.
As I have noticed in microsoft documentation "in PerCall instancing, concurrency is not relevant, because each message is processed by a new service instance.".
But each service instance is thread safe by it self? In other words, each client call to the service cannot change the data of other calls?
King Regards.
J.Campos
' - - - - - - - - - - - - - - - WFC Service Contract - - - - - - - - - - - - - - -
<ServiceContract()>
Public Interface IMyReports
<OperationContract(IsOneWay:=True)>
Sub SvcRequest(ByVal ClientID as integer, ByVal startDate as string, ByVal EndDate)
End Interface
' - - - - - - - - - - - - - - - WFC Service - - - - - - - - - - - - - - -
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerCall)>
Public Class SvcDoRequest
Implements IMyReports
'??? These Private members can be changed by another Service Call?
Private Dat1 as string=""
Private Dat2 as string=""
Private SearchFolder as string=""
Public Sub SvcRequest(StartDate as string, EndDate as String) Implements IMyReports.SvcRequest
SearchFolder= "c:\SearchFolder\"
Dat1 as string=StarDate
Dat2 as string=EndDate
Dim ListOfFiles as new List(of String)
'Recursive File Search
'??? Arguments passed byRef. Can the Arguments be Changed by another Service Call?
Call FGetFiles(SearchFolder, ListOfFiles)
Dim Result as integer=0
If ListOfFiles.Count>0
Dim ZipFileName as string="c:\MyZipFile.Zip"
Dim ErrMsg as string=""
' External Library to Create a ZIP File containing ListOfFiles()
'??? ErrMsg is passed byRef in order to return a possible error message.
'??? Can ErrMsg be Changed by another Service Call?
Dim ClZip As New MyZipLibrary.ZipClass
If ClZip.FCreateZip(ListOfFiles, ZipFileName, ErrMsg)=False Then
Call WriteToLog(ErrMsg)
Result=-1
Else
Result=1
End if
End if
' Upload ZipFile
'
End Sub
Private Function FGetFiles(ByRef Folder As String, ByRef LFiles As List(Of String)) as boolean
'??? is this recursive function safe? Byref args Folder,LFiles can be changed by another Call?
For Each File1 As String In Directory.GetFiles(Folder)
Dim FileInfo1 As New FileInfo(File1)
Dim FileDate As String = FileInfo1.Name.Substring(0,8)
If FileDate >= Dat1 And FileDate <= Dat2 Then
LFiles.Add(FileInfo1.FullName)
End If
Next
For Each Dir1 As String In Directory.GetDirectories(Folder)
Call FGetFiles(Dir1, LFiles)
Next
Return True
End Function
End Class
'- - - - - - - - - - - - - - - - - - - - - - - - - ZIP Library - - - - - - - - - - -
Public Class MyZipLibrary
Public Function FCreateZip(byval ListOfFiles as List(of String),
Byval ZipFileName as string, ByRef ErrMsg as string) as Boolean
If Not CreateZipFile()
'Byref Argument ErrMsg. can be changed by another client Call?
ErrMsg="Unable To Create ZipFile"
Return false
Else
Return True
End if
End function
End Class

Related

Scala - Looping through an array and applying regex

I have an array of log messages. An example of a message in the array below -
Example below -
Output(RequiredSystemOutput(2017-05-21 13:43:59,085 [scala-execution-context-global-43] ERROR Database - Error executing database store for URI (uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350) for transition to state FileArchived : Could not acquire connection-1 - Connection is not available, request timed out after 15000ms.,2020-01-21 13:43:59.086 GMT)) }}
So imagine the above but repeated.
I would like to loop through the array of individual log messages so that rather than printing out the whole message for each one, it only prints out the uri and offset, like so -
uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350
I have the regex which is val regex = "\\(([^()]+)\\)" but I am struggling to apply this in Scala, especially in an array.
I am not sure that the regex which you mentioned in your code will help because you have provided just one example. I can provide with a more selective for the given example.
val string = "Output(RequiredSystemOutput(2017-05-21 13:43:59,085 [scala-execution-context-global-43] ERROR Database - Error executing database store for URI (uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350) for transition to state FileArchived : Could not acquire connection-1 - Connection is not available, request timed out after 15000ms.,2020-01-21 13:43:59.086 GMT)) }}"
val regex = "\\((uri\\:[0-9a-zA-Z\\-]+,offset\\:[0-9]+)\\)".r
val matchOption = regex.findFirstMatchIn(string)
val extractedStringOption = matchOption.map(_.group(1))
// extractedStringOption: Option[String] = Some(uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350)
You could loop the array, and if there is only a single match use findFirstMatchIn.
The pattern you use is very broad, and you might make it a bit more specific by for example starting the match inside the capturing group with uri:
Regex demo | Scala demo
For example
val array = Array (
"Output(RequiredSystemOutput(2017-05-21 13:43:59,085 [scala-execution-context-global-43] ERROR Database - Error executing database store for URI (uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350) for transition to state FileArchived : Could not acquire connection-1 - Connection is not available, request timed out after 15000ms.,2020-01-21 13:43:59.086 GMT)) }}",
"Output(RequiredSystemOutput(2017-05-21 13:43:59,085 [scala-execution-context-global-43] ERROR Database - Error executing database store for URI (uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350) for transition to state FileArchived : Could not acquire connection-1 - Connection is not available, request timed out after 15000ms.,2020-01-21 13:43:59.086 GMT)) }}"
)
val pattern = """\((uri:[^()]+)\)""".r
val res: Array[String] = for {
s <- array
m <- pattern.findAllMatchIn(s)
} yield m.group(1)
res.foreach(println)
Output
uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350
uri:becbfx08-c491-44e3-bd01-d12c0305bcbf,offset:12054350
To get a more specific match, you could use a character class and repeat the preceding hyphen:
\((uri:[a-z0-9]+(?:-[a-z0-9]+)+,offset:[0-9]+)\)
Regex demo

How to Insert a new string into telegraf.conf's inputs.ping using ansible regexp

I'm trying to use ansible to update telegraf.conf's [[inputs.ping]].
telegraf.conf looks like the following:
[[inputs.ping]]
urls = ["tac-temp1","tac-temp2", "tac-temp3","tac-temp4"] #tac
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "tac"
[[inputs.ping]]
urls = ["prod-temp1","prod-temp2", "prod-temp3","prod-temp4"] #prod
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "prod"
[[inputs.ping]]
urls = ["test-temp1","test-temp2", "test-temp3","test-temp4"] #test
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "test"
I'm trying to add ,"tac-temp10" after ,"tac-temp4" in line 2 shown above.
- hosts: Servers
become: yes
become_method: sudo
tasks:
- name: Loading telegraf.conf content for search
shell: cat /tmp/telegraf.conf
register: tele_lookup
- name: Adding Server to /tmp/telegraf.conf if does not exists
lineinfile:
path: /tmp/telegraf.conf
state: present
regexp: '^((.*)"] #tac$)'
line: ',"tac-temp10"'
backup: yes
when: tele_lookup.stdout.find('tac-temp10') != '0'
regexp: '^((.*)"] #tac$)' is replacing the whole line with ,"tac-temp10". Expected output:
[[inputs.ping]]
urls = ["tac-temp1","tac-temp2", "tac-temp3","tac-temp4","tac-temp10"] #tac
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "tac"
Warning: Ugly regexp ahead. Beware of unpredictable understanding for next guys (including you after time passed by...) doing maintenance.
The following will add your server at the end of the list if it is not already present (anywhere in the list) with a single idempotent task.
- name: add our server if needed
lineinfile:
path: /tmp/test.conf
backup: yes
state: present
regexp: '^( *urls *= *\[)(("(?!tac-temp10)([a-zA-Z0-9_-]*)",? *)*)(\] #tac)$'
backrefs: yes
line: '\1\2, "tac-temp10"\5'
You need to use backreferences to put back on the line the already matched parts of the expression. I used backup: yes so I could easily come back to the original for my tests. Feel free to drop it.
As you can see (and as advised in my warning) this is pretty much impossible to understand for anyone having to quickly read the code. If you have to do anything more fancy/complicated, consider using a template and storing your server list in a variable somewhere.

Webscraping with VBA morningstar financial

I'm trying to scrape the inside ownership from Morningstar at this url:
http://investors.morningstar.com/ownership/shareholders-overview.html?t=TWTR&region=usa&culture=en-US
This is the code I'm using:
Sub test()
Dim appIE As Object
Set appIE = CreateObject("InternetExplorer.Application")
With appIE
.Navigate "http://investors.morningstar.com/ownership/shareholders-overview.html?t=TWTR&region=usa&culture=en-US"
.Visible = True
End With
While appIE.Busy
DoEvents
Wend
Set allRowOfData = appIE.Document.getElementById("currentInsiderVal")
Debug.Print allRowOfData
Dim myValue As String: myValue = allRowOfData.Cells(0).innerHTML
appIE.Quit
Set appIE = Nothing
Range("A30").Value = myValue
End Sub
I get run-time error 13 at line
Set allRowOfData = appIE.Document.getElementById("currentInsiderVal")
but I can't see any mismatch. What is going on?
You can just do it with XHR and RegEx instead of cumbersome IE:
Sub Test()
Dim sContent
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "http://investors.morningstar.com/ownership/shareholders-overview.html?t=TWTR&region=usa&culture=en-US", False
.Send
sContent = .ResponseText
End With
With CreateObject("VBScript.RegExp")
.Pattern = ",""currInsiderVal"":(.*?),"
Range("A30").Value = .Execute(sContent).Item(0).SubMatches(0)
End With
End Sub
Here is the description how the code works:
First of all MSXML2.XMLHTTP ActiveX instance is created. GET request opened with target URL in synchronous mode (execution interrupts until response received).
Then VBScript.RegExp is created. By default .IgnoreCase, .Global and .MultiLine properties are False. The pattern is ,"currInsiderVal":(.*?),, where (.*?) is a capturing group, . means any character, .* - zero or more characters, .*? - as few as possible characters (lazy matching). Other characters in pattern to be found as is. .Execute method returns a collection of matches, there is only one match object in it since .Global is False. This match object has a collection of submatches, there is only one submatch in it since the pattern contains the only capturing group.There are some helpful MSDN articles on regex:
Microsoft Beefs Up VBScript with Regular Expressions
Introduction to Regular Expressions
Here is the description how I created the code:
First I found an element containing the target value on the webpage DOM using browser:
The corresponding node is:
<td align="right" id="currrentInsiderVal">143.51</td>
Then I made XHR and found this node in the response HTML, but it didn't contain the value (you can find response in the browser developer tools on network tab after you refresh the page):
<td align="right" id="currrentInsiderVal">
</td>
Such behavior is typical for DHTML. Dynamic HTML content is generated by scripts after the webpage loaded, either after retrieving a data from web via XHR or just processing already loaded withing webpage data. Then I just searched for the value 143.51 in the response, the snippet ,"currInsiderVal":143.51, located within JS function:
fundsArr = {"fundTotalHistVal":132.61,"mutualFunds":[[1,89,"#a71620"],[2,145,"#a71620"],[3,152,"#a71620"],[4,198,"#a71620"],[5,155,"#a71620"],[6,146,"#a71620"],[7,146,"#a71620"],[8,132,"#a71620"]],"insiderHisMaxVal":3.535,"institutions":[[1,273,"#283862"],[2,318,"#283862"],[3,351,"#283862"],[4,369,"#283862"],[5,311,"#283862"],[6,298,"#283862"],[7,274,"#283862"],[8,263,"#283862"]],"currFundData":[2,2202,"#a6001d"],"currInstData":[1,4370,"#283864"],"instHistMaxVal":369,"insiders":[[5,0.042,"#ff6c21"],[6,0.057,"#ff6c21"],[7,0.057,"#ff6c21"],[8,3.535,"#ff6c21"],[5,0],[6,0],[7,0],[8,0]],"currMax":4370,"histLineQuars":[[1,"Q2"],[2,"Q3"],[3,"Q4"],[4,"Q1<br>2015"],[5,"Q2"],[6,"Q3"],[7,"Q4"],[8,"Q1<br>2016"]],"fundHisMaxVal":198,"currInsiderData":[3,143,"#ff6900"],"currFundVal":2202.85,"quarters":[[1,"Q2"],[2,""],[3,""],[4,"Q1<br>2015"],[5,""],[6,""],[7,""],[8,"Q1<br>2016"]],"insiderTotalHistVal":3.54,"currInstVal":4370.46,"currInsiderVal":143.51,"use10YearData":"false","instTotalHistVal":263.74,"maxValue":369};
So the regex pattern created based on that it should find the snippet ,"currInsiderVal":<some text>, where <some text> is our target value.
Had a look on the site and the element you are trying to retrieve has a typo in it; instead of currentInsiderVal try using currrentInsiderVal and you should retrieve the data correctly.
Probably worth considering some error trapping to catch stuff like this for any other fields you retrieve?
After your comment I took a closer look. Your issue seemed like it was trying to trap the id of the individual cell rather than navigating down the object tree. I've modified the code to retrieve the row of the table you are after and then set myValue to be the correct cell within that row. Seemed to be working when I tried it out. Give this a shot?
Sub test()
Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")
With appIE
.Navigate "http://investors.morningstar.com/ownership/shareholders-overview.html?t=TWTR&region=usa&culture=en-US"
.Visible = True
End With
While appIE.Busy
DoEvents
Wend
Set allRowOfData = appIE.Document.getelementbyID("tableTest").getElementsByTagName("tbody")(0).getElementsByTagName("tr")(5)
myValue = allRowOfData.Cells(2).innerHTML
appIE.Quit
Set appIE = Nothing
Range("A30").Value = myValue
End Sub

How to make two columns from one list

I have one list and I want to make two columns from him, something like this:
I have this:
====== Known Errors ======
1.
2.
3.
.....
47.
and I want this
====== Known Errors ======
1. 28.
2. 29.
3. 30.
.... ....
27. 47.
and my code is this :
====== Known Errors ======
- [[testlabplus/known_errors/table_not_accessible|Control table not acessible]]
- [[testlabplus/known_errors/calendar_view|Calendar view used by multiple users]]
- [[testlabplus/known_errors/Unknown_Publisher|Unknown Publisher]]
- [[testlabplus/known_errors/error_during_update|Error during the update of TLP to a new version/SP]]
- [[testlabplus/known_errors/calendar_view/doc_new_version|Create new version of a document]]
- [[testlabplus/known_errors/export_ms_proj|Export to MS Project]]
- [[testlabplus/known_errors/save_filter_in_resource|Save filter in Resource planning]]
- [[testlabplus/known_errors/new_order|Create new order]]
- [[testlabplus/known_errors/open_test_report|Open test report]]
- [[testlabplus/known_errors/app_startup|Application startup]]
- [[testlabplus/known_errors/app_startup_tlp|Application 'TLP.exe' startup ]]
- [[testlabplus/known_errors/proj_code_on_order|Project code on an order]]
FIXME
Wiki documentation offers use directive columns_list.
In your case:
====== Known Errors ======
{{columns_list|2|
- [[testlabplus/known_errors/table_not_accessible|Control table not acessible]]
- [[testlabplus/known_errors/calendar_view|Calendar view used by multiple users]]
- [[testlabplus/known_errors/Unknown_Publisher|Unknown Publisher]]
- [[testlabplus/known_errors/error_during_update|Error during the update of TLP to a new version/SP]]
- [[testlabplus/known_errors/calendar_view/doc_new_version|Create new version of a document]]
- [[testlabplus/known_errors/export_ms_proj|Export to MS Project]]
- [[testlabplus/known_errors/save_filter_in_resource|Save filter in Resource planning]]
- [[testlabplus/known_errors/new_order|Create new order]]
- [[testlabplus/known_errors/open_test_report|Open test report]]
- [[testlabplus/known_errors/app_startup|Application startup]]
- [[testlabplus/known_errors/app_startup_tlp|Application 'TLP.exe' startup ]]
- [[testlabplus/known_errors/proj_code_on_order|Project code on an order]]
}}
For external links:
{{columns_list|2|
- [//testlabplus/known_errors/table_not_accessible Control table not acessible]
- [//testlabplus/known_errors/calendar_view Calendar view used by multiple users]
- [//testlabplus/known_errors/Unknown_Publisher Unknown Publisher]
- [//testlabplus/known_errors/error_during_update Error during the update of TLP to a new version/SP]
- [//testlabplus/known_errors/calendar_view/doc_new_version Create new version of a document]
- [//testlabplus/known_errors/export_ms_proj Export to MS Project]
- [//testlabplus/known_errors/save_filter_in_resource Save filter in Resource planning]
- [//testlabplus/known_errors/new_order Create new order]
- [//testlabplus/known_errors/open_test_report Open test report]
- [//testlabplus/known_errors/app_startup Application startup]
- [//testlabplus/known_errors/app_startup_tlp Application 'TLP.exe' startup ]
- [//testlabplus/known_errors/proj_code_on_order Project code on an order]
}}

Start workflow with web services Sharepoint 2010

I am attempting to run a visual studio sequential workflow on items in a library, but have hit a wall. since the client object model doesn't seem to support starting workflows, I am attempting to use the web service call to "../_vti_bin/workflow.asmx" web service.
Everything seems ok up to the point where it calls
StartWorkflow(item, templateid, workflowParameters)
I get an error saying parameters can't be null. My workflow has no init form, so im not sure what params to pass. can someone help me out here?
here is my code:
Private Sub LoadDataFromSite()
Try
Dim frm As New DateForm
frm.ShowDialog()
fromDate = frm.DateTimePicker1.Value.Date
toDate = frm.DateTimePicker2.Value.Date
Dim siteUrl As String = "http://host.dom.local/payroll/"
Dim clientContext As New ClientOM.ClientContext(siteUrl)
Dim oList As ClientOM.List = clientContext.Web.Lists.GetByTitle("Timesheets")
Dim oListItem As ListItem
Dim camlQuery As New ClientOM.CamlQuery()
camlQuery.ViewXml = "<View/>"
Dim collListItem As ClientOM.ListItemCollection = oList.GetItems(camlQuery)
clientContext.Load(collListItem)
clientContext.ExecuteQuery()
For Each oListItem In collListItem
Console.WriteLine("ID: {0} " & vbCrLf & "Title: {1} " & vbCrLf & "", oListItem.Id, oListItem("Title"))
If CDate(oListItem("Timesheet_x0020_Date")).Date >= fromDate And _
CDate(oListItem("Timesheet_x0020_Date")).Date <= toDate Then
MsgBox("found a timesheet in the specified date range = " & oListItem("Timesheet_x0020_Date"))
Dim sguid As String = "{2009B982-3A49-4217-99AC-7E52C0EE44EF}"
Dim workflowTemplateGuid As New Guid(sguid)
Dim _itemURI As String = "http://host.dom.local/payroll/" & oListItem("Title")
Dim workflow As WSWorkflow.Workflow = New WSWorkflow.Workflow
workflow.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
workflow.StartWorkflow(_itemURI, workflowTemplateGuid, Nothing)
End If
Next oListItem
Catch exs As Microsoft.SharePoint.Client.ServerException
MsgBox("Error starting export workflow on list items. It may not be finished yet, and you may need to export the timesheets manually." & exs.Message)
Catch exss As Microsoft.SharePoint.Client.ClientRequestException
MsgBox("Error starting export workflow on list items. It may not be finished yet, and you may need to export the timesheets manually." & exss.Message)
Catch ext As Microsoft.SharePoint.SoapServer.SoapServerException
MsgBox("Error starting export workflow on list items. Soap exception. " & ext.Message)
End Try
End Sub
so I can't pass NOTHING to the function call, so what do here?
There are two problems with your code.
1) Item URI/URL - its should be ows_EncodedAbsUrl of Item, you can get it from Lists.asmx
2) association data - can not be null.
you can find detailed explanation at.
http://sharepointbuzzer.com/2013/10/15/start-workflow-using-client-object-model/
I hope it solves your error.