Open anthonyma24 opened 4 years ago
Did you start a new project with VisualStudio or with Eclipse Script Wizard. Please try the latter. The Wizard will connect the right standard dependencies. For additional dependencies (using ...) you have to reference them manually.
Hello @anthonyma24, are you trying to run the script from another computer that is not the eclipse installed computer? Citrix in example. If yes, than the executable must be launched from the local disk of the computer that has eclipse installed. if this is your case this piece of code can help you.
namespace VMS.TPS // Do not Change
{
public class Script // Do not Change
{
public void Execute(ScriptContext context) // Do not Change
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = @"Client\Shared$\folder";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var filePath = openFileDialog1;
try
{
var tmpPath = Path.GetTempPath();
var randomfolder = Path.GetRandomFileName().Split('.')[0];
var extension = Path.GetExtension(filePath.FileName);
var dest = Path.Combine(tmpPath,randomfolder);
//MessageBox.Show(dest);
var fileonTmp = Path.Combine(dest, filePath.SafeFileName, filePath.DefaultExt) ;
//MessageBox.Show(fileonTmp);
try
{
Copy(Path.GetDirectoryName(filePath.FileName), dest);
System.Diagnostics.Process.Start(fileonTmp);
}
catch (Exception)
{
throw new Exception("Did not work") ;
}
}
catch (SecurityException ex)
{
MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
$"Details:\n\n{ex.StackTrace}");
}
}
}
public static void Copy(string sourceDirectory, string targetDirectory)
{
var diSource = new DirectoryInfo(sourceDirectory);
var diTarget = new DirectoryInfo(targetDirectory);
CopyAll(diSource, diTarget);
}
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
Directory.CreateDirectory(target.FullName);
// Copy each file into the new directory.
foreach (FileInfo fi in source.GetFiles())
{
Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
}
// Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir =
target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
}
}
Did you start a new project with VisualStudio or with Eclipse Script Wizard. Please try the latter. The Wizard will connect the right standard dependencies. For additional dependencies (using ...) you have to reference them manually.
Thanks Kiragroh, the example I ran was a stand along program from wizard which was working. The program I tried to create myself is based on a VS template. For learning purpose, I copied the cs code from the example, and added all the references. I was hoping it should work too if the two programs have same source code and references. I attached the screen shot of the solution panel for both programs. The first one is the example, and the second one is my test program.
Hello @anthonyma24, are you trying to run the script from another computer that is not the eclipse installed computer? Citrix in example. If yes, than the executable must be launched from the local disk of the computer that has eclipse installed.
Thanks joecastelo. I was running on a tool box. Actually I have the example and my own programs saved under the same folder. However, the example is working without any issue, but the program I created kept getting the error I mentioned. I tested both programs in VS.
Please try the following:
Please try the following:
- use x64 for compiling
- check your vms.tps-dependencies (should be on your C-drive)
- try to use your test project without vms.tps-dependencies and a simple "hello world" code
- google what die badimage-error could mean
Thanks Kiragroh! I think I have found the issue. I should have selected x64 for compiling instead of any cpu. It seems like the vms.tps-dependencies require this setting.
I was testing the example stand along project of loading patient on a tool box, and it's been working fine. However, when I tried to start building from scratch with a vs console template, I ran into an issue whenever I launched the program. I even copied the same cs file and references from the example directly into the project and I still got the same error. Has anyone experience this before? Thanks!
"An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'VMS.TPS.Common.Model.API, Version=1.0.200.43, Culture=neutral, PublicKeyToken=305b81e210ec4b89' or one of its dependencies. An attempt was made to load a program with an incorrect format."
Here I attached the example code:
using System; using System.Linq; using System.Text; using System.Collections.Generic; using VMS.TPS.Common.Model.API; using VMS.TPS.Common.Model.Types;
namespace Example_Patients { class Program { [STAThread] // Do not remove this attribute, otherwise the script will not work static void Main(string[] args) { try { Console.WriteLine("Logging in..."); using (Application app = Application.CreateApplication()) { Console.WriteLine("Running script..."); Execute(app); } } catch (Exception exception) { Console.WriteLine("Exception was thrown:" + exception.Message); }
}