Mirth: How to get source file directory from file reader channel - mirth

I have a file reader channel picking up an xml document. By default, a file reader channel populates the 'originalFilename' in the channel map, which ony gives me the name of the file, not the full path. Is there any way to get the full path, withouth having to hard code something?

You can get any of the Source reader properties like this:
var sourceFolder = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getSourceConnector().getProperties().getProperty('host');
I put it up in the Mirth forums with a list of the other properties you can access
http://www.mirthcorp.com/community/forums/showthread.php?t=2210

You could put the directory in a channel deploy script:
globalChannelMap.put("pickupDirectory", "/Mirth/inbox");
then use that map in both your source connector:
${pickupDirectory}
and in another channel script:
function getFileLastModified(fileName) {
var directory = globalChannelMap.get("pickupDirectory").toString();
var fullPath = directory + "/" + fileName;
var file = Packages.java.io.File(fullPath);
var formatter = new Packages.java.text.SimpleDateFormat("yyyyMMddhhmmss");
formatter.setTimeZone(Packages.java.util.TimeZone.getTimeZone("UTC"));
return formatter.format(file.lastModified());
};

Unfortunately, there is no variable or method for retrieving the file's full path. Of course, you probably already know the path, since you would have had to provide it in the Directory field. I experimented with using the preprocessor to store the path in a channel variable, but the Directory field is unable to reference variables. Thus, you're stuck having to hard code the full path everywhere you need it.

Related

Iterating and reading text files from folder on Android

I made a word game app for android in Unity, where the player has to find a word from a category previously loaded to the game.
The way I load the categories is:
There is a folder named Categories, inside Assets, I run through the folder and read each text file as a category.
The categories are stored in a dictionary where the key is name the of the file and the value is every line of the file as an array element.
It worked well on the PC however no luck on android. Tried changing the path to
"public string categoriesDirectoryPath = Application.persistentDataPath +"Categories";" still does not work.
Original path was "Assets/Categories"
Code for initiating the dictionary with the file values is (Happens on GameManager's Awake()):
private Dictionary<string, string[]> createCategories(string directoryPath)
{
Dictionary<string, string[]> categories = new Dictionary<string, string[]>();
string[] categoryPaths = Directory.GetFiles(directoryPath);
foreach (string path in categoryPaths)
{
if (!path.EndsWith("meta")) {
Debug.Log(path);
string categoryName = Path.GetFileNameWithoutExtension(path);
Debug.Log(categoryName);
string[] categoryData = File.ReadAllLines(path).ToArray();
categories.Add(categoryName, categoryData);
}
}
return categories;
}
Is there a way of iterating the folder and reading the text files that were in Assets/Categories after building the APK?
Is there a way of iterating the folder and reading the text files that
were in Assets/Categories after building the APK?
No.
If you want to access from the project, in a build, you have two options:
1.Put the file a folder named "Resources" then use the Resources to read the file and copy it to the Application.persistentDataPath path. By copying it to Application.persistentDataPath, you'll be able to modify it. Anything in the "Resources" is read only.
2.Put the file in the StreamingAssets folder then use UnityWebRequest, WWW or the System.IO.File API to read it. Atfer this, you can copy it to the Application.persistentDataPath.
Here is a post with code examples on how to do both of these.
3.AssetBundle(Recommended due to performance and loading reaons).
You can build the file as AssetBundle then put them in the StreamingAssets folder and use the AssetBundle API to read it.
Here is a complete example for building and reading AssetBundle data.

How to get the content of all files in a given directory?

Octokit allows me to easily retrieve the list of files in a given folder like so:
var directoryContent = await _githubClient.Repository.Content.GetAllContents("MyUsername", "MyProject", "TheFolderName").ConfigureAwait(false);
Unfortunately, the Content property for each file is null which means that I have to loop through the list of files and retrieve each one separately like so:
foreach (var file in directoryContent)
{
var fileWithContent = await _githubClient.Repository.Content.GetAllContents("MyUsername", "MyProject", file.Path).ConfigureAwait(false);
... do something with the content ...
}
Is there a more efficient way to get the content of all files in a given folder?
Just for reference: This is on purpose. If you read a whole directory and load all the content in one step it's huge load. So, the first call skips the content (Content property is null). The second step requests just this file and then the content is present.
Only thing I'm still missing is a method that can return just one result instead of a list if I pull a single file.

Read globalChannelMap from destination template

I have a source connection reading and constructing my output all in javascript in the channel source.
I need to pass this along to access it from the destination.
So I use
globalChannelMap.put('fullMessage', fullMessage);
Inside the destination in the template window for File Writer I have
${fullMessage}
But it writes exactly that to the file. I want everything inside that variable to be written to the file.
Try this. Use intermediate variables, like:
var data = ${fullMessage};
var fullMessage = DateUtil.convertDate('dd/MM/yyyy', 'yyyyMMdd', $('data'));
globalChannelMap.put('${fullMessage}',fullMessage);

Application.Capturescreenshot(fileName) save to specific path

i am using in my unity project this method that saves the camera viewport to the file system:
Application.Capturescreenshot(fileName)
it is work great but i want it to be saved under a specific path.
for example : Application.Capturescreenshot(c:/screenshots/filename);
how can i managed this?
thnaks!
You could use the absolute file path easily by passing it as a string. In your case, using this statement should work just fine:
Application.CaptureScreenshot("C:/screenshots/filename");
Note that it will give you an error if screeshots folder does not exist. Hence, if you are uncertain of that, you could modify the code accordingly:
// File path
string folderPath = "C:/screenshots/";
string fileName = "filename";
// Create the folder beforehand if not exists
if(!System.IO.Directory.Exists(folderPath))
System.IO.Directory.CreateDirectory(folderPath);
// Capture and store the screenshot
Application.CaptureScreenshot(folderPath + fileName);
Lastly, if you want to use a relative path instead of an absolute one, Unity provides dataPath and persistentDataPath variables to access the data folder path of the project. So, if you want to store the screenshots inside the data folder, you could change the folderPath above accordingly:
string folderPath = Application.dataPath + "/screenshots/";
var nameScreenshot = "Screenshot_" + DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss") + ".png";
ScreenCapture.CaptureScreenshot(nameScreenshot);
Try this !

Mirth: Send file like PDF, zip or Transfer pdf files using mirth

I want to transfer pdf/zip file through mirh.
I am using file reader connector as source and file writer as destination connector.
can any one help me how to send/transfer pdf/zip file?
Set Incoming data: Delimited text
File type: Binary
Outgoing filetype also has to be Binary, otherwise the data are corrupted.
Outgoing template has to be ${message.rawData}
see screen shot for more info.
Channel settings [summary]
Channel settings [Source]
Channel settings [Destination]
var source = "D:/ftproot/PDF/Source";
var fileName = $('fieldId')+".pdf";
var srcpath=source +"\\"+ fileName
var directory = "D:/ftproot/PDF/Target"
var outFileName = $('fieldId')+".pdf";
var destination = directory +"/" + outFileName
importPackage(java.io);
importPackage(org.apache.commons.io);
//var file = new java.io.File(directory);
var inputFile = new File(srcpath);
var outputFile = new File(destination);
FileUtils.copyFile(inputFile,outputFile);
For Transfer your PDF file from one location to another location .You don't need to bother about that.
Place the above code in your Destination trasfarmer .
The above code will pic the PDF file D:/ftproot/PDF/Source from this path and copied the PDF file in to the another mentioned location i.e D:/ftproot/PDF/Target
.You can directly read the file in Mirth using
importPackage(java.io);
importPackage(org.apache.commons.io);
Copy the PDF file using
FileUtils.copyFile(inputFile,outputFile);