Esempio n. 1
0
        public void InvokeEx2(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            string projectPath   = Path.GetDirectoryName(project.ProjectConnStr.Substring(4)); // skip mga=
            string projectName   = Path.GetFileNameWithoutExtension(project.ProjectConnStr.Substring(4));
            string cyphyFilename = project.ProjectConnStr.Substring(4);

            baseOutputDir = Path.Combine(projectPath, projectName + "_PRISMATIC");
            GME.CSharp.GMEConsole console = GME.CSharp.GMEConsole.CreateFromProject(project);
            console.Out.WriteLine("Output directory is " + baseOutputDir);

            META_PATH = GetMetaPathValue();
            if (!Directory.Exists(META_PATH))
            {
                throw new ApplicationException("META_PATH='" + META_PATH + "' doesn't exist. Please install the META toolchain and restart GME.");
            }

            string metaPath = Path.Combine(META_PATH, "meta");

            if (!Directory.Exists(metaPath))
            {
                throw new ApplicationException(metaPath + " doesn't exist");
            }

            ensureDir(baseOutputDir);

            string CyPhyML_udm_xml_path = Path.Combine(metaPath, "CyPhyML_udm.xml");

            if (!File.Exists(CyPhyML_udm_xml_path))
            {
                CyPhyML_udm_xml_path = Path.Combine(metaPath, @"..\generated\CyPhyML\models\CyPhyML_udm.xml");
            }
            string CyPhyML_xsd_path = Path.Combine(metaPath, "CyPhyML.xsd");

            if (!File.Exists(CyPhyML_xsd_path))
            {
                CyPhyML_xsd_path = Path.Combine(metaPath, @"..\generated\CyPhyML.xsd");
            }


            console.Out.WriteLine("Extracting XML model...");
            runProgram(Path.Combine(metaPath, @"..\bin\UdmCopy.exe"), new string[] {
                "-f",
                cyphyFilename,
                Path.Combine(baseOutputDir, projectName + ".xml"),
                CyPhyML_udm_xml_path,
                CyPhyML_xsd_path
            });

            console.Out.WriteLine("Generating Prismatic files...");
            runProgram("C:\\Python26\\python.exe", new string[] { META_PATH + "\\bin\\Prismatic\\" + "cmc.py", Path.Combine(baseOutputDir, projectName + ".xml"), baseOutputDir });
            console.Out.WriteLine("Running Prismatic...");
            runProgram("C:\\Python27\\python.exe", new string[] { baseOutputDir + "\\prismatic.py" });
            console.Out.WriteLine("Prismatic work done.");
        }
Esempio n. 2
0
        public void DumpLog(GME.CSharp.GMEConsole console, string path, Severity filelevel = Severity.Normal, Severity consolelevel = Severity.Normal)
        {
            if (fileMessages.Count > 0)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(Path.Combine(path, LogFileName)))
                {
                    foreach (string item in fileMessages)
                    {
                        file.WriteLine(item);
                    }
                }
            }

            foreach (Message item in consoleMessages)
            {
                Severity level = item.Level;
                string   msg   = item.Content;
                if (level == Severity.Error)
                {
                    console.Error.WriteLine(msg);
                }
                else if (level == Severity.Info)
                {
                    console.Info.WriteLine(msg);
                }
                else if (level == Severity.Warning)
                {
                    console.Warning.WriteLine(msg);
                }
                else
                {
                    console.Out.WriteLine(msg);
                }
            }

            fileMessages.RemoveRange(0, fileMessages.Count());
            consoleMessages.RemoveRange(0, consoleMessages.Count());
            ErrorCnt   = 0;
            WarningCnt = 0;
        }
Esempio n. 3
0
        /// <summary>
        /// Call this function within a transaction!
        /// </summary>
        /// <param name="outputDirectory"></param>
        /// <param name="project"></param>
        /// <param name="rootDS"></param>
        /// <param name="textWriter"></param>
        /// <returns></returns>
        public static MetaAvmProject Create(
            string outputDirectory,
            MgaProject project            = null,
            MgaModel rootDS               = null,
            GME.CSharp.GMEConsole console = null
            )
        {
            MetaAvmProject avmProj = new MetaAvmProject();

            outputDirectory = Path.GetFullPath(outputDirectory);
            Directory.CreateDirectory(outputDirectory);

            string avmProjFileName = Path.GetFullPath(Path.Combine(outputDirectory, "manifest.project.json"));

            using (new MutexWrapper(avmProjFileName))
            {
                if (File.Exists(avmProjFileName))
                {
                    string sjson = "{}";
                    using (StreamReader reader = new StreamReader(avmProjFileName))
                    {
                        sjson = reader.ReadToEnd();

                        try
                        {
                            avmProj = JsonConvert.DeserializeObject <AVM.DDP.MetaAvmProject>(sjson);
                        }
                        catch (Newtonsoft.Json.JsonReaderException ex)
                        {
                            throw new Exception(string.Format("{0} file is probably malformed. Not a valid json. {1}{2}", Path.GetFullPath(avmProjFileName), Environment.NewLine, ex.Message));
                        }
                    }
                }
            }

            if (console != null)
            {
                avmProj.infoTextWriter  = console.Info;
                avmProj.errorTextWriter = console.Error;
            }

            avmProj.OutputDirectory = outputDirectory;
            avmProj.m_filename      = avmProjFileName;


            avmProj.Project.LastModified = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

            if (avmProj.Project.Results.UrlHints.Contains("./results/results.metaresults.json") == false)
            {
                avmProj.Project.Results.UrlHints.Add("./results/results.metaresults.json");
            }

            if (avmProj.Project.Requirements.UrlHints.Contains("./requirements/requirements.json") == false)
            {
                avmProj.Project.Requirements.UrlHints.Add("./requirements/requirements.json");
            }

            string reqSourceRepository = string.Empty;
            string reqId   = string.Empty;
            string reqText = string.Empty;

            if (project != null)
            {
                avmProj.Project.CyPhyProjectFileName = MgaExtensions.MgaExtensions.GetProjectName(project);

                CyPhy.RootFolder rf = ISIS.GME.Dsml.CyPhyML.Classes.RootFolder.GetRootFolder(project);

                var topLevelLinks = rf.Children.RequirementsCollection
                                    .SelectMany(x => x.Children.RequirementLinkCollection);

                var defaults   = topLevelLinks.Where(x => x.Name.ToLowerInvariant() == "default");
                var reqDefault = defaults.FirstOrDefault();
                if (defaults.Count() > 1)
                {
                    // more requ found first one will be used
                    string msg = string.Format("More than one Requirement was not found {0} in use.", reqDefault.Impl.AbsPath);
                    Trace.TraceWarning(msg);
                    avmProj.infoTextWriter.WriteLine(msg);
                }

                if (reqDefault != null)
                {
                    reqSourceRepository = reqDefault.Attributes.SourceRepository;
                    reqId   = reqDefault.Attributes.ID;
                    reqText = reqDefault.Attributes.Text;
                }
                else
                {
                    // requ not found
                    string msg = "Requirement was not found.";
                    Trace.TraceWarning(msg);

                    // RESTORE THIS MESSAGE ONCE WE SWITCH TO USING GMELOGGER
                    // avmProj.infoTextWriter.WriteLine(msg);
                }
            }

            avmProj.Project.Requirements.vfLink = reqSourceRepository;
            avmProj.Project.Requirements.id     = reqId;
            avmProj.Project.Requirements.text   = reqText;

            string dirName = Path.Combine(outputDirectory, "requirements");

            if (Directory.Exists(dirName) == false)
            {
                Directory.CreateDirectory(dirName);
                string requFileName = Path.GetFullPath(Path.Combine(dirName, "requirements.json"));

                using (new MutexWrapper(requFileName))
                {
                    if (File.Exists(requFileName) == false)
                    {
                        using (StreamWriter writer = new StreamWriter(requFileName))
                        {
                            // default requirement
                            writer.WriteLine(@"{");
                            writer.WriteLine("    \"name\": \"Undefined\",");
                            writer.WriteLine("    \"children\": []");
                            writer.WriteLine(@"}");
                        }
                    }
                }
            }

            string designSpaceFolder = "design-space";

            dirName = Path.GetFullPath(Path.Combine(outputDirectory, designSpaceFolder));

            Directory.CreateDirectory(dirName);

            if (rootDS != null)
            {
                // export designspace
                var dsProjectJsonLink = Path.Combine(".", designSpaceFolder, rootDS.Name + ".adm").Replace('\\', '/');
                var dsFileName        = Path.Combine(dirName, rootDS.Name + ".adm");

                if (avmProj.Project.DesignSpaceModels.Contains(dsProjectJsonLink) == false)
                {
                    avmProj.Project.DesignSpaceModels.Add(dsProjectJsonLink);
                }
                var designContainer = ISIS.GME.Dsml.CyPhyML.Classes.DesignContainer.Cast(rootDS);
                var design          = CyPhy2DesignInterchange.CyPhy2DesignInterchange.Convert(designContainer);
                using (new MutexWrapper(dsFileName))
                {
                    design.SaveToFile(dsFileName);
                }
            }

            return(avmProj);
        }