/// <summary> /// Creates a unique folder, used for storing component resources, under the project's "components" folder. /// This operation DOES NOT assign the folder to any component; /// Consider using EnsureComponentDirectory(...) for this purpose. /// </summary> /// <param name="projectPath">The CyPhy MGA project</param> /// <returns>The absolute path of the new folder</returns> public static String CreateComponentFolder(IMgaProject project) { String p_ComponentsDir = Path.Combine(project.GetRootDirectoryPath(), ComponentsFolderName); // No entry exists. Make a folder and also an entry. String s_RandomFolderName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); String p_NewComponentDir = Path.Combine(p_ComponentsDir, s_RandomFolderName); int maxFolders = 0; while (File.Exists(p_NewComponentDir) || Directory.Exists(p_NewComponentDir)) { if (maxFolders++ > 2000000) { throw new Exception( string.Format("Number of tries ({0}) to create an output folder exceeded in {0}. ", maxFolders, p_ComponentsDir)); } s_RandomFolderName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); p_NewComponentDir = Path.Combine( p_ComponentsDir, s_RandomFolderName); } Directory.CreateDirectory(p_NewComponentDir); return(p_NewComponentDir); }
public IMgaFCO ImportDesign(IMgaProject project, string filename) { var importer = new AVMDesignImporter(null, project); var result = importer.ImportFile(filename); return((IMgaFCO)result.Impl); }
public IMgaFCO ImportDesignToComponentAssembly(IMgaProject project, string filename) { var importer = new AVMDesignImporter(null, project); var result = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CAS); return((IMgaFCO)result.Impl); }
/* * returns: ComponentAssembly if the design contains no design space concepts */ public IMgaFCO ImportDesignToDesignSpaceIfApplicable(IMgaProject project, string filename) { var importer = new AVMDesignImporter(null, project); var result = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS); return((IMgaFCO)result.Impl); }
private IEnumerable <CyPhy.ComponentAssembly> GetAllComponentAssemblys(IMgaProject project, bool includeLibraries = false) { var filter = project.CreateFilter(); filter.Kind = "ComponentAssembly"; int componentsId = project.RootMeta.RootFolder.GetDefinedFolderByNameDisp("Components", true).MetaRef; int componentAssembliesId = project.RootMeta.RootFolder.GetDefinedFolderByNameDisp("ComponentAssemblies", true).MetaRef; IEnumerable <MgaFolder> rootFolders = new MgaFolder[] { project.RootFolder }; if (includeLibraries) { rootFolders = rootFolders.Concat( project.RootFolder.ChildFolders.Cast <MgaFolder>().Where(f => String.IsNullOrEmpty(f.LibraryName) == false)); } foreach (MgaFolder rootFolder in rootFolders) { foreach (MgaFolder folder in rootFolder.ChildFolders) { int metaRef = folder.MetaBase.MetaRef; if (metaRef == componentsId || metaRef == componentAssembliesId) { foreach (IMgaObject fco in folder.GetDescendantFCOs(filter)) { yield return(CyPhyClasses.ComponentAssembly.Cast(fco)); } } } } }
public void FormulaTest() { var xmePath = Path.Combine(_exportModelDirectory, "FormulaTest", "InputModel.xme"); string mgaFilename = unpackXme(xmePath); IMgaProject project = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject")); project.OpenEx("MGA=" + mgaFilename, "CyPhyML", null); try { project.BeginTransactionInNewTerr(); try { MgaFCO fco = (MgaFCO)project.RootFolder.ObjectByPath["/@Imported_Components/@FormulaComp"]; Exception e = Assert.Throws(typeof(ApplicationException), () => CyPhyComponentExporter.CyPhyComponentExporterInterpreter.ExportComponentPackage(ISIS.GME.Dsml.CyPhyML.Classes.Component.Cast(fco))); Assert.True(e.Message.Contains("Value assignments for Component Parameters must come from outside the Component itself.")); fco = (MgaFCO)project.RootFolder.ObjectByPath["/@ComponentAssemblies/@ComponentAssembly/@Component"]; CyPhyComponentExporter.CyPhyComponentExporterInterpreter.ExportComponentPackage(ISIS.GME.Dsml.CyPhyML.Classes.Component.Cast(fco)); } finally { project.AbortTransaction(); } } finally { project.Close(true); } }
public LibraryInfo(string mga, string display, Action f, IMgaProject project, System.Windows.Forms.Control control) { mgaName = mga; displayName = display; this.callback = f; this.project = project; this.control = control; }
public void ExportAllComponents(IMgaProject project, String outputDirectory) { var cyPhyComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(project.RootFolder); foreach (var component in cyPhyComponentSet) { var avmComponentModel = CyPhyML2AVM.AVMComponentBuilder.CyPhyML2AVM(component); var safe_component_name = InvalidFileNameRegex.Replace(component.Name, "_"); SerializeAvmComponent(avmComponentModel, Path.Combine(outputDirectory, safe_component_name + ".acm")); } }
public static String GetProjectDirectoryPath(this IMgaProject project) { if (project.ProjectConnStr.StartsWith("MGA=")) { return(Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length))); } else { var mgx = project.ProjectConnStr.Substring("MGX=\"".Length); return(mgx.Substring(0, mgx.IndexOf("\""))); } }
public void ExportAllComponents(IMgaProject project, String outputDirectory) { HashSet <string> avm_ids = new HashSet <string>(); HashSet <string> safe_names = new HashSet <string>(); var cyPhyComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(project.RootFolder); foreach (var component in cyPhyComponentSet) { var avmComponentModel = CyPhyML2AVM.AVMComponentBuilder.CyPhyML2AVM(component); var safe_component_name = InvalidFileNameRegex.Replace(component.Name, "_"); if (avm_ids.Add(avmComponentModel.ID) == false) { throw new ApplicationException(String.Format("Duplicate ID '{0}'", avmComponentModel.ID)); } if (safe_names.Add(safe_component_name) == false) { safe_component_name += avmComponentModel.ID; } SerializeAvmComponent(avmComponentModel, Path.Combine(outputDirectory, safe_component_name + ".acm")); } }
private void performInROTransaction(IMgaProject project, voidDelegate d) { IMgaTerritory territory = project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_READ_ONLY); try { d(); } finally { try { project.AbortTransaction(); } catch { } try { territory.Destroy(); } catch { } } }
public MgaGateway(IMgaProject project) { this.project = project; }
/// <summary> /// Get the absolute path to the root directory of a CyPhy project. /// </summary> /// <param name="project"></param> /// <returns></returns> public static String GetProjectRootPath(IMgaProject project) { return MgaExtensions.MgaExtensions.GetProjectDirectoryPath(project); }
private static Statistics.Statistics Process(IMgaProject project) { Statistics.Statistics stats = new Statistics.Statistics(); if (project == null) { GenerateDummyData(stats); return(stats); } try { IMgaTerritory terr = project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_READ_ONLY); // process meta model stats.ParadigmName = project.MetaName; stats.ProjectName = project.Name; stats.MetaModel.RootGUID = GetGUIDFromInt(project.RootMeta.RootFolder.MetaRef); var rfTree = new Dictionary <string, object>(); stats.Model.ContainmentTree[stats.MetaModel.RootGUID] = rfTree; foreach (MgaMetaAttribute attr in project.RootMeta.RootFolder.DefinedAttributes) { string attrType = attr.ValueType.ToString(); int num = 0; if (stats.MetaModel.Attributes.TryGetValue(attrType, out num)) { stats.MetaModel.Attributes[attrType] = num + 1; } else { stats.MetaModel.Attributes[attrType] = 1; } } foreach (MgaMetaFCO meta in project.RootMeta.RootFolder.DefinedFCOs) { rfTree[GetGUIDFromInt(meta.MetaRef)] = new Dictionary <string, object>(); if (meta is MgaMetaModel) { stats.MetaModel.NumberOfModels += 1; } else if (meta is MgaMetaConnection) { stats.MetaModel.NumberOfConnections += 1; } else if (meta is MgaMetaSet) { stats.MetaModel.NumberOfSets += 1; } else if (meta is MgaMetaReference) { stats.MetaModel.NumberOfReferences += 1; } else if (meta is MgaMetaAtom) { stats.MetaModel.NumberOfAtoms += 1; } } foreach (MgaMetaFolder meta in project.RootMeta.RootFolder.DefinedFolders) { rfTree[GetGUIDFromInt(meta.MetaRef)] = new Dictionary <string, object>(); stats.MetaModel.NumberOfFolders += 1; } // process domain model VisitChildren(stats, project.RootFolder, stats.Model.ContainmentTree); } finally { project.AbortTransaction(); } return(stats); }
/// <summary> /// Get the absolute path to the root directory of a CyPhy project. /// </summary> /// <param name="project"></param> /// <returns></returns> public static String GetProjectRootPath(IMgaProject project) { return(MgaExtensions.MgaExtensions.GetProjectDirectoryPath(project)); }
public void ImportCyberModel(string Cyberpath = null) { string CyberFilename = ""; this.Logger = new CyPhyGUIs.GMELogger(CurrentProj, this.GetType().Name); // - Display a dialog box to let the user choose their Cyber model file bool Cyber_file_chosen = false; //bool test_copy_and_path_only = false; if (string.IsNullOrWhiteSpace(Cyberpath)) { Cyber_file_chosen = get_Cyber_file(out CyberFilename); } else { //test_copy_and_path_only = true; CyberFilename = Cyberpath; if (File.Exists(CyberFilename)) { Cyber_file_chosen = true; } else { this.Logger.WriteError("Invalid Cyber file path passed in: " + Cyberpath); } } // - Run the extractor on the Creo model file #region Run the Extractor List <string> componentList = new List <string>(); IMgaProject project = (IMgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject")); string compName; project.OpenEx("MGA=" + CyberFilename, "CyberComposition", null); try { project.BeginTransactionInNewTerr(); IMgaFCO currentObj; try { IMgaFolder currentFolder = (IMgaFolder)project.RootFolder; IMgaFolders cFolders = currentFolder.ChildFolders; foreach (IMgaFolder f in cFolders) { if (f.MetaFolder.Name == "Components") { IMgaFCOs objects = f.ChildFCOs; foreach (IMgaFCO o in objects) { componentList.Add("/" + f.Name + "/" + o.Name); } } } } finally { project.CommitTransaction(); } // Adapted from ModelicaImporter.cs string result = ""; using (CyberComponentPicker cyberpicker = new CyberComponentPicker(componentList)) { var dialogResult = cyberpicker.ShowDialog(); if (dialogResult != System.Windows.Forms.DialogResult.OK) { this.Logger.WriteInfo("Modelica import was cancelled by the user."); return; } result = cyberpicker.compResult; } var halves = result.Split('/'); compName = halves[1]; project.BeginTransactionInNewTerr(); try { currentObj = (IMgaFCO)project.RootFolder.ObjectByPath[result]; } finally { project.CommitTransaction(); } IMgaComponentEx comp = (IMgaComponentEx)Activator.CreateInstance(Type.GetTypeFromProgID("MGA.Interpreter.CyberComponentExporter")); comp.Initialize((MgaProject)project); comp.InvokeEx((MgaProject)project, (MgaFCO)currentObj, null, 128); project.Save(); } finally { project.Close(true); } #endregion // - Use a function from CyPhy2ComponentModel to convert the extractor's XML format into a CyPhy model fragment #region Convert_to_XML // used in creating the resource object below CyPhy.CyberModel ProcessedCyberModel = null; if (true) { this.Logger.WriteDebug("About to call DeserializeAvmComponentXml..."); StreamReader streamReader = new StreamReader(compName + ".component.acm"); avm.Component ac_import = CyPhyComponentImporter.CyPhyComponentImporterInterpreter.DeserializeAvmComponentXml(streamReader); streamReader.Close(); this.Logger.WriteDebug("... finished DeserializeAvmComponentXml call."); foreach (avm.cyber.CyberModel Cybermodel in ac_import.DomainModel.Where(dm => dm is avm.cyber.CyberModel) .Cast <avm.cyber.CyberModel>()) { var rf = CyPhyClasses.RootFolder.GetRootFolder(CurrentProj); Dictionary <string, CyPhy.Component> avmidComponentMap = new Dictionary <string, CyPhy.Component>(); AVM2CyPhyML.CyPhyMLComponentBuilder newComponent = new AVM2CyPhyML.CyPhyMLComponentBuilder(rf); ProcessedCyberModel = newComponent.process(Cybermodel, GetCurrentComp()); ProcessedCyberModel.Name = Path.GetFileNameWithoutExtension(CyberFilename); } // find the largest current Y value so our new elements are added below the existing design elements foreach (var child in GetCurrentComp().AllChildren) { foreach (MgaPart item in (child.Impl as MgaFCO).Parts) { int read_x, read_y; string read_str; item.GetGmeAttrs(out read_str, out read_x, out read_y); greatest_current_y = (read_y > greatest_current_y) ? read_y : greatest_current_y; } } // layout Cyber model to the "south" of existing elements foreach (MgaPart item in (ProcessedCyberModel.Impl as MgaFCO).Parts) { item.SetGmeAttrs(null, Cyber_MODEL_START_X, greatest_current_y + Cyber_MODEL_START_Y); } // Extend it's properties out to the component level. this.CyberModuleImportExtension(ProcessedCyberModel); } #endregion // - Copy the Cyber Model files into the component's backend folder // - Note: The solution includes a function that can find this folder using the project.manifest.json file. // - For nice organization, create them in a subfolder called "Cyber" // create avmproj #region Copy files to backend folder // used in creating the resource object below string PathforComp = null; var importedCyberFiles = new List <String>(); if (true) { try { // create the destination path PathforComp = GetCurrentComp().GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE); string finalPathName = Path.Combine(PathforComp, "Cyber"); Directory.CreateDirectory(finalPathName); // determine if one part file or all part and assembly files need to be copied string cpsrcfile = System.IO.Path.GetFileName(CyberFilename); // copy the selected file string CyberFileCopyPath = System.IO.Path.Combine(finalPathName, cpsrcfile); System.IO.File.Copy(CyberFilename, CyberFileCopyPath, true); // Set "primary" file as the first in the list. importedCyberFiles.Add(Path.Combine("Cyber", Path.GetFileName(CyberFileCopyPath))); if (true) { // get a string of the XML contents this.Logger.WriteDebug("About to read contents of XML file using class XmlDocument: " + compName + ".component.acm"); XmlDocument doc = new XmlDocument(); doc.Load(compName + ".component.acm"); string xmlcontents = doc.InnerXml; // mine down to the Resource dependencies using (XmlReader reader = XmlReader.Create(new StringReader(xmlcontents))) { // iterate through each file listed in the resourcedependency section while (reader.ReadToFollowing("ResourceDependency") == true) { string res_name = reader.GetAttribute("Name"); string res_path = reader.GetAttribute("Path"); this.Logger.WriteDebug("Copying this file: " + res_path + "\\" + res_name); // Cyber files end in .1 .2 etc. Pick the latest ones var allFiles = Directory.EnumerateFiles(Path.GetDirectoryName(res_path), "*mga." /*n.b. literal dot*/ + "*") .Select(Path.GetFileName) .Select(filename => new { basename = filename.Substring(0, filename.LastIndexOf('.')), version = filename.Substring(filename.LastIndexOf('.') + 1) }) .Where(p => { int val; return(Int32.TryParse(p.version, out val)); }) .OrderByDescending(p => Int32.Parse(p.version)) .ToArray(); foreach (var basename in allFiles.Select(p => p.basename).Distinct()) { var latest = allFiles.Where(p => p.basename == basename).FirstOrDefault(); if (latest != null) { string latestFilename = latest.basename + "." + latest.version; // Need to limit this down to just the filename in question // The XML file changes the name to all caps, so compare apples to apples if (latestFilename.ToUpper().StartsWith(res_name.ToUpper())) { string destpathandname = Path.Combine(finalPathName, latestFilename); if (!importedCyberFiles.Contains(Path.Combine("Cyber", Path.GetFileName(destpathandname)))) { importedCyberFiles.Add(Path.Combine("Cyber", Path.GetFileName(destpathandname))); } File.Copy(Path.Combine(Path.GetDirectoryName(res_path), latestFilename), destpathandname, true); break; } } } } } } } catch (Exception err_create_proj) { this.Logger.WriteError("Error creating AVM project: " + err_create_proj.Message, " - Extraction Failed. Possible ComponentManagement issue."); //cleanup(tempXMLfile, true); return; } } #endregion // - Create Resource objects in the CyPhy Component model that point to these Cyber Model files // - Note: The "paths" of these should be the relative path from that component's root folder if (true) { foreach (var CyberFile in importedCyberFiles) { CyPhy.Resource ResourceObj = CyPhyClasses.Resource.Create(GetCurrentComp()); ResourceObj.Attributes.ID = Guid.NewGuid().ToString("B"); ResourceObj.Attributes.Path = CyberFile; ResourceObj.Attributes.Notes = "Cyber Model Import tool added this resource object for the imported Cyber file"; ResourceObj.Name = Path.GetFileName(CyberFile); // layout Resource just to the side of the Cyber model foreach (MgaPart item in (ResourceObj.Impl as MgaFCO).Parts) { item.SetGmeAttrs(null, RESOURCE_START_X, greatest_current_y + RESOURCE_START_Y); } // The "primary" Cyber model is the first one -- associate it with the CyPhy CyberModel object if (importedCyberFiles.IndexOf(CyberFile) == 0) { // - Create a UsesResource association between the CyPhy CyberModel object and the Resource object that represents the top-level Creo Model file. CyPhyClasses.UsesResource.Connect(ResourceObj, ProcessedCyberModel, null, null, GetCurrentComp()); } } } // throw in an ACM file for the current state of the component. if (true) { var exporter = new CyPhyComponentExporter.CyPhyComponentExporterInterpreter(); String acmPath = Path.Combine(PathforComp, GetCurrentComp().Name + ".component.acm"); CyPhyComponentExporterInterpreter.ExportToFile(GetCurrentComp(), Path.GetDirectoryName(acmPath)); } // Clean up //cleanup(tempXMLfile, true); }
private IEnumerable<CyPhy.ComponentAssembly> GetAllComponentAssemblys(IMgaProject project, bool includeLibraries = false) { var filter = project.CreateFilter(); filter.Kind = "ComponentAssembly"; int componentsId = project.RootMeta.RootFolder.GetDefinedFolderByNameDisp("Components", true).MetaRef; int componentAssembliesId = project.RootMeta.RootFolder.GetDefinedFolderByNameDisp("ComponentAssemblies", true).MetaRef; IEnumerable<MgaFolder> rootFolders = new MgaFolder[] { project.RootFolder }; if (includeLibraries) { rootFolders = rootFolders.Concat( project.RootFolder.ChildFolders.Cast<MgaFolder>().Where(f => String.IsNullOrEmpty(f.LibraryName) == false)); } foreach (MgaFolder rootFolder in rootFolders) { foreach (MgaFolder folder in rootFolder.ChildFolders) { int metaRef = folder.MetaBase.MetaRef; if (metaRef == componentsId || metaRef == componentAssembliesId) { foreach (IMgaObject fco in folder.GetDescendantFCOs(filter)) { yield return CyPhyClasses.ComponentAssembly.Cast(fco); } } } } }
public static CyPhy.TestBenchType Convert(avm.TestBench avmTestBench, IMgaProject project) { if (avmTestBench == null) { throw new ArgumentNullException("avmTestBench"); } var rootFolder = CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project); var testBenchFolder = rootFolder.Children.TestingCollection.Where(d => d.Name == "TestBenches").FirstOrDefault(); #region Create TestBenchesFolder if (testBenchFolder == null) { testBenchFolder = CyPhyClasses.Testing.Create(rootFolder); testBenchFolder.Name = "TestBenches"; } #endregion #region Create TestBench var cyphyTestBench = CyPhyClasses.TestBench.Create(testBenchFolder); cyphyTestBench.Name = avmTestBench.Name; #endregion #region Create TopLevelSystemUnderTest var avmSystemUnderTest = avmTestBench.TopLevelSystemUnderTest; CyPhy.TopLevelSystemUnderTest cyphySystemUnderTest = null; TestBenchPrimitiveWrapper cyphySystemUnderTestReferred = null; if (avmSystemUnderTest != null) { cyphySystemUnderTest = CyPhyClasses.TopLevelSystemUnderTest.Create(cyphyTestBench); SetLayoutData(avmSystemUnderTest, cyphySystemUnderTest.Impl); if (!string.IsNullOrEmpty(avmSystemUnderTest.DesignID)) { // Looking for the referred component assembly var allComponentAssembly = GetAllComponentAssemblies(rootFolder.Children.ComponentAssembliesCollection); var componentAssembly = allComponentAssembly.FirstOrDefault(x => x.Attributes.ConfigurationUniqueID == avmSystemUnderTest.DesignID); if (componentAssembly != null) { cyphySystemUnderTest.GenericReferred = componentAssembly; cyphySystemUnderTest.Name = componentAssembly.Name; cyphySystemUnderTestReferred = new TestBenchPrimitiveWrapper(componentAssembly); } } } #endregion #region Create Parameters var parameterCache = new List <Tuple <avm.Parameter, CyPhy.Parameter> >(); foreach (var avmParameter in avmTestBench.Parameter) { var cyphyTestBenchParameter = CyPhyClasses.Parameter.Create(cyphyTestBench); cyphyTestBenchParameter.Name = avmParameter.Name; cyphyTestBenchParameter.Attributes.Description = avmParameter.Notes; cyphyTestBenchParameter.Attributes.ID = avmParameter.ID; SetLayoutData(avmParameter, cyphyTestBenchParameter.Impl); parameterCache.Add(new Tuple <avm.Parameter, CyPhy.Parameter>(avmParameter, cyphyTestBenchParameter)); #region Set attribute values var avmValue = avmParameter.Value; if (avmValue != null) { CyPhyClasses.Parameter.AttributesClass.DataType_enum cyphyDataType; // TODO: else give a warning if (ConvertCyPhyDataTypeEnum(avmValue.DataType, out cyphyDataType)) { cyphyTestBenchParameter.Attributes.DataType = cyphyDataType; } cyphyTestBenchParameter.Attributes.Dimension = avmValue.Dimensions; var avmValueExpression = avmValue.ValueExpression; if (avmValueExpression != null && avmValueExpression is avm.ParametricValue) { var avmParametricValue = (avm.ParametricValue)avmValueExpression; var avmAssignedValue = avmParametricValue.AssignedValue as FixedValue; var avmDefault = avmParametricValue.Default as FixedValue; var avmMaximum = avmParametricValue.Maximum as FixedValue; var avmMinimum = avmParametricValue.Minimum as FixedValue; if (avmAssignedValue != null && avmAssignedValue.Value != null) { cyphyTestBenchParameter.Attributes.Value = avmAssignedValue.Value; } if (avmDefault != null && avmDefault.Value != null) { cyphyTestBenchParameter.Attributes.DefaultValue = avmDefault.Value; } if (avmMinimum != null && !string.IsNullOrEmpty(avmMinimum.Value) && avmMaximum != null && !string.IsNullOrEmpty(avmMaximum.Value)) { cyphyTestBenchParameter.Attributes.Range = String.Format("{0}..{1}", avmMinimum.Value, avmMaximum.Value); } } } #endregion } #endregion #region Create Metrics var metricCache = new List <Tuple <avm.Metric, CyPhy.Metric> >(); foreach (var avmMetric in avmTestBench.Metric) { var cyphyTestBenchMetric = CyPhyClasses.Metric.Create(cyphyTestBench); cyphyTestBenchMetric.Name = avmMetric.Name; cyphyTestBenchMetric.Attributes.Description = avmMetric.Notes; SetLayoutData(avmMetric, cyphyTestBenchMetric.Impl); metricCache.Add(new Tuple <avm.Metric, CyPhy.Metric>(avmMetric, cyphyTestBenchMetric)); } #endregion #region Create valueflows // Start with TopLevelSystemUnderTest if (avmSystemUnderTest != null && cyphySystemUnderTest != null) { /* * // Parameters and properties * foreach (var avmParameter in avmSystemUnderTest.PropertyInstance.Where(x=>x.Value!=null)) * { * // Target of valueflow * if (avmParameter.Value.ValueExpression is DerivedValue) * { * var derivedValue = (DerivedValue)avmParameter.Value.ValueExpression; * // Look for the parameter instance * dynamic cyphyValueflowSrc = cyphySystemUnderTestReferred.ParameterCollection.FirstOrDefault(x => x.Attributes.ID == avmParameter.IDinSourceModel); * * // Maybe it is a property * if (cyphyValueflowSrc == null) * { * cyphyValueflowSrc = cyphySystemUnderTestReferred.PropertyCollection.FirstOrDefault(x => x.Attributes.ID == avmParameter.IDinSourceModel); * } * * // TODO: Else warning * if (cyphyValueflowSrc != null) * { * var cachePair = parameterCache.FirstOrDefault(x=>x.Item1.Value.ID == derivedValue.ValueSource); * if (cachePair != null) * { * var cyphyValueflowDst = cachePair.Item2; * var srcRef = ((CyPhy.ValueFlowTarget)cyphyValueflowSrc).ParentContainer is CyPhyClasses.TestBench ? null : cyphySystemUnderTest; * var dstRef = ((CyPhy.ValueFlowTarget)cyphyValueflowDst).ParentContainer is CyPhyClasses.TestBench ? null : cyphySystemUnderTest; * // Doesnt work * CyPhyClasses.ValueFlow.Connect((CyPhy.ValueFlowTarget)cyphyValueflowSrc, (CyPhy.ValueFlowTarget)cyphyValueflowDst, srcRef, dstRef, cyphyTestBench); * //CyPhyClasses.ValueFlow.ConnectGeneric((CyPhy.ValueFlowTarget)cyphyValueflowDst, (CyPhy.ValueFlowTarget)cyphyValueflowSrc, null, null, cyphyTestBench); * } * } * } * } */ } #endregion return(cyphyTestBench); }
public AVMDesignImporter(GMEConsole console, IMgaProject project, object messageConsoleParameter = null) : base(CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project), messageConsoleParameter) { projroot = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); init(true); }
/// <summary> /// Get the absolute path to the root directory of a CyPhy project. /// </summary> /// <param name="project"></param> /// <returns></returns> public static String GetProjectRootPath(IMgaProject project) { return Path.GetFullPath(Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length))); }
/// <summary> /// Creates a unique folder, used for storing component resources, under the project's "components" folder. /// This operation DOES NOT assign the folder to any component; /// Consider using EnsureComponentDirectory(...) for this purpose. /// </summary> /// <param name="projectPath">The CyPhy MGA project</param> /// <returns>The absolute path of the new folder</returns> public static String CreateComponentFolder(IMgaProject project) { String p_ComponentsDir = Path.Combine(project.GetRootDirectoryPath(), ComponentsFolderName); // No entry exists. Make a folder and also an entry. String s_RandomFolderName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); String p_NewComponentDir = Path.Combine(p_ComponentsDir, s_RandomFolderName); int maxFolders = 0; while (File.Exists(p_NewComponentDir) || Directory.Exists(p_NewComponentDir)) { if (maxFolders++ > 2000000) { throw new Exception( string.Format("Number of tries ({0}) to create an output folder exceeded in {0}. ", maxFolders, p_ComponentsDir)); } s_RandomFolderName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); p_NewComponentDir = Path.Combine( p_ComponentsDir, s_RandomFolderName); } Directory.CreateDirectory(p_NewComponentDir); return p_NewComponentDir; }
public IMgaFCO ImportDesign(IMgaProject project, string filename) { var importer = new AVMDesignImporter(null, project); var result = importer.ImportFile(filename); return (IMgaFCO)result.Impl; }
/// <summary> /// Given a CyPhy MGA project, return the root directory of the project /// </summary> /// <param name="project"></param> /// <returns>The absolute path to the project's root directory</returns> public static String GetRootDirectoryPath(this IMgaProject project) { return(ComponentLibraryManager.GetProjectRootPath(project)); }
public IMgaFCO ImportDesignToComponentAssembly(IMgaProject project, string filename) { var importer = new AVMDesignImporter(null, project); var result = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CAS); return (IMgaFCO)result.Impl; }
/* * returns: ComponentAssembly if the design contains no design space concepts */ public IMgaFCO ImportDesignToDesignSpaceIfApplicable(IMgaProject project, string filename) { var importer = new AVMDesignImporter(null, project); var result = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS); return (IMgaFCO)result.Impl; }
public IMgaFCOs GetConfigurations(IMgaProject project, string gmeId) { if (project == null) { throw new ArgumentNullException(); } if (string.IsNullOrWhiteSpace(gmeId)) { throw new ArgumentNullException(); } var context = project.GetObjectByID(gmeId); return this.GetConfigurations(context as IMgaModel); }
public static CyPhy.TestBenchType Convert(avm.TestBench avmTestBench, IMgaProject project) { if (avmTestBench == null) throw new ArgumentNullException("avmTestBench"); var rootFolder = CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project); var testBenchFolder = rootFolder.Children.TestingCollection.Where(d => d.Name == "TestBenches").FirstOrDefault(); #region Create TestBenchesFolder if (testBenchFolder == null) { testBenchFolder = CyPhyClasses.Testing.Create(rootFolder); testBenchFolder.Name = "TestBenches"; } #endregion #region Create TestBench var cyphyTestBench = CyPhyClasses.TestBench.Create(testBenchFolder); cyphyTestBench.Name = avmTestBench.Name; #endregion #region Create TopLevelSystemUnderTest var avmSystemUnderTest = avmTestBench.TopLevelSystemUnderTest; CyPhy.TopLevelSystemUnderTest cyphySystemUnderTest = null; TestBenchPrimitiveWrapper cyphySystemUnderTestReferred = null; if (avmSystemUnderTest != null) { cyphySystemUnderTest = CyPhyClasses.TopLevelSystemUnderTest.Create(cyphyTestBench); SetLayoutData(avmSystemUnderTest, cyphySystemUnderTest.Impl); if (!string.IsNullOrEmpty(avmSystemUnderTest.DesignID)) { // Looking for the referred component assembly var allComponentAssembly = GetAllComponentAssemblies(rootFolder.Children.ComponentAssembliesCollection); var componentAssembly = allComponentAssembly.FirstOrDefault(x=>x.Attributes.ConfigurationUniqueID == avmSystemUnderTest.DesignID); if (componentAssembly != null) { cyphySystemUnderTest.GenericReferred = componentAssembly; cyphySystemUnderTest.Name = componentAssembly.Name; cyphySystemUnderTestReferred = new TestBenchPrimitiveWrapper(componentAssembly); } } } #endregion #region Create Parameters var parameterCache = new List<Tuple<avm.Parameter, CyPhy.Parameter>>(); foreach (var avmParameter in avmTestBench.Parameter) { var cyphyTestBenchParameter = CyPhyClasses.Parameter.Create(cyphyTestBench); cyphyTestBenchParameter.Name = avmParameter.Name; cyphyTestBenchParameter.Attributes.Description = avmParameter.Notes; cyphyTestBenchParameter.Attributes.ID = avmParameter.ID; SetLayoutData(avmParameter, cyphyTestBenchParameter.Impl); parameterCache.Add(new Tuple<avm.Parameter, CyPhy.Parameter>(avmParameter, cyphyTestBenchParameter)); #region Set attribute values var avmValue = avmParameter.Value; if (avmValue != null) { CyPhyClasses.Parameter.AttributesClass.DataType_enum cyphyDataType; // TODO: else give a warning if (ConvertCyPhyDataTypeEnum(avmValue.DataType, out cyphyDataType)) { cyphyTestBenchParameter.Attributes.DataType = cyphyDataType; } cyphyTestBenchParameter.Attributes.Dimension = avmValue.Dimensions; var avmValueExpression = avmValue.ValueExpression; if (avmValueExpression != null && avmValueExpression is avm.ParametricValue) { var avmParametricValue = (avm.ParametricValue)avmValueExpression; var avmAssignedValue = avmParametricValue.AssignedValue as FixedValue; var avmDefault = avmParametricValue.Default as FixedValue; var avmMaximum = avmParametricValue.Maximum as FixedValue; var avmMinimum = avmParametricValue.Minimum as FixedValue; if (avmAssignedValue!=null && avmAssignedValue.Value!=null) cyphyTestBenchParameter.Attributes.Value = avmAssignedValue.Value; if (avmDefault!=null && avmDefault.Value!=null) cyphyTestBenchParameter.Attributes.DefaultValue = avmDefault.Value; if (avmMinimum!=null && !string.IsNullOrEmpty(avmMinimum.Value) && avmMaximum!=null && !string.IsNullOrEmpty(avmMaximum.Value)) cyphyTestBenchParameter.Attributes.Range = String.Format("{0}..{1}",avmMinimum.Value,avmMaximum.Value); } } #endregion } #endregion #region Create Metrics var metricCache = new List<Tuple<avm.Metric, CyPhy.Metric>>(); foreach (var avmMetric in avmTestBench.Metric) { var cyphyTestBenchMetric = CyPhyClasses.Metric.Create(cyphyTestBench); cyphyTestBenchMetric.Name = avmMetric.Name; cyphyTestBenchMetric.Attributes.Description = avmMetric.Notes; SetLayoutData(avmMetric, cyphyTestBenchMetric.Impl); metricCache.Add(new Tuple<avm.Metric, CyPhy.Metric>(avmMetric, cyphyTestBenchMetric)); } #endregion #region Create valueflows // Start with TopLevelSystemUnderTest if (avmSystemUnderTest != null && cyphySystemUnderTest != null) { /* // Parameters and properties foreach (var avmParameter in avmSystemUnderTest.PropertyInstance.Where(x=>x.Value!=null)) { // Target of valueflow if (avmParameter.Value.ValueExpression is DerivedValue) { var derivedValue = (DerivedValue)avmParameter.Value.ValueExpression; // Look for the parameter instance dynamic cyphyValueflowSrc = cyphySystemUnderTestReferred.ParameterCollection.FirstOrDefault(x => x.Attributes.ID == avmParameter.IDinSourceModel); // Maybe it is a property if (cyphyValueflowSrc == null) { cyphyValueflowSrc = cyphySystemUnderTestReferred.PropertyCollection.FirstOrDefault(x => x.Attributes.ID == avmParameter.IDinSourceModel); } // TODO: Else warning if (cyphyValueflowSrc != null) { var cachePair = parameterCache.FirstOrDefault(x=>x.Item1.Value.ID == derivedValue.ValueSource); if (cachePair != null) { var cyphyValueflowDst = cachePair.Item2; var srcRef = ((CyPhy.ValueFlowTarget)cyphyValueflowSrc).ParentContainer is CyPhyClasses.TestBench ? null : cyphySystemUnderTest; var dstRef = ((CyPhy.ValueFlowTarget)cyphyValueflowDst).ParentContainer is CyPhyClasses.TestBench ? null : cyphySystemUnderTest; // Doesnt work CyPhyClasses.ValueFlow.Connect((CyPhy.ValueFlowTarget)cyphyValueflowSrc, (CyPhy.ValueFlowTarget)cyphyValueflowDst, srcRef, dstRef, cyphyTestBench); //CyPhyClasses.ValueFlow.ConnectGeneric((CyPhy.ValueFlowTarget)cyphyValueflowDst, (CyPhy.ValueFlowTarget)cyphyValueflowSrc, null, null, cyphyTestBench); } } } } */ } #endregion return cyphyTestBench; }