ATML1671Translator.translator.AixmlTranslator.Parse C# (CSharp) Method

Parse() public method

public Parse ( ) : void
return void
        public void Parse()
        {
            try
            {
                ProjectInfo pi = ProjectManager.ProjectInfo;
                if (pi == null || pi.TranslationInfo == null)
                    throw new TranslationException( "Failed to obtain the Translation Configuration" );

                bool isSegmented = pi.TranslationInfo.Segmented;
                string atlasPath = GetAtlasParserDirectory();
                string projectName = pi.ProjectName;
                string projectId = pi.Uuid;
                string uutName = pi.UutName;
                string uutId = pi.UutId;
                string testStation = pi.ClassName;
                string inputFile = isSegmented ? pi.TranslationInfo.SourcesAsAstring : pi.TranslationInfo.PrimaryFile;

                if (string.IsNullOrEmpty( testStation ))
                    throw new TranslationException( "You must select a Test Station in the Translator Configuration." );

                if (string.IsNullOrEmpty( uutId ))
                    throw new TranslationException( "You must select a UUT." );

                if (string.IsNullOrEmpty( uutName ))
                    throw new TranslationException( "You must select a UUT." );

                var atlasFile =
                    (String)ATMLContext.GetProperty("translator.atlas.parser.application-file", "catlas2aixml.exe");
                atlasFile = Path.Combine( atlasPath, atlasFile );

                if (!File.Exists( atlasFile ))
                    throw new TranslationException(String.Format("Failed to find the ATLAS Parsing Application ({0})", atlasFile));

                //if (_sourceFileInfo == null)
                //    throw new Exception( "The source file is missing." );

                _exeProcess = new Process();
                string xmlPath = ATMLContext.ProjectTranslatorAixmlPath;
                string projectPath = Path.Combine( ATMLContext.TESTSET_PATH, ProjectManager.ProjectName );
                string sourcePath = ATMLContext.ProjectTranslatorSourcePath;
                string aixmlFileName = Path.Combine( xmlPath, projectName + ".aixml.xml" );
                LogManager.Debug( "Obtained Translator Configuration." );
                //string fileName = _sourceFileInfo.Name;

                if (sourcePath == null)
                    throw new TranslationException("Missing Translator Source Path.");

                var args = new StringBuilder();
                args.Append( "\"input_files=" ).Append( inputFile ).Append( "\" " );
                args.Append( "\"test_station=" ).Append( testStation ).Append( "\" " );
                args.Append( "\"uut_name=" ).Append( uutName ).Append( "\" " );
                args.Append( "\"uut_id=" ).Append( uutId ).Append( "\" " );
                args.Append( "\"project_name=" ).Append( projectName ).Append( "\" " );
                args.Append( "\"output_directory=" ).Append( xmlPath ).Append( "\" " );
                args.Append( "\"input_directory=" ).Append( sourcePath ).Append( "\" " );
                args.Append( "\"console_html=" ).Append( "yes" ).Append( "\" " );
                args.Append("\"proc_hier=").Append("yes").Append("\" ");

                LogManager.Debug( "Obtained Parser Arguments." );
                LogManager.Debug( "Executing parser \"{0}\" [{1}] on {2}", atlasFile, args.ToString(),
                                  inputFile );
                LogManager.SourceTrace( ATMLTranslator.SOURCE, "Parsing ATLAS Source Files..." );

                ProcessStartInfo startInfo = _exeProcess.StartInfo;
                startInfo.CreateNoWindow = false;
                startInfo.UseShellExecute = false;
                startInfo.WorkingDirectory = sourcePath;
                startInfo.FileName = atlasFile;
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.Arguments = args.ToString();
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardInput = true;
                startInfo.RedirectStandardError = true;
                startInfo.CreateNoWindow = true;

                _exeProcess.EnableRaisingEvents = true;
                _exeProcess.OutputDataReceived += exeProcess_OutputDataReceived;
                _exeProcess.ErrorDataReceived += exeProcess_ErrorDataReceived;
                _exeProcess.Exited += delegate( object sender, EventArgs eventArgs )
                                     {
                                         FileInfo fileInfo = null;
                                         if (_exeProcess != null)
                                         {
                                             int errorCode = _exeProcess.ExitCode;
                                             if (errorCode > 0)
                                             {
                                                 LogManager.SourceError( ATMLTranslator.SOURCE,
                                                                         "The ATLAS Parser has Failed." );
                                             }
                                             else
                                             {
                                                 LogManager.SourceInfo( ATMLTranslator.SOURCE,
                                                                        "The ATLAS Parser has Successfully Completed.");
                                                 fileInfo = new FileInfo( aixmlFileName );
                                             }
                                         }
                                         //Always call OnParsed to clear parsing states.
                                         OnParsed(fileInfo);
                                         _exeProcess.Close();
                                     };

                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                _exeProcess.Start();

                var sb = new StringBuilder();
                using (StreamReader stdOut = _exeProcess.StandardOutput)
                {
                    do
                    {
                        sb.Append( stdOut.ReadLine() );
                    } while (!stdOut.EndOfStream); //Loops until the stream ends
                    LogManager.SourceTrace( ATMLTranslator.SOURCE, sb.ToString() );
                }
            }
            catch (TranslationException err)
            {
                OnParsed(null);
                LogManager.SourceError(ATMLTranslator.SOURCE, err.Message);
            }
            catch (Exception err)
            {
                OnParsed( null );
                LogManager.SourceError( ATMLTranslator.SOURCE, err );
            }
            finally
            {
            }
        }