コード例 #1
0
 public ReturnCode Generate()
 {
     try
     {
         this.stateBuilder = CreateBuilderFromOption(this.options);
         stateBuilder.Build();
     }
     catch (IOException ioException)
     {
         ts.TraceEvent(TraceEventType.Error, 1, "IOException: {0}", ioException.Message);
         errorCode = ReturnCode.IOException;
     }
     catch (XmlException xmlException)
     {
         ts.TraceEvent(TraceEventType.Error, 1, "XmlException: {0}", xmlException.Message);
         errorCode = ReturnCode.XmlException;
     }
     catch (UnauthorizedAccessException unauthorizedAccessException)
     {
         ts.TraceEvent(TraceEventType.Error, 1, "Unauthorized Access Exception: {0}", unauthorizedAccessException.Message);
         errorCode = ReturnCode.UnauthorizedAccessException;
     }
     catch (Exception exception)
     {
         ts.TraceEvent(TraceEventType.Error, 1, "StackTrace: {0}", exception.StackTrace);
         if (exception.InnerException != null)
         {
             ts.TraceEvent(TraceEventType.Error, 1, "InnerException: {0}", exception.InnerException.Message);
         }
         ts.TraceEvent(TraceEventType.Error, 1, "Exception: {0}", exception.Message);
         errorCode = ReturnCode.Error;
     }
     return(errorCode);
 }
コード例 #2
0
        public ReturnCode Generate()
        {
            string rMsg = "";

            try
            {
                this.stateBuilder = CreateBuilderFromOption(this.options);
                stateBuilder.Build();
            }
            catch (IOException ioException)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "IOException: {0}", ioException.Message);
                errorCode = ReturnCode.IOException;
                rMsg     += ioException.Message + "\n" + ioException.ToString( );
            }
            catch (XmlException xmlException)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "XmlException: {0}", xmlException.Message);
                errorCode = ReturnCode.XmlException;
                rMsg     += xmlException.Message + "\n" + xmlException.ToString( );
            }
            catch (UnauthorizedAccessException unauthorizedAccessException)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "Unauthorized Access Exception: {0}", unauthorizedAccessException.Message);
                errorCode = ReturnCode.UnauthorizedAccessException;
                rMsg     += unauthorizedAccessException.Message + "\n" + unauthorizedAccessException.ToString( );
            }
            catch (Exception exception)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "StackTrace: {0}", exception.StackTrace);
                if (exception.InnerException != null)
                {
                    ts.TraceEvent(TraceEventType.Error, 1, "InnerException: {0}", exception.InnerException.Message);
                }
                ts.TraceEvent(TraceEventType.Error, 1, "Exception: {0}", exception.Message);
                errorCode = ReturnCode.Error;
                rMsg     += exception.Message + "\n" + exception.ToString( );
            }

            //write msg in file for debug
            if (rMsg != "")
            {
                File.AppendAllText("debug_exception.txt", $"\n-----{errorCode}------\n" + rMsg + "----- " + DateTime.Now + "\n\n");
            }

            return(errorCode);
        }
コード例 #3
0
        /// <summary>
        /// Generate the code
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonGenerateCode_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(CurrentFsmFileName))
            {
                openFsmFile_Click(sender, e);
            }

            if (File.Exists(CurrentFsmFileName) == false)
            {
                MessageBox.Show("The file " + CurrentFsmFileName + " does not exist", Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UpdateMostRecentUsedList(CurrentFsmFileName);
            FillComboxBoxInputFilename();

            stateBuilder = new StateBuilder(CurrentFsmFileName);

            try
            {
                this.toolStripStatusLabel.Text = "Generating code";
                // Prepend Copyright
                if (string.IsNullOrEmpty(textBoxPrependFile.Text) == false)
                {
                    stateBuilder.Options.PrependFile = textBoxPrependFile.Text;
                }

                // NoObserver
                stateBuilder.Options.NoObserver = checkBoxNoObserver.Checked;

                // Output directory
                if (String.IsNullOrEmpty(textBoxOutputDirectory.Text) == false)
                {
                    stateBuilder.OutputDirectory = textBoxOutputDirectory.Text;
                }

                // Build it now
                stateBuilder.Build();
                this.toolStripStatusLabel.Text = "Code successfully generated";
                errorCode = ReturnCode.Ok;
            }
            catch (IOException ioException)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "IOException: {0}", ioException.Message);
                MessageBox.Show("IOException in file " + stateBuilder.InputFileName + ": " + ioException.Message, Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorCode = ReturnCode.IOException;
            }
            catch (XmlException xmlException)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "XmlException: {0}", xmlException.Message);
                ts.TraceEvent(TraceEventType.Error, 1, "Line: ({0},{0})", xmlException.LineNumber, xmlException.LinePosition);
                MessageBox.Show("XmlException in file " + stateBuilder.InputFileName + ": " + xmlException.Message, Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorCode = ReturnCode.XmlException;
            }
            catch (UnauthorizedAccessException unauthorizedAccessException)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "Unauthorized Access Exception: {0}", unauthorizedAccessException.Message);
                MessageBox.Show("Unauthorized Access Exception for file " + stateBuilder.InputFileName + ": " + unauthorizedAccessException.Message, Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorCode = ReturnCode.UnauthorizedAccessException;
            }
            catch (Exception exception)
            {
                ts.TraceEvent(TraceEventType.Error, 1, "StackTrace: {0}", exception.StackTrace);
                if (exception.InnerException != null)
                {
                    ts.TraceEvent(TraceEventType.Error, 1, "InnerException: {0}", exception.InnerException.Message);
                }
                ts.TraceEvent(TraceEventType.Error, 1, "Exception: {0}", exception.Message);
                MessageBox.Show("Exception while processing file " + stateBuilder.InputFileName + ": " + exception.Message, Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorCode = ReturnCode.Error;
            }

            if (errorCode != ReturnCode.Ok)
            {
                this.toolStripStatusLabel.Text = "Error while generated code";
            }
        }