コード例 #1
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");
        }
コード例 #2
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;
            }

            // 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");			
        }
コード例 #3
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            Boolean disposeLogger = false;

            if (Logger == null)
            {
                Logger        = new CyPhyGUIs.GMELogger(project, "CyPhyDesignExporter");
                disposeLogger = true;
            }

            // TODO: Add your interpreter code
            Logger.WriteInfo("Running Design Exporter...");

            #region Prompt for Output Path
            // 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 = Environment.CurrentDirectory,
                })
                {
                    DialogResult dr = fbd.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        OutputDir = fbd.SelectedPath;
                    }
                    else
                    {
                        Logger.WriteWarning("Design Exporter cancelled");
                        return;
                    }
                }
            }
            #endregion

            Logger.WriteInfo("Beginning Export...");
            List <CyPhy.DesignEntity>  lde_allCAandDC = new List <CyPhy.DesignEntity>();
            List <CyPhy.TestBenchType> ltbt_allTB     = new List <CyPhy.TestBenchType>();

            if (currentobj != null &&
                currentobj.Meta.Name == "ComponentAssembly")
            {
                lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(currentobj));
            }
            else if (currentobj != null &&
                     currentobj.Meta.Name == "DesignContainer")
            {
                lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(currentobj));
            }
            else if (currentobj != null &&
                     IsTestBenchType(currentobj.MetaBase.Name))
            {
                ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(currentobj));
            }
            else if (selectedobjs != null && selectedobjs.Count > 0)
            {
                foreach (MgaFCO mf in selectedobjs)
                {
                    if (mf.Meta.Name == "ComponentAssembly")
                    {
                        lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(mf));
                    }
                    else if (mf.Meta.Name == "DesignContainer")
                    {
                        lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(mf));
                    }
                    else if (IsTestBenchType(mf.MetaBase.Name))
                    {
                        ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(mf));
                    }
                }
            }
            else
            {
                CyPhy.RootFolder rootFolder = ISIS.GME.Common.Utils.CreateObject <CyPhyClasses.RootFolder>(project.RootFolder as MgaObject);

                MgaFilter filter = project.CreateFilter();
                filter.Kind = "ComponentAssembly";
                foreach (var item in project.AllFCOs(filter).Cast <MgaFCO>())
                {
                    if (item.ParentFolder != null)
                    {
                        lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(item));
                    }
                }

                filter      = project.CreateFilter();
                filter.Kind = "DesignContainer";
                foreach (var item in project.AllFCOs(filter).Cast <MgaFCO>())
                {
                    if (item.ParentFolder != null)
                    {
                        lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(item));
                    }
                }

                filter      = project.CreateFilter();
                filter.Kind = "TestBenchType";
                foreach (var item in project.AllFCOs(filter).Cast <MgaFCO>())
                {
                    if (item.ParentFolder != null)
                    {
                        ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(item));
                    }
                }
            }

            foreach (CyPhy.DesignEntity de in lde_allCAandDC)
            {
                System.Windows.Forms.Application.DoEvents();
                try
                {
                    if (de is CyPhy.ComponentAssembly)
                    {
                        ExportToPackage(de as CyPhy.ComponentAssembly, OutputDir);
                    }
                    else
                    {
                        ExportToFile(de, OutputDir);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteError("{0}: Exception encountered ({1})", de.Name, ex.Message);
                }
                Logger.WriteInfo("{0}: {1}", de.Name, OutputDir);
            }

            foreach (CyPhy.TestBenchType tbt in ltbt_allTB)
            {
                System.Windows.Forms.Application.DoEvents();
                try
                {
                    ExportToFile(tbt, OutputDir);
                }
                catch (Exception ex)
                {
                    Logger.WriteError("{0}: Exception encountered ({1})", tbt.Name, ex.Message);
                }
                Logger.WriteInfo("{0}: {1}", tbt.Name, OutputDir);
            }

            Logger.WriteInfo(String.Format("{0} model(s) exported", lde_allCAandDC.Count + ltbt_allTB.Count));
            Logger.WriteInfo("Design Exporter finished");

            if (disposeLogger)
            {
                DisposeLogger();
            }
        }
コード例 #4
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            Boolean disposeLogger = false;
            if (Logger == null)
            {
                Logger = new CyPhyGUIs.GMELogger(project, "CyPhyDesignExporter");
                disposeLogger = true;
            }

            // TODO: Add your interpreter code
            Logger.WriteInfo("Running Design Exporter...");

            #region Prompt for Output Path
            // 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 = Environment.CurrentDirectory,
                })
                {

                    DialogResult dr = fbd.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        OutputDir = fbd.SelectedPath;
                    }
                    else
                    {
                        Logger.WriteWarning("Design Exporter cancelled");
                        return;
                    }
                }
            }
            #endregion

            Logger.WriteInfo("Beginning Export...");
            List<CyPhy.DesignEntity> lde_allCAandDC = new List<CyPhy.DesignEntity>();
            List<CyPhy.TestBenchType> ltbt_allTB = new List<CyPhy.TestBenchType>();
            
            if (currentobj != null && 
                currentobj.Meta.Name == "ComponentAssembly")
            {
                lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(currentobj));
            }
            else if (currentobj != null &&
                     currentobj.Meta.Name == "DesignContainer")
            {
                lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(currentobj));
            }
            else if (currentobj != null &&
                IsTestBenchType(currentobj.MetaBase.Name))
            {
                ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(currentobj));
            }
            else if (selectedobjs != null && selectedobjs.Count > 0)
            {
                foreach (MgaFCO mf in selectedobjs)
                {
                    if (mf.Meta.Name == "ComponentAssembly")
                    {
                        lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(mf));
                    }
                    else if (mf.Meta.Name == "DesignContainer")
                    {
                        lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(mf));
                    }
                    else if (IsTestBenchType(mf.MetaBase.Name))
                    {
                        ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(mf));
                    }
                }
            }
            else
            {
                CyPhy.RootFolder rootFolder = ISIS.GME.Common.Utils.CreateObject<CyPhyClasses.RootFolder>(project.RootFolder as MgaObject);

                MgaFilter filter = project.CreateFilter();
                filter.Kind = "ComponentAssembly";
                foreach (var item in project.AllFCOs(filter).Cast<MgaFCO>())
                {
                    if (item.ParentFolder != null)
                    {
                        lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(item));
                    }
                }

                filter = project.CreateFilter();
                filter.Kind = "DesignContainer";
                foreach (var item in project.AllFCOs(filter).Cast<MgaFCO>())
                {
                    if (item.ParentFolder != null)
                    {
                        lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(item));
                    }
                }

                filter = project.CreateFilter();
                filter.Kind = "TestBenchType";
                foreach (var item in project.AllFCOs(filter).Cast<MgaFCO>())
                {
                    if (item.ParentFolder != null)
                    {
                        ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(item));
                    }
                }
            }

            foreach (CyPhy.DesignEntity de in lde_allCAandDC)
            {
                System.Windows.Forms.Application.DoEvents();
                try
                {
                    if (de is CyPhy.ComponentAssembly)
                    {
                        ExportToPackage(de as CyPhy.ComponentAssembly, OutputDir);
                    }
                    else
                    {
                        ExportToFile(de, OutputDir);
                    }
                } 
                catch (Exception ex) 
                {
                    Logger.WriteError("{0}: Exception encountered ({1})",de.Name,ex.Message);
                }
                Logger.WriteInfo("{0}: {1}", de.Name, OutputDir);
            }

            foreach (CyPhy.TestBenchType tbt in ltbt_allTB)
            {
                System.Windows.Forms.Application.DoEvents();
                try
                {
                    ExportToFile(tbt, OutputDir);
                }
                catch (Exception ex)
                {
                    Logger.WriteError("{0}: Exception encountered ({1})", tbt.Name, ex.Message);
                }
                Logger.WriteInfo("{0}: {1}", tbt.Name, OutputDir);
            }

            Logger.WriteInfo(String.Format("{0} model(s) exported", lde_allCAandDC.Count + ltbt_allTB.Count));
            Logger.WriteInfo("Design Exporter finished");

            if (disposeLogger)
            {
                DisposeLogger();
            }
        }