Exemple #1
0
        public void InvokeTableEndTemplateEdit(Authentication authentication, Table table, CremaTemplate template)
        {
            this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTableEndTemplateEdit), table);
            if (table.TemplatedParent != null)
            {
                throw new InvalidOperationException(Resources.Exception_InheritedTableTemplateCannotEdit);
            }

            var dataTable  = template.TargetTable;
            var dataSet    = dataTable.DataSet;
            var dataTables = new DataTableCollection(dataSet, this.DataBase);

            try
            {
                dataTables.Modify(this.Repository);
                this.Context.InvokeTableItemChange(authentication, table);
            }
            catch (Exception e)
            {
                this.CremaHost.Error(e);
                this.Repository.Revert();
                throw e;
            }
        }
Exemple #2
0
        public void Import(Authentication authentication, CremaDataSet dataSet, string comment)
        {
            this.Dispatcher?.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(Import), comment);
            this.ValidateImport(authentication, dataSet, comment);
            var query = from item in dataSet.Tables
                        let table = this.Tables[item.Name]
                                    where table.LockInfo.Path != table.Path
                                    select table;

            var items    = query.ToArray();
            var comments = Enumerable.Repeat(comment, items.Length).ToArray();

            foreach (var item in items)
            {
                item.LockInternal(Authentication.System, comment);
            }
            this.InvokeItemsLockedEvent(authentication, items, comments);

            try
            {
                var targetSet = new CremaDataSet();
                foreach (var item in items.Where(i => i.Parent == null))
                {
                    var targetTable = item.ReadSchema(authentication, targetSet);

                    var dataTable = dataSet.Tables[targetTable.TableName];
                    if (dataTable == null)
                    {
                        continue;
                    }

                    foreach (var row in dataTable.Rows)
                    {
                        targetTable.ImportRow(row);
                    }
                    targetTable.ContentsInfo = dataTable.ContentsInfo;
                }

                var dataTables = new DataTableCollection(targetSet, this.DataBase);
                try
                {
                    dataTables.Modify(this.Repository);
                }
                catch
                {
                }

                foreach (var item in items)
                {
                    var dataTable = targetSet.Tables[item.Name, item.Category.Path];
                    item.UpdateContent(dataTable.TableInfo);
                }

                var eventLog = EventLogBuilder.Build(authentication, this, nameof(Import), comment);
                this.Repository.Commit(authentication, comment, eventLog);
                this.OnItemsChanged(new ItemsEventArgs <ITableItem>(Authentication.System, items, targetSet));
            }
            finally
            {
                foreach (var item in items)
                {
                    item.UnlockInternal(Authentication.System);
                }
                this.InvokeItemsUnlockedEvent(authentication, items);
            }
        }