public static bool GetConfigurations(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(testObj as MgaModel); }; Assert.DoesNotThrow(d); } } finally { project.Close(true); } return result; }
public static bool RunContextCheck(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context result = masterInterpreter.TryCheckContext(testObj as MgaModel, out contextCheckerResults); } } finally { project.Close(true); } return(result); }
public static bool RunContextCheck(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context result = masterInterpreter.TryCheckContext(testObj as MgaModel, out contextCheckerResults); } } finally { project.Close(true); } return result; }
public static bool GetConfigurations(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(testObj as MgaModel); }; Assert.DoesNotThrow(d); } } finally { project.Close(true); } return(result); }
public static CyPhyMasterInterpreter.MasterInterpreterResult RunMasterInterpreterAndReturnResults( string projectPath, string absPath, string configPath, bool postToJobManager = false, bool keepTempModels = false, [System.Runtime.CompilerServices.CallerMemberName] string functionName = "") { Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); MgaFCO testObj; MgaFCO configObj; try { testObj = project.ObjectByPath[absPath] as MgaFCO; configObj = project.ObjectByPath[configPath] as MgaFCO; } finally { project.AbortTransaction(); } using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug; if (String.IsNullOrWhiteSpace(functionName) == false) { masterInterpreter.ResultsSubdirectoryName = functionName; var resultsDirPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(projectPath)), "results", masterInterpreter.ResultsSubdirectoryName); if (Directory.Exists(resultsDirPath)) { Directory.Delete(resultsDirPath, true); } } var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels); Assert.True(miResults.Length == 1, "MasterInterpreter.RunInTransactionOnOneConfig should always return one result."); return(miResults[0]); } } finally { project.Close(true); } }
public static void Main(string[] args) { try { // parse command line arguments 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)) { // 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); } } finally { project.Close(true); } } catch (Exception e) { System.Console.Error.WriteLine(e.ToString()); System.Environment.Exit(5); } }
public static CyPhyMasterInterpreter.MasterInterpreterResult RunMasterInterpreterAndReturnResults( string projectPath, string absPath, string configPath, bool postToJobManager = false, bool keepTempModels = false) { Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); MgaFCO testObj; MgaFCO configObj; try { testObj = project.ObjectByPath[absPath] as MgaFCO; configObj = project.ObjectByPath[configPath] as MgaFCO; } finally { project.AbortTransaction(); } using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug; var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels); Assert.True(miResults.Length == 1, "MasterInterpreter.RunInTransactionOnOneConfig should always return one result."); return(miResults[0]); } } finally { project.Close(true); } }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List <IMgaFCO> objectsToCheck = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast <MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker") && x.Name.Contains("ReadOnly") == false).ToList(); objectsToCheck.Sort((x, y) => { return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath)); }); } finally { project.AbortTransaction(); } Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked."); int numContexts = objectsToCheck.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToCheck) { // single test using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults); List <CyPhyMasterInterpreter.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)); }); project.BeginTransactionInNewTerr(); try { MgaObject parent = null; GME.MGA.Meta.objtype_enum type; subject.GetParent(out parent, out type); var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true; if (successExpected == checkerSuccess) { numSuccess++; //GMEConsole.Info.WriteLine("OK"); } else { success = false; foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[Passed]"); tw = Console.Out; } else { sb.Append("[Failed]"); tw = Console.Error; } sb.AppendFormat(" {0} - {1} ", result.Subject.Name, result.Subject.AbsPath); sb.Append(result.Message); tw.WriteLine(sb); } numFailures++; Console.Error.WriteLine("========= FAILED =========="); Console.Error.WriteLine("= {0}", subject.Name); Console.Error.WriteLine("= {0}", subject.AbsPath); Console.Error.WriteLine("==========================="); } } finally { project.AbortTransaction(); } } } if (success) { Console.Out.WriteLine("[OK] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one context was failed to check against the expected results."); } finally { project.Close(true); } }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List<IMgaFCO> objectsToGetConfigurations = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast<MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToGetConfigurations = allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations")).ToList(); objectsToGetConfigurations.Sort((x, y) => { return x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath); }); } finally { project.AbortTransaction(); } Assert.True(objectsToGetConfigurations != null, "There are no object in the project that has to be checked."); int numContexts = objectsToGetConfigurations.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToGetConfigurations) { // single test using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(subject as MgaModel); }; Assert.DoesNotThrow(d); //Assert.True(configurations != null, "GetConfiguration returned with null."); if (configurations == null) { numFailures++; } else { numSuccess++; } // print out nicely in the GME console project.BeginTransactionInNewTerr(); try { Console.Out.WriteLine("{0} [{1}] has {2} configurations.", subject.Name, subject.Meta.Name, configurations.Count); foreach (IMgaFCO configuration in configurations) { Console.Out.WriteLine(" > {0} - {1}", configuration.Name, configuration.ID); } } finally { project.AbortTransaction(); } } } if (success) { Console.Out.WriteLine("[OK] Got configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Tried to get configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one context was failed to check against the expected results."); } finally { project.Close(true); } }
private void NewMasterInterpreterImplementationFull(MgaFCO currentobj) { this.GMEConsole.Clear(); System.Windows.Forms.Application.DoEvents(); this.GMEConsole.Info.WriteLine("Running Master Interpreter 2.0"); if (currentobj == null) { GMEConsole.Error.WriteLine("Context is invalid. This component can be executed only if a valid context is open in the main editor e.g. Test Bench."); return; } var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); masterInterpreter.IsInteractive = this.InteractiveMode; IEnumerable<CyPhyMasterInterpreter.Rules.ContextCheckerResult> contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(currentobj as MgaModel, out contextCheckerResults); List<CyPhyMasterInterpreter.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 out nicely in the GME console MgaGateway.PerformInTransaction(() => { foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i><a href=\"mga:{0}\">{1}</a></i> ", result.Subject.ID, result.Subject.Name); sb.Append(result.Message); tw.WriteLine(sb); } }); if (sortedResults.Any(x => x.Success == false)) { GMEConsole.Error.WriteLine("Context is invalid see messeges above. Please fix the problems."); return; } // context is valid // show GUI for the user CyPhyMasterInterpreter.ConfigurationSelection selection = null; try { selection = masterInterpreter.ShowConfigurationSelectionForm(currentobj as MgaModel); } catch (CyPhyMasterInterpreter.ExecutionCanceledByUserException ex) { GMEConsole.Warning.WriteLine("Operation was canceled by user. {0}", ex.Message); return; } CyPhyMasterInterpreter.MasterInterpreterResult[] miResults = null; // Get a progress dialog using (var progressDialog = new CyPhyMasterInterpreter.ProgressDialog()) { masterInterpreter.MultipleConfigurationProgress += progressDialog.MultipleConfigurationProgressHandler; masterInterpreter.SingleConfigurationProgress += progressDialog.SingleConfigurationProgressHandler; if (masterInterpreter.IsInteractive) { progressDialog.ShowWithDisabledMainWindow(); } try { miResults = masterInterpreter.RunInTransaction(selection); } catch (CyPhyMasterInterpreter.AnalysisModelInterpreterConfigurationFailedException ex) { GMEConsole.Warning.WriteLine("Operation was canceled by user. {0}", ex.Message); } catch (CyPhyMasterInterpreter.ExecutionCanceledByUserException ex) { GMEConsole.Warning.WriteLine("Operation was canceled by user. {0}", ex.Message); } } if (selection.OpenDashboard) { masterInterpreter.OpenDashboardWithChrome(); } GMEConsole.Info.WriteLine(" === Summary === "); MgaGateway.PerformInTransaction(() => { // print failure/success statistics // user master interpreter's result set in case user canceled the execution foreach (var result in masterInterpreter.Results) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i>{0}</i> {1} ", result.Context.Name, result.Configuration.Name); sb.Append(result.Message); tw.WriteLine(sb); } }); this.GMEConsole.Info.WriteLine("Done Master Interpreter 2.0"); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); this.InteractiveMode = this.Convert(param) != ComponentStartMode.GME_SILENT_MODE; //bool runNewImplementationOnly = true; //runNewImplementationOnly = false; //if (runNewImplementationOnly) //{ // this.NewMasterInterpreterImplementationFull(currentobj); // return; //} List<IMgaFCO> objectsToCheck = new List<IMgaFCO>(); List<IMgaFCO> objectsToGetConfigurations = new List<IMgaFCO>(); MgaGateway.PerformInTransaction(() => { if (currentobj == null) { var allObjects = project .RootFolder .ChildFolders .Cast<MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToCheck.AddRange(allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker"))); objectsToGetConfigurations.AddRange(allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations"))); } else { objectsToCheck.Add(currentobj); //objectsToGetConfigurations.Add(currentobj); } objectsToCheck.Sort((x, y) => { return x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath); }); }); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int numContexts = objectsToCheck.Count; int numSuccess = 0; int numFailures = 0; StringBuilder sbAssumptions = new StringBuilder(); sbAssumptions.Append("Implemented".PadToCenter(11)); sbAssumptions.Append("Valid".PadToCenter(11)); sbAssumptions.Append("Context".PadToCenter(30)); sbAssumptions.Append("Assumption"); sbAssumptions.AppendLine(); foreach (var subject in objectsToCheck) { var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); IEnumerable<CyPhyMasterInterpreter.Rules.ContextCheckerResult> contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults); List<CyPhyMasterInterpreter.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 out nicely in the GME console MgaGateway.PerformInTransaction(() => { MgaObject parent = null; GME.MGA.Meta.objtype_enum type; subject.GetParent(out parent, out type); var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true; sbAssumptions.AppendFormat("{0}{1}{2}{3}", (successExpected == checkerSuccess).ToString().PadToCenter(11), successExpected.ToString().PadToCenter(11), subject.Meta.Name.PadToCenter(30), subject.Name.ToSentenceCase()); sbAssumptions.AppendLine(); if (successExpected == checkerSuccess) { numSuccess++; //GMEConsole.Info.WriteLine("OK"); if (currentobj != null) { foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i><a href=\"mga:{0}\">{1}</a></i> ", result.Subject.ID, result.Subject.Name); sb.Append(result.Message); tw.WriteLine(sb); } } } else { foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i><a href=\"mga:{0}\">{1}</a></i> ", result.Subject.ID, result.Subject.Name); sb.Append(result.Message); tw.WriteLine(sb); } numFailures++; GMEConsole.Error.WriteLine("========= FAILED =========="); GMEConsole.Error.WriteLine("= {0}", subject.Name); GMEConsole.Error.WriteLine("= {0}", subject.AbsPath); GMEConsole.Error.WriteLine("==========================="); } }); if (currentobj != null) { CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null; MgaGateway.PerformInTransaction(() => { analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(subject as MgaModel); }); GMEConsole.Info.WriteLine("AnalysisProcessor type: {0}", analysisModelProcessor.GetType().Name); GMEConsole.Info.WriteLine("Interpreters: {0}", string.Join(", ", analysisModelProcessor.Interpreters)); GMEConsole.Info.WriteLine("InterpretersToConfigure: {0}", string.Join(", ", analysisModelProcessor.InterpretersToConfiguration)); MgaFCO configuration = null; configuration = masterInterpreter.GetConfigurations(subject as MgaModel).Cast<MgaFCO>().FirstOrDefault(); var results = masterInterpreter.RunInTransaction(subject as MgaModel, configuration, keepTempModels: true); MgaGateway.PerformInTransaction(() => { foreach (var result in results) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i>{0}</i> {1} ", result.Context.Name, result.Configuration.Name); sb.Append(result.Message); tw.WriteLine(sb); } }); } } File.WriteAllText("master_interpreter_assumptions.txt", sbAssumptions.ToString()); foreach (var subject in objectsToGetConfigurations) { var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); // we are not checking the models again, these test models must be valid enough to get configurations from them var configurations = masterInterpreter.GetConfigurations(subject as MgaModel); // print out nicely in the GME console MgaGateway.PerformInTransaction(() => { GMEConsole.Info.WriteLine("{0} has {1} configurations.", subject.Name, configurations.Count); //GMEConsole.Info.WriteLine("- {0}", string.Join(", ", configurations.Cast<MgaFCO>().Select(x => x.Name))); }); //CyPhyMasterInterpreter.MasterInterpreterResult[] masterInterpreterResults = null; //using (var progressDialog = new CyPhyMasterInterpreter.ProgressDialog()) //{ // masterInterpreter.MultipleConfigurationProgress += progressDialog.MultipleConfigurationProgressHandler; // masterInterpreter.SingleConfigurationProgress += progressDialog.SingleConfigurationProgressHandler; // progressDialog.ShowWithDisabledMainWindow(); // masterInterpreterResults = masterInterpreter.RunInTransaction(subject as IMgaModel, configurations); //} } GMEConsole.Info.WriteLine("ContextChecks: {0}", numContexts); GMEConsole.Info.WriteLine("Successful : {0}", numSuccess); GMEConsole.Info.WriteLine("Failures : {0}", numFailures); if (numContexts == numSuccess) { GMEConsole.Info.WriteLine("ALL GREEN :-)"); } else { GMEConsole.Error.WriteLine("You need to work more on the code..."); } GMEConsole.Info.WriteLine( "Duration: {0}.", sw.Elapsed.ToString("c")); } finally { System.Windows.Forms.Application.DoEvents(); if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List<IMgaFCO> objectsToCheck = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast<MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker") && x.Name.Contains("ReadOnly") == false).ToList(); objectsToCheck.Sort((x, y) => { return x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath); }); } finally { project.AbortTransaction(); } Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked."); int numContexts = objectsToCheck.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToCheck) { // single test using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults); List<CyPhyMasterInterpreter.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); }); project.BeginTransactionInNewTerr(); try { MgaObject parent = null; GME.MGA.Meta.objtype_enum type; subject.GetParent(out parent, out type); var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true; if (successExpected == checkerSuccess) { numSuccess++; //GMEConsole.Info.WriteLine("OK"); } else { success = false; foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[Passed]"); tw = Console.Out; } else { sb.Append("[Failed]"); tw = Console.Error; } sb.AppendFormat(" {0} - {1} ", result.Subject.Name, result.Subject.AbsPath); sb.Append(result.Message); tw.WriteLine(sb); } numFailures++; Console.Error.WriteLine("========= FAILED =========="); Console.Error.WriteLine("= {0}", subject.Name); Console.Error.WriteLine("= {0}", subject.AbsPath); Console.Error.WriteLine("==========================="); } } finally { project.AbortTransaction(); } } } if (success) { Console.Out.WriteLine("[OK] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one context was failed to check against the expected results."); } finally { project.Close(true); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); this.InteractiveMode = this.Convert(param) != ComponentStartMode.GME_SILENT_MODE; //bool runNewImplementationOnly = true; //runNewImplementationOnly = false; //if (runNewImplementationOnly) //{ // this.NewMasterInterpreterImplementationFull(currentobj); // return; //} List <IMgaFCO> objectsToCheck = new List <IMgaFCO>(); List <IMgaFCO> objectsToGetConfigurations = new List <IMgaFCO>(); MgaGateway.PerformInTransaction(() => { if (currentobj == null) { var allObjects = project .RootFolder .ChildFolders .Cast <MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToCheck.AddRange(allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker"))); objectsToGetConfigurations.AddRange(allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations"))); } else { objectsToCheck.Add(currentobj); //objectsToGetConfigurations.Add(currentobj); } objectsToCheck.Sort((x, y) => { return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath)); }); }); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int numContexts = objectsToCheck.Count; int numSuccess = 0; int numFailures = 0; StringBuilder sbAssumptions = new StringBuilder(); sbAssumptions.Append("Implemented".PadToCenter(11)); sbAssumptions.Append("Valid".PadToCenter(11)); sbAssumptions.Append("Context".PadToCenter(30)); sbAssumptions.Append("Assumption"); sbAssumptions.AppendLine(); foreach (var subject in objectsToCheck) { var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); IEnumerable <CyPhyMasterInterpreter.Rules.ContextCheckerResult> contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults); List <CyPhyMasterInterpreter.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 out nicely in the GME console MgaGateway.PerformInTransaction(() => { MgaObject parent = null; GME.MGA.Meta.objtype_enum type; subject.GetParent(out parent, out type); var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true; sbAssumptions.AppendFormat("{0}{1}{2}{3}", (successExpected == checkerSuccess).ToString().PadToCenter(11), successExpected.ToString().PadToCenter(11), subject.Meta.Name.PadToCenter(30), subject.Name.ToSentenceCase()); sbAssumptions.AppendLine(); if (successExpected == checkerSuccess) { numSuccess++; //GMEConsole.Info.WriteLine("OK"); if (currentobj != null) { foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i><a href=\"mga:{0}\">{1}</a></i> ", result.Subject.ID, result.Subject.Name); sb.Append(result.Message); tw.WriteLine(sb); } } } else { foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i><a href=\"mga:{0}\">{1}</a></i> ", result.Subject.ID, result.Subject.Name); sb.Append(result.Message); tw.WriteLine(sb); } numFailures++; GMEConsole.Error.WriteLine("========= FAILED =========="); GMEConsole.Error.WriteLine("= {0}", subject.Name); GMEConsole.Error.WriteLine("= {0}", subject.AbsPath); GMEConsole.Error.WriteLine("==========================="); } }); if (currentobj != null) { CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null; MgaGateway.PerformInTransaction(() => { analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(subject as MgaModel); }); GMEConsole.Info.WriteLine("AnalysisProcessor type: {0}", analysisModelProcessor.GetType().Name); GMEConsole.Info.WriteLine("Interpreters: {0}", string.Join(", ", analysisModelProcessor.Interpreters)); GMEConsole.Info.WriteLine("InterpretersToConfigure: {0}", string.Join(", ", analysisModelProcessor.InterpretersToConfiguration)); MgaFCO configuration = null; configuration = masterInterpreter.GetConfigurations(subject as MgaModel).Cast <MgaFCO>().FirstOrDefault(); var results = masterInterpreter.RunInTransaction(subject as MgaModel, configuration, keepTempModels: true); MgaGateway.PerformInTransaction(() => { foreach (var result in results) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i>{0}</i> {1} ", result.Context.Name, result.Configuration.Name); sb.Append(result.Message); tw.WriteLine(sb); } }); } } File.WriteAllText("master_interpreter_assumptions.txt", sbAssumptions.ToString()); foreach (var subject in objectsToGetConfigurations) { var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); // we are not checking the models again, these test models must be valid enough to get configurations from them var configurations = masterInterpreter.GetConfigurations(subject as MgaModel); // print out nicely in the GME console MgaGateway.PerformInTransaction(() => { GMEConsole.Info.WriteLine("{0} has {1} configurations.", subject.Name, configurations.Count); //GMEConsole.Info.WriteLine("- {0}", string.Join(", ", configurations.Cast<MgaFCO>().Select(x => x.Name))); }); //CyPhyMasterInterpreter.MasterInterpreterResult[] masterInterpreterResults = null; //using (var progressDialog = new CyPhyMasterInterpreter.ProgressDialog()) //{ // masterInterpreter.MultipleConfigurationProgress += progressDialog.MultipleConfigurationProgressHandler; // masterInterpreter.SingleConfigurationProgress += progressDialog.SingleConfigurationProgressHandler; // progressDialog.ShowWithDisabledMainWindow(); // masterInterpreterResults = masterInterpreter.RunInTransaction(subject as IMgaModel, configurations); //} } GMEConsole.Info.WriteLine("ContextChecks: {0}", numContexts); GMEConsole.Info.WriteLine("Successful : {0}", numSuccess); GMEConsole.Info.WriteLine("Failures : {0}", numFailures); if (numContexts == numSuccess) { GMEConsole.Info.WriteLine("ALL GREEN :-)"); } else { GMEConsole.Error.WriteLine("You need to work more on the code..."); } GMEConsole.Info.WriteLine( "Duration: {0}.", sw.Elapsed.ToString("c")); } finally { System.Windows.Forms.Application.DoEvents(); if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
private void NewMasterInterpreterImplementationFull(MgaFCO currentobj) { this.GMEConsole.Clear(); System.Windows.Forms.Application.DoEvents(); this.GMEConsole.Info.WriteLine("Running Master Interpreter 2.0"); if (currentobj == null) { GMEConsole.Error.WriteLine("Context is invalid. This component can be executed only if a valid context is open in the main editor e.g. Test Bench."); return; } var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); masterInterpreter.IsInteractive = this.InteractiveMode; IEnumerable <CyPhyMasterInterpreter.Rules.ContextCheckerResult> contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(currentobj as MgaModel, out contextCheckerResults); List <CyPhyMasterInterpreter.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 out nicely in the GME console MgaGateway.PerformInTransaction(() => { foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i><a href=\"mga:{0}\">{1}</a></i> ", result.Subject.ID, result.Subject.Name); sb.Append(result.Message); tw.WriteLine(sb); } }); if (sortedResults.Any(x => x.Success == false)) { GMEConsole.Error.WriteLine("Context is invalid see messeges above. Please fix the problems."); return; } // context is valid // show GUI for the user CyPhyMasterInterpreter.ConfigurationSelection selection = null; try { selection = masterInterpreter.ShowConfigurationSelectionForm(currentobj as MgaModel); } catch (CyPhyMasterInterpreter.ExecutionCanceledByUserException ex) { GMEConsole.Warning.WriteLine("Operation was canceled by user. {0}", ex.Message); return; } CyPhyMasterInterpreter.MasterInterpreterResult[] miResults = null; // Get a progress dialog using (var progressDialog = new CyPhyMasterInterpreter.ProgressDialog()) { masterInterpreter.MultipleConfigurationProgress += progressDialog.MultipleConfigurationProgressHandler; masterInterpreter.SingleConfigurationProgress += progressDialog.SingleConfigurationProgressHandler; if (masterInterpreter.IsInteractive) { progressDialog.ShowWithDisabledMainWindow(); } try { miResults = masterInterpreter.RunInTransaction(selection); } catch (CyPhyMasterInterpreter.AnalysisModelInterpreterConfigurationFailedException ex) { GMEConsole.Warning.WriteLine("Operation was canceled by user. {0}", ex.Message); } catch (CyPhyMasterInterpreter.ExecutionCanceledByUserException ex) { GMEConsole.Warning.WriteLine("Operation was canceled by user. {0}", ex.Message); } } if (selection.OpenDashboard) { masterInterpreter.OpenDashboardWithChrome(); } GMEConsole.Info.WriteLine(" === Summary === "); MgaGateway.PerformInTransaction(() => { // print failure/success statistics // user master interpreter's result set in case user canceled the execution foreach (var result in masterInterpreter.Results) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[<b style=\"color:darkgreen\">Passed</b>]"); tw = GMEConsole.Info; } else { sb.Append("[<b style=\"color:red\">Failed</b>]"); tw = GMEConsole.Error; } sb.AppendFormat(" <i>{0}</i> {1} ", result.Context.Name, result.Configuration.Name); sb.Append(result.Message); tw.WriteLine(sb); } }); this.GMEConsole.Info.WriteLine("Done Master Interpreter 2.0"); }
public static bool RunMasterInterpreter( string projectPath, string absPath, string configPath, bool postToJobManager = false, bool keepTempModels = false) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; var configObj = project.ObjectByPath[configPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug; var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels); result = miResults.Any(x => x.Success == false) ? false: true; } } finally { project.Close(true); } return result; }
public CyPhyMasterInterpreter.MasterInterpreterResult Test(string tbpath, string configPath, int jobRunTimeout) { string tbId; string configId; project.BeginTransactionInNewTerr(); try { var tb = project.RootFolder.ObjectByPath[tbpath]; if (tb == null) { throw new ApplicationException("Could not find " + tbpath); } tbId = tb.ID; var config = project.RootFolder.ObjectByPath[configPath]; if (config == null) { throw new ApplicationException("Could not find " + configPath); } configId = config.ID; } finally { project.AbortTransaction(); } var configurationSelection = new CyPhyMasterInterpreter.ConfigurationSelectionLight() { PostToJobManager = true, ContextId = tbId, SelectedConfigurationIds = new string[] { configId } }; if (masterApi != null) { masterApi.Dispose(); } masterApi = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(); masterApi.Initialize(project); var results = masterApi.RunInTransactionWithConfigLight(configurationSelection); if (results.First().Success == false) { throw new ApplicationException("MasterInterpreter run failed"); } while (true) { Job job; if (jobUpdates.TryTake(out job, jobRunTimeout)) { if (Job.IsFailedStatus(job.Status)) { // TODO dump logs, stdout.txt, stderr.txt throw new ApplicationException("Remote run failed: " + job.Status); } else if (job.Status == Job.StatusEnum.Succeeded) { break; } } else { throw new TimeoutException(); } } return(results[0]); }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List <IMgaFCO> objectsToGetConfigurations = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast <MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToGetConfigurations = allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations")).ToList(); objectsToGetConfigurations.Sort((x, y) => { return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath)); }); } finally { project.AbortTransaction(); } Assert.True(objectsToGetConfigurations != null, "There are no object in the project that has to be checked."); int numContexts = objectsToGetConfigurations.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToGetConfigurations) { // single test using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(subject as MgaModel); }; Assert.DoesNotThrow(d); //Assert.True(configurations != null, "GetConfiguration returned with null."); if (configurations == null) { numFailures++; } else { numSuccess++; } // print out nicely in the GME console project.BeginTransactionInNewTerr(); try { Console.Out.WriteLine("{0} [{1}] has {2} configurations.", subject.Name, subject.Meta.Name, configurations.Count); foreach (IMgaFCO configuration in configurations) { Console.Out.WriteLine(" > {0} - {1}", configuration.Name, configuration.ID); } } finally { project.AbortTransaction(); } } } if (success) { Console.Out.WriteLine("[OK] Got configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Tried to get configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one context was failed to check against the expected results."); } finally { project.Close(true); } }