Exemplo n.º 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);
 }
Exemplo n.º 2
0
        private StateBuilder CreateBuilderFromOption(Options options)
        {
            StateBuilder stateBuilder = new StateBuilder(options.InputStateMachineFiles[0]);

            // Output directory
            if (string.IsNullOrEmpty(options.outputDirectory) == false)
            {
                stateBuilder.OutputDirectory = options.outputDirectory;
            }
            return(stateBuilder);
        }
        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);
        }
Exemplo n.º 4
0
        private bool parseArgs(string[] args)
        {
            options = new Options();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));

            if (!parser.ParseArguments(args, options) || (options.InputStateMachineFiles.Count != 1))
            {
                ts.TraceEvent(TraceEventType.Error, 1, "Error parsing command line: {0}", Environment.CommandLine);
                errorCode = ReturnCode.InvalidCommandLine;
                return(false);
            }

            stateBuilder = new StateBuilder(options.InputStateMachineFiles[0]);
            // Input file
            ts.TraceEvent(TraceEventType.Verbose, 1, "Input file: {0}", stateBuilder.InputFileName);
            // Output directory
            if (string.IsNullOrEmpty(options.outputDirectory) == false)
            {
                stateBuilder.OutputDirectory = options.outputDirectory;
            }
            ts.TraceEvent(TraceEventType.Verbose, 1, "Output directory: {0}", stateBuilder.OutputDirectory);

            return(true);
        }
Exemplo n.º 5
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";
            }
        }