Ejemplo n.º 1
0
        /// <summary>
        /// Creates and returns a <see cref="DataGridPresenterMap"/> from the specified <paramref name="model"/>
        /// </summary>
        /// <param name="queryMap">The query map</param>
        /// <param name="model">The model</param>
        /// <returns></returns>
        public static DataGridPresenterMap FromDataModel(QueryMap queryMap, DataGridPresenterMapDataModel model)
        {
            // Create the map
            var dataGridPresenterMap = new DataGridPresenterMap(queryMap)
            {
                Id          = model.Id,
                Name        = model.Name,
                Description = model.Description,
                Color       = model.Color,
            };

            foreach (var dataGridMapDataModel in model.DataGrids)
            {
                var dataGridMap = dataGridPresenterMap.DataGrids.First(x => x.Type.Name == dataGridMapDataModel.TypeName);

                dataGridMap.AllowAdd      = dataGridMapDataModel.AllowAdd;
                dataGridMap.AllowEdit     = dataGridMapDataModel.AllowEdit;
                dataGridMap.AllowDelete   = dataGridMapDataModel.AllowDelete;
                dataGridMap.Columns       = dataGridMapDataModel.ColumnNames.Select(x => dataGridMap.Type.GetProperty(x)).ToList();
                dataGridMap.SearchColumns = dataGridMapDataModel.SearchColumnNames.Select(x => dataGridMap.Type.GetProperty(x)).ToList();
                if (!dataGridMapDataModel.DateColumnName.IsNullOrEmpty())
                {
                    dataGridMap.DateColumn = dataGridMap.Type.GetProperty(dataGridMapDataModel.DateColumnName);
                }
            }

            // Return the map
            return(dataGridPresenterMap);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="queryMap">The query map</param>
 /// <param name="type">The type that contains the <see cref="PropertyInfo"/></param>
 /// <param name="property">The property that's getting map.</param>
 /// <param name="column">
 /// The column.
 /// NOTE: The column will be <see cref="null"/> when the <see cref="PropertyInfo"/> is a navigation property!
 /// </param>
 public PropertyMap(QueryMap queryMap, Type type, PropertyInfo property, IDbProviderColumn column = null) : base()
 {
     Column       = column;
     QueryMap     = queryMap ?? throw new ArgumentNullException(nameof(queryMap));
     Type         = type ?? throw new ArgumentNullException(nameof(type));
     PropertyInfo = property ?? throw new ArgumentNullException(nameof(property));
     Table        = QueryMap.Tables.First(x => x.TableName == queryMap.GetTableName(type));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public DataGridPresenterMap(QueryMap queryMap) : base(queryMap)
        {
            var dataGridsCollection = new List <DataGridMap>();

            foreach (var type in queryMap.DataModelTypes)
            {
                dataGridsCollection.Add(new DataGridMap(this, type));
            }

            DataGrids = dataGridsCollection;
        }
        /// <summary>
        /// Creates and adds the required GUI elements
        /// </summary>
        private void CreateGUI()
        {
            // Create the add button
            AddButton = ControlsFactory.CreateStandardAddCircularButton();

            AddButton.Command = new RelayCommand(async() =>
            {
                // Create the form
                var form = new DataForm <DataGridPresenterMap>(new DataGridPresenterMap(QueryMap))
                {
                    Mapper = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value
                }
                .ShowInput(x => x.Name, settings => { settings.Name = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value.GetTitle(x => x.Name); settings.IsRequired = true; })
                .ShowInput(x => x.Description, settings => settings.Name      = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value.GetTitle(x => x.Description))
                .ShowStringColorInput(x => x.Color, settings => settings.Name = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value.GetTitle(x => x.Color));

                // Show an add dialog
                var dialogResult = await DialogHelpers.ShowConventionalAddDialogAsync(this, "Data grid creation", null, form);

                // If we didn't get positive feedback...
                if (!dialogResult.Feedback)
                {
                    // Return
                    return;
                }

                // Get the manager
                var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                // Register it
                QueryMap.Add(form.Model);

                // Save the changes
                var result = await manager.SaveChangesAsync();

                // If there was an error...
                if (!result.Successful)
                {
                    // Show the error
                    await result.ShowDialogAsync(this);

                    // Return
                    return;
                }

                // Add the model
                DataPresenter.Add(form.Model);
            });

            // Add it to the content grid
            ContentGrid.Children.Add(AddButton);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates and returns a <see cref="PropertyMap"/> from the specified <paramref name="model"/>
 /// </summary>
 /// <param name="queryMap">The query map</param>
 /// <param name="type">The type that contains the <see cref="PropertyInfo"/></param>
 /// <param name="model">The model</param>
 /// <returns></returns>
 public static PropertyMap FromDataModel(QueryMap queryMap, Type type, PropertyMapDataModel model)
 {
     // Create and return the column map
     return(new PropertyMap(queryMap, type, type.GetProperty(model.PropertyName), queryMap.Columns.FirstOrDefault(x => x.TableName == model.TableName && x.ColumnName == model.ColumnName))
     {
         Id = model.Id,
         Color = model.Color,
         Description = model.Description,
         Name = model.Name,
         Attributes = model.Attributes,
         IsRequired = model.IsRequired,
         IsEditable = model.IsEditable,
         IsPreview = model.IsPreview,
         DefaultValue = model.DefaultValue,
         Order = model.Order
     });
 }
        /// <summary>
        /// Updates the specified <paramref name="model"/>
        /// </summary>
        /// <param name="model">The model</param>
        /// <returns></returns>
        public async Task <IFailable <object> > UpdateDataAsync(object model)
        {
            // Create the result
            var result = new Failable <object>();

            try
            {
                // Get the type of the model
                var modelType = model.GetType();

                // Get the name of the table
                var tableName = QueryMap.GetTableName(modelType);

                // Get the primary key column
                var primaryKeyColumn = QueryMap.Columns.First(x => x.TableName == tableName && x.IsPrimaryKey);

                // Get the primary key property
                var primaryKeyProperty = modelType.GetProperty(primaryKeyColumn.ColumnName);

                // Get the existing model
                var existingModel = await DbContext.FindAsync(modelType, primaryKeyProperty.GetValue(model));

                // For every property of the model...
                // TODO: Better implementation by using AutoMapper!
                foreach (var property in modelType.GetProperties())
                {
                    // Update the property value of the existing model
                    property.SetValue(existingModel, property.GetValue(model));
                }

                // Mark the existing model for update
                DbContext.Update(existingModel);

                // Save the changes
                await DbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                // Set the error
                result.ErrorMessage = ex.Message;
            }

            // Return the result
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Unregisters the specified <paramref name="queryMap"/>
        /// </summary>
        /// <param name="queryMap">The query map</param>
        public async Task <IFailable> Unregister(QueryMap queryMap)
        {
            // Create the result
            var result = new Failable();

            try
            {
                await Task.Delay(1);

                mQueryMaps.Remove(queryMap);
            }
            catch (Exception ex)
            {
                // Set the error message
                result.ErrorMessage = ex.Message;
            }

            // Return the result
            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbContext"/> class
 /// using the specified options. The <see cref="DbContext.OnConfiguring(DbContextOptionsBuilder)"/>
 /// method will still be called to allow further configuration of the options.
 /// </summary>
 /// <param name="options">The options for this context.</param>
 /// <param name="queryMap">The query map</param>
 public PresenterDbContext(DbContextOptions options, QueryMap queryMap) : base(options)
 {
     QueryMap = queryMap ?? throw new ArgumentNullException(nameof(queryMap));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="queryMap">The query map</param>
        public PropertyMapsAndPresentersPage(QueryMap queryMap) : base()
        {
            QueryMap = queryMap ?? throw new ArgumentNullException(nameof(queryMap));

            CreateGUI();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Registers the specified <paramref name="queryMap"/>
        /// </summary>
        /// <param name="queryMap">The query map</param>
        public Task <IFailable> RegisterAsync(QueryMap queryMap)
        {
            mQueryMaps.Add(queryMap);

            return(Task.FromResult <IFailable>(new Failable()));
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="presenterMap">The data grid presenter map</param>
 public DataGridPresenterDataStorage(DataGridPresenterMap presenterMap) : base(presenterMap)
 {
     DataGridMap        = PresenterMap.DataGrids.First(x => x.Type == QueryMap.RootType);
     PrimaryKeyColumn   = QueryMap.Columns.First(x => x.IsPrimaryKey && x.TableName == QueryMap.GetTableName(QueryMap.RootType));
     PrimaryKeyProperty = QueryMap.RootType.GetProperty(PrimaryKeyColumn.ColumnName);
 }
        /// <summary>
        /// Creates and returns the <see cref="BaseItemsControlPage{TClass}.DataPresenter"/>
        /// </summary>
        /// <returns></returns>
        protected override IDataPresenter <DataGridPresenterMap> CreateDataPresenter()
        {
            var collapsibleDataGrid = new CollapsibleDataGrid <DataGridPresenterMap>()
            {
                Mapper = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value
            }
            .ShowData(x => x.Name)
            .ShowData(x => x.Description)
            .ShowData(x => x.DataGrids)

            .SetColorUIElement(x => x.Color)
            .SetDataPresenterSubElement(x => x.DataGrids, model => model.DataGrids.Count().ToString("grid", "grids", "No grids"), (model) =>
            {
                var dataGrid = new CollapsibleDataGrid <DataGridMap>()
                {
                    Translator = CeidDiplomatikiDataModelHelpers.DataGridMapTranslator.Value, Mapper = CeidDiplomatikiDataModelHelpers.DataGridMapMapper.Value
                }
                .ShowData(x => x.Type)
                .ShowData(x => x.AllowAdd)
                .ShowData(x => x.AllowEdit)
                .ShowData(x => x.AllowDelete)
                .ShowData(x => x.Columns)
                .ShowData(x => x.DateColumn)
                .ShowData(x => x.SearchColumns)

                .SetBooleanUIElement(x => x.AllowAdd)
                .SetBooleanUIElement(x => x.AllowEdit)
                .SetBooleanUIElement(x => x.AllowDelete)

                .SetCustomUIElement(x => x.DateColumn,
                                    (grid, row, model) =>
                {
                    return(new TextButton()
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment = VerticalAlignment.Center,
                        Text = model.DateColumn?.Name,
                        BorderThickness = new Thickness(VisibleBorderThickness),
                        Command = new RelayCommand(async() =>
                        {
                            // Show the dialog
                            var dialogResult = await DialogHelpers.ShowUniformGridSelectSingleDialogAsync(this, "Date column selection", null, model.Type.GetProperties().Where(x => x.PropertyType.IsDate()), (prop) => new InformationalButton()
                            {
                                Text = prop.Name
                            }, null, IconPaths.CalendarCheckPath);

                            // If we didn't get positive feedback...
                            if (!dialogResult.Feedback)
                            {
                                // Return
                                return;
                            }

                            // Update the model
                            model.DateColumn = dialogResult.Model;

                            var result = await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync();

                            // If there was an error...
                            if (!result.Successful)
                            {
                                // Show the error
                                await result.ShowDialogAsync(this);

                                // Return
                                return;
                            }

                            // Update the grid
                            grid.Update(model);
                        })
                    });
                },
                                    (grid, row, model, element) => element.Text = model.DateColumn?.Name)

                .SetDataPresenterSubElement(propertySelector: x => x.Columns,
                                            textValueExtractor: model => model.Columns?.Count().ToString("column", "columns", "No columns"),
                                            presenterImplementationFactory: model =>
                {
                    return(new DataGrid <PropertyInfo>()
                           .ShowData(x => x.Name, RelationalAnalyzersHelpers.DbProviderColumnMapper.Value.GetTitle(x => x.ColumnName)));
                },
                                            optionButtonConfiguration: (p, m, b) =>
                {
                    b.VectorSource = IconPaths.EditPath;

                    b.Command = new RelayCommand(async() =>
                    {
                        // Create the form
                        var form = new OptionsSelectionForm <PropertyInfo>();

                        // For every column
                        foreach (var column in m.Type.GetProperties())
                        {
                            // Show it for selection
                            form.ShowOption(column, column.Name, null, null, m.Columns.Any(x => x.Equals(column)));
                        }

                        // Show the dialog
                        var dialogResult = await DialogHelpers.ShowSelectMultipleDialogAsync(this, "Columns selection", null, form);

                        // If we didn't get positive feedback...
                        if (!dialogResult.Feedback)
                        {
                            // Return
                            return;
                        }

                        // Update the columns
                        m.Columns = form.GetOptions();

                        // Get the manager
                        var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                        // Save the changes
                        var result = await manager.SaveChangesAsync();

                        // If there was an error...
                        if (!result.Successful)
                        {
                            // Show the error
                            await result.ShowDialogAsync(this);

                            // Return
                            return;
                        }

                        p.SetItemsSource(m.Columns);

                        DataPresenter.Update(model);
                    });
                })
                .SetDataPresenterSubElement(propertySelector: x => x.SearchColumns,
                                            textValueExtractor: model => model.SearchColumns?.Count().ToString("column", "columns", "No columns"),
                                            presenterImplementationFactory: model =>
                {
                    return(new DataGrid <PropertyInfo>()
                           .ShowData(x => x.Name, RelationalAnalyzersHelpers.DbProviderColumnMapper.Value.GetTitle(x => x.ColumnName)));
                },
                                            optionButtonConfiguration: (p, m, b) =>
                {
                    b.VectorSource = IconPaths.EditPath;

                    b.Command = new RelayCommand(async() =>
                    {
                        // Create the form
                        var form = new OptionsSelectionForm <PropertyInfo>();

                        // For every column
                        foreach (var column in m.Type.GetProperties().Where(x => x.PropertyType == typeof(string)))
                        {
                            // Show it for selection
                            form.ShowOption(column, column.Name, null, null, m.SearchColumns.Any(x => x.Equals(column)));
                        }

                        // Show the dialog
                        var dialogResult = await DialogHelpers.ShowSelectMultipleDialogAsync(this, "Search columns selection", null, form);

                        // If we didn't get positive feedback...
                        if (!dialogResult.Feedback)
                        {
                            // Return
                            return;
                        }

                        // Update the columns
                        m.SearchColumns = form.GetOptions();

                        // Get the manager
                        var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                        // Save the changes
                        var result = await manager.SaveChangesAsync();

                        // If there was an error...
                        if (!result.Successful)
                        {
                            // Show the error
                            await result.ShowDialogAsync(this);

                            // Return
                            return;
                        }

                        p.SetItemsSource(m.SearchColumns);

                        DataPresenter.Update(model);
                    });
                });
                dataGrid.ConfigureOptions((container, grid, row, model) =>
                {
                    container.AddEditOption("Data grid modification", null, () =>
                    {
                        return(new DataForm <DataGridMap>()
                        {
                            Mapper = CeidDiplomatikiDataModelHelpers.DataGridMapMapper.Value
                        }
                               .ShowInput(x => x.AllowAdd)
                               .ShowInput(x => x.AllowEdit)
                               .ShowInput(x => x.AllowDelete));
                    }, async model => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync());
                });

                return(dataGrid);
            });

            collapsibleDataGrid.ConfigureOptions((container, grid, row, model) =>
            {
                container.AddEditOption("Data grid presenter modification", null, () =>
                {
                    return(new DataForm <DataGridPresenterMap>()
                    {
                        Mapper = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value
                    }
                           .ShowInput(x => x.Name, settings => settings.IsRequired = true)
                           .ShowInput(x => x.Description)
                           .ShowStringColorInput(x => x.Color));
                }, async model => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync());
                container.AddDeleteOption("Data grid presenter deletion", null, async model =>
                {
                    // Get the manager
                    var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                    // Unregister the data presenter
                    QueryMap.Remove(model);

                    // Save the changes
                    return(await manager.SaveChangesAsync());
                });
            });

            return(collapsibleDataGrid);
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="queryMap">The query map</param>
        public DataGridPresenterMapsPage(QueryMap queryMap) : base()
        {
            QueryMap = queryMap ?? throw new ArgumentNullException(nameof(queryMap));

            CreateGUI();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates and returns the <see cref="BaseItemsControlPage{TClass}.DataPresenter"/>
        /// </summary>
        /// <returns></returns>
        protected override IItemsControl <PropertyMap> CreateItemsControl()
        {
            return(new CollapsibleDataGrid <PropertyMap>()
            {
                Mapper = CeidDiplomatikiDataModelHelpers.PropertyMapMapper.Value
            }
                   .ShowData(x => x.TableName)
                   .ShowData(x => x.ColumnName)
                   .ShowData(x => x.ValueType)
                   .ShowData(x => x.Name)
                   .ShowData(x => x.Description)
                   .ShowData(x => x.Attributes)
                   .ShowData(x => x.Color)
                   .ShowData(x => x.DefaultValue)
                   .ShowData(x => x.Order)
                   .ShowData(x => x.IsEditable)
                   .ShowData(x => x.IsRequired)
                   .ShowData(x => x.IsPreview)

                   .SetColorUIElement(x => x.Color)
                   .SetLabelUIElement(x => x.ValueType, model => model.ValueType.ToLocalizedString(), model => model.ValueType.ToColorHex())
                   .SetBooleanUIElement(x => x.IsEditable)
                   .SetBooleanUIElement(x => x.IsRequired)
                   .SetBooleanUIElement(x => x.IsPreview)
                   .SetSubElement(x => x.Attributes,
                                  model => model.Attributes?.Count().ToString("attribute", "attributes", "No attributes"),
                                  async(row, model) =>
            {
                var itemsControl = new WrapPanelItemsControl <ColumnAttribute, BorderedTextBlock>(x =>
                {
                    var label = ControlsFactory.CreateLabelTag(x.Name, x.Color);

                    label.Margin = new Thickness(NormalUniformMargin);

                    return label;
                })
                {
                    Orientation = Orientation.Horizontal,
                    HorizontalAlignment = HorizontalAlignment.Center
                };

                itemsControl.SetItemsSource(model.Attributes);

                return await Task.FromResult(itemsControl);
            },
                                  (row, model, element) => element.SetItemsSource(model.Attributes))
                   .SetTextInputUIElement(x => x.Order, async(row, model, value) =>
            {
                var result = await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync();

                return new Failable <PropertyMap>()
                {
                    ErrorMessage = result.ErrorMessage
                };
            })

                   .ConfigureOptions((container, grid, row, model) =>
            {
                container.AddEditOption("Property map modification", null, () =>
                {
                    return new DataForm <PropertyMap>()
                    {
                        Mapper = CeidDiplomatikiDataModelHelpers.PropertyMapMapper.Value
                    }
                    .ShowInput(x => x.Name, settings => settings.IsRequired = true)
                    .ShowInput(x => x.Description)
                    .ShowStringColorInput(x => x.Color)
                    .ShowSelectMultipleOptionsInput(x => x.Attributes, (form, propertyInfo) => new DropDownMenuOptionsFormInput <ColumnAttribute>(form, propertyInfo, ColumnAttributes.Data.Value, x => x.Name), settings => settings.IsRequired = true)
                    .ShowNumericInput(x => x.Order)
                    .ShowInput(x => x.DefaultValue)
                    .ShowInput(x => x.IsEditable)
                    .ShowInput(x => x.IsRequired)
                    .ShowInput(x => x.IsPreview);
                }, async(model) => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync(), null, IconPaths.TableColumnPath);
                container.AddDeleteOption("Property map deletion", null, async(model) =>
                {
                    // Get the manager
                    var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                    // Unregister the map
                    QueryMap.Remove(model);

                    // Save the changes
                    return await manager.SaveChangesAsync();
                }, null, IconPaths.TableColumnPath);
            }));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates and adds the required GUI elements
        /// </summary>
        private void CreateGUI()
        {
            // Create the add button
            AddButton = ControlsFactory.CreateStandardAddCircularButton();

            AddButton.Command = new RelayCommand(async() =>
            {
                // Disable the button
                AddButton.IsEnabled = false;

                // Create a steps presenter
                var stepsPresenter = new StepsPresenter()
                {
                    AllowArbitraryNavigation = false
                };

                // Create a columns container
                var propertiesContainer = new UniformGridCollapsibleVerticalMenuCategorizingItemsControl <PropertyInfo, InformationalButton>()
                {
                    Columns            = 3,
                    CategoryNameGetter = (prop) => prop.DeclaringType.Name.Split("-").Last()
                };

                propertiesContainer.Linker = (prop) => new InformationalButton()
                {
                    MinWidth = 0,
                    Text     = prop.Name,
                    Command  = new RelayCommand(() =>
                    {
                        foreach (var element in propertiesContainer.Elements)
                        {
                            element.Selected = false;
                        }

                        propertiesContainer.GetElement(prop).Selected = true;
                    })
                };

                // Add the tables
                propertiesContainer.SetItemsSource(QueryMap.DataModelTypes.SelectMany(x => x.GetProperties().Where(y => !DataPresenter.Items.Any(z => z.PropertyInfo == y))).OrderBy(x => x.Name));

                // Add it to the steps presenter
                stepsPresenter.Add("Property", propertiesContainer, (element) => element.Elements.Any(x => x.Selected));

                // Create the form
                var form = new DataForm <PropertyMap>()
                {
                    Mapper = CeidDiplomatikiDataModelHelpers.PropertyMapMapper.Value
                }
                .ShowInput(x => x.Name, settings => settings.IsRequired = true)
                .ShowInput(x => x.Description)
                .ShowStringColorInput(x => x.Color)
                .ShowSelectMultipleOptionsInput(x => x.Attributes, (form, propertyInfo) => new DropDownMenuOptionsFormInput <ColumnAttribute>(form, propertyInfo, ColumnAttributes.Data.Value, x => x.Name), null, settings => settings.IsRequired = true)
                .ShowNumericInput(x => x.Order)
                .ShowInput(x => x.DefaultValue)
                .ShowInput(x => x.IsEditable)
                .ShowInput(x => x.IsRequired)
                .ShowInput(x => x.IsPreview);

                // Add it to the steps presenter
                stepsPresenter.Add("Info", form, (element) => element.Validate());

                // Show a dialog
                var dialogResult = await DialogHelpers.ShowStepsDialogAsync(this, "Property map creation", null, stepsPresenter, IconPaths.TableColumnPath);

                // If we didn't get positive feedback...
                if (!dialogResult.Feedback)
                {
                    // Re enable the button
                    AddButton.IsEnabled = true;

                    // Return
                    return;
                }

                // Get the selected property
                var property = propertiesContainer.Get(propertiesContainer.Elements.First(x => x.Selected));

                // Create the model
                var model = new PropertyMap(QueryMap, property.DeclaringType, property, QueryMap.GetColumnOrNull(property));

                // Set it to the form
                form.Model = model;

                // Update its values
                form.UpdateModelValues();

                // Get the manager
                var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager;

                // Register the model
                QueryMap.Add(model);

                // Save the changes
                var result = await manager.SaveChangesAsync();

                // If there was an error...
                if (!result.Successful)
                {
                    // Show the error
                    await result.ShowDialogAsync(this);

                    // Re enable the button
                    AddButton.IsEnabled = true;

                    // Return
                    return;
                }

                // Add it to the presenter
                DataPresenter.Add(model);

                // Re enable the button
                AddButton.IsEnabled = true;
            });

            // Add it to the content grid
            ContentGrid.Children.Add(AddButton);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="queryMap">The query map</param>
 public BasePresenterMap(QueryMap queryMap) : base()
 {
     QueryMap = queryMap ?? throw new System.ArgumentNullException(nameof(queryMap));
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates and returns a <see cref="QueryMap"/> from the specified <paramref name="dataModel"/>.
        /// NOTE: If the model is not set, then the default values are used!
        /// </summary>
        /// <param name="databaseOptions">The database options</param>
        /// <param name="database">The database that contains the mapped table</param>
        /// <param name="columns">The columns of the tables</param>
        /// <param name="tables">The tables</param>
        /// <param name="joins">The joins</param>
        /// <param name="dataModel">The data model</param>
        /// <returns></returns>
        public static QueryMap FromDataModel(BaseDatabaseOptionsDataModel databaseOptions, IDbProviderDatabase database, IEnumerable <IDbProviderTable> tables, IEnumerable <IDbProviderColumn> columns, IEnumerable <JoinMap> joins, QueryMapDataModel dataModel = null)
        {
            // Create the map
            var queryMap = new QueryMap(databaseOptions, database, tables, columns, joins);

            // If there is a data model...
            if (dataModel != null)
            {
                queryMap.Id          = dataModel.Id;
                queryMap.Color       = dataModel.Color;
                queryMap.Description = dataModel.Description;
                queryMap.Name        = dataModel.Name;
            }

            var tableToTypeBuilderMapper = new Dictionary <IDbProviderTable, TypeBuilder>();

            // For every table...
            foreach (var table in tables)
            {
                // Create the builder
                var typeBuilder = CeidDiplomatikiHelpers.GetTypeBuilder(queryMap.Id + "-" + table.TableName);

                // For every table column...
                foreach (var column in columns.Where(x => x.TableName == table.TableName))
                {
                    // Create a property
                    TypeBuilderHelpers.CreateProperty(typeBuilder, column.ColumnName, column.DataType);
                }

                // Map it
                tableToTypeBuilderMapper.Add(table, typeBuilder);
            }

            // For every join...
            foreach (var join in joins)
            {
                // Get the principle model type builder
                var principleModelTypeBuilder = tableToTypeBuilderMapper.First(x => x.Key == join.Table).Value;

                // Get the referenced model type builder
                var referencedModelTypeBuilder = tableToTypeBuilderMapper.First(x => x.Key == join.ReferencedTable).Value;

                // Create the principle navigation property type
                var principleNavigationPropertyType = typeof(IEnumerable <>).MakeGenericType(referencedModelTypeBuilder);

                // Add it to the principle model
                TypeBuilderHelpers.CreateProperty(principleModelTypeBuilder, CeidDiplomatikiHelpers.GetPluralForm(join.ReferencedTable.TableName), principleNavigationPropertyType);

                // Add the foreign navigation property type
                TypeBuilderHelpers.CreateProperty(referencedModelTypeBuilder, join.Table.TableName, principleModelTypeBuilder);
            }

            var tableToTypeMapper = new Dictionary <IDbProviderTable, Type>();

            // For every table to type builder map...
            foreach (var map in tableToTypeBuilderMapper)
            {
                // Build the type
                var type = map.Value.CreateType();

                if (joins.Any(x => x.Index == 0 && x.Table.TableName == map.Key.TableName))
                {
                    queryMap.RootType = type;
                }
                else if (joins.Count() == 0)
                {
                    queryMap.RootType = type;
                }

                // Map it
                tableToTypeMapper.Add(map.Key, type);
            }

            // Set the types to the query
            queryMap.DataModelTypes = tableToTypeMapper.Select(x => x.Value).ToList();

            // Create the db context type builder
            var dbContextTypeBuilder = CeidDiplomatikiHelpers.GetTypeBuilder(Guid.NewGuid().ToString() + "-DbContext");

            // Set the base type
            var baseType = typeof(PresenterDbContext);

            // Inherit from the PresenterDbContext
            dbContextTypeBuilder.SetParent(baseType);

            // For every data model type...
            foreach (var map in tableToTypeMapper)
            {
                // Create the DbSet type that will be set as a property to the DbContext
                var dbSetType = typeof(DbSet <>).MakeGenericType(map.Value);

                // Add it to the type
                TypeBuilderHelpers.CreateProperty(dbContextTypeBuilder, map.Key.TableName, dbSetType);
            }

            // Create the constructors
            TypeBuilderHelpers.CreatePassThroughConstructors(dbContextTypeBuilder, baseType);

            // Create the db context type
            queryMap.DbContextType = dbContextTypeBuilder.CreateType();

            // If there is a data model...
            // NOTE: We create the column and the data presenter maps at the end of the initialization
            //       because some properties of the query map are required to get set!
            if (dataModel != null)
            {
                dataModel.PropertyMaps.ForEach(model => queryMap.Add(PropertyMap.FromDataModel(queryMap, queryMap.DataModelTypes.First(x => queryMap.GetTableName(x) == model.TableName), dataModel.PropertyMaps.First(x => x.TableName == model.TableName && x.ColumnName == model.ColumnName))));
                dataModel.DataGridPresenterMaps.ForEach(model => queryMap.Add(DataGridPresenterMap.FromDataModel(queryMap, model)));
            }

            // Return the map
            return(queryMap);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes the manager.
        /// NOTE: This method should be called before the usage of the manager,
        ///       usually at the entry point of the application!
        /// </summary>
        /// <returns></returns>
        public async Task InitializeAsync()
        {
            // If there isn't an options file...
            if (!File.Exists(OptionsFileName))
            {
                // There is nothing to initialize from, so return
                return;
            }

            // Get the options
            var options = XMLHelpers.FromXml <CeidDiplomatikiOptionsDataModel>(OptionsFileName);

            // For every database...
            foreach (var database in options.Databases)
            {
                // Add it
                Register(database);
            }

            // For every database options...
            foreach (var databaseOptions in Databases)
            {
                // Get the connection string
                databaseOptions.TryGetConnectionString(out var connectionString);

                // Get the analyzer
                var analyzer = CeidDiplomatikiDI.GetDatabaseAnalyzer(databaseOptions.Provider);

                // Get the database
                var database = analyzer.GetDatabases().First(x => x.DatabaseName == databaseOptions.DatabaseName);

                // Get the tables
                var tables = analyzer.GetTables(databaseOptions.DatabaseName);

                // Get the columns
                var columns = analyzer.GetColumns(database.DatabaseName, null);

                // For every query map related to that database...
                foreach (var queryMapDataModel in options.QueryMaps.Where(x => x.DatabaseId == databaseOptions.Id))
                {
                    // The joins collection
                    var joins = new List <JoinMap>();

                    // For every pair...
                    foreach (var joinDataModel in queryMapDataModel.Joins)
                    {
                        // Get the principle column
                        var principleColumn = columns.First(x => x.ColumnName == joinDataModel.PrincipleKeyColumnName);

                        // Get the foreign key column
                        var referencedColumn = columns.First(x => x.ColumnName == joinDataModel.ForeignKeyColumnName);

                        // Create the join map
                        var joinMap = new JoinMap(tables.First(x => x.TableName == joinDataModel.TableName), principleColumn, tables.First(x => x.TableName == joinDataModel.ReferencedTableName), referencedColumn, joinDataModel.Index, joinDataModel.IsInverted);

                        // Add it to the joins
                        joins.Add(joinMap);
                    }

                    // Create the map
                    var queryMap = QueryMap.FromDataModel(databaseOptions, database, tables.Where(x => queryMapDataModel.TableNames.Contains(x.TableName)).ToList(), columns.Where(x => queryMapDataModel.TableNames.Contains(x.TableName)).ToList(), joins, queryMapDataModel);

                    // Register it
                    await RegisterAsync(queryMap);
                }
            }

            // For every page...
            foreach (var page in options.PageMaps)
            {
                // Add it
                Register(PageMap.FromDataModel(page, null));
            }

            // Await a task
            await Task.CompletedTask;
        }