public WebProjectSelectionNode(Core.VplControl hostCanvas) : base(hostCanvas) { DataContext = this; AddOutputPortToNode("Project", typeof(object)); // Call the Singleton Class to get the actual loaded elements -> Connection to the DataModel _controller = DataController.Instance; IsResizeable = true; var webControl = new ProjectSelection(_controller.IntBase); { Visibility = Visibility.Visible; }; // webControl.ProjectChangedEventHandler += ProjectSelectionViewModelOnProjectChangedEventHandler; // webControl.TeamChangedEventHandler += ProjectSelectionViewModelOnTeamChangedEventHandler; var pr = new ContentPresenter { Content = webControl, MinWidth = 600, MinHeight = 600 }; AddControlToNode(pr); }
public static DapperProject Selection(this DapperProject project, string pattern, Action <DapperProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { var globalSettings = project.GlobalSelection().Settings; selection = new ProjectSelection <DapperProjectSettings> { Pattern = pattern, Settings = new DapperProjectSettings { ForceOverwrite = globalSettings.ForceOverwrite, SimplifyDataTypes = globalSettings.SimplifyDataTypes, UseAutomaticPropertiesForEntities = globalSettings.UseAutomaticPropertiesForEntities, EnableDataBindings = globalSettings.EnableDataBindings, UseStringBuilderForQueries = globalSettings.UseStringBuilderForQueries, InsertExclusions = globalSettings.InsertExclusions.Select(item => item).ToList(), UpdateExclusions = globalSettings.UpdateExclusions.Select(item => item).ToList(), AddPagingForGetAllOperation = globalSettings.AddPagingForGetAllOperation } }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
public static EntityFrameworkCoreProject Select(this EntityFrameworkCoreProject project, string pattern, Action <EntityFrameworkCoreProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { var globalSettings = project.GlobalSelection().Settings; selection = new ProjectSelection <EntityFrameworkCoreProjectSettings> { Pattern = pattern, Settings = new EntityFrameworkCoreProjectSettings { UseDataAnnotations = globalSettings.UseDataAnnotations, AddDataBindings = globalSettings.AddDataBindings, EntitiesWithDataContracts = globalSettings.EntitiesWithDataContracts } }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
private void ButtonOnClick(object sender, RoutedEventArgs routedEventArgs) { if (_dataController.IntBase == null) { Login(); } if (_dataController.IntBase == null) { return; } _dataController.IntBase.EventHandlerCore.ProjectChanged += EventHandlerCoreOnProjectChanged; _projectSelection = new ProjectSelection(_dataController.IntBase); contentGrid = new Grid() { Height = 600, Width = 500 }; contentGrid.Children.Add(_projectSelection); hostWindow = new Window() { WindowStartupLocation = WindowStartupLocation.CenterOwner, SizeToContent = SizeToContent.WidthAndHeight }; hostWindow.Content = contentGrid; hostWindow.ShowDialog(); }
public static DapperProject GlobalSelection(this DapperProject project, Action <DapperProjectSettings> action = null) { var settings = new DapperProjectSettings(); var selection = project.Selections.FirstOrDefault(item => item.IsGlobal); if (selection == null) { selection = new ProjectSelection <DapperProjectSettings> { Pattern = ProjectSelection <DapperProjectSettings> .GlobalPattern, Settings = settings }; project.Selections.Add(selection); } else { settings = selection.Settings; } action?.Invoke(settings); return(project); }
public static AspNetCoreProject Selection(this AspNetCoreProject project, string pattern, Action <AspNetCoreProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { var globalSettings = project.GlobalSelection().Settings; selection = new ProjectSelection <AspNetCoreProjectSettings> { Pattern = pattern, Settings = new AspNetCoreProjectSettings { ForceOverwrite = globalSettings.ForceOverwrite, UseLogger = globalSettings.UseLogger, ConcurrencyToken = globalSettings.ConcurrencyToken, AuditEntity = new AuditEntity { CreationUserColumnName = globalSettings.AuditEntity.CreationUserColumnName, CreationDateTimeColumnName = globalSettings.AuditEntity.CreationDateTimeColumnName, LastUpdateUserColumnName = globalSettings.AuditEntity.LastUpdateUserColumnName, LastUpdateDateTimeColumnName = globalSettings.AuditEntity.LastUpdateDateTimeColumnName }, EntitiesWithDataContracts = globalSettings.EntitiesWithDataContracts } }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
private void btnContinue_Click(object sender, EventArgs e) { //Hide error text lblLoginError.Visible = false; //Get input values string username = txtUsername.Text, password = txtPassword.Text; //Check if user exists if (!Validation.CheckIfUserExists(username)) { lblLoginError.Text = "User does not exists"; lblLoginError.Visible = true; return; } //Hash password string hashedPassword = Hashing.HashPassword(password); //Check login credentials if (!Validation.CheckLoginCredentials(username, hashedPassword)) { lblLoginError.Text = "Incorrect password"; lblLoginError.Visible = true; return; } else { ProjectSelection projectSetup = new ProjectSelection(); this.Visible = false; Settings.Default.Username = username; projectSetup.Show(); } }
public static AspNetCoreProject Selection(this AspNetCoreProject project, string pattern, Action <AspNetCoreProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { var globalSettings = project.GlobalSelection().Settings; selection = new ProjectSelection <AspNetCoreProjectSettings> { Pattern = pattern, Settings = new AspNetCoreProjectSettings { ForceOverwrite = globalSettings.ForceOverwrite, UseLogger = globalSettings.UseLogger } }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
private void projectSelectionToolStripMenuItem_Click(object sender, EventArgs e) { ProjectSelection projectSelection = new ProjectSelection(); Settings.Default.ProjectID = ""; projectSelection.Show(); this.Close(); }
public ViewModelLocator() { Document document = new Document(); CreateSampleData(document); ProjectSelection projectSelection = new ProjectSelection(); _main = new MainViewModel(document, projectSelection); }
public void Post([FromBody] ProjectSelection projectSelection) { try { _logger.LogInformation("Creating new project selection: {p.PojectListID}", projectSelection.ProjectListID); // CreatedBy and UpdatedBy are the same for creating Project_Selection writeProject.InsertProjectSelection(projectSelection.ProjectListID, projectSelection.CreatedBy, projectSelection.UpdatedBy, DateTime.Now); } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw ex; } }
public static EntityFrameworkCoreProject Selection(this EntityFrameworkCoreProject project, string pattern, Action <EntityFrameworkCoreProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { var globalSettings = project.GlobalSelection().Settings; selection = new ProjectSelection <EntityFrameworkCoreProjectSettings> { Pattern = pattern, Settings = new EntityFrameworkCoreProjectSettings { ForceOverwrite = globalSettings.ForceOverwrite, SimplifyDataTypes = globalSettings.SimplifyDataTypes, UseAutomaticPropertiesForEntities = globalSettings.UseAutomaticPropertiesForEntities, EnableDataBindings = globalSettings.EnableDataBindings, UseDataAnnotations = globalSettings.UseDataAnnotations, DeclareNavigationProperties = globalSettings.DeclareNavigationProperties, DeclareNavigationPropertiesAsVirtual = globalSettings.DeclareNavigationPropertiesAsVirtual, NavigationPropertyEnumerableNamespace = globalSettings.NavigationPropertyEnumerableNamespace, NavigationPropertyEnumerableType = globalSettings.NavigationPropertyEnumerableType, ConcurrencyToken = globalSettings.ConcurrencyToken, EntityInterfaceName = globalSettings.EntityInterfaceName, AuditEntity = globalSettings.AuditEntity == null ? null : new AuditEntity { CreationUserColumnName = globalSettings.AuditEntity.CreationUserColumnName, CreationDateTimeColumnName = globalSettings.AuditEntity.CreationDateTimeColumnName, LastUpdateUserColumnName = globalSettings.AuditEntity.LastUpdateUserColumnName, LastUpdateDateTimeColumnName = globalSettings.AuditEntity.LastUpdateDateTimeColumnName }, EntitiesWithDataContracts = globalSettings.EntitiesWithDataContracts, BackingFields = globalSettings.BackingFields.Select(item => item).ToList(), InsertExclusions = globalSettings.InsertExclusions.Select(item => item).ToList(), UpdateExclusions = globalSettings.UpdateExclusions.Select(item => item).ToList(), AddConfigurationForForeignKeysInFluentAPI = globalSettings.AddConfigurationForForeignKeysInFluentAPI, AddConfigurationForUniquesInFluentAPI = globalSettings.AddConfigurationForUniquesInFluentAPI, AddConfigurationForChecksInFluentAPI = globalSettings.AddConfigurationForChecksInFluentAPI, AddConfigurationForDefaultsInFluentAPI = globalSettings.AddConfigurationForDefaultsInFluentAPI, } }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
public void ProcessRegistration(string name, string pw1, string pw2, string email) { if (Networking.Networking.instance.Create_User(Username, Password2)) { Console.WriteLine("Registered"); IProjectSelection window = new ProjectSelection(); window.Show(); window.Close(); Notification.Notification.instance.showNotification("User " + Username + "has been registered"); } else { Notification.Notification.instance.showNotification("User could not be registered"); Console.WriteLine("User could not be created"); } }
public static EntityFrameworkCoreProject Select(this EntityFrameworkCoreProject project, string pattern, Action <EntityFrameworkCoreProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { selection = new ProjectSelection <EntityFrameworkCoreProjectSettings> { Pattern = pattern, Settings = new EntityFrameworkCoreProjectSettings() }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
public static DapperProject Selection(this DapperProject project, string pattern, Action <DapperProjectSettings> action = null) { var selection = project.Selections.FirstOrDefault(item => item.Pattern == pattern); if (selection == null) { selection = new ProjectSelection <DapperProjectSettings> { Pattern = pattern, Settings = new DapperProjectSettings() }; project.Selections.Add(selection); } action?.Invoke(selection.Settings); return(project); }
internal static Project SelectProjectManually() { if (Global.GetSolutionProjects().Count == 0) { System.Windows.MessageBox.Show("No projects can be identified in the solution", "Error"); return(null); } var dialog = new ProjectSelection(Global.GetSolutionProjects()); IVsUIShell uiShell = (IVsUIShell)Global.GetService(typeof(SVsUIShell)); IntPtr mainWnd; uiShell.GetDialogOwnerHwnd(out mainWnd); WindowInteropHelper helper = new WindowInteropHelper(dialog); helper.Owner = mainWnd; dialog.ShowDialog(); return(dialog.SelectedItem); }
private static MethodDefinition GetGetAllMethodWithoutForeigns(ProjectFeature <EntityFrameworkCoreProjectSettings> projectFeature, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table) { var project = projectFeature.GetEntityFrameworkCoreProject(); return(new MethodDefinition(AccessModifier.Public, string.Format("IQueryable<{0}>", project.GetEntityName(table)), project.GetGetAllRepositoryMethodName(table)) { Lines = { new CodeLine("return DbContext.{0};", project.GetDbSetPropertyName(table)) } }); }
public static ClassDefinition GetEntityClassDefinition(this EntityFrameworkCoreProject project, ITable table, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection) { return(new ClassDefinition { Name = table.Name }); }
private static MethodDefinition GetGetMethod(ProjectFeature <EntityFrameworkCoreProjectSettings> projectFeature, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table) { var project = projectFeature.GetEntityFrameworkCoreProject(); var expression = string.Empty; if (table.Identity == null) { expression = string.Format("item => {0}", string.Join(" && ", table.PrimaryKey.Key.Select(item => string.Format("item.{0} == entity.{0}", project.CodeNamingConvention.GetPropertyName(item))))); } else { expression = string.Format("item => item.{0} == entity.{0}", project.CodeNamingConvention.GetPropertyName(table.Identity.Name)); } var existingViews = project.Database.Views.Count(item => item.Name == table.Name); var genericTypeName = existingViews == 0 ? project.GetEntityName(table) : project.GetFullEntityName(table); var dbSetName = existingViews == 0 ? project.GetDbSetPropertyName(table, projectSelection.Settings.PluralizeDbSetPropertyNames) : project.GetFullDbSetPropertyName(table); if (projectSelection.Settings.EntitiesWithDataContracts) { var lines = new List <ILine> { new CodeLine("return await DbContext.{0}", dbSetName) }; if (projectSelection.Settings.DeclareNavigationProperties) { foreach (var foreignKey in table.ForeignKeys) { var foreignTable = project.Database.FindTable(foreignKey.References); if (foreignKey == null) { continue; } lines.Add(new CodeLine(1, ".Include(p => p.{0})", foreignKey.GetParentNavigationProperty(foreignTable, project).Name)); } } lines.Add(new CodeLine(1, ".FirstOrDefaultAsync({0});", expression)); return(new MethodDefinition { AccessModifier = AccessModifier.Public, IsAsync = true, Type = string.Format("Task<{0}>", project.GetEntityName(table)), Name = project.GetGetRepositoryMethodName(table), Parameters = { new ParameterDefinition(project.GetEntityName(table), "entity") }, Lines = lines }); } else { return(new MethodDefinition { AccessModifier = AccessModifier.Public, IsAsync = true, Type = string.Format("Task<{0}>", project.GetEntityName(table)), Name = project.GetGetRepositoryMethodName(table), Parameters = { new ParameterDefinition(project.GetEntityName(table), "entity") }, Lines = { new CodeLine("return await DbContext.{0}.FirstOrDefaultAsync({1});", dbSetName, expression) } }); } }
private static MethodDefinition GetGetMethod(ProjectFeature <EntityFrameworkCoreProjectSettings> projectFeature, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table) { var efCoreProject = projectFeature.GetEntityFrameworkCoreProject(); var expression = string.Empty; if (table.Identity == null) { expression = string.Format("item => {0}", string.Join(" && ", table.PrimaryKey.Key.Select(item => string.Format("item.{0} == entity.{0}", efCoreProject.CodeNamingConvention.GetPropertyName(item))))); } else { expression = string.Format("item => item.{0} == entity.{0}", efCoreProject.CodeNamingConvention.GetPropertyName(table.Identity.Name)); } if (projectSelection.Settings.EntitiesWithDataContracts) { var lines = new List <ILine> { new CodeLine("return await DbContext.{0}", efCoreProject.GetDbSetPropertyName(table)) }; foreach (var foreignKey in table.ForeignKeys) { var foreignTable = efCoreProject.Database.FindTable(foreignKey.References); if (foreignKey == null) { continue; } lines.Add(new CodeLine(1, ".Include(p => p.{0})", foreignKey.GetParentNavigationProperty(foreignTable, efCoreProject).Name)); } lines.Add(new CodeLine(1, ".FirstOrDefaultAsync({0});", expression)); return(new MethodDefinition(string.Format("Task<{0}>", efCoreProject.GetEntityName(table)), efCoreProject.GetGetRepositoryMethodName(table), new ParameterDefinition(efCoreProject.GetEntityName(table), "entity")) { IsAsync = true, Lines = lines }); } else { return(new MethodDefinition(string.Format("Task<{0}>", efCoreProject.GetEntityName(table)), efCoreProject.GetGetRepositoryMethodName(table), new ParameterDefinition(efCoreProject.GetEntityName(table), "entity")) { IsAsync = true, Lines = { new CodeLine("return await DbContext.{0}.FirstOrDefaultAsync({1});", efCoreProject.GetDbSetPropertyName(table), expression) } }); } }
private static void GetGetAllMethodWithoutForeigns(this CSharpClassDefinition definition, ProjectFeature <EntityFrameworkCoreProjectSettings> projectFeature, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table) { var efCoreProject = projectFeature.GetEntityFrameworkCoreProject(); definition.Methods.Add(new MethodDefinition(string.Format("IQueryable<{0}>", efCoreProject.GetEntityName(table)), efCoreProject.GetGetAllRepositoryMethodName(table)) { Lines = { new CodeLine("return DbContext.{0};", efCoreProject.GetDbSetPropertyName(table)) } }); }
private static void GetGetAllMethod(this CSharpClassDefinition definition, ProjectFeature <EntityFrameworkCoreProjectSettings> projectFeature, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table) { var efCoreProject = projectFeature.GetEntityFrameworkCoreProject(); var returnType = string.Empty; var lines = new List <ILine>(); if (projectSelection.Settings.EntitiesWithDataContracts) { returnType = efCoreProject.GetDataContractName(table); var dataContractPropertiesSets = new[] { new { IsForeign = false, Type = string.Empty, Nullable = false, ObjectSource = string.Empty, PropertySource = string.Empty, Target = string.Empty } }.ToList(); var entityAlias = NamingConvention.GetCamelCase(efCoreProject.GetEntityName(table)); foreach (var column in table.Columns) { var propertyName = column.GetPropertyName(); dataContractPropertiesSets.Add(new { IsForeign = false, column.Type, column.Nullable, ObjectSource = entityAlias, PropertySource = propertyName, Target = propertyName }); } foreach (var foreignKey in table.ForeignKeys) { var foreignTable = projectFeature.Project.Database.FindTable(foreignKey.References); if (foreignTable == null) { continue; } var foreignKeyAlias = NamingConvention.GetCamelCase(efCoreProject.GetEntityName(foreignTable)); foreach (var column in foreignTable?.GetColumnsWithNoPrimaryKey()) { if (dataContractPropertiesSets.Where(item => string.Format("{0}.{1}", item.ObjectSource, item.PropertySource) == string.Format("{0}.{1}", entityAlias, column.GetPropertyName())).Count() == 0) { var target = string.Format("{0}{1}", efCoreProject.GetEntityName(foreignTable), column.GetPropertyName()); dataContractPropertiesSets.Add(new { IsForeign = true, column.Type, column.Nullable, ObjectSource = foreignKeyAlias, PropertySource = column.GetPropertyName(), Target = target }); } } } lines.Add(new CommentLine(" Get query from DbSet")); lines.Add(new CodeLine("var query = from {0} in DbContext.Set<{1}>()", entityAlias, efCoreProject.GetEntityName(table))); foreach (var foreignKey in table.ForeignKeys) { var foreignTable = projectFeature.Project.Database.FindTable(foreignKey.References); if (foreignTable == null) { continue; } var foreignKeyEntityName = efCoreProject.GetDbSetPropertyName(foreignTable); var foreignKeyAlias = NamingConvention.GetCamelCase(efCoreProject.GetEntityName(foreignTable)); if (projectFeature.Project.Database.HasDefaultSchema(foreignTable)) { definition.Namespaces.AddUnique(efCoreProject.GetEntityLayerNamespace()); } else { definition.Namespaces.AddUnique(efCoreProject.GetEntityLayerNamespace(foreignTable.Schema)); } if (foreignKey.Key.Count == 0) { lines.Add(new PreprocessorDirectiveLine(1, " There isn't definition for key in foreign key '{0}' in your current database", foreignKey.References)); } else if (foreignKey.Key.Count == 1) { if (foreignTable == null) { lines.Add(LineHelper.Warning(" There isn't definition for '{0}' in your current database", foreignKey.References)); } else { var column = table.Columns.FirstOrDefault(item => item.Name == foreignKey.Key.First()); var x = efCoreProject.CodeNamingConvention.GetPropertyName(foreignKey.Key.First()); var y = efCoreProject.CodeNamingConvention.GetPropertyName(foreignTable.PrimaryKey.Key.First()); if (column.Nullable) { lines.Add(new CodeLine(1, "join {0}Join in DbContext.{1} on {2}.{3} equals {0}Join.{4} into {0}Temp", foreignKeyAlias, foreignKeyEntityName, entityAlias, x, y)); lines.Add(new CodeLine(2, "from {0} in {0}Temp.DefaultIfEmpty()", foreignKeyAlias, entityAlias, x, y)); } else { lines.Add(new CodeLine(1, "join {0} in DbContext.{1} on {2}.{3} equals {0}.{4}", foreignKeyAlias, foreignKeyEntityName, entityAlias, x, y)); } } } else { lines.Add(LineHelper.Warning(" Add logic for foreign key with multiple key")); } } lines.Add(new CodeLine(1, "select new {0}", returnType)); lines.Add(new CodeLine(1, "{")); for (var i = 0; i < dataContractPropertiesSets.Count; i++) { var property = dataContractPropertiesSets[i]; if (string.IsNullOrEmpty(property.ObjectSource) && string.IsNullOrEmpty(property.Target)) { continue; } if (property.IsForeign) { var dbType = projectFeature.Project.Database.ResolveType(property.Type); if (dbType == null) { throw new ObjectRelationMappingException(string.Format("There isn't mapping for '{0}' type", property.Type)); } var clrType = dbType.GetClrType(); if (clrType.FullName == typeof(byte[]).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(byte[]) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(bool).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(bool?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(string).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? string.Empty : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(DateTime).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(DateTime?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(TimeSpan).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(TimeSpan?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(byte).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(byte?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(short).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(short?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(int).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(int?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(long).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(long?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(decimal).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(decimal?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(double).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(double?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(float).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(float?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else if (clrType.FullName == typeof(Guid).FullName) { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(Guid?) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } else { lines.Add(new CodeLine(2, "{0} = {1} == null ? default(object) : {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } } else { lines.Add(new CodeLine(2, "{0} = {1}.{2},", property.Target, property.ObjectSource, property.PropertySource)); } } lines.Add(new CodeLine(1, "};")); lines.Add(new CodeLine()); } else { returnType = efCoreProject.GetEntityName(table); lines.Add(new CommentLine(" Get query from DbSet")); lines.Add(new CodeLine("var query = DbContext.{0}.AsQueryable();", efCoreProject.GetDbSetPropertyName(table))); lines.Add(new CodeLine()); } var parameters = new List <ParameterDefinition>(); if (table.ForeignKeys.Count == 0) { lines.Add(new CodeLine("return query;")); } else { for (var i = 0; i < table.ForeignKeys.Count; i++) { var foreignKey = table.ForeignKeys[i]; if (foreignKey.Key.Count == 1) { var column = table.Columns.First(item => item.Name == foreignKey.Key.First()); var parameterName = efCoreProject.GetParameterName(column); parameters.Add(new ParameterDefinition(projectFeature.Project.Database.ResolveDatabaseType(column), parameterName, "null")); if (projectFeature.Project.Database.ColumnIsDateTime(column)) { lines.Add(new CommentLine(" Filter by: '{0}'", column.Name)); lines.Add(new CodeLine("if ({0}.HasValue)", parameterName)); lines.Add(new CodeLine(1, "query = query.Where(item => item.{0} == {1});", column.GetPropertyName(), parameterName)); lines.Add(new CodeLine()); } else if (projectFeature.Project.Database.ColumnIsNumber(column)) { lines.Add(new CommentLine(" Filter by: '{0}'", column.Name)); lines.Add(new CodeLine("if ({0}.HasValue)", parameterName)); lines.Add(new CodeLine(1, "query = query.Where(item => item.{0} == {1});", column.GetPropertyName(), parameterName)); lines.Add(new CodeLine()); } else if (projectFeature.Project.Database.ColumnIsString(column)) { lines.Add(new CommentLine(" Filter by: '{0}'", column.Name)); lines.Add(new CodeLine("if (!string.IsNullOrEmpty({0}))", parameterName)); lines.Add(new CodeLine(1, "query = query.Where(item => item.{0} == {1});", column.GetPropertyName(), parameterName)); lines.Add(new CodeLine()); } else { lines.Add(new CommentLine(" Filter by: '{0}'", column.Name)); lines.Add(new CodeLine("if ({0} != null)", parameterName)); lines.Add(new CodeLine(1, "query = query.Where(item => item.{0} == {1});", column.GetPropertyName(), parameterName)); lines.Add(new CodeLine()); } } else { lines.Add(LineHelper.Warning("Add logic for foreign key with multiple key")); } } lines.Add(new CodeLine("return query;")); } definition.Methods.Add(new MethodDefinition(string.Format("IQueryable<{0}>", returnType), efCoreProject.GetGetAllRepositoryMethodName(table), parameters.ToArray()) { Lines = lines }); }
public static DbContextClassDefinition GetDbContextClassDefinition(this EntityFrameworkCoreProject project, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection) { var definition = new DbContextClassDefinition { Namespaces = { "System", "Microsoft.EntityFrameworkCore", project.GetEntityLayerNamespace() }, Namespace = project.GetDataLayerNamespace(), AccessModifier = AccessModifier.Public, Name = project.GetDbContextName(project.Database), BaseClass = "DbContext" }; if (!projectSelection.Settings.UseDataAnnotations) { definition.Namespaces.Add(project.GetDataLayerConfigurationsNamespace()); } definition.Constructors.Add(new ClassConstructorDefinition { AccessModifier = AccessModifier.Public, Parameters = { new ParameterDefinition(string.Format("DbContextOptions<{0}>", definition.Name), "options") }, Invocation = "base(options)" }); definition.Methods.Add(GetOnModelCreatingMethod(project)); foreach (var table in project.Database.Tables) { if (!project.Database.HasDefaultSchema(table)) { definition.Namespaces.AddUnique(project.GetEntityLayerNamespace(table.Schema)); } var existingViews = project.Database.Views.Count(item => item.Name == table.Name); var genericTypeName = existingViews == 0 ? project.GetEntityName(table) : project.GetFullEntityName(table); var name = existingViews == 0 ? project.GetDbSetPropertyName(table) : project.GetFullDbSetPropertyName(table); definition.Properties.Add( new PropertyDefinition { AccessModifier = AccessModifier.Public, Type = string.Format("DbSet<{0}>", genericTypeName), Name = name, IsAutomatic = true } ); } foreach (var view in project.Database.Views) { if (!project.Database.HasDefaultSchema(view)) { definition.Namespaces.AddUnique(project.GetEntityLayerNamespace(view.Schema)); } var existingTables = project.Database.Tables.Count(item => item.Name == view.Name); var genericTypeName = existingTables == 0 ? project.GetEntityName(view) : project.GetFullEntityName(view); var name = existingTables == 0 ? project.GetDbSetPropertyName(view) : project.GetFullDbSetPropertyName(view); definition.Properties.Add( new PropertyDefinition { AccessModifier = AccessModifier.Public, Type = string.Format("DbSet<{0}>", genericTypeName), Name = name, IsAutomatic = true } ); } foreach (var table in project.Database.Tables) { if (!projectSelection.Settings.UseDataAnnotations && !project.Database.HasDefaultSchema(table)) { definition.Namespaces.AddUnique(project.GetDataLayerConfigurationsNamespace(table.Schema)); } } foreach (var view in project.Database.Views) { if (!projectSelection.Settings.UseDataAnnotations && !project.Database.HasDefaultSchema(view)) { definition.Namespaces.AddUnique(project.GetDataLayerConfigurationsNamespace(view.Schema)); } } foreach (var scalarFunction in project.Database.ScalarFunctions) { var parameterType = string.Empty; if (project.Database.HasTypeMappedToClr(scalarFunction.Parameters[0])) { var clrType = project.Database.GetClrMapForType(scalarFunction.Parameters[0]); parameterType = clrType.AllowClrNullable ? string.Format("{0}?", clrType.GetClrType().Name) : clrType.GetClrType().Name; } else { parameterType = "object"; } var method = new MethodDefinition { Attributes = { new MetadataAttribute("DbFunction") { Sets = { new MetadataAttributeSet("FunctionName", string.Format("\"{0}\"", scalarFunction.Name)), new MetadataAttributeSet("Schema", string.Format("\"{0}\"", scalarFunction.Schema)) } } }, IsStatic = true, Type = parameterType, AccessModifier = AccessModifier.Public, Name = project.GetScalarFunctionMethodName(scalarFunction), Lines = { new CodeLine("throw new Exception();") } }; var parameters = scalarFunction.Parameters.Where(item => !string.IsNullOrEmpty(item.Name)).ToList(); foreach (var parameter in parameters) { var propertyType = project.Database.ResolveDatabaseType(parameter); method.Parameters.Add(new ParameterDefinition(parameterType, project.GetPropertyName(parameter))); } definition.Methods.Add(method); } if (projectSelection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }
public static PropertyDefinition GetChildNavigationProperty(this EntityFrameworkCoreProject project, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table, ForeignKey foreignKey) { var propertyType = string.Format("{0}<{1}>", projectSelection.Settings.NavigationPropertyEnumerableType, project.GetEntityName(table)); return(new PropertyDefinition(propertyType, project.GetNavigationPropertyName(table)) { AccessModifier = AccessModifier.Public, IsVirtual = projectSelection.Settings.DeclareNavigationPropertiesAsVirtual }); }
public static ClassDefinition GetEntityClassDefinition(this DapperProject project, ITable table, ProjectSelection <DapperProjectSettings> projectSelection) { return(new ClassDefinition { Name = table.Name }); }
public MainViewModel(Document document, ProjectSelection projectSelection) { _document = document; _projectSelection = projectSelection; }
public ProjectViewModel(Project project, ProjectSelection projectSelection) { _project = project; _projectSelection = projectSelection; }
private static MethodDefinition GetGetAllMethodWithoutForeigns(ProjectFeature <EntityFrameworkCoreProjectSettings> projectFeature, ProjectSelection <EntityFrameworkCoreProjectSettings> projectSelection, ITable table) { var project = projectFeature.GetEntityFrameworkCoreProject(); var existingViews = project.Database.Views.Count(item => item.Name == table.Name); var genericTypeName = existingViews == 0 ? project.GetEntityName(table) : project.GetFullEntityName(table); var dbSetName = existingViews == 0 ? project.GetDbSetPropertyName(table) : project.GetFullDbSetPropertyName(table); return(new MethodDefinition { AccessModifier = AccessModifier.Public, Type = string.Format("IQueryable<{0}>", genericTypeName), Name = project.GetGetAllRepositoryMethodName(table), Lines = { new CodeLine("return DbContext.{0};", dbSetName) } }); }
public static ClassDefinition GetEntityClassDefinition(this DapperProject project, ITable table, ProjectSelection <DapperProjectSettings> projectSelection) { var definition = new ClassDefinition { Name = table.Name }; foreach (var column in table.Columns) { definition.Properties.Add(new PropertyDefinition(column.Type, column.Name)); } return(definition); }
/// <summary> /// Show Project Selection Button clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShowProjectSelectionButton_OnClick(object sender, RoutedEventArgs e) { if(_projSelectionlayoutAnchorable == null) _projSelectionlayoutAnchorable = new LayoutAnchorable { Title = "Project Selection" }; if (_projSel == null) { _projSel = new ProjectSelection(DataController.Instance.IntBase); _projSelectionlayoutAnchorable.Content = _projSel; _projSelectionlayoutAnchorable.AddToLayout(myDockingManager, AnchorableShowStrategy.Left); } if (_projSelectionlayoutAnchorable.IsVisible) { _projSelectionlayoutAnchorable.Hide(); } else { _projSelectionlayoutAnchorable.Show(); } }