Inconsistent results during debugging - Web API - c#

I have some code that uses a library for a product called Fusion Pro. Based on some config and data files it will generate a PDF file. I have been getting consistent result of a complete lack of output without any thrown exceptions. However when debugging I have been able to get the PDF to generate by attaching the debugger to the code running in my local IIS and stepping through line by line. Nothing is consistent though. It seems to have a higher success rate if I use F11 instead of F10 and going "slow but steady" through each line. Unfortunately it doesn't always produce a PDF even with stepping through the code.
I have never experienced code behaving so inconstantly with the same inputs each time.
The only other relevant bits of information is this code is working in another asmx service without issue, it is running under a specific domain account (requires special security), and it is running in 32bit mode.
DLQueueClient client = new DLQueueClient();
DLQueueJob vdpQueueJob = new DLQueueJob();
string fileName = message.OutputFilePath;
var dataFilePath = CreateDataFile(fileName, message.DefFilePath, message.VariableDataContent, message.QTY);
var pdfFilePath = Path.Combine(new[] { message.OutputFilePath, dataFilePath.Replace(".txt", ".pdf") });
vdpQueueJob.Priority = priority;
vdpQueueJob.Queue = queueName;
string cmd = "\"" + Settings.FusionProExe + "\" \"" + dataFilePath + "\" \""
+ message.DiffFilePath + "\" \"" +
(isProof ? message.ProofConfigFilePath : message.PrintConfigFilePath) + "\" \""
+ pdfFilePath + "\"";
vdpQueueJob.CommandLine = cmd;
client.ConnectRemote(Settings.FusionProServer, Settings.FusionProUser, Settings.FusionProPassword, Settings.FusionProTimeout);
client.SubmitJob(vdpQueueJob, Settings.FusionProTimeout, true);
return pdfFilePath;

Related

WPF: unable to map network drive for all users

I'm trying to create a function for an application to automatically copy over specific files during the final stage of a job. The only issue here is that the copy location is a protected share drive and uses a separate login instead of being validated by the active directory so I've got to do a bit of a workaround to get File.Copy() working. My workaround has been to call the built in net.exe utility and passing a command line argument that points to the share drive to open up a connection to the drive then using File.Copy() to get the file where it needs to go then deleting the connection. The issue at hand is that this works great on my computer but when anyone else on the team runs the same program a "Logon failure: unknown user name or bad password" is thrown. I'm at a bit of loss as to why this would happen since the username and password are static and not being changed and everyone on the team has the same network permissions I do. Here is the WPF/C# code I'm using to do this:
try
{
string mrdfDropPath = #"dropPathHere";
string MRDFPath = #"storePath\test.xml";
string command = #"use " + mrdfDropPath + #" /user:CORP\Username Password";
Process.Start("net.exe", command);
File.Copy(MRDFPath, mrdfDropPath + "test.xml");
string command2 = #"use " + mrdfDropPath + #" /delete";
Process.Start("net.exe", command2);
StreamWriter writer = new StreamWriter(#"logPath\log.txt", true);
writer.WriteLine(mrdfDropPath + "test.xml" + "," + File.GetLastWriteTime(MRDFPath).ToString());
writer.Close();
}
catch (Exception e)
{
StreamWriter writer = new StreamWriter(#"logPath\log.txt", true);
writer.WriteLine(e.Message);
writer.Close();
}
Like I said this works as expected during debug and when I run the application, but for anyone else it is throwing the error.

How to run a exe on cmd with multiple parameters programmatically on C#

I need to execute a exe with parameters as shown above screen shot via C# code.
it looks like
C:\Users\singha33\Desktop\1111>TaskFileSigner.exe
TaskFile="C:\Users\singha33\Desktop\1111\ApplyingSecurity.eTask.xml"
ProcessFile="C:\Users\singha33\Desktop\1111\Firefox_Setup_Stub_46.0.1.exe"
GenKey="Y" Singner="Ak"
I tried
System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
proc.FileName = "C:\\Users\\singha33\\Desktop\\1111\\TaskFileSigner.exe";
string temp = "C:\\Users\\singha33\\Desktop\\1111\\ApplyingSecurity.eTask.xml";
string argument1 = "TaskFile=" + '"' + temp + '"';
string argument2 = "ProcessFile =" + '"' + "C:\\Users\\singha33\\Desktop\\1111\\Firefox_Setup_Stub_46.0.1.exe" + '"';
string argument3 = "GenKey =" + '"' + "Y" + '"';
string argument4 = "Signer =" + '"' + "Aksh" + '"';
proc.Arguments = String.Format("{0} {1} {2} {3}", argument1, argument2, argument3, argument4);
//proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(proc);
But it is not working. I am very new to this kind of work and has no clue how to proceed further. May be i am not passing the argument properly or anything else.
Any help would be great.
I have searched similar kind of question on stack and found some helpful topics but it did not work. I think the argument is not properly formatted as it should be, but I have no idea how to format it properly.
One observation: I am getting exception
"The Process object must have the UseShellExecute property set to false in order to use environment variables."
when I debug and wait at the process start function " System.Diagnostics.Process.Start(proc);". And when I do not wait and just press F5 it does not give any exception but the operation does not get successful either.
This behaviour can be reproduced.
When inspecting the ProcessStartInfo variable (your proc variable) in the watch window by opening it to see all properties then this Exception occurs. When closing it in the watch window so that all properties are hidden, the error is not thrown!
It is possible to watch the proc.Arguments and probably some others too.
I think that one of the getters internally changes something so it leads to this error.
My german exception message is "System.InvalidOperationException: 'Für das Process-Objekt muss die UseShellExecute-Eigenschaft auf "false" festgelegt sein, um Umgebungsvariablen zu verwenden.'"

Enreco Video Rotation in Asp.Net Virtual Machine is not completing

I am developing an ASP.NET Web Api in which I need to concatenate some video clips and rotate them. I could achieve the same when I tried in my local system. When I deployed the same project to an Azure Virtual Machine I am not getting response. I am pretty sure that there isn't any issue till video concatenation because I could see the concatenated video in the expected folder. Here is the code snippet.
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
NReco.VideoConverter.ConcatSettings set = new NReco.VideoConverter.ConcatSettings();
ffMpeg.GetVideoThumbnail(_fileNames[0], imageRootPath + tobename + ".jpg");
if (_fileNames.Count() > 1)
{
ffMpeg.ConcatMedia(_fileNames, videoRootPath + tobename + "_r.mp4", NReco.VideoConverter.Format.mp4, set);
string path = HttpContext.Current.Server.MapPath("~\\bin\\");
System.Diagnostics.Process ffmpeg = new System.Diagnostics.Process();
ffmpeg.StartInfo.FileName = path + "\\" + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = "-i " + videoRootPath + tobename + "_r.mp4" + " -c copy -metadata:s:v:0 rotate=90 " + videoRootPath + tobename + ".mp4";
ffmpeg.Start();
ffmpeg.WaitForExit();
}
ffmpeg.ConcateMedia is working fine. I can't figure out why the External process that I have invoked does not complete. The same piece is working fine in my local Visual Studio.
Thank you in advance
It seems you are using Nreco VideoConvertor for joinging videos and external process to rotate the video.
You can always use Invoke method to write the custom commandline. something like this
ffMpeg.Invoke("-i " + videoRootPath + tobename + "_r.mp4" + " -c copy -metadata:s:v:0 rotate=90 " + videoRootPath + tobename + ".mp4");
Hope this Helps...
Your path ends with a slash, and when adding the paths together you also add a slash.
Use Path.Combine:
string path = HttpContext.Current.Server.MapPath("~\\bin");
ffmpeg.StartInfo.FileName = System.IO.Path.Combine(path, "ffmpeg.exe");

Java (Minecraft) doesnt start from c#

When I copy paste the javaw.exe -arguments to console it works but, when I launch it like this it doesn't work.
string directory = "C:\\Users\\Can\\AppData\\Roaming\\.minecraft";
string java = #"C:\windows\system32\javaw.exe";
string javaLocation = "C:\\Program Files\\Java\\jre7\\bin\\javaw.exe";
string RAM = "1G";
string username = "namehere";
string token = "--session token:"+tokenGenerated;
string version = "1.6.2";
string launch = "-Xmx" + RAM + " -Djava.library.path={0}\\versions\\1.6.2\\1.6.2-natives-7453523379463 -cp {0}\\libraries\\net\\sf\\jopt-simple\\jopt-simple\\4.5\\jopt-simple-4.5.jar;{0}\\libraries\\com\\paulscode\\codecjorbis\\20101023\\codecjorbis-20101023.jar;{0}\\libraries\\com\\paulscode\\codecwav\\20101023\\codecwav-20101023.jar;{0}\\libraries\\com\\paulscode\\libraryjavasound\\20101123\\libraryjavasound-20101123.jar;{0}\\libraries\\com\\paulscode\\librarylwjglopenal\\20100824\\librarylwjglopenal-20100824.jar;{0}\\libraries\\com\\paulscode\\soundsystem\\20120107\\soundsystem-20120107.jar;{0}\\libraries\\argo\\argo\\2.25_fixed\\argo-2.25_fixed.jar;{0}\\libraries\\org\\bouncycastle\\bcprov-jdk15on\\1.47\\bcprov-jdk15on-1.47.jar;{0}\\libraries\\com\\google\\guava\\guava\\14.0\\guava-14.0.jar;{0}\\libraries\\org\\apache\\commons\\commons-lang3\\3.1\\commons-lang3-3.1.jar;{0}\\libraries\\commons-io\\commons-io\\2.4\\commons-io-2.4.jar;{0}\\libraries\\net\\java\\jinput\\jinput\\2.0.5\\jinput-2.0.5.jar;{0}\\libraries\\net\\java\\jutils\\jutils\\1.0.0\\jutils-1.0.0.jar;{0}\\libraries\\com\\google\\code\\gson\\gson\\2.2.2\\gson-2.2.2.jar;{0}\\libraries\\org\\lwjgl\\lwjgl\\lwjgl\\2.9.0\\lwjgl-2.9.0.jar;{0}\\libraries\\org\\lwjgl\\lwjgl\\lwjgl_util\\2.9.0\\lwjgl_util-2.9.0.jar;{0}\\versions\\1.6.2\\1.6.2.jar net.minecraft.client.main.Main --username " + username + " " + token + " --version " + version + " --gameDir {0} --assetsDir {0}\\assets";
launch = String.Format(launch, directory);
string text = launch;
// WriteAllText creates a file, writes the specified string to the file,
// and then closes the file.
Directory.SetCurrentDirectory(#"C:\windows\system32\");
Process.Start("javaw.exe",
Path.Combine(launch));
What am I doing wrong?
Why do you need to call Path.Combine if your whole path is in one string?
Assuming your javaw.exe is actually in C:\windows\system32\, Process.Start("java.exe", launch); should work as intended.
Source - Path on MSDN: http://msdn.microsoft.com/en-us/library/system.io.path.aspx
Just use Java's real location instead of "javaw" like "c:\programfiles\Java\jre7\bin\javaw.exe"

Unable to generate file from ASP.NET with inkscape

I have an ASP.NET application on my local machine that works. This application takes an SVG file and creates a PNG from it using inkscape. I have tried to migrate that application to my production server. Oddly, the png creation is not working. The really strange part is, an Exception is not being thrown either. I have taken the command line parameters that are being created and copied and pasted them into the command line environment and they work. For instance, here is the line:
inkscape.exe -f "C:\inetpub\wwwroot\MyTest\sample.svg" -e "C:\inetpub\wwwroot\MyTest\sample.png"
I thought it was something simple, so I extracted the code into a sample web project. This project just converts a .svg to a .png. Once again, it worked in my local environment, but not in the production environment. Here is the code:
protected void executeButton_Click(object sender, EventArgs e)
{
try
{
string sourceFile = Server.MapPath("svg") + "\\" + ConfigurationManager.AppSettings["sourceFile"];
string targetFile = Server.MapPath("png") + "\\" + ConfigurationManager.AppSettings["targetFile"];
string args = "-f \"" + sourceFile + "\" -e \"" + targetFile + "\" -w100 -h40";
string inkscape = ConfigurationManager.AppSettings["inkscapeExe"];
// Generate the png via inkscape
ProcessStartInfo inkscapeInfo = new ProcessStartInfo(inkscape, args);
Process inkscape = Process.Start(inkscapeInfo);
inkscape.WaitForExit(5000);
runLiteral.Text = "Success!<br />" + args;
}
catch (Exception ex)
{
runLiteral.Text = ex.GetType().FullName + "<br />" + ex.Message + "<br />" + ex.StackTrace;
}
}
Can someone tell me what I'm doing wrong?
Thank you!
A couple things to check:
Make sure that the application pool identity for the web application (found in IIS, usually NetworkService) has permissions to execute inkscape.exe
If that is fine, check to make sure that the directory grants Modify permissions to the apppool identity on the directory(ies) you are writing the PNG to ("C:\inetpub\wwwroot\MyTest")
Alternatively, you can use impersonation to run the executable under a specific Windows account.

Categories

Resources