public override IEnumerator <FileItem> GetEnumerator() { if (formProcessing != null) { formProcessing.Close(); } formProcessing = new FormProcessing(); formProcessing.Show(); formProcessing.Update(); formProcessing.ShowLogMessage("Start generating.", IconKey.Start); List <FileItem> list = new List <FileItem>(); try { formProcessing.ShowLogMessage("Getting database schema.", IconKey.Schema); formProcessing.Cursor = Cursors.WaitCursor; Mapping newMapping = MappingFactory.CreateMapping(this.InputFilePath, this.InputFileContents); Mapping oldMapping = GetLocalMapping(newMapping); formProcessing.Cursor = Cursors.Default; formProcessing.ShowLogMessage("Generating mapping.", IconKey.Dbsx); list.Add(new FileItem(this.MappingName, ItemType.CacheSettingTemplate, !Equalizer.IsEqual(oldMapping.DataAccessNamespaces, newMapping.DataAccessNamespaces))); list.Add(new FileItem(this.MappingName, ItemType.ConnectionStrings, !Equalizer.IsEqual(oldMapping.ConnectionStringName, newMapping.ConnectionStringName))); list.Add(new FileItem(this.MappingName, ItemType.Document, !Equalizer.IsEqual(oldMapping.Database, newMapping.Database))); list.Add(new FileItem(this.MappingName, ItemType.Enums, !Equalizer.IsEqual(oldMapping.Enums, newMapping.Enums))); foreach (ModelNamespace ns in newMapping.ModelNamespaces) { if (ns.Models.Count > 0) { if (oldMapping.ModelNamespaces.Contains(ns.Name)) { list.Add(new FileItem(this.MappingName, ns.Name, ItemType.Models, !Equalizer.IsEqual(oldMapping.ModelNamespaces[ns.Name], ns))); } else { list.Add(new FileItem(this.MappingName, ns.Name, ItemType.Models, true)); } } } foreach (DataAccessNamespace ns in newMapping.DataAccessNamespaces) { if (ns.DataAccesses.Count > 0) { if (oldMapping.DataAccessNamespaces.Contains(ns.Name)) { list.Add(new FileItem(this.MappingName, ns.Name, ItemType.DataAccess, !Equalizer.IsEqual(oldMapping.DataAccessNamespaces[ns.Name], ns))); } else { list.Add(new FileItem(this.MappingName, ns.Name, ItemType.DataAccess, true)); } } } mappingContent = Serializer.Serialize(newMapping); generatedSuccessfully = true; processBarStep = (100 - formProcessing.progressBarGenerating.Value) / list.Count; } catch (Exception ex) { formProcessing.Cursor = Cursors.Default; base.LogException(ex); mappingContent = ex.Message; generatedSuccessfully = false; formProcessing.ShowLogMessage("Error: " + ex.Message, IconKey.Error); list.Clear(); } return(list.GetEnumerator()); }
private List <FileItem> GetFileItems(Mapping newMapping, Mapping oldMapping) { List <FileItem> list = new List <FileItem>(); try { list.Add(new FileItem(this.mappingName, FileItemType.CacheSettingTemplate, this.firstRunOfThisGeneratorVersion || oldMapping == null || !Equalizer.IsEqual(oldMapping.DataAccessNamespaces, newMapping.DataAccessNamespaces))); list.Add(new FileItem(this.mappingName, FileItemType.ConnectionStrings, this.firstRunOfThisGeneratorVersion || oldMapping == null || !Equalizer.IsEqual(oldMapping.ConnectionStringName, newMapping.ConnectionStringName))); list.Add(new FileItem(this.mappingName, FileItemType.Document, this.firstRunOfThisGeneratorVersion || oldMapping == null || !Equalizer.IsEqual(oldMapping.Database, newMapping.Database))); foreach (ModelNamespace ns in newMapping.ModelNamespaces) { if (ns.Models.Count > 0) { if (oldMapping != null && oldMapping.ModelNamespaces.Contains(ns.Name)) { list.Add(new FileItem(this.mappingName, ns.Name, FileItemType.Models, this.firstRunOfThisGeneratorVersion || !Equalizer.IsEqual(oldMapping.ModelNamespaces[ns.Name], ns))); } else { list.Add(new FileItem(this.mappingName, ns.Name, FileItemType.Models, true)); } } } foreach (DataAccessNamespace ns in newMapping.DataAccessNamespaces) { if (ns.DataAccesses.Count > 0) { if (oldMapping != null && oldMapping.DataAccessNamespaces.Contains(ns.Name)) { list.Add(new FileItem(this.mappingName, ns.Name, FileItemType.DataAccess, this.firstRunOfThisGeneratorVersion || !Equalizer.IsEqual(oldMapping.DataAccessNamespaces[ns.Name], ns))); } else { list.Add(new FileItem(this.mappingName, ns.Name, FileItemType.DataAccess, true)); } } } progressStep = (100 - progress) / list.Count; progress += progressStep; if (ProgressChanged != null) { ProgressChanged(progress); } } catch (Exception ex) { ExceptionThrown(ex); //mappingContent = ex.Message; list.Clear(); } return(list); }