/// <summary> /// Checks all rules from this dll. /// </summary> /// <returns>True if there are no errors, otherwise false</returns> public bool Check(IMgaTraceability traceability) { bool result = true; // check current context if (this.mainParameters.CurrentFCO == null || this.mainParameters.CurrentFCO.Meta.Name != typeof(ISIS.GME.Dsml.CyPhyML.Interfaces.TestBenchSuite).Name) { this.Logger.WriteError("A TestBenchSuite must be opened."); result = false; NbrOfErrors = 1; return(result); } // reset the results dictionary this.Results = new Dictionary <RuleDescriptor, List <RuleFeedbackBase> >(); // Create a checker object DesignConsistencyChecker.Framework.Checker dccChecker = new DesignConsistencyChecker.Framework.Checker(this.mainParameters.CurrentFCO, this.mainParameters.Project, traceability, this.Logger); dccChecker.RegisterRulesForTypes(new Type[] { typeof(CyPhySoT.Rules.Global) }, "CyPhySoT"); NbrOfErrors = 0; NbrOfWarnings = 0; // get all rules and check them List <RuleFeedbackBase> ruleFeedbacks; List <CheckerFeedback> checkerFeedbacks; dccChecker.CheckRules(dccChecker.GetRegisteredRules, out ruleFeedbacks, out checkerFeedbacks); if (ruleFeedbacks.Any(x => x.FeedbackType == FeedbackTypes.Error)) { result = false; } NbrOfErrors += ruleFeedbacks.Where(x => x.FeedbackType == FeedbackTypes.Error).Count(); NbrOfWarnings += ruleFeedbacks.Where(x => x.FeedbackType == FeedbackTypes.Warning).Count(); return(result); }
/// <summary> /// Checks all rules from this dll. /// </summary> /// <returns>True if there are no errors, otherwise false</returns> public bool Check(IMgaTraceability traceability) { bool result = true; // check current context if (this.mainParameters.CurrentFCO == null || this.mainParameters.CurrentFCO.Meta.Name != typeof(ISIS.GME.Dsml.CyPhyML.Interfaces.TestBenchSuite).Name) { this.Logger.WriteError("A TestBenchSuite must be opened."); result = false; NbrOfErrors = 1; return result; } // reset the results dictionary this.Results = new Dictionary<RuleDescriptor, List<RuleFeedbackBase>>(); // Create a checker object DesignConsistencyChecker.Framework.Checker dccChecker = new DesignConsistencyChecker.Framework.Checker(this.mainParameters.CurrentFCO, this.mainParameters.Project, traceability, this.Logger); dccChecker.RegisterRulesForTypes(new Type[] { typeof(CyPhySoT.Rules.Global) }, "CyPhySoT"); NbrOfErrors = 0; NbrOfWarnings = 0; // get all rules and check them List<RuleFeedbackBase> ruleFeedbacks; List<CheckerFeedback> checkerFeedbacks; dccChecker.CheckRules(dccChecker.GetRegisteredRules, out ruleFeedbacks, out checkerFeedbacks); if (ruleFeedbacks.Any(x => x.FeedbackType == FeedbackTypes.Error)) { result = false; } NbrOfErrors += ruleFeedbacks.Where(x => x.FeedbackType == FeedbackTypes.Error).Count(); NbrOfWarnings += ruleFeedbacks.Where(x => x.FeedbackType == FeedbackTypes.Warning).Count(); return result; }
public static int Main( String[] args ) { if( args.Length < 1 ) { Console.Out.WriteLine( "Usage: <program> CyPhyMLFile.mga [-f] [outputDirectory]" ); Environment.Exit( 1 ); } MgaProject mgaProject = null; string outputDirectory = "."; bool flat = false; for( int ix = 0; ix < args.Length; ++ix ) { if( args[ ix ] == "-f" ) { flat = true; } else if ( mgaProject == null ) { mgaProject = GetProject( args[ ix ] ); } else { outputDirectory = args[ ix ]; } } if ( mgaProject == null ) { Console.Out.WriteLine( "Usage: <program> CyPhyMLFile.mga [-f] [outputDirectory]" ); Environment.Exit( 1 ); } MgaGateway mgaGateway = new MgaGateway( mgaProject ); bool bExceptionOccurred = false; mgaGateway.PerformInTransaction( delegate { try { CyPhyML.RootFolder cyPhyMLRootFolder = ISIS.GME.Common.Utils.CreateObject<CyPhyMLClasses.RootFolder>( mgaProject.RootFolder ); HashSet<CyPhyML.Component> cyPhyMLComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet( cyPhyMLRootFolder ); var ruleChecker = new DesignConsistencyChecker.Framework.Checker(null, mgaProject); ruleChecker.RegisterRuleDll("DesignConsistencyChecker.dll"); var uniqueNameRule = ruleChecker.GetRegisteredRules.FirstOrDefault(x => x.Name == "UniquePPMNames"); int i_Counter = 1; foreach (var cyPhyMLComponent in cyPhyMLComponentSet) { try { if (uniqueNameRule != null) { var feedBacks = uniqueNameRule.Check((MgaFCO)cyPhyMLComponent.Impl).ToList(); if (feedBacks.Any(x => x.FeedbackType == FeedbackTypes.Error)) { foreach (var fb in feedBacks.Where(x => x.FeedbackType == FeedbackTypes.Error)) { Console.Error.WriteLine("Rule {0} failed: {1}", uniqueNameRule.Name, fb.Message); } continue; } } //foreach (CyPhyML.Component cyPhyMLComponent in cyPhyMLComponentList) { avm.Component avmComponent = CyPhy2ComponentModel.Convert.CyPhyML2AVMComponent(cyPhyMLComponent); string componentPath = null; if (flat) { componentPath = outputDirectory; } else { componentPath = cyPhyMLComponent.Path; componentPath = outputDirectory + "/" + componentPath.Substring(componentPath.IndexOf("/")); } Directory.CreateDirectory(componentPath); if (!flat) { Directory.CreateDirectory(componentPath + "/images"); //Directory.CreateDirectory( componentPath + "/CyPhyML" ); Directory.CreateDirectory(componentPath + "/doc"); Directory.CreateDirectory(componentPath + "/CAD"); } String s_outFilePath = String.Format("{0}/{1}.component.acm", componentPath, Safeify(cyPhyMLComponent.Name)); using (FileStream stream = new FileStream(s_outFilePath, FileMode.Create)) { XSD2CSharp.AvmXmlSerializer.Serialize(avmComponent, stream); stream.Close(); } Console.Out.WriteLine(string.Format("({0}/{1}) {2}", i_Counter++, cyPhyMLComponentSet.Count, Safeify(cyPhyMLComponent.Name))); //} } catch( Exception ex ) { Console.Error.WriteLine( "Exception: {0}", ex.Message.ToString() ); Console.Error.WriteLine( "Stack: {0}", ex.StackTrace.ToString() ); bExceptionOccurred = true; } } } catch( Exception ex ) { Console.Error.WriteLine( "Exception: {0}", ex.Message.ToString() ); Console.Error.WriteLine("Stack: {0}", ex.StackTrace.ToString()); bExceptionOccurred = true; } }, abort: false ); mgaProject.Close(); if (bExceptionOccurred) return -1; return 0; }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // TODO: Add your interpreter code GMEConsole.Info.WriteLine("Running Component Exporter..."); #region Prompt for Output Path GMEConsole.Info.WriteLine("Beginning Export..."); int i_count = 0; HashSet <CyPhy.Component> cyPhyComponentSet = null; if (currentobj != null) { cyPhyComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(currentobj); } else if (selectedobjs != null && selectedobjs.Count > 0) { cyPhyComponentSet = new HashSet <CyPhy.Component>(); foreach (MgaFCO mf in selectedobjs) { cyPhyComponentSet.UnionWith(CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(mf)); } } else { cyPhyComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(project.RootFolder); } if (cyPhyComponentSet.Count == 0) { GMEConsole.Warning.WriteLine("Nothing to export."); return; } string startupPath; if (false == String.IsNullOrWhiteSpace(previousExportPath) && Directory.Exists(previousExportPath)) { startupPath = previousExportPath; } else { startupPath = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); } // Get an output path from the user. if (this.OutputDir == null) { using (META.FolderBrowserDialog fbd = new META.FolderBrowserDialog() { Description = "Choose a path for the generated files.", //ShowNewFolderButton = true, SelectedPath = startupPath, }) { DialogResult dr = fbd.ShowDialog(); if (dr == DialogResult.OK) { OutputDir = fbd.SelectedPath; previousExportPath = OutputDir; } else { GMEConsole.Warning.WriteLine("Component Exporter cancelled"); return; } } } #endregion var ruleChecker = new DesignConsistencyChecker.Framework.Checker(currentobj, project); ruleChecker.RegisterRuleDll("DesignConsistencyChecker.dll"); var uniqueNameRule = ruleChecker.GetRegisteredRules.FirstOrDefault(x => x.Name == "UniquePPMNames"); foreach (CyPhy.Component c in cyPhyComponentSet) { if (uniqueNameRule != null) { var feedBacks = uniqueNameRule.Check((MgaFCO)c.Impl).ToList(); if (feedBacks.Any(x => x.FeedbackType == FeedbackTypes.Error)) { foreach (var fb in feedBacks.Where(x => x.FeedbackType == FeedbackTypes.Error)) { GMEConsole.Error.WriteLine("Rule {0} failed: {1}", uniqueNameRule.Name, fb.Message); } continue; } } try { ExportComponentPackage(c, OutputDir); i_count++; } catch (ApplicationException ex) { GMEConsole.Error.WriteLine(ex.Message); } catch (Exception ex) { GMEConsole.Error.WriteLine("{0} encountered while exporting {1}: {2}", ex.GetType().Name, c.Name, ex.Message); } } GMEConsole.Info.WriteLine(String.Format("{0} Component(s) exported", i_count)); GMEConsole.Info.WriteLine("Component Exporter finished"); }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // TODO: Add your interpreter code GMEConsole.Info.WriteLine("Running Component Exporter..."); #region Prompt for Output Path GMEConsole.Info.WriteLine("Beginning Export..."); int i_count = 0; HashSet<CyPhy.Component> cyPhyComponentSet = null; if (currentobj != null) { cyPhyComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(currentobj); } else if (selectedobjs != null && selectedobjs.Count > 0) { cyPhyComponentSet = new HashSet<CyPhy.Component>(); foreach (MgaFCO mf in selectedobjs) { cyPhyComponentSet.UnionWith(CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(mf)); } } else { cyPhyComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(project.RootFolder); } if (cyPhyComponentSet.Count == 0) { GMEConsole.Warning.WriteLine("Nothing to export."); return; } // MOT-387: Remember the path used previously string startupPath; if (false == String.IsNullOrWhiteSpace(previousExportPath) && Directory.Exists(previousExportPath)) { startupPath = previousExportPath; } else { startupPath = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); } // Get an output path from the user. if (this.OutputDir == null) { using (META.FolderBrowserDialog fbd = new META.FolderBrowserDialog() { Description = "Choose a path for the generated files.", //ShowNewFolderButton = true, SelectedPath = startupPath, }) { DialogResult dr = fbd.ShowDialog(); if (dr == DialogResult.OK) { OutputDir = fbd.SelectedPath; previousExportPath = OutputDir; } else { GMEConsole.Warning.WriteLine("Component Exporter cancelled"); return; } } } #endregion var ruleChecker = new DesignConsistencyChecker.Framework.Checker(currentobj, project); ruleChecker.RegisterRuleDll("DesignConsistencyChecker.dll"); var uniqueNameRule = ruleChecker.GetRegisteredRules.FirstOrDefault(x => x.Name == "UniquePPMNames"); foreach (CyPhy.Component c in cyPhyComponentSet) { if (uniqueNameRule != null) { var feedBacks = uniqueNameRule.Check((MgaFCO)c.Impl).ToList(); if (feedBacks.Any(x => x.FeedbackType == FeedbackTypes.Error)) { foreach (var fb in feedBacks.Where(x => x.FeedbackType == FeedbackTypes.Error)) { GMEConsole.Error.WriteLine("Rule {0} failed: {1}", uniqueNameRule.Name, fb.Message); } continue; } } try { ExportComponentPackage(c, OutputDir); i_count++; } catch (Exception ex) { Console.Error.WriteLine("{0} encountered while exporting {1}: {2}", ex.GetType().Name, c.Name, ex.Message); } } GMEConsole.Info.WriteLine(String.Format("{0} Component(s) exported", i_count)); GMEConsole.Info.WriteLine("Component Exporter finished"); }
public static int Main(String[] args) { if (args.Length < 1) { Console.Out.WriteLine("Usage: <program> CyPhyMLFile.mga [-f] [outputDirectory]"); Environment.Exit(1); } MgaProject mgaProject = null; string outputDirectory = "."; bool flat = false; for (int ix = 0; ix < args.Length; ++ix) { if (args[ix] == "-f") { flat = true; } else if (mgaProject == null) { mgaProject = GetProject(args[ix]); } else { outputDirectory = args[ix]; } } if (mgaProject == null) { Console.Out.WriteLine("Usage: <program> CyPhyMLFile.mga [-f] [outputDirectory]"); Environment.Exit(1); } MgaGateway mgaGateway = new MgaGateway(mgaProject); bool bExceptionOccurred = false; mgaGateway.PerformInTransaction(delegate { try { CyPhyML.RootFolder cyPhyMLRootFolder = ISIS.GME.Common.Utils.CreateObject <CyPhyMLClasses.RootFolder>(mgaProject.RootFolder); HashSet <CyPhyML.Component> cyPhyMLComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(cyPhyMLRootFolder); var ruleChecker = new DesignConsistencyChecker.Framework.Checker(null, mgaProject); ruleChecker.RegisterRuleDll("DesignConsistencyChecker.dll"); var uniqueNameRule = ruleChecker.GetRegisteredRules.FirstOrDefault(x => x.Name == "UniquePPMNames"); int i_Counter = 1; foreach (var cyPhyMLComponent in cyPhyMLComponentSet) { try { if (uniqueNameRule != null) { var feedBacks = uniqueNameRule.Check((MgaFCO)cyPhyMLComponent.Impl).ToList(); if (feedBacks.Any(x => x.FeedbackType == FeedbackTypes.Error)) { foreach (var fb in feedBacks.Where(x => x.FeedbackType == FeedbackTypes.Error)) { Console.Error.WriteLine("Rule {0} failed: {1}", uniqueNameRule.Name, fb.Message); } continue; } } //foreach (CyPhyML.Component cyPhyMLComponent in cyPhyMLComponentList) { avm.Component avmComponent = CyPhy2ComponentModel.Convert.CyPhyML2AVMComponent(cyPhyMLComponent); string componentPath = null; if (flat) { componentPath = outputDirectory; } else { componentPath = cyPhyMLComponent.Path; componentPath = outputDirectory + "/" + componentPath.Substring(componentPath.IndexOf("/")); } Directory.CreateDirectory(componentPath); if (!flat) { Directory.CreateDirectory(componentPath + "/images"); //Directory.CreateDirectory( componentPath + "/CyPhyML" ); Directory.CreateDirectory(componentPath + "/doc"); Directory.CreateDirectory(componentPath + "/CAD"); } String s_outFilePath = String.Format("{0}/{1}.component.acm", componentPath, Safeify(cyPhyMLComponent.Name)); using (FileStream stream = new FileStream(s_outFilePath, FileMode.Create)) { XSD2CSharp.AvmXmlSerializer.Serialize(avmComponent, stream); stream.Close(); } Console.Out.WriteLine(string.Format("({0}/{1}) {2}", i_Counter++, cyPhyMLComponentSet.Count, Safeify(cyPhyMLComponent.Name))); //} } catch (Exception ex) { Console.Error.WriteLine("Exception: {0}", ex.Message.ToString()); Console.Error.WriteLine("Stack: {0}", ex.StackTrace.ToString()); bExceptionOccurred = true; } } } catch (Exception ex) { Console.Error.WriteLine("Exception: {0}", ex.Message.ToString()); Console.Error.WriteLine("Stack: {0}", ex.StackTrace.ToString()); bExceptionOccurred = true; } }, abort: false); mgaProject.Close(); if (bExceptionOccurred) { return(-1); } return(0); }