Script inside a loop. error during 2nd execution - variables

I have an ssis package that runs a script task inside a loop.
public void Main()
{
int intCount;
intCount = (int)Dts.Variables["User::Count"].Value;
//some logic
Dts.TaskResult = (int)ScriptResults.Success;
}
During the first iteration code works fine. during subsequent execution I get the below error if I try lookup the value of any variable in immediate window or quick watch
Dts.Variables["User::Count"].Value error CS1704: An assembly with the
same simple name 'ST_850053c10abd463da6fd571ece4d8f95' has already
been imported. Try removing one of the references (e.g.
'ST_850053c10abd463da6fd571ece4d8f95.dll') or sign them to enable
side-by-side.

Related

linqpad In parent script Util.complile and run async sub-scrip hangs on execution

I'm trying to call a linqpad script from another linqpad script but it tends to just hand. The subscript is an async process so im not sure what im doing wrong. I dont get any Dumps out either so Im not sure what is going on. I do know the subscript does work as it runs fine by it self.
void Main()
{
var testPass = new TestObject();
var compiledQuery = Util.Compile(#".\TestSubScript.linq", false);
var retVal = compiledQuery.Run(QueryResultFormat.Html, testPass);
retVal.AsString();
}
And the subscript looks like the following
async Task Main(TestObject input)
{
"In sub script".Dump();
// bunch of asnyc calls
}
I had a Util.ReadLine(). I had forgotten about a Util.ReadLine() I was using to ask for details to run the query against. Once I passed in the correct data object to use the code I had set to bypass this Util.ReadLine() the script worked as intended.

How to know which line of code was being executed when a signal is received

I'm trying to do something like this
$SIG{ALRM} = sub {
print $line_number_when_alarm_went_off;
};
alarm 10;
# rest of the script
I'm using ALRM as an example, I will end up using a different signal to kill from the outside to trigger it. Is there a neat way of doing this sort of operation?
I have some slow scripts and sometimes I would like to send them a signal to know where the code is at that moment.
I want to make this as unobtrusive as possible so I could package it and add it to legacy code.
You can use caller in list context to get the package, file and line number of the place that the current sub got called from.
$SIG{ALRM} = sub {
my ($pkg, $file, $line) = caller;
CORE::say $line;
die;
};
alarm 2;
while (1) {
1;
}
This will output 11 (if I counted correctly, in my file it's 1740, and the $SIG line is 1730.
It also works with other signal handlers, like warn.
$SIG{__WARN__} = sub {
my ($pkg, $file, $line) = caller;
CORE::say $line;
};
warn 'foo';
This will output 7
Note that your code has a syntax error. You are assigning a hash reference as a signal handler, not a sub reference!

Primefaces p:fileUpload - do something on beginning and end of upload (multiple files)

Primefaces 4.0 has nice component to upload files, including multiple files at once. By some dark miracle, it actually works.
Code:
<p:fileUpload fileUploadListener="#{someBean.handleSingleFileUpload}"
mode="advanced" multiple="true" auto="true" dragDropSupport="true"
update=":form_info" sizeLimit="100000" allowTypes="/(\.|\/)(xml)$/" />
Problem is that listener someBean.handleSingleFileUpload is called once for each file. I dealt with that nicely, but I cannot see any way to execute some code at beginning and on end of entire upload process. IMO rather large oversight.
For example:
at beginning clear info textarea
now multiple files are uploaded simultaneously...
at end reload something based on data that was just uploaded
Of course, things at beginning and end should be executed only once, regardless of amount of files. Is there any way to do that? In primefaces docs for p:fileUpload there are no other attribute calling bean method than fileUploadListener.
Well, I ended up simply using counter. Obvious in hindsight, eh. Example:
private int eventCounter = 0;
public void handleSingleFileUpload(FileUploadEvent event)
{
beginImport();
try
{
// code to import file, for example parse xml
} catch (Exception ex)
{
ex.printStackTrace(); /// or whatever
} // block catch Exception
finally
{
finishImport();
} // block finally
}
private synchronized void beginImport()
{
if (eventCounter == 0)
{
// insert code to execute before first file is started
} // block if just started
eventCounter++;
}
private synchronized void finishImport()
{
eventCounter--;
if (eventCounter < 0) eventCounter = 0; // Just in case...
if (eventCounter > 0) return; // not really finished yet
// insert code to execute when last file is done
}
It is hackish solution and I fear that in some cases it could call begin-n-finish pair twice (it should not do begin or finish code twice in row) and that could theoretically interfere with ongoing import of n-th file.
It works for me, at least for now. Will see how it holds when xml will have thousands or more of entries instead of dozen. I would prefer something like onStartOfEverything and onEndOfEverything as arguments in p:fileUpload tag, but ah well.

How do i stop SSIS Script component to process data

i am processing a ragged semicolon delimited file using script component as transformation.
The component is able to process the data and load to oledb destination. But when error is found it should stop processing further. As i am using try catch block the component doesn't fail and continue to process till the end.
Is there any way i could stop the processing further without failing the component/package?
Let me know if any other information/details required?
sample code:
str.split(";");
if(column[0] == "H")
{
col1=Column[3];
}
if(column[0] != "T")
{
try
{
Row.col1=Column[0];
Row.col2=Column[1];
.....
}
catch
{
update the variable to check if we have error in file.
}
}
Thank you for your time.
The general idea will be that you want to use try/catch blocks to ensure the data processing itself doesn't abort. Once you know your script isn't reporting a failure back to the engine, it's a simple process to not call the AddRow()
Pseudocode
foreach(line in fileReader)
{
try
{
// perform dangerous operations here
// Only add row if you have been able to parse current line
Output0Buffer.AddRow();
Output0Buffer.Col1 = parsedContent;
}
catch
{
// Signal that we should break out of the loop
// do not propagate the error
// You might want to do something though so you know you
// have an incomplete load
break;
}
}
If you are looking to just skip the current bad line, you can substitute continue for the break above.
C# loop - break vs. continue
I didn't get any help from anywhere, But as a work around i have placed a return statement in the code. It checks the error variable if it's true then i will return without processing further. But the thing still is it processes the whole file :(. But it works!!!

Automatically close PhantomJs after running script

I want to run PhantomJs scripts from my program, but since the scripts may not be written by me, I need to make sure PhantomJs exits after the execution are either completed or fails for any reason (e.g., invalid syntax, timeout, etc). So far, All I've read says you must always include the instruction phantom.exit() for PhantomJs to exit. Is there any way to automatically close PhantomJs after it executes a given script?
Thanks.
Create a file run-javascript.js:
var system = require('system');
try {
for (var i=1; i<system.args.length; i++) {
var scriptFileName = system.args[i];
console.log("Running " + scriptFileName + " ...");
require(scriptFileName);
}
}
catch(error) {
console.log(error);
console.log(error.stack);
}
finally {
phantom.exit();
}
Then to run your file myscript.js:
phantomjs run-javascript.js ./myscript.js
You have to include an explicit path for the myscript.js, i.e. ./myscript.js, otherwise phantomjs will look for the script as a module.
There are three execution scenarios that are handled here:
Successful execution, in which case phantom.exit() is called in the finally clause.
Error in the script being run, in which case the require function prints a stacktrace and returns (without throwing any error to the calling code).
Error running the script (e.g. it doesn't exist), in which case the catch clause prints out the stacktrace and phantom.exit() is called in the finally clause.