WriteSummary() public method

public WriteSummary ( CyPhyMasterInterpreter.MasterInterpreterResult results ) : void
results CyPhyMasterInterpreter.MasterInterpreterResult
return void
        private void Process(MgaFCO currentobj)
        {
            if (currentobj == null)
            {
                this.Logger.WriteError("Context is invalid. This component can be executed only if a valid context is open in the main editor (e.g.: Test Bench, Component Assembly).");
                return;
            }

            MgaGateway.PerformInTransaction(() =>
            {
                this.Logger.WriteInfo("Processing {0} [{1}] model", currentobj.Name, currentobj.MetaBase.Name);
            });

            using (var masterInterpreter = new CyPhyMasterInterpreterAPI(currentobj.Project, this.Logger))
            {
                masterInterpreter.IsInteractive = this.InteractiveMode;
                this.Logger.WriteDebug("Interactive mode: {0}", masterInterpreter.IsInteractive);

                Rules.ContextCheckerResult[] contextCheckerResults = null;

                // check context
                var checkerSuccess = false;
                try
                {
                    checkerSuccess = masterInterpreter.TryCheckContext(currentobj as MgaModel, out contextCheckerResults);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    this.Logger.WriteDebug(ex.ToString());
                    this.Logger.WriteError(ex.Message);
                    return;
                }

                List<Rules.ContextCheckerResult> sortedResults = contextCheckerResults.ToList();

                // sort results Passed, Failed, then alphabetically based on message.
                sortedResults.Sort((x, y) =>
                {
                    return x.Success == y.Success ?
                        x.Message.CompareTo(y.Message) :
                        y.Success.CompareTo(x.Success);
                });

                // Print Checker results
                MgaGateway.PerformInTransaction(() =>
                {
                    foreach (var result in sortedResults)
                    {
                        if (result.Success)
                        {
                            this.Logger.WriteCheckPassed(" <i><a href=\"mga:{0}\">{1}</a></i> {2}", result.Subject.ID, result.Subject.Name, result.Message);
                        }
                        else
                        {
                            this.Logger.WriteCheckFailed(" <i><a href=\"mga:{0}\">{1}</a></i> {2}", result.Subject.ID, result.Subject.Name, result.Message);
                        }
                    }
                });

                if (sortedResults.Any(x => x.Success == false))
                {
                    this.Logger.WriteError("Context is invalid see messeges above. Please fix the problems.");

                    bool controlWasHeld = false;
                    int VK_CONTROL = 0x11;
                    // if user held the control ignore the checker results ... for debugging purposes ONLY!
                    if ((bool)((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000))
                    {
                        controlWasHeld = true;
                    }

                    if (controlWasHeld == false)
                    {
                        return;
                    }
                    else
                    {
                        this.Logger.WriteWarning("Bypassing checker results. This mode is strictly for debugging purposes.");
                    }
                }

                if (checkerSuccess == false)
                {
                    return;
                }

                // context is valid
                // show GUI for the user
                ConfigurationSelection selection = null;

                try
                {
                    selection = masterInterpreter.ShowConfigurationSelectionForm(currentobj as MgaModel);
                    MgaGateway.PerformInTransaction(() =>
                    {
                        this.Logger.WriteDebug("MasterExe command: CyPhyMasterExe.exe \"{0}\" \"{1}\" \"{2}\"", currentobj.Project.ProjectConnStr, GMELightObject.ShortenAbsPath(currentobj.AbsPath),
                            String.Join("\" \"", selection.SelectedConfigurations.Cast<IMgaFCO>().Select(f => GMELightObject.ShortenAbsPath(f.AbsPath)).ToArray()));
                    });
                }
                catch (ExecutionCanceledByUserException ex)
                {
                    this.Logger.WriteWarning("Operation was canceled by user. {0}", ex.Message);
                    return;
                }



                MasterInterpreterResult[] miResults = null;

                // Get a progress dialog
                using (var progressDialog = new ProgressDialog(masterInterpreter))
                {
                    masterInterpreter.MultipleConfigurationProgress += progressDialog.MultipleConfigurationProgressHandler;
                    masterInterpreter.SingleConfigurationProgress += progressDialog.SingleConfigurationProgressHandler;

                    if (masterInterpreter.IsInteractive)
                    {
                        progressDialog.ShowWithDisabledMainWindow();
                    }

                    try
                    {
                        miResults = masterInterpreter.RunInTransactionWithConfig(selection);
                    }
                    catch (AnalysisModelInterpreterConfigurationFailedException ex)
                    {
                        this.Logger.WriteWarning("Operation was canceled by user. {0}", ex.Message);
                    }
                    catch (ExecutionCanceledByUserException ex)
                    {
                        this.Logger.WriteWarning("Operation was canceled by user. {0}", ex.Message);
                    }
                }

                if (selection.OpenDashboard)
                {
                    masterInterpreter.OpenDashboardWithChrome();
                }

                masterInterpreter.WriteSummary(miResults);
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            try
            {
                bool noJobCollectionDone = false;
                // parse command line arguments
                string jobCollectionId = new Guid().ToString("D");
                while (true)
                {
                    if (args[0] == "--job-collection-id")
                    {
                        jobCollectionId = args[1];
                        args            = args.Skip(2).ToArray();
                    }
                    else if (args[0] == "--no-job-collection-done")
                    {
                        noJobCollectionDone = true;
                        args = args.Skip(1).ToArray();
                    }
                    else
                    {
                        break;
                    }
                }
                if (args[0] == "--send-job-collection-done")
                {
                    var dispatch = new JobManagerDispatch(jobCollectionId);
                    dispatch.StartJobManager(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                    dispatch.Done();
                    return;
                }
                string   projectConnStr    = args[0];
                string   originalSubjectID = args[1];
                string[] configIDs         = args.Skip(2).ToArray();

                if (projectConnStr.StartsWith("MGA=") == false)
                {
                    // use the full absolute path
                    projectConnStr = "MGA=" + Path.GetFullPath(projectConnStr);
                }

                MgaProject project = new MgaProject();
                bool       ro_mode;
                project.Open(projectConnStr, out ro_mode);

                try
                {
                    // get an instance of the master interpreter
                    using (var master = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
                    {
                        master.SetJobCollectionID(jobCollectionId);
                        if (noJobCollectionDone == true)
                        {
                            master.SetSendJobCollectionDone(false);
                        }
                        // create a configuration for the run
                        var configLight = new CyPhyMasterInterpreter.ConfigurationSelectionLight();
                        configLight.ContextId = originalSubjectID;
                        configLight.SelectedConfigurationIds = configIDs;
                        configLight.KeepTemporaryModels      = false;
                        configLight.PostToJobManager         = true;

                        // run master interpreter on configuration
                        var results = master.RunInTransactionWithConfigLight(configLight);

                        // summarize results
                        master.WriteSummary(results);
                        System.Environment.Exit(results.Where(r => r.Success == false).Count());
                    }
                }
                finally
                {
                    project.Close(true);
                }
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine(e.ToString());
                System.Environment.Exit(5);
            }
        }