Lua strings won't concatenate - winapi

I am trying to concatenate a variable to make my output "prettier", however it seems to output as an empty string when concatenated with other string values.
The output code excerpt looks like this:
local name = ""
local SendMessage = alien.User32.SendMessageA
SendMessage:types{ret = "int", abi = "stdcall", "pointer", "int", "int", "string"}
SendMessage(handle, LB_GETTEXT, index, name)
print(type(name)) --To verify that it is a string type
print(name) --Prints the name "Sample 1" perfectly fine
print("Title: " .. name .. "\n") --Doesn't print the name variable "Sample 1"
Output:
The name variable is set via Alien for Lua call to the WINAPI SendMessage function from User32.dll. I think this might be part of the issue, however as you can see above, the variable is set to type (Lua) "string" and prints fine when called by itself. However whenever you concatenate it with anything, it acts like the empty string (or something similar).
EDIT: I have also tried tostring(name) and alien.tostring(name). Neither of which fix the issue.

After a lot of trial and error as well as reading the Lua Alien documentation, I discovered that using an Alien Buffer solves the issue of converting between the hybrid C-Lua string and a native Lua string:
local name = alien.buffer()
print("Title: " .. name:tostring() .. "\n")
You can then use the tostring() method on the variable at any time to get the native Lua string.
NOTE: The buffer variable will be of type userdata. If you try to print it out by itself, it will show its contents, but if you try to concatenate it like a string (without the :tostring()) Lua will throw an error because you cannot concatenate a string with userdata.

Related

Escaping underscore in SSIS

I have an SSIS expression.as per below:
I am sending the results of this package as an sms,however the sms does not show the underscores,I have therefore opted to using dashes for now.
The sms is showing at as OLEGALINITTEST
I there a way i can escape the underscore so that it shows on the sms?
REPLACE(#[System::PackageName], "_", "-") = O-LEGAL-INIT-TEST
Desired output is O_LEGAL_INIT_TEST
I am replacing the underscore's in the string with "-" dashes .I am sending the variable to an Oracle package that send the actual sms.
#[System::PackageName] is generally the same as the file name without the file extension so given a package named This-Is-Fun.dtsx we would expect to see the PackageName property as This-Is-Fun.
But, there are cases where this not the case. If we named our package A=B.C_D.dtsx, the resulting object name for our package is A B C_D. Each offending character is replaced with spaces.
If you attempt to name an SSIS object with "something weird" it will throw an error on the operation like
The name cannot contain any of the following characters: / \ : [ ] . =
The restrictions are similar, but different, for the package name itself as Windows/Visual Studio will balk with
contain any of the following characters: / ? : & \ * " < > | # %
contain Unicode control characters contain invalid surrogate
characters be system reserved names, including 'CON', 'AUX', 'PRN', 'COM1'
or 'LPT2' be '.' or '..'
As always with expressions in SSIS, check what you're building. Create an SSIS Variable where you specify an expression.
Assuming you create an SSIS variable called SMS_CONTENT data type of string and then I'm going to replace spaces with underscores. The expression is
REPLACE(#[System::PackageName], " ", "_")
Given a starting package name of
a=b.SO_61618859_This_Is_Fun.dtsx
System::PackageName becomes a b SO_61618859_This_Is_Fun
SMS_CONTENT becomes a_b_SO_61618859_This_Is_Fun
If it works fine during development but goes awry in production, log the value via a script task's information event so you can review logs after the run. https://billfellows.blogspot.com/2016/04/biml-script-task-test-for-echo.html You don't need to Biml it, just mark the variable as part of the Read only variable collection and the following script will record the values in the log. In your case, I'd add System::PackageName and then my SSIS variable, User::SMS_CONTENT
bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}

Validation fails when passing a file path as Input Argument to Orchestrator API StartJobs

I am trying to use file name path (Ex: C:\Document\Report.txt) as a parameter through uipath orchastrator api. I tried different approach and In each approach I am getting Bad request error "{"message":"Argument Values validation failed.","errorCode":2003,"resourceIds":null}"
Below is my Example code
FileListUploaded ="C\\Documents\\report.txt";
string parameter1 = "{\"startInfo\": {\"ReleaseKey\": \"xxxxx-xxx-xxx-xxx-xxxxxx\"," +
"\"RobotIds\": [xxxxx]," +
"\"JobsCount\": 0," +
"\"InputArguments\": \"{ "+
"\\\"reports_or_other_files\\\": \\\" + FileListUploaded + \\\"}\"}}";
request_startRobot.AddParameter("application/json; charset=utf-16", parameter, ParameterType.RequestBody);
IRestResponse response_startRobot = client_startRobot.Execute(request_startRobot);
That's a bit messy to look at, but it appears you are not quoting and escaping your JSON correctly.
I might suggest building an array and serializing it into JSON to make it easier to read, or using a HEREDOC or string formatting. If you do continue to concatenate your JSON body string together, dump out the results to see how it is coming together.
The final results of the JSON should look something like
{
"startInfo": {
"ReleaseKey":"{{uipath_releaseKey}}",
"Strategy":"JobsCount",
"JobsCount":1,
"InputArguments":"{\"reports_or_other_files\":\"C:\\\\Documents\\\\report.txt\"}"
}
}
With the InputArguments:
Looks like you are missing some quotes
Might need to double escape your backslashes in the FileListUploaded variable
Missing a colon after the C in the path

Ruby String to access an object attribute

I have a text file (objects.txt) which contains Objects and its attributes.
The content of the file is something like:
Object.attribute = "data"
On a different file, I am Loading the objects.txt file and if I type:
puts object.attribute it prints out data
The issue comes when I am trying to access the object and/or the attribute with a string. What I am doing is:
var = "object" + "." + "access"
puts var
It prints out object.access and not the content of it "data".
I have already tried with instance_variable_get and it works, but I have to modify the object.txt and append an # at the beginning to make it an instance variable, but I cannot do this, because I am not the owner of the object.txt file.
As a workaround I can parse the object.txt file and get the data that I need but I don't want to do this, as I want take advantage of what is already there.
Any suggestions?
Yes, puts is correctly spitting out "object.access" because you are creating that string exactly.
In order to evaluate a string as if it were ruby code, you need to use eval()
eg:
var = "object" + "." + "access"
puts eval(var)
=> "data"
Be aware that doing this is quite dangerous if you are evaluating anything that potentially comes from another user.

Use embedded string as variable name

I have a YAML file that uses the encoding __firstname__ as a placeholder which signifies that an existing method firstname should be used, rather than the literal string in a subsequent process.
I am trying to understand the most ruby way to to do this. Basically, I need to extract the part between the underscores and send it to an object. Here is pseudocode:
variable = '__firstname__'
if variable is prefixed and suffixed with underscores
result = object.send(variable.removeunderscores)
else
result = variable
end
puts result
I was about to write this procedurally like this, but this is the type of thing that I think ruby can less clunkily if only I knew the language better.
What is a clean why to write this?
There's nothing wrong with verbose code if it's clear to read IMO.
I'd do something like this using String#start_with? and String#end_with?:
variable = '__firstname__'
if variable.start_with?("__") && variable.end_with?("__")
result = object.send(variable[2...-2])
else
result = variable
end

Is Nothing comparison gives type mismatch

I am trying to check if the 'Listivew.Tag property is nothing'.
I used to do the 'Is Nothing' check universally for all scenarios as first check to avoid errors
Can someone explain how to do it in VB 6?
If Not .lvwLocation.Tag Is Nothing Then
'COMPANY
str = str & IIf(Len(.lvwLocation.Tag) > 0, " and u.location_id in " & .lvwLocation.Tag, "")
End If
Gives error 'type-mismatch'
Nothing is a valid value for Object variables, and Is is the way to compare object pointers.
But a VB6 control's Tag property is a String, and VB6's String type is not an Object; it's a primitive type. That means a String variable can't be assigned Nothing -- its emptiest possible value is the empty string. (And an Object variable can't be assigned a String value.) For strings just use the same equality/inequality/comparision operators that you use for other primitive (numeric/boolean/date) types:
If .lvwLocation.Tag <> "" Then ...
In VB6 it appears that using Is Nothing to compare Objects works, Every other data type that I tried did not. In .Net Nothing represents the default value of any data type and will work like you expect.
Dim test as Object
If Not test Is Nothing Then
/////
End If
Since it appears the data type of th Tag property in VB6 is a string. I would use something like:
If .lvwLocation.Tag <> "" Then
/////
End If

Resources