Exemplo n.º 1
0
        private static void SaveDiagramFiles(string rootFolder, nHydrateDiagram diagram)
        {
            var fileName = Path.Combine(rootFolder, "diagram.xml");
            var document = new XmlDocument();

            document.LoadXml(@"<configuration type=""diagram""></configuration>");
            foreach (var shape in diagram.NestedChildShapes)
            {
                if (shape is EntityShape)
                {
                    var item = ((shape as EntityShape).ModelElement as Entity);
                    var node = XmlHelper.AddElement(document.DocumentElement, "element");
                    node.AddAttribute("id", shape.ModelElement.Id);
                    node.AddAttribute("bounds", shape.AbsoluteBoundingBox.ToXmlValue());
                }
                else if (shape is ViewShape)
                {
                    var item = ((shape as ViewShape).ModelElement as View);
                    var node = XmlHelper.AddElement(document.DocumentElement, "element");
                    node.AddAttribute("id", shape.ModelElement.Id);
                    node.AddAttribute("bounds", shape.AbsoluteBoundingBox.ToXmlValue());
                }
            }
            document.Save(fileName);
        }
Exemplo n.º 2
0
 public ModelUtilitiesForm(nHydrateModel model, Microsoft.VisualStudio.Modeling.Store store, nHydrateDiagram diagram)
     : this()
 {
     _model   = model;
     _store   = store;
     _diagram = diagram;
 }
Exemplo n.º 3
0
        public RefactorCombineTableForm(Microsoft.VisualStudio.Modeling.Store store, nHydrateDiagram diagram, nHydrateModel model, Entity entity1, Entity entity2)
            : this()
        {
            _store   = store;
            _model   = model;
            _diagram = diagram;
            _entity1 = entity1;
            _entity2 = entity2;

            lblEntity1.Text = entity1.Name;
            lblEntity2.Text = entity2.Name;

            var fieldList = new List <Field>();

            fieldList.AddRange(entity1.Fields);
            fieldList.AddRange(entity2.Fields);
            fieldList.Remove(x => entity2.PrimaryKeyFields.Contains(x));

            if (fieldList.Select(x => x.Name.ToLower()).Count() != fieldList.Select(x => x.Name.ToLower()).Distinct().Count())
            {
                cmdApply.Enabled = false;
                lblError.Text    = "Duplicate field names are not allowed.";
                lblError.Visible = true;
            }

            fieldList.ForEach(x => lstField.Items.Add(x.Name));
        }
        public static void LoadDiagramFiles(nHydrateModel model, string rootFolder, string modelName, nHydrateDiagram diagram)
        {
            if (!model.ModelToDisk)
                return;

            var fileName = Path.Combine(GetModelFolder(rootFolder, modelName), "diagram.xml");
            if (!File.Exists(fileName)) return;
            using (var transaction = model.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
            {
                var document = new XmlDocument();
                var id = Guid.Empty;
                try
                {
                    document.Load(fileName);
                    if (document.DocumentElement == null) throw new Exception("No Root"); //this is thrown away

                    foreach (XmlNode node in document.DocumentElement.ChildNodes)
                    {
                        id = XmlHelper.GetAttributeValue(node, "id", Guid.Empty);
                        var shape = diagram.NestedChildShapes.FirstOrDefault(x => x.ModelElement.Id == id) as Microsoft.VisualStudio.Modeling.Diagrams.NodeShape;
                        if (shape != null)
                            shape.Bounds = Extensions.ConvertRectangleDFromXmlValue(XmlHelper.GetAttributeValue(node, "bounds", string.Empty));
                    }
                }
                catch (Exception ex) { return; }
                transaction.Commit();
            }
        }
        public RefactorPreviewCreateAssociativeForm(Microsoft.VisualStudio.Modeling.Store store, nHydrateDiagram diagram, nHydrateModel model, Entity entity1, Entity entity2)
            : this()
        {
            _store   = store;
            _model   = model;
            _diagram = diagram;
            _entity1 = entity1;
            _entity2 = entity2;

            lblEntity1.Text = entity1.Name;
            lblEntity2.Text = entity2.Name;
            txtName.Text    = _entity1.Name + _entity2.Name;
        }
        public RefactorSplitTableForm(Microsoft.VisualStudio.Modeling.Store store, nHydrateDiagram diagram, nHydrateModel model, Entity entity)
            : this()
        {
            _store   = store;
            _model   = model;
            _diagram = diagram;
            _entity  = entity;
            wizard1.FinishEnabled = false;
            lblSourceEntity.Text  = entity.Name;

            foreach (var field in entity.Fields.Where(x => !x.IsPrimaryKey).OrderBy(x => x.Name))
            {
                lstField1.Items.Add(new DisplayFieldItem()
                {
                    Field = field
                });
            }
        }
Exemplo n.º 7
0
        public static void SaveToDisk(nHydrateModel model, string rootFolder, string modelName, nHydrateDiagram diagram)
        {
            var diskModel = new DiskModelYaml();

            model.IsSaving = true;
            try
            {
                diskModel.ModelProperties.CompanyName       = model.CompanyName;
                diskModel.ModelProperties.EmitSafetyScripts = model.EmitSafetyScripts;
                diskModel.ModelProperties.DefaultNamespace  = model.DefaultNamespace;
                diskModel.ModelProperties.ProjectName       = model.ProjectName;
                diskModel.ModelProperties.UseUTCTime        = model.UseUTCTime;
                diskModel.ModelProperties.Version           = model.Version;
                diskModel.ModelProperties.Id = model.Id;
                diskModel.ModelProperties.TenantColumnName           = model.TenantColumnName;
                diskModel.ModelProperties.CreatedByColumnName        = model.CreatedByColumnName;
                diskModel.ModelProperties.CreatedDateColumnName      = model.CreatedDateColumnName;
                diskModel.ModelProperties.ModifiedByColumnName       = model.ModifiedByColumnName;
                diskModel.ModelProperties.ModifiedDateColumnName     = model.ModifiedDateColumnName;
                diskModel.ModelProperties.ConcurrencyCheckColumnName = model.ConcurrencyCheckColumnName;
                diskModel.ModelProperties.GrantExecUser = model.GrantUser;

                var folderName  = modelName.Replace(".nhydrate", ".model");
                var modelFolder = GetModelFolder(rootFolder, folderName);
                nHydrate.Dsl.Custom.SQLFileManagement.SaveToDisk(diskModel, model.Views);
                nHydrate.Dsl.Custom.SQLFileManagement.SaveToDisk(diskModel, model.Entities);
                FileManagement.Save2(rootFolder, modelName, diskModel);
                nHydrate.Dsl.Custom.SQLFileManagement.SaveDiagramFiles(modelFolder, diagram);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                model.IsSaving = false;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Saves Stored Procedures to disk
        /// </summary>
        private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable <Entity> list, string rootFolder, nHydrateDiagram diagram, List <string> generatedFileList)
        {
            var folder = Path.Combine(rootFolder, FOLDER_ET);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            #region Save other parameter/field information
            foreach (var item in list)
            {
                var document = new XmlDocument();
                document.LoadXml(@"<configuration type=""entity"" name=""" + item.Name + @"""></configuration>");

                XmlHelper.AddLineBreak(document.DocumentElement);
                XmlHelper.AddCData(document.DocumentElement, "summary", item.Summary);
                XmlHelper.AddLineBreak(document.DocumentElement);

                XmlHelper.AddAttribute(document.DocumentElement, "id", item.Id);
                XmlHelper.AddAttribute(document.DocumentElement, "allowcreateaudit", item.AllowCreateAudit);
                XmlHelper.AddAttribute(document.DocumentElement, "allowmodifyaudit", item.AllowModifyAudit);
                XmlHelper.AddAttribute(document.DocumentElement, "allowtimestamp", item.AllowTimestamp);
                XmlHelper.AddAttribute(document.DocumentElement, "codefacade", item.CodeFacade);
                XmlHelper.AddAttribute(document.DocumentElement, "immutable", item.Immutable);
                XmlHelper.AddAttribute(document.DocumentElement, "isassociative", item.IsAssociative);
                XmlHelper.AddAttribute(document.DocumentElement, "typedentity", item.TypedEntity.ToString());
                XmlHelper.AddAttribute(document.DocumentElement, "schema", item.Schema);
                XmlHelper.AddAttribute(document.DocumentElement, "generatesdoublederived", item.GeneratesDoubleDerived);
                XmlHelper.AddAttribute(document.DocumentElement, "isTenant", item.IsTenant);

                #region Fields
                {
                    var fieldsNodes = XmlHelper.AddElement(document.DocumentElement, "fieldset") as XmlElement;
                    XmlHelper.AddLineBreak((XmlElement)fieldsNodes);
                    foreach (var field in item.Fields.OrderBy(x => x.Name))
                    {
                        var fieldNode = XmlHelper.AddElement(fieldsNodes, "field");

                        XmlHelper.AddLineBreak((XmlElement)fieldNode);
                        XmlHelper.AddCData((XmlElement)fieldNode, "summary", field.Summary);
                        XmlHelper.AddLineBreak((XmlElement)fieldNode);

                        XmlHelper.AddAttribute(fieldNode, "id", field.Id);
                        XmlHelper.AddAttribute(fieldNode, "name", field.Name);
                        XmlHelper.AddAttribute(fieldNode, "nullable", field.Nullable);
                        XmlHelper.AddAttribute(fieldNode, "datatype", field.DataType.ToString());
                        XmlHelper.AddAttribute(fieldNode, "identity", field.Identity.ToString());
                        XmlHelper.AddAttribute(fieldNode, "codefacade", field.CodeFacade);
                        XmlHelper.AddAttribute(fieldNode, "dataformatstring", field.DataFormatString);
                        XmlHelper.AddAttribute(fieldNode, "default", field.Default);
                        XmlHelper.AddAttribute(fieldNode, "defaultisfunc", field.DefaultIsFunc);
                        XmlHelper.AddAttribute(fieldNode, "formula", field.Formula);
                        XmlHelper.AddAttribute(fieldNode, "isindexed", field.IsIndexed);
                        XmlHelper.AddAttribute(fieldNode, "isprimarykey", field.IsPrimaryKey);
                        XmlHelper.AddAttribute(fieldNode, "Iscalculated", field.IsCalculated);
                        XmlHelper.AddAttribute(fieldNode, "isunique", field.IsUnique);
                        XmlHelper.AddAttribute(fieldNode, "length", field.Length);
                        XmlHelper.AddAttribute(fieldNode, "scale", field.Scale);
                        XmlHelper.AddAttribute(fieldNode, "sortorder", field.SortOrder);
                        XmlHelper.AddAttribute(fieldNode, "isreadonly", field.IsReadOnly);
                        XmlHelper.AddAttribute(fieldNode, "obsolete", field.Obsolete);

                        XmlHelper.AddLineBreak((XmlElement)fieldsNodes);
                    }
                    XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
                }
                #endregion

                XmlHelper.AddLineBreak(document.DocumentElement);
                var f = Path.Combine(folder, item.Name + ".configuration.xml");
                WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);

                //Save other files
                SaveEntityIndexes(folder, item, generatedFileList);
                SaveRelations(folder, item, generatedFileList);
                SaveEntityStaticData(folder, item, generatedFileList);
            }
            #endregion

            WriteReadMeFile(folder, generatedFileList);
        }
 private static void SaveDiagramFiles(string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
 {
     var fileName = Path.Combine(rootFolder, "diagram.xml");
     var document = new XmlDocument();
     document.LoadXml(@"<configuration type=""diagram""></configuration>");
     foreach (var shape in diagram.NestedChildShapes)
     {
         if (shape is EntityShape)
         {
             var item = ((shape as EntityShape).ModelElement as Entity);
             var node = XmlHelper.AddElement(document.DocumentElement, "element");
             XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
             XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
         }
         else if (shape is ViewShape)
         {
             var item = ((shape as ViewShape).ModelElement as View);
             var node = XmlHelper.AddElement(document.DocumentElement, "element");
             XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
             XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
         }
         else if (shape is StoredProcedureShape)
         {
             var item = ((shape as StoredProcedureShape).ModelElement as StoredProcedure);
             var node = XmlHelper.AddElement(document.DocumentElement, "element");
             XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
             XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
         }
         else if (shape is FunctionShape)
         {
             var item = ((shape as FunctionShape).ModelElement as Function);
             var node = XmlHelper.AddElement(document.DocumentElement, "element");
             XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
             XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
         }
     }
     WriteFileIfNeedBe(fileName, document.ToIndentedString(), generatedFileList);
 }
Exemplo n.º 10
0
        public static void SaveToDisk(nHydrateModel modelRoot, string rootFolder, string modelName, nHydrateDiagram diagram)
        {
            modelRoot.IsSaving = true;
            try
            {
                var folderName        = modelName.Replace(".nhydrate", ".model");
                var modelFolder       = GetModelFolder(rootFolder, folderName);
                var generatedFileList = new List <string>();
                nHydrate.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.Views, modelFolder, diagram, generatedFileList); //must come before entities
                nHydrate.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.Entities, modelFolder, diagram, generatedFileList);
                nHydrate.Dsl.Custom.SQLFileManagement.SaveDiagramFiles(modelFolder, diagram, generatedFileList);
                RemoveOrphans(modelFolder, generatedFileList);

                try
                {
                    var compressedFile = Path.Combine(rootFolder, modelName + ".zip");
                    if (File.Exists(compressedFile))
                    {
                        File.Delete(compressedFile);
                        System.Threading.Thread.Sleep(300);
                    }

                    //Create ZIP file with entire model folder
                    System.IO.Compression.ZipFile.CreateFromDirectory(modelFolder, compressedFile, System.IO.Compression.CompressionLevel.Fastest, true);

                    //Now add the top level model artifacts
                    var artifacts = Directory.GetFiles(rootFolder, $"{modelName}.*").ToList();
                    artifacts.RemoveAll(x => x == compressedFile);
                    using (var zipToOpen = System.IO.Compression.ZipFile.Open(compressedFile, System.IO.Compression.ZipArchiveMode.Update))
                    {
                        foreach (var ff in artifacts)
                        {
                            var fi = new FileInfo(ff);
                            zipToOpen.CreateEntryFromFile(ff, fi.Name);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Do Nothing
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                modelRoot.IsSaving = false;
            }
        }
Exemplo n.º 11
0
        protected override void OnMenuPaste(object sender, global::System.EventArgs args)
        {
            nHydrateModel model = null;

            try
            {
                nHydrateDiagram     diagram        = null;
                nHydrate.Dsl.Entity selectedEntity = null;
                foreach (var item in this.CurrentSelection)
                {
                    if (diagram == null && item is nHydrateDiagram)
                    {
                        diagram = item as nHydrateDiagram;
                    }
                    if (diagram == null && item is Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement)
                    {
                        diagram = (item as Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement).Diagram as nHydrateDiagram;
                        if (item is EntityShape)
                        {
                            selectedEntity = (item as EntityShape).ModelElement as nHydrate.Dsl.Entity;
                        }
                    }
                }

                if (diagram != null)
                {
                    model           = diagram.ModelElement as nHydrateModel;
                    model.IsLoading = true;
                }

                var beforeList = model.Entities.ToList();
                base.OnMenuPaste(sender, args);
                var afterList = model.Entities.ToList().Except(beforeList).ToList();

                #region Check indexes after Entity paste to make sure they are setup
                foreach (var item in afterList)
                {
                    try
                    {
                        var settings = Extensions.FromXml <CopyStateSettings>(item.CopyStateInfo);
                        using (var transaction = item.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
                        {
                            //Now reset all indexes
                            item.Indexes.Clear();

                            foreach (var indexDef in settings.Indexes)
                            {
                                var newIndex = item.Indexes.AddNew() as nHydrate.Dsl.Index;
                                newIndex.Clustered = indexDef.Clustered;
                                newIndex.IsUnique  = indexDef.IsUnique;
                                newIndex.Summary   = indexDef.Summary;
                                newIndex.IndexType = indexDef.IndexType;

                                foreach (var columnDef in indexDef.Columns)
                                {
                                    var newColumn = newIndex.IndexColumns.AddNew() as IndexColumn;
                                    newColumn.Ascending = columnDef.Acending;
                                    var fieldRef = item.FieldList.FirstOrDefault(x => x.Name == columnDef.Name);
                                    if (fieldRef != null)
                                    {
                                        newColumn.FieldID = (fieldRef as Microsoft.VisualStudio.Modeling.ModelElement).Id;
                                    }
                                }
                            }
                            transaction.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                #endregion

                #region We have pasted some fields so verify indexes
                //THIS DOES NOT WORK. NEED TO SAVE FIELDS BEFORE/AFTER AND COMPARE
                //if (afterList.Count == 0 && this.CurrentSelection.Count == 1 && selectedEntity != null)
                //{
                //    var item = selectedEntity;
                //    using (var transaction = item.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
                //    {
                //        foreach (Field field in item.FieldList)
                //        {
                //            if (field.IsIndexed)
                //            {
                //                if (!item.Indexes.Any(x => x.FieldList.Any(z => z.Id == field.Id) && x.IndexType == IndexTypeConstants.IsIndexed))
                //                {
                //                    var newIndex = item.Indexes.AddNew() as nHydrate.Dsl.Index;
                //                    newIndex.Clustered = false;
                //                    newIndex.IsUnique = false;
                //                    newIndex.IndexType = IndexTypeConstants.IsIndexed;

                //                    var newColumn = newIndex.IndexColumns.AddNew() as IndexColumn;
                //                    newColumn.Ascending = true;
                //                    newColumn.FieldID = field.Id;
                //                }
                //            }
                //        }

                //        transaction.Commit();
                //    }

                //}
                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (model != null)
                {
                    model.IsLoading = false;
                }
            }
        }
        /// <summary>
        /// Saves Modules to disk
        /// </summary>
        private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable<Module> list, string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
        {
            var folder = rootFolder;
            if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);

            var document = new XmlDocument();
            document.LoadXml(@"<configuration type=""module""></configuration>");

            foreach (var item in list)
            {
                var moduleNode = XmlHelper.AddElement(document.DocumentElement, "module") as XmlElement;
                XmlHelper.AddLineBreak(moduleNode);
                XmlHelper.AddCData(moduleNode, "summary", item.Summary);
                XmlHelper.AddAttribute(moduleNode, "id", item.Id);
                XmlHelper.AddAttribute(moduleNode, "name", item.Name);
                XmlHelper.AddLineBreak(moduleNode);

                var rulesNodes = XmlHelper.AddElement(moduleNode, "ruleset") as XmlElement;
                XmlHelper.AddLineBreak((XmlElement)rulesNodes);

                foreach (var rule in item.ModuleRules.OrderBy(x => x.Name))
                {
                    var fieldNode = XmlHelper.AddElement(rulesNodes, "rule");

                    XmlHelper.AddLineBreak((XmlElement)fieldNode);
                    XmlHelper.AddCData((XmlElement)fieldNode, "summary", rule.Summary);
                    XmlHelper.AddLineBreak((XmlElement)fieldNode);

                    XmlHelper.AddAttribute(fieldNode, "status", rule.Status.ToString("d"));
                    XmlHelper.AddAttribute(fieldNode, "dependentmodule", rule.DependentModule);
                    XmlHelper.AddAttribute(fieldNode, "name", rule.Name);
                    XmlHelper.AddAttribute(fieldNode, "inclusion", rule.Inclusion);
                    XmlHelper.AddAttribute(fieldNode, "enforced", rule.Enforced);

                    XmlHelper.AddLineBreak((XmlElement)rulesNodes);
                }

            }

            var f = Path.Combine(folder, "modules.configuration.xml");
            WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
            WriteReadMeFile(folder, generatedFileList);
        }
        /// <summary>
        /// Saves Functions to disk
        /// </summary>
        private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable<Function> list, string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
        {
            var folder = Path.Combine(rootFolder, FOLDER_FC);
            if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
            foreach (var item in list)
            {
                var f = Path.Combine(folder, item.Name + ".sql");
                WriteFileIfNeedBe(f, item.SQL, generatedFileList);
            }

            #region Save other parameter/field information
            foreach (var item in list)
            {
                var document = new XmlDocument();
                document.LoadXml(@"<configuration type=""function"" name=""" + item.Name + @"""></configuration>");

                XmlHelper.AddLineBreak(document.DocumentElement);
                XmlHelper.AddCData(document.DocumentElement, "summary", item.Summary);
                XmlHelper.AddLineBreak(document.DocumentElement);

                XmlHelper.AddAttribute(document.DocumentElement, "id", item.Id);
                XmlHelper.AddAttribute(document.DocumentElement, "precedenceorder", item.PrecedenceOrder);
                XmlHelper.AddAttribute(document.DocumentElement, "codefacade", item.CodeFacade);
                XmlHelper.AddAttribute(document.DocumentElement, "isgenerated", item.IsGenerated);
                XmlHelper.AddAttribute(document.DocumentElement, "schema", item.Schema);
                XmlHelper.AddAttribute(document.DocumentElement, "istable", item.IsTable);
                XmlHelper.AddAttribute(document.DocumentElement, "returnvariable", item.ReturnVariable);

                var fieldsNodes = XmlHelper.AddElement(document.DocumentElement, "fieldset") as XmlElement;
                XmlHelper.AddLineBreak((XmlElement)fieldsNodes);

                foreach (var field in item.Fields.OrderBy(x => x.Name))
                {
                    var fieldNode = XmlHelper.AddElement(fieldsNodes, "field");

                    XmlHelper.AddLineBreak((XmlElement)fieldNode);
                    XmlHelper.AddCData((XmlElement)fieldNode, "summary", field.Summary);
                    XmlHelper.AddLineBreak((XmlElement)fieldNode);

                    XmlHelper.AddAttribute(fieldNode, "id", field.Id);
                    XmlHelper.AddAttribute(fieldNode, "name", field.Name);
                    XmlHelper.AddAttribute(fieldNode, "nullable", field.Nullable);
                    XmlHelper.AddAttribute(fieldNode, "datatype", field.DataType.ToString());
                    XmlHelper.AddAttribute(fieldNode, "codefacade", field.CodeFacade);
                    XmlHelper.AddAttribute(fieldNode, "default", field.Default);
                    XmlHelper.AddAttribute(fieldNode, "isgenerated", field.IsGenerated);
                    XmlHelper.AddAttribute(fieldNode, "length", field.Length);
                    XmlHelper.AddAttribute(fieldNode, "scale", field.Scale);

                    XmlHelper.AddLineBreak((XmlElement)fieldsNodes);
                }

                var parametersNodes = XmlHelper.AddElement(document.DocumentElement, "parameterset") as XmlElement;
                XmlHelper.AddLineBreak((XmlElement)parametersNodes);

                foreach (var parameter in item.Parameters.OrderBy(x => x.Name))
                {
                    var parameterNode = XmlHelper.AddElement(parametersNodes, "parameter");

                    XmlHelper.AddLineBreak((XmlElement)parameterNode);
                    XmlHelper.AddCData((XmlElement)parameterNode, "summary", parameter.Summary);
                    XmlHelper.AddLineBreak((XmlElement)parameterNode);

                    XmlHelper.AddAttribute(parameterNode, "id", parameter.Id);
                    XmlHelper.AddAttribute(parameterNode, "name", parameter.Name);
                    XmlHelper.AddAttribute(parameterNode, "nullable", parameter.Nullable);
                    XmlHelper.AddAttribute(parameterNode, "datatype", parameter.DataType.ToString());
                    XmlHelper.AddAttribute(parameterNode, "codefacade", parameter.CodeFacade);
                    XmlHelper.AddAttribute(parameterNode, "default", parameter.Default);
                    XmlHelper.AddAttribute(parameterNode, "isgenerated", parameter.IsGenerated);
                    XmlHelper.AddAttribute(parameterNode, "length", parameter.Length);
                    XmlHelper.AddAttribute(parameterNode, "scale", parameter.Scale);

                    XmlHelper.AddLineBreak((XmlElement)parametersNodes);
                }

                XmlHelper.AddLineBreak(document.DocumentElement);
                var f = Path.Combine(folder, item.Name + ".configuration.xml");
                WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);

                //Save other files
                SaveModules(folder, item, generatedFileList);

            }
            #endregion

            WriteReadMeFile(folder, generatedFileList);
        }
        private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable<ModelMetadata> list, string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
        {
            if (!list.Any())
                return;

            var document = new XmlDocument();
            document.LoadXml(@"<configuration type=""model.metadata""></configuration>");

            XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
            foreach (var metadata in list)
            {
                var metaDataNode = XmlHelper.AddElement(document.DocumentElement, "metadata");
                XmlHelper.AddAttribute(metaDataNode, "key", metadata.Key);
                XmlHelper.AddAttribute(metaDataNode, "value", metadata.Value);
                XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
            }

            var f = Path.Combine(rootFolder, "metadata.configuration.xml");
            WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
        }
        /// <summary>
        /// Saves Stored Procedures to disk
        /// </summary>
        private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable<Entity> list, string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
        {
            var folder = Path.Combine(rootFolder, FOLDER_ET);
            if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);

            #region Save other parameter/field information
            foreach (var item in list)
            {
                var document = new XmlDocument();
                document.LoadXml(@"<configuration type=""entity"" name=""" + item.Name + @"""></configuration>");

                XmlHelper.AddLineBreak(document.DocumentElement);
                XmlHelper.AddCData(document.DocumentElement, "summary", item.Summary);
                XmlHelper.AddLineBreak(document.DocumentElement);

                XmlHelper.AddAttribute(document.DocumentElement, "id", item.Id);
                XmlHelper.AddAttribute(document.DocumentElement, "allowaudittracking", item.AllowAuditTracking);
                XmlHelper.AddAttribute(document.DocumentElement, "allowcreateaudit", item.AllowCreateAudit);
                XmlHelper.AddAttribute(document.DocumentElement, "allowmodifyaudit", item.AllowModifyAudit);
                XmlHelper.AddAttribute(document.DocumentElement, "allowtimestamp", item.AllowTimestamp);
                XmlHelper.AddAttribute(document.DocumentElement, "codefacade", item.CodeFacade);
                XmlHelper.AddAttribute(document.DocumentElement, "immutable", item.Immutable);
                XmlHelper.AddAttribute(document.DocumentElement, "enforceprimarykey", item.EnforcePrimaryKey);
                XmlHelper.AddAttribute(document.DocumentElement, "isassociative", item.IsAssociative);
                XmlHelper.AddAttribute(document.DocumentElement, "typedentity", item.TypedEntity.ToString());
                XmlHelper.AddAttribute(document.DocumentElement, "schema", item.Schema);
                XmlHelper.AddAttribute(document.DocumentElement, "generatesdoublederived", item.GeneratesDoubleDerived);
                XmlHelper.AddAttribute(document.DocumentElement, "isgenerated", item.IsGenerated);
                XmlHelper.AddAttribute(document.DocumentElement, "isTenant", item.IsTenant);

                #region Fields
                {
                    var fieldsNodes = XmlHelper.AddElement(document.DocumentElement, "fieldset") as XmlElement;
                    XmlHelper.AddLineBreak((XmlElement)fieldsNodes);
                    foreach (var field in item.Fields.OrderBy(x => x.Name))
                    {
                        var fieldNode = XmlHelper.AddElement(fieldsNodes, "field");

                        XmlHelper.AddLineBreak((XmlElement)fieldNode);
                        XmlHelper.AddCData((XmlElement)fieldNode, "summary", field.Summary);
                        XmlHelper.AddLineBreak((XmlElement)fieldNode);

                        XmlHelper.AddAttribute(fieldNode, "id", field.Id);
                        XmlHelper.AddAttribute(fieldNode, "name", field.Name);
                        XmlHelper.AddAttribute(fieldNode, "nullable", field.Nullable);
                        XmlHelper.AddAttribute(fieldNode, "datatype", field.DataType.ToString());
                        XmlHelper.AddAttribute(fieldNode, "identity", field.Identity.ToString());
                        XmlHelper.AddAttribute(fieldNode, "codefacade", field.CodeFacade);
                        XmlHelper.AddAttribute(fieldNode, "dataformatstring", field.DataFormatString);
                        XmlHelper.AddAttribute(fieldNode, "default", field.Default);
                        XmlHelper.AddAttribute(fieldNode, "defaultisfunc", field.DefaultIsFunc);
                        XmlHelper.AddAttribute(fieldNode, "formula", field.Formula);
                        XmlHelper.AddAttribute(fieldNode, "isgenerated", field.IsGenerated);
                        XmlHelper.AddAttribute(fieldNode, "isindexed", field.IsIndexed);
                        XmlHelper.AddAttribute(fieldNode, "isprimarykey", field.IsPrimaryKey);
                        XmlHelper.AddAttribute(fieldNode, "Iscalculated", field.IsCalculated);
                        XmlHelper.AddAttribute(fieldNode, "isunique", field.IsUnique);
                        XmlHelper.AddAttribute(fieldNode, "length", field.Length);
                        XmlHelper.AddAttribute(fieldNode, "scale", field.Scale);
                        XmlHelper.AddAttribute(fieldNode, "sortorder", field.SortOrder);
                        XmlHelper.AddAttribute(fieldNode, "isreadonly", field.IsReadOnly);
                        XmlHelper.AddAttribute(fieldNode, "category", field.Category);
                        XmlHelper.AddAttribute(fieldNode, "collate", field.Collate);
                        XmlHelper.AddAttribute(fieldNode, "friendlyname", field.FriendlyName);
                        XmlHelper.AddAttribute(fieldNode, "isbrowsable", field.IsBrowsable);
                        XmlHelper.AddAttribute(fieldNode, "max", field.Max);
                        XmlHelper.AddAttribute(fieldNode, "min", field.Min);
                        XmlHelper.AddAttribute(fieldNode, "validationexpression", field.ValidationExpression);

                        XmlHelper.AddLineBreak((XmlElement)fieldsNodes);
                    }
                    XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
                }
                #endregion

                XmlHelper.AddLineBreak(document.DocumentElement);
                var f = Path.Combine(folder, item.Name + ".configuration.xml");
                WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);

                //Save other files
                SaveEntityIndexes(folder, item, generatedFileList);
                SaveModules(folder, item, generatedFileList);
                SaveRelations(folder, item, generatedFileList);
                SaveEntityStaticData(folder, item, generatedFileList);
                SaveEntityMetaData(folder, item, generatedFileList);
                SaveEntityComposites(folder, item, generatedFileList);

            }
            #endregion

            WriteReadMeFile(folder, generatedFileList);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Saves Views to disk
        /// </summary>
        private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable <View> list, string rootFolder, nHydrateDiagram diagram, List <string> generatedFileList)
        {
            var folder = Path.Combine(rootFolder, FOLDER_VW);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            foreach (var item in list)
            {
                var f = Path.Combine(folder, item.Name + ".sql");
                WriteFileIfNeedBe(f, item.SQL, generatedFileList);
            }

            #region Save other parameter/field information
            foreach (var item in list)
            {
                var document = new XmlDocument();
                document.LoadXml(@"<configuration type=""view"" name=""" + item.Name + @"""></configuration>");

                XmlHelper.AddLineBreak(document.DocumentElement);
                XmlHelper.AddCData(document.DocumentElement, "summary", item.Summary);
                XmlHelper.AddLineBreak(document.DocumentElement);

                XmlHelper.AddAttribute(document.DocumentElement, "id", item.Id);
                XmlHelper.AddAttribute(document.DocumentElement, "codefacade", item.CodeFacade);
                XmlHelper.AddAttribute(document.DocumentElement, "schema", item.Schema);
                XmlHelper.AddAttribute(document.DocumentElement, "generatesdoublederived", item.GeneratesDoubleDerived);

                var fieldsNodes = XmlHelper.AddElement(document.DocumentElement, "fieldset") as XmlElement;
                XmlHelper.AddLineBreak((XmlElement)fieldsNodes);

                foreach (var field in item.Fields.OrderBy(x => x.Name))
                {
                    var fieldNode = XmlHelper.AddElement(fieldsNodes, "field");

                    XmlHelper.AddLineBreak((XmlElement)fieldNode);
                    XmlHelper.AddCData((XmlElement)fieldNode, "summary", field.Summary);
                    XmlHelper.AddLineBreak((XmlElement)fieldNode);

                    XmlHelper.AddAttribute(fieldNode, "id", field.Id);
                    XmlHelper.AddAttribute(fieldNode, "name", field.Name);
                    XmlHelper.AddAttribute(fieldNode, "nullable", field.Nullable);
                    XmlHelper.AddAttribute(fieldNode, "datatype", field.DataType.ToString());
                    XmlHelper.AddAttribute(fieldNode, "codefacade", field.CodeFacade);
                    XmlHelper.AddAttribute(fieldNode, "default", field.Default);
                    XmlHelper.AddAttribute(fieldNode, "length", field.Length);
                    XmlHelper.AddAttribute(fieldNode, "scale", field.Scale);
                    XmlHelper.AddAttribute(fieldNode, "isprimarykey", field.IsPrimaryKey);

                    XmlHelper.AddLineBreak((XmlElement)fieldsNodes);
                }

                XmlHelper.AddLineBreak(document.DocumentElement);
                var f = Path.Combine(folder, item.Name + ".configuration.xml");
                WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
            }
            #endregion

            WriteReadMeFile(folder, generatedFileList);
        }
Exemplo n.º 17
0
        public static void LoadDiagramFiles(nHydrateModel model, string rootFolder, string modelName, nHydrateDiagram diagram)
        {
            if (!model.ModelToDisk)
            {
                return;
            }

            var fileName = Path.Combine(GetModelFolder(rootFolder, modelName), "diagram.xml");

            if (!File.Exists(fileName))
            {
                return;
            }
            using (var transaction = model.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
            {
                var document = new XmlDocument();
                var id       = Guid.Empty;
                try
                {
                    document.Load(fileName);
                    if (document.DocumentElement == null)
                    {
                        throw new Exception("No Root");                                   //this is thrown away
                    }
                    foreach (XmlNode node in document.DocumentElement.ChildNodes)
                    {
                        id = XmlHelper.GetAttributeValue(node, "id", Guid.Empty);
                        var shape = diagram.NestedChildShapes.FirstOrDefault(x => x.ModelElement.Id == id) as Microsoft.VisualStudio.Modeling.Diagrams.NodeShape;
                        if (shape != null)
                        {
                            shape.Bounds = Extensions.ConvertRectangleDFromXmlValue(XmlHelper.GetAttributeValue(node, "bounds", string.Empty));
                        }
                    }
                }
                catch (Exception ex) { return; }
                transaction.Commit();
            }
        }
 public static void SaveToDisk(nHydrateModel modelRoot, string rootFolder, string modelName, nHydrateDiagram diagram)
 {
     modelRoot.IsSaving = true;
     try
     {
         var modelFolder = GetModelFolder(rootFolder, modelName);
         var generatedFileList = new List<string>();
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.ModelMetadata, modelFolder, diagram, generatedFileList);
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.Modules, modelFolder, diagram, generatedFileList);
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.Views, modelFolder, diagram, generatedFileList); //must come before entities (view relations)
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.Entities, modelFolder, diagram, generatedFileList);
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.StoredProcedures, modelFolder, diagram, generatedFileList);
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveToDisk(modelRoot, modelRoot.Functions, modelFolder, diagram, generatedFileList);
         nHydrate2.Dsl.Custom.SQLFileManagement.SaveDiagramFiles(modelFolder, diagram, generatedFileList);
         RemoveOrphans(modelFolder, generatedFileList);
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         modelRoot.IsSaving = false;
     }
 }