コード例 #1
0
        /// <summary>
        /// Runs a process to convert a .crz file to a .cruise file
        /// </summary>
        /// <param name="targetPath">.crz file to convert</param>
        /// <param name="outputPath">path to create the new .cruise file at</param>
        /// <param name="updateCaller">optional event handler to get called whenever the process progress updates</param>
        /// <returns></returns>
        public bool Convert(
            string targetPath,
            string outputPath,
            ProcessUpdateEventHandler updateHandler)
        {
            try
            {
                targetPath = Path.GetFullPath(targetPath);                                      //convert paths to full paths
                outputPath = Path.GetFullPath(outputPath);

                if (File.Exists(targetPath) == false)
                {
                    Trace.TraceError("target path \"{0}\" can not be found", targetPath);
                    throw new FileNotFoundException("target path can not be found", targetPath);
                }

                if (File.Exists(COConvertEXE) == false)                                               //throw exception if we are unable to locate python.exe
                {
                    Trace.TraceError("COConverter can not be found");
                    throw new FileNotFoundException("COConverter can not be found", COConvertEXE);
                }

                if (this.Output.Count != 0)
                {
                    this.Output.Clear();
                }                                                                               //reset output property

                using (Process myProcess = new Process())
                {
                    try
                    {
                        myProcess.StartInfo.UseShellExecute = true;
                        myProcess.StartInfo.FileName        = COConvertEXE;
                        myProcess.StartInfo.Arguments       =
                            String.Format(
                                " -w \"{0}\" \"{1}\" ",
                                targetPath,
                                outputPath);
                        myProcess.StartInfo.CreateNoWindow = false;

                        //myProcess.StartInfo.RedirectStandardInput = true;

                        //_processUpdateEventHandle = updateHandler;
                        //myProcess.StartInfo.RedirectStandardOutput = true;
                        //myProcess.StartInfo.RedirectStandardError = true;
                        //myProcess.OutputDataReceived +=
                        //    new DataReceivedEventHandler(OutputDataReceived);

                        myProcess.Start();
                        //StreamWriter inputWriter = myProcess.StandardInput;

                        //myProcess.BeginOutputReadLine();

                        //inputWriter.WriteLine();
                        //this.ErrorOutput = myProcess.StandardError.ReadToEnd();
                        myProcess.WaitForExit();
                    }
                    finally
                    {
                        _processUpdateEventHandle = null;
                    }

                    if (myProcess.ExitCode == 1)
                    {
                        return(false);
                    }
                    else if (myProcess.ExitCode == 0)
                    {
                        return(true);
                    }
                }
                return(false);//fall through case, shouln't be reachable
            }
            catch (Exception e)
            {
                if (_processUpdateEventHandle != null)
                {
                    ProcessUpdateEventArgs args = new ProcessUpdateEventArgs();
                    args.output = e.ToString();
                    _processUpdateEventHandle(args);
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Runs a process to convert a .crz file to a .cruise file
        /// </summary>
        /// <param name="targetPath">.crz file to convert</param>
        /// <param name="outputPath">path to create the new .cruise file at</param>
        /// <param name="updateCaller">optional event handler to get called whenever the process progress updates</param>
        /// <returns></returns>
        public bool Convert(
            string targetPath,
            string outputPath,
            ProcessUpdateEventHandler updateHandler)
        {
            try
            {
                targetPath = Path.GetFullPath(targetPath);                                      //convert paths to full paths
                outputPath = Path.GetFullPath(outputPath);

                if (File.Exists(targetPath) == false)
                {
                    Trace.TraceError("target path \"{0}\" can not be found", targetPath);
                    throw new FileNotFoundException("target path can not be found", targetPath);
                }

                if (File.Exists(COConvertEXE) == false)                                               //throw exception if we are unable to locate python.exe
                {
                    Trace.TraceError("COConverter can not be found");
                    throw new FileNotFoundException("COConverter can not be found", COConvertEXE);
                }

                if (this.Output.Count != 0) { this.Output.Clear(); }                            //reset output property

                using (Process myProcess = new Process())
                {
                    try
                    {
                        myProcess.StartInfo.UseShellExecute = true;
                        myProcess.StartInfo.FileName = COConvertEXE;
                        myProcess.StartInfo.Arguments =
                            String.Format(
                            " -w \"{0}\" \"{1}\" ",
                            targetPath,
                            outputPath);
                        myProcess.StartInfo.CreateNoWindow = false;

                        //myProcess.StartInfo.RedirectStandardInput = true;

                        //_processUpdateEventHandle = updateHandler;
                        //myProcess.StartInfo.RedirectStandardOutput = true;
                        //myProcess.StartInfo.RedirectStandardError = true;
                        //myProcess.OutputDataReceived +=
                        //    new DataReceivedEventHandler(OutputDataReceived);

                        myProcess.Start();
                        //StreamWriter inputWriter = myProcess.StandardInput;

                        //myProcess.BeginOutputReadLine();

                        //inputWriter.WriteLine();
                        //this.ErrorOutput = myProcess.StandardError.ReadToEnd();
                        myProcess.WaitForExit();
                    }
                    finally
                    {
                        _processUpdateEventHandle = null;
                    }

                    if (myProcess.ExitCode == 1)
                    {
                        return false;
                    }
                    else if (myProcess.ExitCode == 0)
                    {
                        return true;
                    }
                }
                return false;//fall through case, shouln't be reachable
            }
            catch (Exception e)
            {
                if (_processUpdateEventHandle != null)
                {
                    ProcessUpdateEventArgs args = new ProcessUpdateEventArgs();
                    args.output = e.ToString();
                    _processUpdateEventHandle(args);
                    return false;
                }
                else
                {
                    throw;
                }
            }
        }