public void Export() { int modelClassExtensions; int modelEnumExtensions; int maxCount; System.IO.FileInfo modelFile; ExtensionManager pluginManager; ModelClass classEntry; modelFile = new System.IO.FileInfo(fileName); pluginManager = ExtensionManager.GetInstance(); modelClassExtensions = 0; modelEnumExtensions = 0; foreach (OutputExtension extension in pluginManager.OutputExtensions.Values) { if (extension.ExtensionType == OutputExtensionType.ModelClass) { modelClassExtensions++; } else if (extension.ExtensionType == OutputExtensionType.ModelEnum) { modelEnumExtensions++; } } maxCount = 0; foreach (ModelFolder folder in folders) { foreach (object item in folder.Items) { if (item is ModelClass) { maxCount += modelClassExtensions; } else if (item is ModelEnum) { maxCount += modelEnumExtensions; } } } this.OnProgressStart(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarExportText, name), string.Empty, "EXPORT", new ProgressBarConfig(0, maxCount, 0, 1))); foreach (ModelFolder folder in folders) { foreach (object i in folder.Items) { if (i is ModelClass) { classEntry = (ModelClass)i; foreach (OutputExtension extension in pluginManager.OutputExtensions.Values) { extension.Init(classEntry, null); if (extension.IsWebControl & classEntry.WebOutputPath != string.Empty) { extension.FileName = PathConverter.GetAbsolutePath(modelFile.DirectoryName, classEntry.WebOutputPath) + "/" + string.Format(extension.OutputFileNameFormat, classEntry.Name); } else { extension.FileName = PathConverter.GetAbsolutePath(modelFile.DirectoryName, classEntry.OutputPath) + "/" + string.Format(extension.OutputFileNameFormat, classEntry.Name); } this.OnProgressUpdate(this, new DataModelEventArgs( string.Format(Properties.Resources.ProgressBarExportClass, name, folder, classEntry.Name, extension.Name), string.Empty, "EXPORT")); extension.Load(); extension.Execute(); } } } } // This is here to allow enough time to display the completed // progress bar, otherwise it will always look like the last // few steps are incomplete. System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(100)); this.OnProgressStop(this, new DataModelEventArgs( Properties.Resources.ProgressBarExportComplete, string.Empty, "EXPORT")); }
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")); }