protected override async Task OnEndEditAsync(Authentication authentication)
        {
            var template    = this.TemplateSource;
            var dataSet     = template.DataTable.DataSet;
            var dataBaseSet = await DataBaseSet.CreateAsync(this.table.DataBase, dataSet);

            var tableInfo = template.TableInfo;
            var taskID    = this.Domain.ID;

            this.Domain.Result = new TableInfo[] { tableInfo };
            await this.Container.InvokeTableEndTemplateEditAsync(authentication, tableInfo, dataBaseSet);

            await base.OnEndEditAsync(authentication);

            await this.Dispatcher.InvokeAsync(() =>
            {
                this.table.UpdateTemplate(template.TableInfo);
                this.table.UpdateTags(template.Tags);
                this.table.UpdateComment(template.Comment);
                this.table.TableState = TableState.None;
                this.Container.InvokeTablesStateChangedEvent(authentication, this.tables);
                this.Container.InvokeTablesTemplateChangedEvent(authentication, this.tables, dataSet);
                this.DataBase.InvokeTaskCompletedEvent(authentication, taskID);
            });

            await this.Repository.UnlockAsync(authentication, this, nameof(OnEndEditAsync), this.ItemPaths);
        }
        protected override async Task OnEndEditAsync(Authentication authentication)
        {
            var dataSet     = this.TemplateSource.DataSet;
            var dataTable   = this.TemplateSource.DataTable;
            var taskID      = this.Domain.ID;
            var dataTables  = EnumerableUtility.Friends(dataTable, dataTable.DerivedTables).ToArray();
            var itemPaths   = dataTables.Select(item => item.FullPath).ToArray();
            var dataBaseSet = await DataBaseSet.CreateAsync(this.DataBase, dataSet, DataBaseSetOptions.OmitUnlock | DataBaseSetOptions.AllowTableCreation);

            await this.Repository.LockAsync(authentication, this, nameof(OnEndEditAsync), itemPaths);

            try
            {
                dataBaseSet.TablesToCreate = dataTables;
                this.tables = await this.Container.AddNewAsync(authentication, dataBaseSet);

                this.Domain.Result = dataTables.Select(item => item.TableInfo).ToArray();
                await base.OnEndEditAsync(authentication);

                await this.Dispatcher.InvokeAsync(() => this.DataBase.InvokeTaskCompletedEvent(authentication, taskID));

                this.parent     = null;
                this.permission = null;
            }
            finally
            {
                await this.Repository.UnlockAsync(authentication, this, nameof(OnEndEditAsync), itemPaths);
            }
            await this.Repository.UnlockAsync(authentication, this, nameof(OnCancelEditAsync), this.ItemPaths);
        }
        public async Task <Table[]> InheritAsync(Authentication authentication, Table table, string newTableName, string categoryPath, bool copyContent)
        {
            try
            {
                this.ValidateExpired();
                var path = await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.DebugMethod(authentication, this, nameof(InheritAsync), this, table, newTableName, categoryPath, copyContent);
                    this.ValidateInherit(authentication, table, newTableName, categoryPath, copyContent);
                    return(table.Path);
                });

                var taskID     = GuidUtility.FromName(nameof(InheritAsync) + categoryPath + newTableName + copyContent);
                var itemName   = new ItemName(path);
                var targetName = new ItemName(categoryPath, newTableName);
                var dataSet    = await table.ReadDataForCopyAsync(authentication, categoryPath);

                var dataTable    = dataSet.Tables[itemName.Name, itemName.CategoryPath];
                var dataTables   = dataSet.Tables.ToArray();
                var newDataTable = dataTable.Inherit(targetName, copyContent);
                newDataTable.CategoryPath = categoryPath;
                using var dataBaseSet     = await DataBaseSet.CreateAsync(this.DataBase, dataSet, DataBaseSetOptions.AllowTableCreation);

                var tables = await this.AddNewAsync(authentication, dataBaseSet);

                await this.Dispatcher.InvokeAsync(() => this.DataBase.InvokeTaskCompletedEvent(authentication, taskID));

                return(tables);
            }
            catch (Exception e)
            {
                this.CremaHost.Error(e);
                throw;
            }
        }
        protected override async Task OnEndEditAsync(Authentication authentication)
        {
            var dataSet     = this.TypeSource.DataSet;
            var dataType    = this.TypeSource;
            var taskID      = this.Domain.ID;
            var dataTypes   = new CremaDataType[] { dataType };
            var itemPaths   = new string[] { dataType.FullPath };
            var dataBaseSet = await DataBaseSet.CreateAsync(this.DataBase, dataSet, DataBaseSetOptions.OmitUnlock | DataBaseSetOptions.AllowTypeCreation);

            await this.Repository.LockAsync(authentication, this, nameof(OnEndEditAsync), itemPaths);

            try
            {
                dataBaseSet.TypesToCreate = dataTypes;
                this.types = await this.Types.AddNewAsync(authentication, dataBaseSet);

                this.type          = this.types.First();
                this.Domain.Result = dataTypes.Select(item => item.TypeInfo).ToArray();
                await base.OnEndEditAsync(authentication);

                await this.Dispatcher.InvokeAsync(() => this.DataBase.InvokeTaskCompletedEvent(authentication, taskID));
            }
            finally
            {
                await this.Repository.UnlockAsync(authentication, this, nameof(OnEndEditAsync), itemPaths);
            }
            await this.Repository.UnlockAsync(authentication, this, nameof(OnCancelEditAsync), this.ItemPaths);
        }
Exemple #5
0
        public async Task <Guid> RenameAsync(Authentication authentication, string name)
        {
            try
            {
                if (authentication is null)
                {
                    throw new ArgumentNullException(nameof(authentication));
                }
                if (authentication.IsExpired == true)
                {
                    throw new AuthenticationExpiredException(nameof(authentication));
                }
                if (name is null)
                {
                    throw new ArgumentNullException(nameof(name));
                }

                this.ValidateExpired();
                var tuple = await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.DebugMethod(authentication, this, nameof(RenameAsync), this, name);
                    base.ValidateRename(authentication, name);
                    var items      = new Type[] { this };
                    var oldNames   = items.Select(item => item.Name).ToArray();
                    var oldPaths   = items.Select(item => item.Path).ToArray();
                    var typeInfo   = base.TypeInfo;
                    var targetName = new ItemName(base.Path)
                    {
                        Name = name
                    };
                    return(items, oldNames, oldPaths, typeInfo, targetName);
                });

                var taskID  = Guid.NewGuid();
                var dataSet = await this.ReadDataForPathAsync(authentication, tuple.targetName);

                using var dataBaseSet = await DataBaseSet.CreateAsync(this.DataBase, dataSet);

                await this.Container.InvokeTypeRenameAsync(authentication, tuple.typeInfo, name, dataBaseSet);

                await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.Sign(authentication);
                    base.Rename(authentication, name);
                    this.Container.InvokeTypesRenamedEvent(authentication, tuple.items, tuple.oldNames, tuple.oldPaths, dataSet);
                    this.DataBase.InvokeTaskCompletedEvent(authentication, taskID);
                });

                return(taskID);
            }
            catch (Exception e)
            {
                this.CremaHost.Error(e);
                throw;
            }
        }
Exemple #6
0
        public async Task <Guid> MoveAsync(Authentication authentication, string categoryPath)
        {
            try
            {
                if (authentication is null)
                {
                    throw new ArgumentNullException(nameof(authentication));
                }
                if (authentication.IsExpired == true)
                {
                    throw new AuthenticationExpiredException(nameof(authentication));
                }
                if (categoryPath is null)
                {
                    throw new ArgumentNullException(nameof(categoryPath));
                }

                this.ValidateExpired();
                var tuple = await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.DebugMethod(authentication, this, nameof(Move), this, categoryPath);
                    base.ValidateMove(authentication, categoryPath);
                    var items            = EnumerableUtility.One(this).ToArray();
                    var oldPaths         = items.Select(item => item.Path).ToArray();
                    var oldCategoryPaths = items.Select(item => item.Category.Path).ToArray();
                    var typeInfo         = base.TypeInfo;
                    var targetName       = new ItemName(categoryPath, base.Name);
                    return(items, oldPaths, oldCategoryPaths, typeInfo, targetName);
                });

                var taskID  = Guid.NewGuid();
                var dataSet = await this.ReadDataForPathAsync(authentication, tuple.targetName);

                using var dataBaseSet = await DataBaseSet.CreateAsync(this.DataBase, dataSet);

                await this.Container.InvokeTypeMoveAsync(authentication, tuple.typeInfo, categoryPath, dataBaseSet);

                await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.Sign(authentication);
                    base.Move(authentication, categoryPath);
                    this.Container.InvokeTypesMovedEvent(authentication, tuple.items, tuple.oldPaths, tuple.oldCategoryPaths, dataSet);
                    this.DataBase.InvokeTaskCompletedEvent(authentication, taskID);
                });

                return(taskID);
            }
            catch (Exception e)
            {
                this.CremaHost.Error(e);
                throw;
            }
        }
Exemple #7
0
        public async Task <Type> CopyAsync(Authentication authentication, string typeName, string newTypeName, string categoryPath)
        {
            try
            {
                this.ValidateExpired();
                var tuple = await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.DebugMethod(authentication, this, nameof(CopyAsync), typeName, newTypeName, categoryPath);
                    this.ValidateCopy(authentication, typeName, newTypeName);
                    return(this[typeName], this[typeName].Path);
                });

                var type       = tuple.Item1;
                var path       = tuple.Path;
                var taskID     = GuidUtility.FromName(categoryPath + newTypeName);
                var itemName   = new ItemName(tuple.Path);
                var targetName = new ItemName(categoryPath, newTypeName);
                var dataSet    = await type.ReadDataForCopyAsync(authentication, categoryPath);

                var dataType    = dataSet.Types[itemName.Name, itemName.CategoryPath];
                var newDataType = dataType.Copy(targetName);
                using var dataBaseSet = await DataBaseSet.CreateAsync(this.DataBase, dataSet, DataBaseSetOptions.AllowTypeCreation);

                var typePaths = new string[] { categoryPath + newTypeName };
                await this.InvokeTypeCreateAsync(authentication, typePaths, dataBaseSet);

                var result = await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.Sign(authentication);
                    var newType = this.BaseAddNew(newTypeName, categoryPath, authentication);
                    newType.Initialize(newDataType.TypeInfo);
                    this.InvokeTypesCreatedEvent(authentication, new Type[] { newType }, dataSet);
                    this.DataBase.InvokeTaskCompletedEvent(authentication, taskID);
                    return(newType);
                });

                return(result);
            }
            catch (Exception e)
            {
                this.CremaHost.Error(e);
                throw;
            }
        }
Exemple #8
0
            public async Task BeginContentAsync(Authentication authentication)
            {
                try
                {
                    this.dataSet = await this.Container.ReadDataForContentAsync(authentication, this.Tables);

                    this.domain      = new TableContentDomain(authentication, dataSet, this.DataBase, this.path, typeof(TableContent).Name, this);
                    this.dataBaseSet = await DataBaseSet.CreateAsync(this.DataBase, dataSet);

                    this.itemPaths = this.dataSet.GetItemPaths();
                    await this.DomainContext.AddAsync(authentication, this.domain, this.DataBase);
                }
                catch
                {
                    if (this.dataBaseSet != null)
                    {
                        await this.Repository.UnlockAsync(authentication, this, nameof(BeginContentAsync), this.dataBaseSet.ItemPaths);
                    }
                    this.dataSet     = null;
                    this.domain      = null;
                    this.dataBaseSet = null;
                    throw;
                }
                await this.Dispatcher.InvokeAsync(() =>
                {
                    foreach (var item in this.Contents)
                    {
                        item.Domain           = this.domain;
                        item.domainHost       = this;
                        item.DataTable        = dataSet.Tables[item.Table.Name, item.Table.Category.Path];
                        item.Table.TableState = TableState.IsBeingEdited;
                        item.IsModified       = domain.ModifiedTables.Contains(item.dataTable.Name);
                    }
                });

                await this.domain.Dispatcher.InvokeAsync(this.AttachDomainEvent);

                await this.Dispatcher.InvokeAsync(() =>
                {
                    this.Container.InvokeTablesStateChangedEvent(authentication, this.Tables);
                });
            }
Exemple #9
0
        public async Task <Guid> ImportAsync(Authentication authentication, CremaDataSet dataSet, string comment)
        {
            try
            {
                if (authentication is null)
                {
                    throw new ArgumentNullException(nameof(authentication));
                }
                if (authentication.IsExpired == true)
                {
                    throw new AuthenticationExpiredException(nameof(authentication));
                }
                if (dataSet is null)
                {
                    throw new ArgumentNullException(nameof(dataSet));
                }
                if (comment is null)
                {
                    throw new ArgumentNullException(nameof(comment));
                }

                await this.Dispatcher.InvokeAsync(() =>
                {
                    this.CremaHost.DebugMethod(authentication, this, nameof(ImportAsync), comment);
                    this.ValidateImport(authentication, dataSet, comment);
                    this.CremaHost.Sign(authentication);
                });

                var taskID = Guid.NewGuid();
                var filter = new CremaDataSetFilter()
                {
                    Tables      = dataSet.Tables.Select(item => item.Name).ToArray(),
                    OmitContent = true
                };
                var targetSet = await this.GetDataSetAsync(authentication, filter, string.Empty);

                await this.Dispatcher.InvokeAsync(() =>
                {
                    this.LockTypes(authentication, targetSet, comment);
                    this.LockTables(authentication, targetSet, comment);
                });

                try
                {
                    targetSet.SignatureDateProvider = new SignatureDateProvider(authentication.ID);
                    foreach (var item in targetSet.Tables)
                    {
                        var dataTable = dataSet.Tables[item.Name];
                        foreach (var row in dataTable.Rows)
                        {
                            item.ImportRow(row);
                        }
                        item.BeginLoad();
                        foreach (var row in item.Rows)
                        {
                            row.CreationInfo     = authentication.SignatureDate;
                            row.ModificationInfo = authentication.SignatureDate;
                        }
                        item.ContentsInfo = authentication.SignatureDate;
                        item.EndLoad();
                    }
                    var dataBaseSet = await DataBaseSet.CreateAsync(this, targetSet);

                    await this.Repository.Dispatcher.InvokeAsync(() =>
                    {
                        try
                        {
                            this.Repository.Modify(dataBaseSet);
                            this.Repository.Commit(authentication, comment);
                        }
                        catch
                        {
                            this.Repository.Revert();
                            throw;
                        }
                    });

                    await this.Dispatcher.InvokeAsync(() =>
                    {
                        this.UpdateTables(authentication, targetSet);
                    });

                    return(taskID);
                }
                finally
                {
                    await this.Dispatcher.InvokeAsync(() =>
                    {
                        this.UnlockTypes(authentication, targetSet);
                        this.UnlockTables(authentication, targetSet);
                    });
                }
            }
            catch (Exception e)
            {
                this.CremaHost.Error(e);
                throw;
            }
        }