public static string Header(GME.MGA.MgaProject project = null) { StringBuilder logFileHeader = new StringBuilder(); logFileHeader.AppendLine("=== HEADER ==================================================="); logFileHeader.AppendLine(string.Format("Date/Time: {0}", DateTime.Now)); logFileHeader.AppendLine(string.Format("Windows Version: {0}", System.Environment.OSVersion.VersionString)); logFileHeader.AppendLine(string.Format("x64 bit OS: {0}", System.Environment.Is64BitOperatingSystem)); logFileHeader.AppendLine(string.Format("GME version: {0}", META.VersionInfo.GmeVersion)); logFileHeader.AppendLine(string.Format("META version: {0}", META.VersionInfo.MetaVersion)); logFileHeader.AppendLine(string.Format("META install: {0}", META.VersionInfo.MetaPath)); logFileHeader.AppendLine(string.Format("CyPhyML version: {0}", META.VersionInfo.CyPhyML)); logFileHeader.AppendLine(string.Format("CyPhyML GUID: {0}", META.VersionInfo.CyPhyMLGuid)); logFileHeader.AppendLine(string.Format("Python Dll: {0}", META.VersionInfo.PythonVersion)); logFileHeader.AppendLine(string.Format("Python Exe: {0}", META.VersionInfo.PythonExe)); logFileHeader.AppendLine(string.Format("Python27 VE exe: {0}", META.VersionInfo.PythonVEnvExe)); logFileHeader.AppendLine(string.Format("PROE ISIS Ext. : {0}", META.VersionInfo.ProeISISExtPath)); logFileHeader.AppendLine(string.Format("PROE ISIS ver. : {0}", META.VersionInfo.ProeISISExtVer)); logFileHeader.AppendLine(string.Format("Username: {0}", Environment.UserName)); logFileHeader.AppendLine("Currently opened paradigm information"); if (project != null) { bool transactionAlreadyOpen = (project.ProjectStatus & 8) == 0; try { if (transactionAlreadyOpen) { project.BeginTransactionInNewTerr(); } logFileHeader.AppendLine(string.Format(" MetaName : {0}", project.MetaName)); logFileHeader.AppendLine(string.Format(" MetaVersion : {0}", project.MetaVersion)); //logFileHeader.AppendLine(string.Format(" MetaGuid : {0}", ByteArrayToString((project.MetaGUID as IEnumerable<byte>).ToList()))); } finally { if (transactionAlreadyOpen) { project.AbortTransaction(); } } } else { logFileHeader.AppendLine(string.Format(" Not available.")); } return logFileHeader.ToString(); }
public static void AddFileListener(string loggingFileName, string name, GME.MGA.MgaProject project = null) { if (string.IsNullOrWhiteSpace(name)) { name = System.Reflection.Assembly.GetExecutingAssembly().FullName; } if (string.IsNullOrWhiteSpace(loggingFileName)) { // get temp path and temp file name loggingFileName = System.IO.Path.GetTempPath() + System.Reflection.Assembly.GetExecutingAssembly().FullName + ".trace.txt"; } loggingFileName = Path.GetFullPath(loggingFileName); var dirName = Path.GetDirectoryName(loggingFileName); if (Directory.Exists(dirName) == false) { Directory.CreateDirectory(dirName); } if (LoggingFiles.Keys.Contains(loggingFileName) == false) { // set up tracing // print header and version info var fs = new FileStream(loggingFileName, FileMode.Create); TraceListener fileTL = new TextWriterTraceListener(fs) { //TraceOutputOptions = TraceOptions.DateTime, Name = name, }; // use TraceXXX to get timestamp per http://stackoverflow.com/questions/863394/add-timestamp-to-trace-writeline Trace.AutoFlush = true; Trace.Listeners.Add(fileTL); LoggingFiles.Add(loggingFileName, fileTL); Trace.TraceInformation("{0} trace file listener was created.", loggingFileName); Trace.TraceInformation("{0}", Header(project)); } else { Console.WriteLine("{0} already exists for logging.", loggingFileName); } }
public ComponentInfo(GME.MGA.IMgaFCO gmeObject, string modelType = null, CyPhyCOMInterfaces.IMgaTraceability traceability = null) { this.Name = gmeObject.Name; this.AbsPath = gmeObject.AbsPath; this.ID = gmeObject.ID; this.Path = this.GetPath(); this.Kind = gmeObject.Meta.Name; this.ModelType = modelType; if (this.Kind == typeof(CyPhy.Component).Name) { var component = CyPhyClasses.Component.Cast(gmeObject); this.AVMID = component.Attributes.AVMID; } if (traceability != null) { string id = string.Empty; if (traceability.TryGetMappedObject(gmeObject.ID, out id)) { GME.MGA.MgaFCO baseComponent = gmeObject.Project.GetFCOByID(id); if (baseComponent != null) { if (baseComponent.Status == 1) { // object is already deleted // try to get it in a different way. var idChain = gmeObject.RegistryValue["Elaborator/ID_Chain"]; if (string.IsNullOrWhiteSpace(idChain) == false) { id = idChain.Split(new char[] { ',' }).LastOrDefault(); if (id != null) { baseComponent = gmeObject.Project.GetFCOByID(id); if (baseComponent != null) { this.Reference = new ComponentInfo(baseComponent, modelType); } } } } else { this.Reference = new ComponentInfo(baseComponent, modelType); } } } } }
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; }
/// <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(); string currentDir = Environment.CurrentDirectory; Directory.SetCurrentDirectory(outputDirectory); string avmProjFileName = Path.GetFullPath(Path.Combine(outputDirectory, "manifest.project.json")); if (File.Exists(avmProjFileName)) { string sjson = "{}"; using (StreamReader reader = new StreamReader(avmProjFileName)) { sjson = reader.ReadToEnd(); avmProj = JsonConvert.DeserializeObject<AVM.DDP.MetaAvmProject>(sjson); } } if (console != null) { avmProj.infoTextWriter = console.Info; avmProj.errorTextWriter = console.Error; } 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) { 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); avmProj.infoTextWriter.WriteLine(msg); } } avmProj.Project.Requirements.vfLink = reqSourceRepository; avmProj.Project.Requirements.id = reqId; avmProj.Project.Requirements.text = reqText; string dirName = Path.GetFullPath(Path.Combine(outputDirectory, "requirements")); if (Directory.Exists(dirName) == false) { Directory.CreateDirectory(dirName); string requFileName = Path.GetFullPath(Path.Combine(dirName, "requirements.json")); 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)); if (Directory.Exists(dirName) == false) { Directory.CreateDirectory(dirName); } if (rootDS != null) { // export designspace var dsProjectJsonLink = Path.Combine(".", designSpaceFolder, rootDS.Name + ".metadesign.json").Replace('\\', '/'); var dsFileName = Path.Combine(dirName, rootDS.Name + ".metadesign.json"); 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); string d = design.SerializeToFile(Path.GetFullPath(dsFileName)); } Directory.SetCurrentDirectory(currentDir); return avmProj; }
private bool CAHasDyanmicConnectors(GME.MGA.IMgaFCO mgaCA) { bool hasDynamicConnectors = false; if (string.IsNullOrWhiteSpace(mgaCA.RegistryValue["hasConn"])) { var ca = CyPhyClasses.ComponentAssembly.Cast(mgaCA); //hasDynamicConnectors = ca.Children.ConnectorCollection.Where(c => c.Children.ModelicaConnectorCollection.Any()).Any() || // ca.Children.ModelicaConnectorCollection.Any(); // // For now treat all ComponentAssemblies as Dynamic one hasDynamicConnectors = true; } else { hasDynamicConnectors = mgaCA.RegistryValue["hasConn"] == "1"; } return hasDynamicConnectors; }
private bool ComponentHasDynamicConnections(GME.MGA.IMgaFCO mgaComponent) { var component = CyPhyClasses.Component.Cast(mgaComponent); var modelicaModel = this.GetModelicaModelFromComponent(component); if (modelicaModel == null) { return false; } foreach (var mc in modelicaModel.Children.ModelicaConnectorCollection) { if (mc.DstConnections.PortCompositionCollection.Any() || mc.SrcConnections.PortCompositionCollection.Any()) { return true; } } return false; }
private void SetDynamicModelFlag(GME.MGA.IMgaFCO context, bool value) { context.RegistryValue["isDynamicModel"] = value ? "1" : "0"; }
private bool GetDynamicModelFlag(GME.MGA.IMgaFCO context) { bool isDynamic = false; if (string.IsNullOrWhiteSpace(context.RegistryValue["isDynamicModel"])) { context.RegistryValue["isDynamicModel"] = "0"; } isDynamic = context.RegistryValue["isDynamicModel"] == "1"; return isDynamic; }
private void PropagateDynamicFlagRec(GME.MGA.MgaModel ca) { foreach (GME.MGA.MgaModel child in ca.GetChildrenOfKind(typeof(CyPhy.ComponentAssembly).Name)) { if (this.GetDynamicModelFlag(child)) { this.PropagateDynamicFlagRec(child); } else { var filter = this.MainParameters.Project.CreateFilter(); filter.Kind = typeof(CyPhy.Component).Name; foreach (GME.MGA.IMgaFCO c in child.GetDescendantFCOs(filter)) { this.SetDynamicModelFlag(c, false); } filter.Kind = typeof(CyPhy.ComponentAssembly).Name; foreach (GME.MGA.IMgaFCO c in child.GetDescendantFCOs(filter)) { this.SetDynamicModelFlag(c, false); } } } }
private void PrintDynamicFlagStatusRec(GME.MGA.MgaModel ca, int level = 1) { foreach (GME.MGA.MgaModel child in ca.GetChildrenOfKind(typeof(CyPhy.ComponentAssembly).Name)) { if (this.GetDynamicModelFlag(child)) { this.Logger.WriteDebug("<b>{0} {1}</b>", new String('-', level), child.Name); } else { this.Logger.WriteDebug("{0} {1}", new String('-', level), child.Name); } this.PrintDynamicFlagStatusRec(child, level + 1); } foreach (GME.MGA.MgaModel child in ca.GetChildrenOfKind(typeof(CyPhy.Component).Name)) { if (this.GetDynamicModelFlag(child)) { this.Logger.WriteDebug("<b>{0} {1}</b>", new String('-', level), child.Name); } else { this.Logger.WriteDebug("{0} {1}", new String('-', level), child.Name); } } }
public static GMEConsole CreateFromProject(GME.MGA.MgaProject project) { GMEConsole console = new GMEConsole(); try { // Initializing console console.gme = (IGMEOLEApp)project.GetClientByName("GME.Application").OLEServer; } catch (System.Runtime.InteropServices.COMException ex) { // if GME is not present, the interpreter is called from standalone test application if (ex.ErrorCode != -2023423888) // HResult 0x87650070: "Search by name failed" { throw; } console.gme = null; } return console; }
private static IEnumerable<RuleFeedbackBase> checkModelicaModelURI(GME.MGA.MgaFCO mgaModelicaModel) { var result = new List<RuleFeedbackBase>(); string[] splitURI = null; string modelicaClass = mgaModelicaModel.GetStrAttrByNameDisp("Class"); splitURI = modelicaClass.Split('.'); int pathLength = splitURI.Length; // URI must have at least 2 classes, i.e., AttachedLib.Model, (3 might be better) if (splitURI.Length < 2) { var feedback = new GenericRuleFeedback() { FeedbackType = FeedbackTypes.Error, Message = string.Format("{0}: 'Class' attribute {1} should refer to a model within the attached package (path is too short or empty)", mgaModelicaModel.Name, modelicaClass) }; feedback.InvolvedObjectsByRole.Add(mgaModelicaModel); result.Add(feedback); return result; } getExternalPackageNames(mgaModelicaModel); if (externalPackageNames.Contains(splitURI[0]) == false) { var feedback = new GenericRuleFeedback() { FeedbackType = FeedbackTypes.Error, Message = string.Format("{0}: the first element in the 'Class' attribute {1} should refer to an attached package", mgaModelicaModel.Name, modelicaClass) }; feedback.InvolvedObjectsByRole.Add(mgaModelicaModel); result.Add(feedback); return result; } string badCharacters = null; foreach (string name in splitURI) { string additionalBadChars = checkForInvalidCharacters(name); if (string.IsNullOrEmpty(additionalBadChars) == false) { badCharacters = badCharacters + additionalBadChars; } if (name.Length > 0 && char.IsDigit(name[0])) { var feedback = new GenericRuleFeedback() { FeedbackType = FeedbackTypes.Error, Message = string.Format( "{0} has an invalid Class {1}; Classes must not begin with a digit", mgaModelicaModel.Name, modelicaClass) }; feedback.InvolvedObjectsByRole.Add(mgaModelicaModel); result.Add(feedback); return result; } } if (badCharacters != null && badCharacters != "") { var feedback = new GenericRuleFeedback() { FeedbackType = FeedbackTypes.Error, Message = string.Format( "{0} - Class field contains invalid characters: {1}", mgaModelicaModel.Name, badCharacters) }; feedback.InvolvedObjectsByRole.Add(mgaModelicaModel); result.Add(feedback); } return result; }
public virtual void GetPortLocation(GME.MGA.MgaFCO fco, out int sx, out int sy, out int ex, out int ey) { sx = sy = ex = ey = 0; // By default we don't support ports }