public void AddReference(string fileName) { ReferenceEntry r = new ReferenceEntry(fileName); references.Add(r); DataModel m = new DataModel(); m.Load(fileName); foreach (ModelFolder folder in m.Folders) { foreach (object i in folder.Items) { if (i is ModelClass) { DataTypeManager.AddDataType(new ReferenceType((ModelClass)i, r)); } } } }
private void parse1_11File(XmlTextReader r) { string fileVersion; ModelFolder defaultFolder = null; fileVersion = "1.11"; name = r.ReadElementString("Name"); defaultNamespace = r.ReadElementString("DefaultNamespace"); if (r.LocalName == "Description") { description = r.ReadElementString("Description"); } if (r.LocalName == "ConnectionString") { connectionString = r.ReadElementString("ConnectionString"); } if (r.LocalName == "ConnectionStringIsCoded") { connectionStringIsCoded = bool.Parse(r.ReadElementString("ConnectionStringIsCoded")); } if (r.LocalName == "ConnectionStringIsConfigKey") { connectionStringIsConfigKey = bool.Parse(r.ReadElementString("ConnectionStringIsConfigKey")); } if (r.LocalName == "VersionMajor") { version.Major = int.Parse(r.ReadElementString("VersionMajor")); } if (r.LocalName == "VersionMinor") { version.Minor = int.Parse(r.ReadElementString("VersionMinor")); } if (r.LocalName == "VersionBuild") { version.Build = int.Parse(r.ReadElementString("VersionBuild")); } if (r.Name == "References" && !r.IsEmptyElement) { r.Read(); while (r.LocalName == "ReferenceEntry") { references.Add(new ReferenceEntry(r)); } r.ReadEndElement(); } else { r.Read(); } // // Skip Field Data Types on 1.1 models // while (r.Name != "ChildDataTypes") { r.Read(); } if (r.Name == "ChildDataTypes" && !r.IsEmptyElement) { r.Read(); while (r.LocalName == "ChildDataType") { DataTypeManager.AddDataType(new ReferenceType(r)); } r.ReadEndElement(); } else { r.Read(); } if ((r.Name == "ModelFolders" | r.Name == "ClassObjects") && !r.IsEmptyElement) { r.Read(); while (r.LocalName == "ClassObject" | r.LocalName == "ModelFolder") { if (r.LocalName == "ClassObject") { // Create a default folder for the class object if it // is not already created. if (defaultFolder == null) { defaultFolder = new ModelFolder(); defaultFolder.Caption = "General"; defaultFolder.Description = "General"; defaultFolder.Name = "General"; defaultFolder.ParentModel = this; defaultFolder.IsBrowsable = true; defaultFolder.IsExpanded = true; this.Folders.Add(defaultFolder); } // Load ClassEntry ModelClass c = new ModelClass(r, fileVersion); c.ParentModel = this; // Add Class Entry to Default Folder defaultFolder.Items.Add(c); } // Add Model Folder if (r.LocalName == "ModelFolder") { ModelFolder f = new ModelFolder(r, this, fileVersion); folders.Add(f); } } r.ReadEndElement(); } else { r.Read(); } }
public void Load(string fileName) { ModelClass classEntry; ReferenceField childEntry; EnumField enumEntry; FileInfo file = new FileInfo(fileName); // Progress Start Event this.OnProgressStart(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadText, name), string.Empty, "LOAD", new ProgressBarConfig(0, 5, 0, 1))); // // Test for file existence. // if (!File.Exists(fileName)) { // Try Loading the NitroCast File fileName = fileName.Replace(".DbModel", ".NitroGen"); if (!File.Exists(fileName)) { this.OnProgressStop(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadFailed, file.Name), string.Empty, "LOAD")); throw new System.IO.FileNotFoundException( string.Format(Properties.Resources.ProgressBarLoadFailed, file.Name)); } } this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadInitialize, file.Name), string.Empty, "LOAD")); #region Clear References and Classes references.Clear(); folders.Clear(); #endregion this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadParse, file.Name), string.Empty, "LOAD")); #region Parse Model this.fileName = fileName; XmlTextReader r = new XmlTextReader(fileName); r.WhitespaceHandling = WhitespaceHandling.None; r.MoveToContent(); if (!(r.Name == "dbModel" | r.Name == "NitroCast")) { throw new Exception("Source file does not match NitroCast DTD."); } r.MoveToAttribute("version"); string version = r.Value; r.MoveToContent(); switch (version) { // case "1.0": // r.Read(); // parse1_0File(r); // break; // case "1.1": // r.Read(); // parse1_1File(r); // break; case "1.11": r.Read(); parse1_11File(r); break; default: r.Close(); throw new Exception(string.Format("Source file version '{0}' incompatible.", version)); } r.Close(); #endregion this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadReferences, file.Name), string.Empty, "LOAD")); #region Load Referenced Data Types // // Create DataTypes For References Class Entries // foreach (ReferenceEntry reference in references) { DataModel m = new DataModel(); m.Load(PathConverter.GetAbsolutePath(file.DirectoryName, reference.FileName)); reference.Name = m.Name; foreach (ModelFolder folder in m.Folders) { foreach (object item in folder.Items) { if (item is ModelClass) { DataTypeManager.AddDataType(new ReferenceType((ModelClass)item, reference)); } else if (item is ModelEnum) { DataTypeManager.AddDataType(new EnumType((ModelEnum)item, reference)); } } } } #endregion this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadBuild, file.Name), string.Empty, "LOAD")); #region Load Internal Data Types foreach (ModelFolder f in folders) { foreach (object item in f.Items) { if (item is ModelClass) { DataTypeManager.AddDataType(new ReferenceType((ModelClass)item, null)); } else if (item is ModelEnum) { DataTypeManager.AddDataType(new EnumType((ModelEnum)item, null)); } } } #endregion this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadSort, file.Name), string.Empty, "LOAD")); DataTypeManager.ReferenceTypes.Sort(ModelEntryCompareKey.Name); DataTypeManager.ValueTypes.Sort(ModelEntryCompareKey.Name); DataTypeManager.EnumTypes.Sort(ModelEntryCompareKey.Name); this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarLoadAssociate, file.Name), string.Empty, "LOAD")); #region Associate Datatypes to Children // // Associate DataTypes to class children. // foreach (ModelFolder folder in folders) { foreach (object item in folder.Items) { if (item is ModelClass) { classEntry = (ModelClass)item; foreach (ClassFolder classFolder in classEntry.Folders) { foreach (object folderItem in classFolder.Items) { if (folderItem is ReferenceField) { childEntry = (ReferenceField)folderItem; if (childEntry.ReferenceType.IsCustom) { foreach (ReferenceType cType in DataTypeManager.ReferenceTypes) { if (childEntry.ReferenceType.Name == cType.Name & childEntry.ReferenceType.NameSpace == cType.NameSpace) { childEntry.ReferenceType = cType; } } } } else if (folderItem is EnumField) { enumEntry = (EnumField)folderItem; if (enumEntry.EnumType.IsCustom) { foreach (EnumType cType in DataTypeManager.EnumTypes) { if (enumEntry.EnumType.Name == cType.Name & enumEntry.EnumType.NameSpace == cType.NameSpace) { enumEntry.EnumType = cType; } } } } } } } } } #endregion this.OnProgressStop(this, new DataModelEventArgs(string.Empty, string.Empty, "LOAD")); }