public async Task NewColumnAsync()
        {
            var items = await this.Template.Dispatcher.InvokeAsync(() => this.Template.Select(item => item.Name).ToArray());

            var selectableTypes = await this.Template.Dispatcher.InvokeAsync(() => this.Template.SelectableTypes);

            var name   = NameUtility.GenerateNewName("Column", items);
            var dialog = new NewColumnViewModel(selectableTypes)
            {
                Name     = name,
                IsKey    = items.Any() == false,
                DataType = typeof(string).GetTypeName()
            };

            if (await dialog.ShowDialogAsync() == true)
            {
                var member = await this.Template.AddNewAsync(this.authentication);

                await member.SetNameAsync(this.authentication, dialog.Name);

                await member.SetDataTypeAsync(this.authentication, dialog.DataType);

                await member.SetCommentAsync(this.authentication, dialog.Comment);

                await member.SetIsKeyAsync(this.authentication, dialog.IsKey);

                await this.Template.EndNewAsync(this.authentication, member);
            }
        }
Example #2
0
        public static void RenameTest(this IType type, Authentication authentication)
        {
            var types   = type.GetService(typeof(ITypeCollection)) as ITypeCollection;
            var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), types.Select(item => item.Name));

            type.Rename(authentication, newName);
        }
Example #3
0
        private static void FillColumns(CremaDataTable diffTable, CremaDataTable dataTable, List <DiffPiece> lines)
        {
            var index = 0;

            foreach (var item in lines)
            {
                var diffColumn = diffTable.Columns.Add();
                if (item.Text != null && dataTable != null)
                {
                    var dataColumn = dataTable.Columns[index];
                    diffColumn.ColumnName = dataColumn.ColumnName;
                    diffColumn.CopyFrom(dataColumn);
                    index++;
                }
                else
                {
                    diffColumn.ColumnName = GenerateDummyName();
                }
                DiffUtility.SetDiffState(diffColumn, (DiffState)item.Type);
            }

            string GenerateDummyName()
            {
                return(NameUtility.GenerateNewName(DiffUtility.DiffDummyKey, diffTable.Columns.Select(item => item.ColumnName)));
            }
        }
Example #4
0
        public CremaDataTable Inherit()
        {
            var tables    = this.DataSet != null ? this.DataSet.Tables : Enumerable.Empty <CremaDataTable>();
            var tableName = NameUtility.GenerateNewName("DerivedTable", tables.Select(item => item.TableName));

            return(this.Inherit(tableName));
        }
Example #5
0
        protected override async Task <CremaTemplate> CreateSourceAsync(Authentication authentication)
        {
            if (this.parent is TableCategory category)
            {
                var typeContext  = category.GetService(typeof(TypeContext)) as TypeContext;
                var tableContext = category.GetService(typeof(TableContext)) as TableContext;
                var dataSet      = await category.ReadDataForNewTemplateAsync(authentication);

                var tableNames = await tableContext.Dispatcher.InvokeAsync(() => tableContext.Tables.Select((Table item) => item.Name).ToArray());

                var newName        = NameUtility.GenerateNewName(nameof(Table), tableNames);
                var templateSource = CremaTemplate.Create(dataSet, newName, category.Path);
                return(templateSource);
            }
            else if (this.parent is Table table)
            {
                var dataSet = await table.ReadDataForNewTemplateAsync(authentication);

                var dataTable  = dataSet.Tables[table.Name, table.Category.Path];
                var childNames = await table.Dispatcher.InvokeAsync(() => table.Childs.Select(item => item.TableName).Concat(new string[] { table.TableName }).ToArray());

                var newName  = NameUtility.GenerateNewName(ChildString, childNames);
                var template = CremaTemplate.Create(dataTable);
                template.TableName = newName;
                return(template);
            }
            throw new NotImplementedException();
        }
        public static async Task GenerateStandardFlagsAsync(this ITypeCategory category, Authentication authentication)
        {
            var types     = category.GetService(typeof(ITypeCollection)) as ITypeCollection;
            var typeNames = await types.Dispatcher.InvokeAsync(() => types.Select(item => item.Name).ToArray());

            var newName  = NameUtility.GenerateNewName("Flag", typeNames);
            var template = await category.AddNewTypeAsync(authentication);

            await template.SetTypeNameAsync(authentication, newName);

            await template.SetIsFlagAsync(authentication, true);

            await template.SetCommentAsync(authentication, "Standard Flag");

            await template.AddMemberAsync(authentication, "None", 0, "None Value");

            await template.AddMemberAsync(authentication, "A", 1, "A Value");

            await template.AddMemberAsync(authentication, "B", 2, "B Value");

            await template.AddMemberAsync(authentication, "C", 4, "C Value");

            await template.AddMemberAsync(authentication, "D", 8, "D Value");

            await template.AddMemberAsync(authentication, "AC", 1 | 4, "AC Value");

            await template.AddMemberAsync(authentication, "ABC", 1 | 2 | 4, "AC Value");

            await template.AddMemberAsync(authentication, "BD", 2 | 8, "AC Value");

            await template.AddMemberAsync(authentication, "All", 1 | 2 | 4 | 8, "All Value");

            await template.EndEditAsync(authentication);
        }
Example #7
0
        public InternalDataColumn AddColumn()
        {
            var columnNames = from DataColumn item in this.Columns select item.ColumnName;
            var columnName  = NameUtility.GenerateNewName(columnNameString, columnNames.ToArray());

            return(this.AddColumn(columnName));
        }
Example #8
0
        public InternalDataTable AddChild()
        {
            var childNames = from item in this.ChildItems select item.LocalName;
            var childName  = NameUtility.GenerateNewName(childNameString, childNames.ToArray());

            return(this.AddChild(childName));
        }
 public static Task <string> GenerateNewCategoryNameAsync(this ITableCategory tableCategory, string name)
 {
     return(tableCategory.Dispatcher.InvokeAsync(() =>
     {
         var names = tableCategory.Categories.Select(item => item.Name);
         return NameUtility.GenerateNewName(name, names);
     }));
 }
Example #10
0
        public CremaDataTable Copy()
        {
            var tables    = this.Parent != null ? this.Parent.Childs : (this.DataSet != null ? this.DataSet.Tables : Enumerable.Empty <CremaDataTable>());
            var tableName = NameUtility.GenerateNewName("CopiedTable", tables.Select(item => item.TableName));
            var name      = CremaDataTable.GenerateName(this.ParentName, tableName);

            return(this.Copy(name));
        }
Example #11
0
        public static void RenameTest(this ITypeCategory category, Authentication authentication)
        {
            Assert.AreNotEqual(null, category.Parent);
            var parent  = category.Parent;
            var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), parent.Categories.Select(item => item.Name));

            category.Rename(authentication, newName);
        }
Example #12
0
 public void Add(CremaDataType type)
 {
     this.ValidateAdd(type);
     if (type.TypeName == string.Empty)
     {
         type.TypeName = NameUtility.GenerateNewName("Type", this.Select(item => item.TypeName).ToArray());
     }
     this.tables.Add(type.InternalObject);
 }
Example #13
0
        protected override CremaTemplate CreateSource(Authentication authentication)
        {
            var typeContext    = this.category.GetService(typeof(TypeContext)) as TypeContext;
            var dataSet        = typeContext.Root.ReadData(authentication, true);
            var newName        = NameUtility.GenerateNewName("Table", this.category.Context.Tables.Select((Table item) => item.Name));
            var templateSource = CremaTemplate.Create(dataSet, newName, this.category.Path);

            return(templateSource);
        }
Example #14
0
        public static bool GenerateUser(this IUserContext context, Authentication authentication)
        {
            var category = context.Categories.Random();
            var newID    = NameUtility.GenerateNewName("Test", context.Users.Select(item => item.ID).ToArray());
            var newName  = newID.Replace("Test", "테스트");

            category.AddNewUser(authentication, newID, null, newName, Authority.Member);

            return(true);
        }
Example #15
0
        protected override CremaDataType CreateSource(Authentication authentication)
        {
            var newName  = NameUtility.GenerateNewName("Type", this.Types.Select((Type item) => item.Name).ToArray());
            var dataSet  = CremaDataSet.Create(new SignatureDateProvider(authentication.ID));
            var dataType = dataSet.Types.Add();

            dataType.TypeName     = newName;
            dataType.CategoryPath = this.category.Path;
            return(dataType);
        }
Example #16
0
        public async Task CreateAsync()
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var category       = await this.GetCategoryAsync(this.CategoryPath ?? this.GetCurrentDirectory());

            var typeNames = await this.GetTypeNamesAsync();

            var template = await category.AddNewTypeAsync(authentication);

            var typeName = NameUtility.GenerateNewName("Type", typeNames);
            var typeInfo = JsonTypeInfo.Default;

            typeInfo.TypeName = typeName;

            try
            {
                if (JsonEditorHost.TryEdit(ref typeInfo) == false)
                {
                    return;
                }
                if (this.CommandContext.ReadYesOrNo($"do you want to create type '{typeInfo.TypeName}'?") == false)
                {
                    return;
                }

                await template.SetTypeNameAsync(authentication, typeInfo.TypeName);

                await template.SetIsFlagAsync(authentication, typeInfo.IsFlag);

                await template.SetCommentAsync(authentication, typeInfo.Comment);

                foreach (var item in typeInfo.Members)
                {
                    var member = await template.AddNewAsync(authentication);

                    await member.SetNameAsync(authentication, item.Name);

                    await member.SetValueAsync(authentication, item.Value);

                    await member.SetCommentAsync(authentication, item.Comment);

                    await template.EndNewAsync(authentication, member);
                }
                await template.EndEditAsync(authentication);

                template = null;
            }
            finally
            {
                if (template != null)
                {
                    await template.CancelEditAsync(authentication);
                }
            }
        }
Example #17
0
        public TypeMember(TypeTemplateBase template, DataTable table)
            : base(template.Domain, table)
        {
            this.template = template;
            var query = from DataRow item in table.Rows
                        select item.Field <string>("Name");

            var newName = NameUtility.GenerateNewName("Type", query);

            this.SetField(null, "Name", newName);
        }
Example #18
0
        protected override async Task <CremaDataType> CreateSourceAsync(Authentication authentication)
        {
            var dataSet = await this.category.ReadDataForNewTemplateAsync(authentication);

            var typeName = NameUtility.GenerateNewName(nameof(Type), this.Types.Select((Type item) => item.Name).ToArray());
            var dataType = dataSet.Types.Add();

            dataType.TypeName     = typeName;
            dataType.CategoryPath = this.category.Path;
            return(dataType);
        }
Example #19
0
        public TableColumn(TableTemplateBase template, DataTable table)
            : base(template.Domain, table)
        {
            this.template = template;
            var query = from DataRow item in table.Rows
                        where (item.RowState == DataRowState.Deleted || item.RowState == DataRowState.Detached) == false
                        select item.Field <string>("ColumnName");

            var newName = NameUtility.GenerateNewName("Column", query);

            this.SetField(null, "ColumnName", newName);
        }
Example #20
0
 public static void RenameTest(this ITable table, Authentication authentication)
 {
     if (table.Parent == null)
     {
         var tables  = table.GetService(typeof(ITableCollection)) as ITableCollection;
         var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), tables.Select(item => item.Name));
         table.Rename(authentication, newName);
     }
     else
     {
         var parent  = table.Parent;
         var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), parent.Childs.Select(item => item.Name));
         table.Rename(authentication, newName);
     }
 }
Example #21
0
 public void TypeRenameFailTest()
 {
     cremaHost.Dispatcher.Invoke(() =>
     {
         try
         {
             var types   = this.type.GetService(typeof(ITypeCollection)) as ITypeCollection;
             var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), types.Select(item => item.Name));
             this.type.Rename(this.guest, newName);
             Assert.Fail("Rename");
         }
         catch (PermissionDeniedException)
         {
         }
     });
 }
Example #22
0
        public void Create()
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var category       = this.GetCategory(this.CategoryPath ?? this.GetCurrentDirectory());
            var typeNames      = this.GetTypeNames();
            var template       = category.Dispatcher.Invoke(() => category.NewType(authentication));
            var typeName       = NameUtility.GenerateNewName("Type", typeNames);
            var typeInfo       = JsonTypeInfo.Default;

            typeInfo.TypeName = typeName;

            try
            {
                if (JsonEditorHost.TryEdit(ref typeInfo) == false)
                {
                    return;
                }
                if (this.CommandContext.ReadYesOrNo($"do you want to create type '{typeInfo.TypeName}'?") == false)
                {
                    return;
                }

                template.Dispatcher.Invoke(() =>
                {
                    template.SetTypeName(authentication, typeInfo.TypeName);
                    template.SetIsFlag(authentication, typeInfo.IsFlag);
                    template.SetComment(authentication, typeInfo.Comment);
                    foreach (var item in typeInfo.Members)
                    {
                        var member = template.AddNew(authentication);
                        member.SetName(authentication, item.Name);
                        member.SetValue(authentication, item.Value);
                        member.SetComment(authentication, item.Comment);
                        template.EndNew(authentication, member);
                    }
                    template.EndEdit(authentication);
                    template = null;
                });
            }
            finally
            {
                if (template != null)
                {
                    template.Dispatcher.Invoke(() => template.CancelEdit(authentication));
                }
            }
        }
Example #23
0
        public static async Task <TypeMember> CreateAsync(Authentication authentication, TypeTemplateBase template, DataTable table)
        {
            var domain = template.Domain;
            var tuple  = await domain.DataDispatcher.InvokeAsync(() =>
            {
                var member = new TypeMember(template, table);
                var query  = from DataRow item in table.Rows
                             select item.Field <string>(CremaSchema.Name);

                var newName = NameUtility.GenerateNewName("Member", query);
                return(member, newName);
            });

            await tuple.member.SetFieldAsync(authentication, CremaSchema.Name, tuple.newName);

            return(tuple.member);
        }
Example #24
0
        public InternalDataTable AddTable()
        {
            var name = NameUtility.GenerateNewName("Table", GetTableNames());

            return(this.AddTable(name));

            IEnumerable <string> GetTableNames()
            {
                foreach (var item in this.Tables)
                {
                    if (item is InternalDataTable tableItem)
                    {
                        yield return(tableItem.Name);
                    }
                }
            }
        }
Example #25
0
 public static void RenameFailTest <T>(ITable table, Authentication authentication) where T : Exception
 {
     Assert.AreNotEqual(null, table.Parent);
     table.Dispatcher.Invoke(() =>
     {
         try
         {
             var parent  = table.Parent;
             var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), parent.Childs.Select(item => item.Name));
             table.Rename(authentication, newName);
             Assert.Fail("RenameFailTest");
         }
         catch (T)
         {
         }
     });
 }
Example #26
0
 public static void RenameFailTest <T>(ITable table, Authentication authentication) where T : Exception
 {
     Assert.AreEqual(null, table.Parent);
     table.Dispatcher.Invoke(() =>
     {
         try
         {
             var tables  = table.GetService(typeof(ITableCollection)) as ITableCollection;
             var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), tables.Select(item => item.Name));
             table.Rename(authentication, newName);
             Assert.Fail("RenameFailTest");
         }
         catch (T)
         {
         }
     });
 }
Example #27
0
        public static void TableRenameTest(this IDataBase dataBase, Authentication authentication)
        {
            dataBase.Dispatcher.Invoke(() =>
            {
                var tables = dataBase.GetService(typeof(ITableCollection)) as ITableCollection;
                var table  = tables.RandomOrDefault(item => item.TemplatedParent == null);

                if (table == null)
                {
                    return;
                }

                var newName = NameUtility.GenerateNewName(RandomUtility.NextIdentifier(), tables.Select(item => item.Name));

                table.Rename(authentication, newName);
            });
        }
Example #28
0
        public static async Task <TableColumn> CreateAsync(Authentication authentication, TableTemplateBase template, DataTable table)
        {
            var domain = template.Domain;
            var tuple  = await domain.DataDispatcher.InvokeAsync(() =>
            {
                var column = new TableColumn(template, table);
                var query  = from DataRow item in table.Rows
                             where (item.RowState == DataRowState.Deleted || item.RowState == DataRowState.Detached) == false
                             select item.Field <string>(CremaSchema.ColumnName);

                var newName = NameUtility.GenerateNewName("Column", query);
                return(column, newName);
            });

            await tuple.column.SetFieldAsync(authentication, CremaSchema.ColumnName, tuple.newName);

            return(tuple.column);
        }
Example #29
0
        public static void GenerateStandardFlags(this ITypeCategory category, Authentication authentication)
        {
            var newName  = NameUtility.GenerateNewName("Flag", category.DataBase.TypeContext.Types.Select(item => item.Name).ToArray());
            var template = category.NewType(authentication);

            template.SetTypeName(authentication, newName);
            template.SetIsFlag(authentication, true);
            template.SetComment(authentication, "Standard Flag");

            template.AddMember(authentication, "None", 0, "None Value");
            template.AddMember(authentication, "A", 1, "A Value");
            template.AddMember(authentication, "B", 2, "B Value");
            template.AddMember(authentication, "C", 4, "C Value");
            template.AddMember(authentication, "D", 8, "D Value");
            template.AddMember(authentication, "AC", 1 | 4, "AC Value");
            template.AddMember(authentication, "ABC", 1 | 2 | 4, "AC Value");
            template.AddMember(authentication, "BD", 2 | 8, "AC Value");
            template.AddMember(authentication, "All", 1 | 2 | 4 | 8, "All Value");

            template.EndEdit(authentication);
        }
        public async Task NewTableAsync()
        {
            var dataSet = new CremaDataSet();

            foreach (var item in this.dataSet.Types)
            {
                item.CopyTo(dataSet);
            }
            var tableName = NameUtility.GenerateNewName("Table", this.dataSet.Tables.Select(item => item.Name));
            var template  = CremaTemplate.Create(dataSet, tableName, this.categoryPath);
            var dialog    = new NewTableViewModel(this.dataSet, template);

            if (await dialog.ShowDialogAsync() != true)
            {
                return;
            }

            var dataTable = template.DataTable.CopyTo(this.dataSet);
            var viewModel = new TableTreeViewItemViewModel(dataTable, this.selector)
            {
                Parent = this,
            };
        }