Esempio n. 1
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     ScaffoldConfig.Load();
     Application.Run(new Form1());
 }
Esempio n. 2
0
        /// <summary>
        ///     Return driver types.
        /// </summary>
        /// <returns>
        ///     The <see cref="object[]" />.
        /// </returns>
        public object[] ReturnLanguageOutputs()
        {
            List <ComboboxItem> items = new List <ComboboxItem>();

            items.Add(new ComboboxItem {
                Text = "Please select"
            });

            if (this.Data != null)
            {
                IDataType dataType = ScaffoldConfig.ReturnDataType(this.Data.DataType);

                foreach (LanguageOutputDetails selectedLanguageDetails in dataType.LanguageOutputDetails)
                {
                    foreach (var language in ScaffoldConfig.LanguageOutputs)
                    {
                        if (selectedLanguageDetails.LanguageOutput
                            == new Guid(language.Metadata["ValueMetaData"].ToString()))
                        {
                            items.Add(
                                new ComboboxItem
                            {
                                Text  = (string)language.Metadata["NameMetaData"],
                                Value = new Guid(language.Metadata["ValueMetaData"].ToString())
                            });

                            break;
                        }
                    }
                }
            }

            return(items.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            if (this.DataSource != null)
            {
                this.loading = true;

                this.TabControl.TabPages.Clear();
                IDriverTypeUI driverTypeUI;

                foreach (IDriverType driverType in this.DriverTypes)
                {
                    var page = new TabPage {
                        Text = driverType.Name, BackColor = DefaultBackColor
                    };
                    driverTypeUI = ScaffoldConfig.ReturnDriverDataTypeUi(driverType.Id, DisplayType.WinForm);
                    page.Controls.Add(driverTypeUI as Control);
                    IDictionary <string, string> parameterList = new Dictionary <string, string>();
                    parameterList.Add("basePath", this.SavePath);
                    driverTypeUI.LoadConfig(parameterList);
                    this.TabControl.TabPages.Add(page);
                }

                this.loading = false;
            }
        }
        static Utilities()
        {
            var di = new DirectoryInfo(Environment.CurrentDirectory);

            file           = Directory.GetFiles(di.Parent.Parent.Parent.Parent.FullName, ".Scaffolding.xml", SearchOption.AllDirectories).FirstOrDefault();
            scaffoldConfig = ScaffoldConfig;
        }
        public void ProjectDomainDetailsUserControlUnitTest_Test()
        {
            ScaffoldConfig.Load();

            ProjectDomainDetailsUserControl control =
                new ProjectDomainDetailsUserControl
            {
                ApplicationService =
                    new ProjectDefinitionApplicationServiceFile()
            };

            control.ApplicationService.AddDomain();

            // Todo:Add Back
            control.ApplicationService.ProjectDefinition.Domains[0].DriverId =
                new Guid(ScaffoldConfig.Drivers[0].Metadata["ValueMetaData"].ToString());

            // control.ApplicationService.ProjectDefinition.Domains[0].DriverTypeId;
            // new Guid(ScaffoldConfig.LanguageOutputs[0].Metadata["ValueMetaData"].ToString())
            control.SelectedDomain = control.ApplicationService.ProjectDefinition.Domains[0];

            Assert.AreEqual(1, control.ReturnDriverTypes().Length, "There should 1 DriverType");
            Assert.AreEqual(3, control.ReturnNamingConventions().Length, "Three should 3 NamingConventionId");
            Assert.AreEqual(1, control.ReturnSourceTypes().Length, "There should 1 Sourcetype");
        }
        /// <summary>
        ///     Returns the data types as Templates
        /// </summary>
        /// <returns>
        ///     The <see cref="List" />.
        /// </returns>
        /// <summary>
        ///     Validate class.
        /// </summary>
        /// <returns>
        ///     The <see cref="List{T}" />
        ///     Errors returned
        /// </returns>
        public List <Validation> Validate()
        {
            Logger.Trace($"Started Validate()");
            this.ValidationResult = this.ProjectDefinition.Validate();
            List <Validation> validations;

            foreach (DomainDefinition definition in this.ProjectDefinition.Domains)
            {
                foreach (Template template in definition.Package.Templates)
                {
                    var parameters =
                        new Dictionary <string, string> {
                        { "basePath", this.ProjectDefinition.OutputPath }
                    };

                    IDataType dataType = ScaffoldConfig.ReturnDataType(template.DataType);
                    dataType.DomainDefinition = this.ProjectDefinition.Domains[0];
                    dataType.Load(parameters);
                    validations = dataType.Validate();

                    foreach (Validation validation in validations)
                    {
                        this.ValidationResult.Add(validation);
                    }
                }
            }

            Logger.Trace($"Completed Validate()");
            return(this.ValidationResult);
        }
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (DataSource != null)
            {
                this.loading = true;

                sourceType = ScaffoldConfig.ReturnSourceType(DataSource.SourceTypeId);

                ITableHierarchyService applicationService = new TempateHierarchyService();
                List <Hierarchy>       hierarchy          =
                    applicationService.ReturnHierarchyFromList(DataSource.Tables, true, true, true);

                AddNodes("Models", DomainTreeView, hierarchy, applicationService);

                this.loading = false;
            }
            else
            {
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
Esempio n. 8
0
        internal static void FormattingXml(Model model, DatabaseModel databaseModel)
        {
            var entityTypes = model.GetEntityTypes();
            var newConfig   = new ScaffoldConfig
            {
                Namespaces = ScaffoldConfig.Namespaces?.OrderBy(o => o.Value).ToArray(),
                Classes    = Array.Empty <Class>(),
            };

            IList <Class> list = new List <Class>();

            foreach (var table in databaseModel.Tables.OrderBy(o => o.Name))
            {
                // TODO: may has issue.
                var   entityType   = entityTypes.FirstOrDefault(o => table.Name.Replace("_", string.Empty).Equals(o.Name, StringComparison.InvariantCultureIgnoreCase));
                var   configEntity = ScaffoldConfig.Classes.FirstOrDefault(o => o.Name == entityType.Name);
                Class entity       = new Class
                {
                    Name       = entityType.Name,
                    Table      = table.GetType() == typeof(DatabaseView) ? null : table.Name,
                    View       = table.GetType() == typeof(DatabaseView) ? table.Name : null,
                    Summary    = string.IsNullOrEmpty(table.Comment) ? configEntity?.Summary : table.Comment,
                    PrimaryKey = table.PrimaryKey == null ? null : string.Join(",", table.PrimaryKey.Columns.Select(o => o.Name)),
                };
                var properties = entityType.GetProperties();

                IList <Models.Property> propertyList = new List <Models.Property>();
                foreach (var column in table.Columns)
                {
                    // TODO: may has issue.
                    var property       = properties.FirstOrDefault(o => o.Name.Equals(column.Name.Replace("_", string.Empty), StringComparison.InvariantCultureIgnoreCase));
                    var configProperty = configEntity?.Properties.FirstOrDefault(o => o.Name == property.Name);
                    var p = new Models.Property
                    {
                        Name            = property.Name,
                        DefaultValueSql = column.DefaultValueSql,
                        Column          = column.Name,
                        ValueGenerated  = column.ValueGenerated?.ToString(),
                        Summary         = string.IsNullOrEmpty(column.Comment) ? configProperty?.Summary : column.Comment,
                        Type            = configProperty?.Type,
                        Converter       = configProperty?.Converter,
                    };
                    propertyList.Add(p);
                }

                list.Add(entity);
                entity.Properties = propertyList.ToArray();
            }

            newConfig.Classes = list.ToArray();
            string xmlSerialized = Serialize(newConfig);

            File.WriteAllText(file, xmlSerialized, Encoding.UTF8);
        }
        private void DomainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (CurrentlySelectedControl == null ||
                (CurrentlySelectedControl != null && CurrentlySelectedControl.Validate().Count == 0))
            {
                if (e.Node.Tag is Table)
                {
                    var table = e.Node.Tag as Table;
                    modelControl.DataSource  = table;
                    CurrentlySelectedControl = modelControl;
                    modelControl.BringToFront();
                }
                else if (e.Node.Tag is Column)
                {
                    var column = e.Node.Tag as Column;
                    fieldControl.DataSource  = column;
                    CurrentlySelectedControl = fieldControl;
                    fieldControl.BringToFront();
                }
                else if (e.Node.Tag is Relationship)
                {
                    var relationship = e.Node.Tag as Relationship;
                    relationshipControl.Domain     = DataSource;
                    relationshipControl.DataSource = relationship;
                    CurrentlySelectedControl       = relationshipControl;
                    relationshipControl.BringToFront();
                }
                else if (e.Node.Tag is Index)
                {
                    var index = e.Node.Tag as Index;
                    indexUserControl.DataSource = index;
                    CurrentlySelectedControl    = indexUserControl;
                    indexUserControl.BringToFront();
                }
                else if (e.Node.Tag == null)
                {
                    defaultModelControl.BringToFront();

                    if (e.Node.Text.ToLower() == "indexes" && ScaffoldConfig.ReturnSourceType(DataSource.SourceTypeId).GetType().Name == "EdmxSourceType")
                    {
                        SelectedTable = e.Node.Parent.Tag as Table;
                        btnAddIndex.BringToFront();
                        lblAddIndex.BringToFront();
                    }
                    else
                    {
                        SelectedTable = null;
                        btnAddIndex.SendToBack();
                        lblAddIndex.SendToBack();
                    }
                }
            }
        }
Esempio n. 10
0
        public void Save()
        {
            IDriverTypeUI driverTypeUI;

            foreach (IDriverType driverType in this.DriverTypes)
            {
                driverTypeUI = ScaffoldConfig.ReturnDriverDataTypeUi(driverType.Id, DisplayType.WinForm);
                IDictionary <string, string> parameterList = new Dictionary <string, string>();
                parameterList.Add("basePath", this.SavePath);
                driverTypeUI.SaveConfig(parameterList);
            }
        }
Esempio n. 11
0
        internal static void FormattingXml(Model model, DatabaseModel databaseModel)
        {
            var entityTypes = model.GetEntityTypes();
            var newConfig   = new ScaffoldConfig
            {
                Namespaces = ScaffoldConfig.Namespaces.OrderBy(o => o.Value).ToArray(),
                Entities   = Array.Empty <Entity>(),
            };

            IList <Entity> list = new List <Entity>();

            foreach (var table in databaseModel.Tables.OrderBy(o => o.Name))
            {
                // TODO: may has issue.
                var    entityType   = entityTypes.FirstOrDefault(o => table.Name.Replace("_", string.Empty).Equals(o.Name, StringComparison.InvariantCultureIgnoreCase));
                var    configEntity = ScaffoldConfig.Entities.FirstOrDefault(o => o.Name == entityType.Name);
                Entity entity       = new Entity
                {
                    Name = entityType.Name,
                    //TableName = table.Name,
                    Summary = configEntity?.Summary,
                };
                var properties = entityType.GetProperties();

                IList <Scaffolding.Property> propertyList = new List <Scaffolding.Property>();
                foreach (var column in table.Columns)
                {
                    // TODO: may has issue.
                    var property       = properties.FirstOrDefault(o => o.Name.Equals(column.Name.Replace("_", string.Empty), StringComparison.InvariantCultureIgnoreCase));
                    var configProperty = configEntity?.Properties.FirstOrDefault(o => o.Name == property.Name);
                    var p = new Scaffolding.Property
                    {
                        Name = property.Name,
                        //ColumnName = field.Name,
                        Summary    = configProperty?.Summary,
                        CSharpType = configProperty?.CSharpType,
                        Converter  = configProperty?.Converter,
                    };
                    propertyList.Add(p);
                }

                list.Add(entity);
                entity.Properties = propertyList.ToArray();
            }

            newConfig.Entities = list.ToArray();
            string xmlSerialized = Serialize(newConfig);

            File.WriteAllText(file, xmlSerialized, Encoding.UTF8);
        }
        public void Load(string dllPath = "")
        {
            Logger.Trace($"Started Load() - Path: {this.FilePersistenceOptions.Path}");
            this.ProjectDefinition = ObjectXMLSerializer <ProjectDefinition> .Load(this.FilePersistenceOptions.Path);

            ScaffoldConfig.Load(dllPath);
            foreach (var domain in this.ProjectDefinition.Domains)
            {
                // Todo: The fix shouldn't come from the SourceType
                var sourceType = ScaffoldConfig.ReturnSourceType(domain.SourceTypeId);
                sourceType.Fix(domain.Tables);
            }

            Logger.Trace($"Completed Load() - Path: {this.FilePersistenceOptions.Path}");
        }
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (this.DataSource != null)
            {
                this.sourceType = ScaffoldConfig.ReturnSourceType(this.DataSource.SourceTypeId);
                var a = this.sourceType.Import(this.sourceType.Load(this.SavePath));
            }
            else
            {
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
Esempio n. 14
0
        /// <summary>
        ///     The validate.
        /// </summary>
        /// <returns>
        ///     The <see cref="List" />.
        /// </returns>
        public override List <Validation> Validate()
        {
            this.ValidationResult = new List <Validation>();
            this.MissingApplicationList.Clear();

            if (this.ApplicationServiceDataType == null)
            {
                this.ApplicationServiceDataType =
                    ScaffoldConfig.ReturnDataType(new Guid("1BC1B0C4-1E41-9146-82CF-599181CE4420")) as ApplicationServiceDataType;
            }

            foreach (var webApiServiceData in this.WebApiDataList)
            {
                foreach (ApplicationServiceData serviceData in webApiServiceData.Models)
                {
                    if (!this.ApplicationServiceDataType.ApplicationServiceData.Exists(t => t.Id == serviceData.Id))
                    {
                        this.ValidationResult.Add(
                            new Validation(
                                ValidationType.ApplicationServicesMissing,
                                $"The {webApiServiceData.WebApiName} WebApi is missing {serviceData.ApplicationServiceName} Application Service"));
                        this.MissingApplicationList.Add(
                            new ApplicationServiceDataError
                        {
                            ApplicationServiceName = serviceData.ApplicationServiceName,
                            ApplicationServiceData = serviceData
                        });
                    }

                    if (string.IsNullOrEmpty(webApiServiceData.WebApiName))
                    {
                        this.ValidationResult.Add(
                            new Validation(ValidationType.ContextNameEmpty, "WebApiDataList must have a name"));
                    }
                }
            }

            if (this.LanguageOutputDetails.Count == 0)
            {
                this.ValidationResult.Add(
                    new Validation(
                        ValidationType.DataTypeLanguageMissing,
                        "A Datatype must have at least one LanguageOption"));
            }

            return(this.ValidationResult);
        }
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (this.DataSource != null)
            {
                this.updateModelsFromSourceUserControl1.SavePath = this.SavePath;
                this.sourceType = ScaffoldConfig.ReturnSourceType(this.DataSource.SourceTypeId);
                this.updateModelsFromSourceUserControl1.DataSource = this.DataSource;
            }
            else
            {
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
Esempio n. 16
0
        /// <summary>
        /// The return driver types.
        /// </summary>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        private List <IDriverType> ReturnDriverTypes()
        {
            List <IDriverType> result = new List <IDriverType>();

            IDriver driver;

            foreach (Guid driverId in this.DataSource.DriverIdList)
            {
                driver = ScaffoldConfig.ReturnDriver(driverId);

                if (!result.Any(d => d.Id == driver.DriverType.Id))
                {
                    result.Add(driver.DriverType);
                }
            }

            return(result);
        }
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (this.DataSource != null)
            {
                this.sourceType = ScaffoldConfig.ReturnSourceType(this.DataSource.SourceTypeId);
                this.panel1.Controls.Clear();
                this.sourceTypeControl            = this.sourceType.AddConfigUI(this.panel1) as IDataSourceUI;
                this.sourceTypeControl.SourceType = this.sourceType;
                this.sourceTypeControl.LoadData(this.SavePath);
            }
            else
            {
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
        /// <summary>
        /// Create test values.
        /// </summary>
        /// <param name="applicationService">
        /// The application Service.
        /// </param>
        protected void CreateTestValues(IConfigurationApplicationService applicationService)
        {
            List <DataType> dataTypes = new List <DataType>();

            dataTypes.Add(new DataType {
                Id = Guid.NewGuid(), Name = "Context"
            });
            dataTypes.Add(new DataType {
                Id = Guid.NewGuid(), Name = "Entity"
            });
            dataTypes.Add(new DataType {
                Id = Guid.NewGuid(), Name = "Repository"
            });
            dataTypes.Add(new DataType {
                Id = Guid.NewGuid(), Name = "Application Service"
            });
            dataTypes.Add(new DataType {
                Id = Guid.NewGuid(), Name = "ViewModel"
            });
            applicationService.ApplicationSettings.DataTypes = dataTypes;

            ScaffoldConfig.Load();

            Template template = new Template
            {
                ConfigLocation   = ConfigLocation.Data,
                DataType         = Guid.Empty,
                Id               = Guid.NewGuid(),
                Name             = "Template",
                Version          = 1,
                TemplatePath     = "Test.t4",
                LanguageOutputId =
                    new Guid(
                        ScaffoldConfig.LanguageOutputs[0].Metadata["ValueMetaData"]
                        .ToString()),
                GeneratorTypeId = new Guid(
                    ScaffoldConfig.OutputGenerators[0].Metadata["ValueMetaData"]
                    .ToString())
            };

            applicationService.ApplicationSettings.Templates.Add(template);
        }
Esempio n. 19
0
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (DataSource != null)
            {
                this.loading = true;

                ModelFormUserControl1.SavePath = SavePath;
                sourceType = ScaffoldConfig.ReturnSourceType(DataSource.SourceTypeId);
                ModelFormUserControl1.DataSource = DataSource;

                this.loading = false;
            }
            else
            {
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
Esempio n. 20
0
        /// <summary>
        /// The combo box language output_ selected index changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ComboBoxLanguageOutput_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboboxItem selectedItem = (sender as ComboBox).SelectedItem as ComboboxItem;

            if (selectedItem != null && this.DataSourceInitialized)
            {
                if (selectedItem.Value != null)
                {
                    this.LanguageId = new Guid(selectedItem.Value.ToString());

                    IDataType             dataType             = ScaffoldConfig.ReturnDataType(this.Data.DataType);
                    LanguageOutputDetails languageOutputDetail =
                        dataType.LanguageOutputDetails.FirstOrDefault(l => l.LanguageOutput == this.LanguageId);

                    this.GeneratorTypeId = languageOutputDetail.OutputGenerator;

                    this.ComboBoxGeneratorOutput.SelectedValue = this.GeneratorTypeId;

                    this.ListBoxTemplates.Items.Clear();
                    foreach (string template in languageOutputDetail.Templates)
                    {
                        this.ListBoxTemplates.Items.Add(template);
                    }

                    if (languageOutputDetail?.Templates != null && languageOutputDetail.Templates.Any())
                    {
                        this.TemplatePath = languageOutputDetail.Templates[0];
                    }
                }
                else
                {
                    this.LanguageId      = Guid.Empty;
                    this.GeneratorTypeId = Guid.Empty;
                    this.ComboBoxGeneratorOutput.SelectedIndex = 0;
                    this.ListBoxTemplates.Items.Clear();
                }

                this.UpdateRelatedPackages();
            }
        }
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (this.DataSource != null)
            {
                Thread splashthread = this.StartSplashScreen();
                Thread.Sleep(100);
                SplashScreen.UdpateStatusText("Loading schema information");

                this.sourceType = ScaffoldConfig.ReturnSourceType(this.DataSource.SourceTypeId);
                this.tabPage2.Controls.Clear();
                this.sourceTypeControl            = this.sourceType.AddConfigUI(this.tabPage2) as IDataSourceUI;
                this.sourceTypeControl.SourceType = this.sourceType;

                if (this.sourceTypeControl.LoadData(this.SavePath))
                {
                    Thread.Sleep(100);
                    this.CloseSplashScreen();
                }
                else
                {
                    Thread.Sleep(100);
                    this.CloseSplashScreen();

                    MessageBox.Show(
                        "Failed to Connect to Datasource",
                        "Loading",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
            }
            else
            {
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
Esempio n. 22
0
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (this.DataSource != null)
            {
                this.sourceType = ScaffoldConfig.ReturnSourceType(this.DataSource.SourceTypeId);

                var sourceOptions = this.sourceType.Load(this.SavePath);

                if (this.sourceType.Test(sourceOptions))
                {
                    this.StartSplashScreen();
                    Thread.Sleep(100);
                    SplashScreen.UdpateStatusText("Loading schema information");

                    this.sourceDomain = this.sourceType.Import(sourceOptions);

                    IApplicationTableCollectionDifference differenceService =
                        new ApplicationTableCollectionDifference(new ApplicationTableDifference());
                    this.differences = differenceService.CompareTables(this.DataSource.Tables, this.sourceDomain.Tables);

                    ITableHierarchyService applicationService = new TempateHierarchyService();
                    List <Hierarchy>       hierarchy          = applicationService.ReturnHierarchyFromList(
                        this.differences.FirstExtraTables,
                        false,
                        false,
                        false);
                    this.AddNodes("Models", this.TreeViewAdd, hierarchy, applicationService);

                    hierarchy = applicationService.ReturnHierarchyFromList(this.differences.RefreshTable, false, false, false);

                    this.AddNodes("Models", this.TreeViewRefresh, hierarchy, applicationService);

                    hierarchy = applicationService.ReturnHierarchyFromList(
                        this.differences.FirstMissingTables,
                        false,
                        false,
                        false);

                    this.AddNodes("Models", this.TreeViewDelete, hierarchy, applicationService);
                    this.Valid = true;

                    Thread.Sleep(100);
                    this.CloseSplashScreen(false);
                }
                else
                {
                    MessageBox.Show(
                        "Invalid configuration. Please update source configuration.",
                        "Configuration Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    this.Valid = false;
                }
            }
            else
            {
                this.Valid = false;
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }