public static bool CheckMetaCompatibility( MgaProject project, ISIS.GME.Common.Interfaces.RootFolder rootFolder) { bool result = true; foreach (var item in rootFolder.MetaRefs) { try { MgaMetaBase b = project.RootMeta.FindObject[item.Key]; if (b == null) { throw new Exception("Meta incompatibility"); } else { // TODO: Namespaces??? this will not work if (b.Name != item.Value.Name) { throw new Exception("Meta incompatibility"); } } } catch (Exception ex) { throw new Exception("Meta incompatibility", ex); } } return(result); }
public static int Main(String[] args) { if (args.Length < 2 || args.Length > 4) { usage(); return(1); } MgaProject mgaProject; List <String> lp_FilesToImport = new List <string>(); string avmFilePath = ""; string mgaProjectPath = ""; string componentReplacementPath = ""; bool rOptionUsed = false; bool pOptionUsed = false; for (int ix = 0; ix < args.Length; ++ix) { if (args[ix].ToLower() == "-r") { if (pOptionUsed) { usage(); return(1); } rOptionUsed = true; if (++ix >= args.Length) { usage(); return(1); } if (avmFilePath != null && avmFilePath != "") { if (mgaProjectPath != null && mgaProjectPath != "") { usage(); return(1); } mgaProjectPath = avmFilePath; avmFilePath = ""; lp_FilesToImport.Clear(); } String sImportDirectory = args[ix]; String startingDirectory = Path.GetFullPath(sImportDirectory); string[] xmlFiles = Directory.GetFiles(startingDirectory, "*.acm", SearchOption.AllDirectories); foreach (String p_XMLFile in xmlFiles) { lp_FilesToImport.Add(Path.GetFullPath(p_XMLFile)); } } else if (args[ix].ToLower() == "-p") { if (rOptionUsed) { usage(); return(1); } pOptionUsed = true; if (++ix >= args.Length) { usage(); return(1); } componentReplacementPath = args[ix]; } else if (lp_FilesToImport.Count == 0 && avmFilePath == "") { avmFilePath = args[ix]; try { lp_FilesToImport.Add(Path.GetFullPath(avmFilePath)); } catch (System.ArgumentException ex) { Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(avmFilePath); throw ex; } } else { if (mgaProjectPath != null && mgaProjectPath != "") { usage(); return(1); } mgaProjectPath = args[ix]; } } mgaProject = GetProject(mgaProjectPath); try { bool bExceptionOccurred = false; if (mgaProject != null) { MgaGateway mgaGateway = new MgaGateway(mgaProject); mgaGateway.PerformInTransaction(delegate { string libroot = Path.GetDirectoryName(Path.GetFullPath(mgaProjectPath)); CyPhyML.RootFolder cyPhyMLRootFolder = ISIS.GME.Common.Utils.CreateObject <CyPhyMLClasses.RootFolder>(mgaProject.RootFolder as MgaObject); #region Attach QUDT library if needed IMgaFolder oldQudt = mgaProject.RootFolder.ChildFolders.Cast <IMgaFolder>().Where(x => x.LibraryName != "" && (x.Name.ToLower().Contains("qudt"))).FirstOrDefault(); string mgaQudtPath = Meta_Path + "\\meta\\CyPhyMLQudt.mga"; bool needAttach = false; if (oldQudt == null) { needAttach = true; } else { long loldModTime; DateTime oldModTime = long.TryParse(oldQudt.RegistryValue["modtime"], out loldModTime) ? DateTime.FromFileTimeUtc(loldModTime) : DateTime.MinValue; needAttach = System.IO.File.GetLastWriteTimeUtc(mgaQudtPath).CompareTo(oldModTime) > 0; if (!needAttach) { Console.Error.WriteLine("QUDT is up-to-date: embedded library modified " + oldModTime.ToString() + ", CyPhyMLQudt.mga modified " + System.IO.File.GetLastWriteTimeUtc(mgaQudtPath).ToString()); } } if (needAttach) { Console.Error.WriteLine("Attaching library " + mgaQudtPath); ISIS.GME.Common.Interfaces.RootFolder newQudt = ISIS.GME.Common.Classes.RootFolder.GetRootFolder(mgaProject).AttachLibrary("MGA=" + mgaQudtPath); DateTime modtime = System.IO.File.GetLastWriteTimeUtc(mgaQudtPath); ((newQudt as ISIS.GME.Common.Classes.RootFolder).Impl as GME.MGA.IMgaFolder).RegistryValue["modtime"] = modtime.ToFileTimeUtc().ToString(); if (oldQudt != null) { ReferenceSwitcher.Switcher sw = new ReferenceSwitcher.Switcher(oldQudt, newQudt.Impl, null); sw.UpdateSublibrary(); oldQudt.DestroyObject(); } ((newQudt as ISIS.GME.Common.Classes.RootFolder).Impl as GME.MGA.IMgaFolder).LibraryName = "UnitLibrary QUDT"; Console.Error.WriteLine((oldQudt == null ? "Attached " : "Refreshed") + " Qudt library."); } #endregion var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter(); importer.Initialize(cyPhyMLRootFolder.Impl.Project); importer.ImportFiles(cyPhyMLRootFolder.Impl.Project, libroot, lp_FilesToImport.ToArray(), true); importer.DisposeLogger(); bExceptionOccurred = importer.Errors.Count > 0; }, abort: false); mgaProject.Save(); if (bExceptionOccurred) { return(-1); } } } finally { mgaProject.Close(true); } return(0); }