Access properties of Flat File Destination in SSIS via Script - scripting

I have a Data Flow task that has a Flat File Destination in it. The 'Overwrite' property is set to False by default. I have a project parameter (boolean) that I need to check and if it is true then I need to set the Flat File Destination Overwrite property to true.
I have a script that checks my parameter but I can not find the "path" to take to get to the variable I need to change:
public void Main()
{
if (Convert.ToBoolean(Dts.Variables["$Package::IsMonthly"].Value)==true)
{SET OVERWRITE PROPERTY TO TRUE}
Dts.TaskResult = (int)ScriptResults.Success;
}
Can someone help me with the correct variable/path for this?
Thanks,
Leslie

You should use an expression on the Flat File Destination that checks whether the parameter is true/false and use that to overwrite the default value of that property

Related

eWAM Allow Multiple Sessions

The value of highlighted constant is “/MULTISESSION:”
I want to know from where this value is fetched for this parameter. Is there any specific config file I have to refer?
function AllowMultipleSessions return Boolean
var curParam : CString
curParam = WF.GetParam(kw_MultipleSessions)
if curParam <> ''
_Result = curParam = 'TRUE'
endIf
endFunc
The value for the parameter "/MULTISESSION" is set in the config file “MLRC.cfg” which is located at “[..]\Admin\RunningContext\MLRC.cfg”.
"/MULTISESSION" is a command line parameter whose value can be supplied by a config file. The path of this config file is defined in the "Cmd line:" field of the running context(in Running Context catalog under "Run" tab).
This (/MULTISESSION) process var needs to be set on the process's execution context:
eWEDRpc process (Param.ini file, referenced from WnetConf.ini file of the application server/WSM).
Process variable inside wNetConf.ini itself, under correct GSP process node.

How copy selected property (not all) from camel to activiti

Camel scenario:
read file
do something e.g store content in database
run activiti process and pass variable from previous step
RouteBuilder:
from("file:/home/work/Inbox")
.to("bean:sourceFileService?method=storeFile")
.to("activiti:Receive?copyVariablesFromProperties=true")
During call bean sourceFileService property 'sourceFileId' is set.
This variable should be transferred to the process Receive as variable.
If I don't use copyVariablesFromProperties any variable is not set in process.
One the other side when copyVariablesFromProperties=true then camel try pass all properties and exception occurs:
ActivitiException: couldn't find a variable type that is able to serialize GenericFile
(because one of property is object represents read file, there are 7 other unwanted property )
How pass only selected property to activiti endpoint or in camel any next 'to' ?
change sourceFileService's storeFile method signature as follows;
public String storeFile(... your other params, #OutHeaders Map headers) {
...
headers.put("sourceFileId", "32132132");
....
}
and you can access the set sourceFileId in your activiti endpoint
I have found that the use of copyVariablesFromProperties is not necessary.
The same is achieved by
.setBody().properties()
.to("activiti:Receive")
When in body is Map camel set variables for activiti process using that map.
But I still get exception for the same reason (pass unwanted, not serializable object).
The only solution I have found is
from("file:/home/work/Inbox")
.to("bean:sourceFileService?method=storeFile")
.setBody(method(Helper.class))
.to("activiti:Receive")
where
public class Helper {
#Handler
public Map getProcessVariables(Exchange exchange) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("sourceFileId, exchange.getProperty("sourceFileId"));
return variables;
}
}

SSIS ScriptTask change Value property of Variable

I try to simply change value of SSIS variable doing this code in ScriptTask:
string path = Dts.Connections["BazyPobrane"].ConnectionString.ToString();
string[] nameZIParray = Directory.GetFiles(path, "*.ZIP");
string[] nameRARarray = Directory.GetFiles(path, "*.RAR");
foreach (string nameZIP in nameZIParray) //search new ZIP
{
if (File.GetCreationTime(nameZIP) > DateTime.Now.AddDays(-1))
{
Dts.Variables["User::NazwaPliku"].Value = Path.GetFileName(nameZIP);
}
}
foreach (string nameRAR in nameRARarray) //search new RAR
{
if (File.GetCreationTime(nameRAR) > DateTime.Now.AddDays(-1))
{
Dts.Variables["User::NazwaPliku"].Value = Path.GetFileName(nameRAR);
}
}
Dts.TaskResult = (int)ScriptResults.Success;
After executing ScriptTask it simply don't change the variable Value. Debug mode seems fine. Maybe i miss some component settings?
Thx!
Some things to check:
Are you sure the variable isn't changing? If you put a subsequent script task with a MessageBox in place, does it show the correct value?
I don't think you need the variable type, i.e. remove "user::"
Make sure the variable is in the ReadWriteVariables property, as suggested by #OcasoP
What's the scope of the variable? Make sure you don't have two copies at different scopes, or that at least the one you do have is visible from the scope of the script
You could try locking the variable before writing to it (which should be equivalent to (3) above)
Code example for the last point:
IDTSVariables100 variables = null;
this.VariableDispenser.LockOneForWrite("NazwaPliku",ref variables);
variables[0].Value = myValue;
variables.Unlock();
debug your script task adding MsgBox(variable_name) and see its value through the execution.
Best debugging option :)

How to get the name of a temporary file created by File.tmpfile in D2?

I need to generate a temporary file, fill it with some data and feed it to an external program. Based on description of D available here I'm using File.tmpfile() method:
auto f = File.tmpfile();
writeln(f.name());
which doesn't provide a way to get the generated file name. It's documented that name might be empty. In Python I would do that like this:
(o_fd, o_filename) = tempfile.mkstemp('.my.own.suffix')
Is there a simple, safe and cross-platform way to do that in D2?
Due to how tmpfile() works, if you need the name of the file you can't use it. However, I have already created a module to work with temporary files. It uses conditional compilation to decide on the method of finding the temporary directory. On windows, it uses the %TMP% environment variable. On Posix, it uses /tmp/.
This code is licensed under the WTFPL, so you can do whatever you want with it.
module TemporaryFiles;
import std.conv,
std.random,
std.stdio;
version(Windows) {
import std.process;
}
private static Random rand;
/// Returns a file with the specified filename and permissions
public File getTempFile(string filename, string permissions) {
string path;
version(Windows) {
path = getenv("TMP") ~ '\\';
} else version(Posix) {
path = "/tmp/";
// path = "/var/tmp/"; // Uncomment to survive reboots
}
return File(path~filename, permissions);
}
/// Returns a file opened for writing, which the specified filename
public File getTempFile(string filename) {
return getTempFile(filename, "w");
}
/// Returns a file opened for writing, with a randomly generated filename
public File getTempFile() {
string filename = to!string(uniform(1L, 1000000000L, rand)) ~ ".tmp";
return getTempFile(filename, "w");
}
To use this, simply call getTempFile() with whatever arguments you want. Defaults to write permission.
As a note, the "randomly generated filenames" aren't truely random, as the seed is set at compile time.

dynamic file path in log4php

I am new to log4php.
I would like to save the log files in the format /logs/UserId/Info_ddmmyyyy.php
where the UserId is dynamic data.
(I would basically like to save one log per user.)
Is there any way to change the log file path dynamically?
This behaviour is not supported by default. But you can extend LoggerAppenderFile (or RollingFile, DailyFile whatever your preference is) to support it.
Create your own class for that and make it load to your script.
Then extend from this class:
http://svn.apache.org/repos/asf/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
class MyAppender extends LoggerAppenderFile { ... }
You'll need to overwrite the setFile() method, similar to:
public function setFile($file) {
$path = getYourFullPath();
$this->file = $path.$file;
}
After all you need to use your new Appender in you config
log4php.appender.myAppender = MyAppender
log4php.appender.myAppender.layout = LoggerLayoutSimple
log4php.appender.myAppender.file = my.log
Please note, instead of giving your full path to the log file you now need to add a plain name. The full path (including username) must be calculated with your getYourFullPath() method.
Hope that helps!
Christian