Ejemplo n.º 1
0
        public ImportDatabaseForm(
            nHydrateModel model,
            nHydrate.DataImport.Database currentDatabase,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            _model = model;
            this.CurrentDatabase = currentDatabase;

            this.DatabaseConnectionControl1.FileName = Path.Combine((new FileInfo(docData.FileName)).DirectoryName, "importconnection.cache");

            tvwAdd.AfterCheck     += new TreeViewEventHandler(treeView1_AfterCheck);
            tvwRefresh.AfterCheck += new TreeViewEventHandler(treeView1_AfterCheck);
            tvwDelete.AfterCheck  += new TreeViewEventHandler(treeView1_AfterCheck);

            //tvwAdd.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            //tvwRefresh.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            //tvwDelete.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);

            wizard1.BeforeSwitchPages   += new nHydrate.Wizard.Wizard.BeforeSwitchPagesEventHandler(wizard1_BeforeSwitchPages);
            wizard1.AfterSwitchPages    += new nHydrate.Wizard.Wizard.AfterSwitchPagesEventHandler(wizard1_AfterSwitchPages);
            wizard1.Finish              += new EventHandler(wizard1_Finish);
            wizard1.FinishEnabled        = false;
            chkSettingPK.CheckedChanged += new EventHandler(chkSettingPK_CheckedChanged);
            cmdTestConnection.Click     += new EventHandler(cmdTestConnection_Click);

            this.Settings = new ImportModelSettings();
            this.Settings.OverridePrimaryKey = chkSettingPK.Checked;

            DatabaseConnectionControl1.LoadSettings();

            EnableButtons();
        }
Ejemplo n.º 2
0
 public StaticDataForm(Entity entity, Microsoft.VisualStudio.Modeling.Store store, nHydrateModel model, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
     : this()
 {
     _entity  = entity;
     _store   = store;
     _model   = model;
     _docData = docData;
     this.LoadData();
 }
Ejemplo n.º 3
0
 public StaticDataForm(Entity entity, Microsoft.VisualStudio.Modeling.Store store, nHydrateModel model, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
     : this()
 {
     _entity = entity;
     _store = store;
     _model = model;
     _docData = docData;
     this.LoadData();
 }
Ejemplo n.º 4
0
        public RefreshItemFromDatabase(
            nHydrateModel model,
            nHydrate.Dsl.IDatabaseEntity modelElement,
            Microsoft.VisualStudio.Modeling.Store store,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            if (modelElement == null)
            {
                throw new Exception("Model element canot be null.");
            }

            _model        = model;
            _store        = store;
            _modelElement = modelElement;
            _importDomain = new nHydrate.DataImport.SqlClient.ImportDomain();

            this.DatabaseConnectionControl1.FileName = Path.Combine((new FileInfo(docData.FileName)).DirectoryName, "importconnection.cache");
            DatabaseConnectionControl1.LoadSettings();

            //Setup new model
            _auditFields.Add(new SpecialField {
                Name = _model.CreatedByColumnName, Type = SpecialFieldTypeConstants.CreatedBy
            });
            _auditFields.Add(new SpecialField {
                Name = _model.CreatedDateColumnName, Type = SpecialFieldTypeConstants.CreatedDate
            });
            _auditFields.Add(new SpecialField {
                Name = _model.ModifiedByColumnName, Type = SpecialFieldTypeConstants.ModifiedBy
            });
            _auditFields.Add(new SpecialField {
                Name = _model.ModifiedDateColumnName, Type = SpecialFieldTypeConstants.ModifedDate
            });
            _auditFields.Add(new SpecialField {
                Name = _model.TimestampColumnName, Type = SpecialFieldTypeConstants.Timestamp
            });
            _auditFields.Add(new SpecialField {
                Name = _model.TenantColumnName, Type = SpecialFieldTypeConstants.Tenant
            });

            wizard1.FinishEnabled = false;
        }
Ejemplo n.º 5
0
        public void Generate(nHydrateModel model, Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
        {
            this.ErrorList    = new List <string>();
            GeneratedFileList = new List <nHydrate.Generator.Common.EventArgs.ProjectItemGeneratedEventArgs>();
            try
            {
                #region Generation

                //Clean up delete tracking
                model.RemovedTables.Remove(x => model.Entities.Select(y => y.PascalName).Contains(x));
                model.RemovedViews.Remove(x => model.Views.Select(y => y.PascalName).Contains(x));

                var g = new nHydrate.Generator.Common.GeneratorFramework.GeneratorHelper();
                g.ProjectItemGenerated += new nHydrate.Generator.Common.GeneratorFramework.ProjectItemGeneratedEventHandler(g_ProjectItemGenerated);

                var genList = BuildModelList(model, diagram, docData);

                var excludeList       = new List <Type>();
                var generatorTypeList = g.GetProjectGenerators(genList.First());
                if (generatorTypeList.Count == 0)
                {
                    return; //add message box
                }
                if (ChooseGenerators(model, genList, generatorTypeList, excludeList, g))
                {
                    //Perform actual generation
                    if (genList.Count > 0)
                    {
                        PerformGeneration(model, genList, diagram.Store, docData, excludeList, g);
                    }

                    model.RemovedTables.Clear();
                    model.RemovedViews.Clear();
                }

                #endregion

                //Remove temp file
                try
                {
                    genList.ForEach(x => System.IO.File.Delete(x.FileName));
                }
                catch { }

#if DEBUG
                if (this.ErrorList.Count > 0)
                {
                    var F = new nHydrate.DslPackage.Forms.ErrorForm();
                    F.SetErrors(this.ErrorList);
                    F.ShowDialog();
                }
#endif
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        private List <nHydrateGeneratorProject> BuildModelList(nHydrateModel model, Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
        {
            var genList = new List <nHydrateGeneratorProject>();

            var genProject = new nHydrateGeneratorProject();

            genList.Add(genProject);
            var root = CreatePOCOModel(model, diagram);

            root.SetKey(model.Id.ToString());
            root.GeneratorProject            = genProject;
            genProject.RootController.Object = root;
            var fi = new System.IO.FileInfo(docData.FileName);

            genProject.FileName = docData.FileName + ".generating";
            var document = new System.Xml.XmlDocument();

            document.LoadXml("<modelRoot guid=\"" + model.Id + "\" type=\"nHydrate.Generator.nHydrateGeneratorProject\" assembly=\"nHydrate.Generator.dll\"><ModelRoot></ModelRoot></modelRoot>");
            ((nHydrate.Generator.Common.GeneratorFramework.IXMLable)root).XmlAppend(document.DocumentElement.ChildNodes[0]);
            System.IO.File.WriteAllText(genProject.FileName, document.ToIndentedString());

            ProcessRenamed(genProject.FileName + ".sql.lastgen", root);

            root.RemovedTables.AddRange(model.RemovedTables);

            //NOTE: This caused diff scripts to be generated EVERY time so removed for now
            //Remove associative tables since they cause issues if they exist
            //root.RemovedTables.AddRange(model.Entities.Where(x => x.IsAssociative && x.IsGenerated).Select(x => x.Name));

            root.RemovedViews.AddRange(model.RemovedViews);
            //Remove EnumOnly type-tables from the project
            root.RemovedTables.AddRange(model.Entities.Where(x => x.TypedEntity == TypedEntityConstants.EnumOnly).Select(x => x.Name));

            return(genList);
        }
Ejemplo n.º 7
0
        private void PerformGeneration(
            nHydrateModel model,
            List <nHydrateGeneratorProject> genList,
            Microsoft.VisualStudio.Modeling.Store store,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData,
            List <Type> excludeList,
            nHydrate.Generator.Common.GeneratorFramework.GeneratorHelper genHelper)
        {
            _totalFileCount     = 0;
            _processedFileCount = 0;
            var pkey = string.Empty;

            try
            {
                var startTime      = DateTime.Now;
                var isLicenseError = false;
                try
                {
                    //Get the last version we generated on this machine
                    //We will use this to determine if any other generations have been performed on other machines
                    var cacheFile = new nHydrate.Generator.Common.ModelCacheFile(genList.First());
                    var cachedGeneratedVersion = cacheFile.GeneratedVersion;

                    var generatedVersion = cachedGeneratedVersion + 1;

                    pkey = ProgressHelper.ProgressingStarted("Generating...", false, 240000); //Put a 4 minute timer on it
                    foreach (var generator in genList)
                    {
                        var modelRoot = (generator.Model as nHydrate.Generator.Models.ModelRoot);
                        modelRoot.GeneratedVersion = generatedVersion;
                        _totalFileCount           += genHelper.GetFileCount(generator, excludeList);
                    }
                    System.Diagnostics.Debug.WriteLine($"File count: {_totalFileCount}");

                    //Save document
                    var isDirty = 0;
                    docData.IsDirty(out isDirty);
                    if (model.IsDirty || (isDirty != 0))
                    {
                        (docData as nHydrateDocData).Save(docData.FileName, 1, 0);
                    }

                    _startTime = DateTime.Now;
                    foreach (var item in genList)
                    {
                        genHelper.GenerateAll(item, excludeList);
                    }

                    var modelKey = (genList.FirstOrDefault()?.Model as nHydrate.Generator.Models.ModelRoot)?.Key;

                    //Save model statistics
                    var eCount = model.Entities.Count;
                    var fCount = model.Entities.SelectMany(x => x.FieldList).Count();
                    ModelStatsFile.Log(modelKey, eCount, fCount);

                    //Save local copy of last generated version
                    cacheFile.GeneratedVersion = generatedVersion;
                    cacheFile.ModelerVersion   = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                    cacheFile.Save();

                    this.ErrorList = genHelper.GetErrorList().ToList();
                }
                catch (nHydrate.Generator.Common.Exceptions.LicenseException ex)
                {
                    ProgressHelper.ProgressingComplete(pkey);
                    MessageBox.Show("This product is not properly licensed.", "License Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    isLicenseError = true;
                }
                catch (Exception ex)
                {
                    throw;
                }
                finally
                {
                    ProgressHelper.ProgressingComplete(pkey);
                }

                var endTime  = DateTime.Now;
                var duration = endTime.Subtract(startTime);
                #region Show Generation Complete Dialog
                if (!isLicenseError)
                {
                    using (var F = new StatisticsForm())
                    {
                        var text = "The generation was successful.\r\n\r\n";
                        text += "Files generated: " + this.FilesSuccess + "\r\n";
                        text += "Files skipped: " + this.FilesSkipped + "\r\n";
                        text += "Files failed: " + this.FilesFailed + "\r\n";
                        text += "\r\n\r\n";
                        text += "Generation time: " + duration.Hours.ToString("00") + ":" +
                                duration.Minutes.ToString("00") + ":" +
                                duration.Seconds.ToString("00");
                        F.DisplayText       = text;
                        F.GeneratedFileList = this.GeneratedFileList;
                        F.ShowDialog();
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                ProgressHelper.ProgressingComplete(pkey);
                GlobalHelper.ShowError(ex);
            }
        }
Ejemplo n.º 8
0
        public ImportStaticDataForm(nHydrate.Dsl.Entity entity, Microsoft.VisualStudio.Modeling.Store store, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            _entity = entity;
            _store  = store;

            lblWelcome.Text = "This wizard will walk you through the process of import static data from a database entity. The database entity schema must match the target function '" + entity.Name + "' in the modelRoot.";

            this.DatabaseConnectionControl1.FileName = Path.Combine((new FileInfo(docData.FileName)).DirectoryName, "importconnection.cache");
            DatabaseConnectionControl1.LoadSettings();
        }
Ejemplo n.º 9
0
        public ImportDatabaseForm(
            nHydrateModel model,
            Microsoft.VisualStudio.Modeling.Store store,
            Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram,
            nHydrate.DataImport.Database currentDatabase,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            _model = model;
            _store = store;
            _diagram = diagram;
            _docData = docData;
            this.CurrentDatabase = currentDatabase;

            this.DatabaseConnectionControl1.FileName = Path.Combine((new FileInfo(docData.FileName)).DirectoryName, "importconnection.cache");

            tvwAdd.AfterCheck += new TreeViewEventHandler(treeView1_AfterCheck);
            tvwRefresh.AfterCheck += new TreeViewEventHandler(treeView1_AfterCheck);
            tvwDelete.AfterCheck += new TreeViewEventHandler(treeView1_AfterCheck);

            //tvwAdd.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            //tvwRefresh.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            //tvwDelete.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);

            wizard1.BeforeSwitchPages += new nHydrate.Wizard.Wizard.BeforeSwitchPagesEventHandler(wizard1_BeforeSwitchPages);
            wizard1.AfterSwitchPages += new nHydrate.Wizard.Wizard.AfterSwitchPagesEventHandler(wizard1_AfterSwitchPages);
            wizard1.Finish += new EventHandler(wizard1_Finish);
            wizard1.FinishEnabled = false;
            chkSettingPK.CheckedChanged += new EventHandler(chkSettingPK_CheckedChanged);
            cmdTestConnection.Click += new EventHandler(cmdTestConnection_Click);

            this.Settings = new ImportModelSettings();
            this.Settings.OverridePrimaryKey = chkSettingPK.Checked;

            DatabaseConnectionControl1.LoadSettings();

            cboModule.Items.Add("(Choose One)");
            model.Modules.ForEach(x => cboModule.Items.Add(x.Name));
            cboModule.SelectedIndex = 0;
            cboModule.Enabled = model.UseModules;
            chkMergeModule.Visible = model.UseModules;

            EnableButtons();
        }