public static Task <MoveTableCategoryViewModel> CreateInstanceAsync(Authentication authentication, ITableCategoryDescriptor descriptor)
        {
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (descriptor.Target is ITableCategory category)
            {
                return(category.Dispatcher.InvokeAsync(() =>
                {
                    var categories = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
                    var targetPaths = categories.Select(item => item.Path).ToArray();
                    return new MoveTableCategoryViewModel(authentication, category, targetPaths);
                }));
            }
            else
            {
                throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor));
            }
        }
예제 #2
0
        private async Task MoveTableCategoryAsync(Authentication authentication, ITableCategory sourceCategory, string newPath)
        {
            var destPath   = new DataBasePath(newPath);
            var destObject = await this.GetObjectAsync(authentication, destPath.Path);

            var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase;
            var tables   = sourceCategory.GetService(typeof(ITableCollection)) as ITableCollection;

            if (destPath.DataBaseName != dataBase.Name)
            {
                throw new InvalidOperationException($"cannot move to : {destPath}");
            }
            if (destPath.Context != CremaSchema.TableDirectory)
            {
                throw new InvalidOperationException($"cannot move to : {destPath}");
            }
            if (destObject is ITable)
            {
                throw new InvalidOperationException($"cannot move to : {destPath}");
            }

            using (await UsingDataBase.SetAsync(dataBase, authentication))
            {
                if (destObject is ITableCategory destCategory)
                {
                    if (sourceCategory.Parent != destCategory)
                    {
                        await sourceCategory.MoveAsync(authentication, destCategory.Path);
                    }
                }
                else
                {
                    if (NameValidator.VerifyCategoryPath(destPath.ItemPath) == true)
                    {
                        throw new InvalidOperationException($"cannot move to : {destPath}");
                    }
                    var itemName   = new ItemName(destPath.ItemPath);
                    var categories = sourceCategory.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
                    if (await categories.ContainsAsync(itemName.CategoryPath) == false)
                    {
                        throw new InvalidOperationException($"cannot move to : {destPath}");
                    }
                    if (sourceCategory.Name != itemName.Name && await tables.ContainsAsync(itemName.Name) == true)
                    {
                        throw new InvalidOperationException($"cannot move to : {destPath}");
                    }
                    if (sourceCategory.Parent.Path != itemName.CategoryPath)
                    {
                        await sourceCategory.MoveAsync(authentication, itemName.CategoryPath);
                    }
                    if (sourceCategory.Name != itemName.Name)
                    {
                        await sourceCategory.RenameAsync(authentication, itemName.Name);
                    }
                }
            }
        }
예제 #3
0
        public static async Task <ITable[]> AddRandomDerivedTableAsync(this ITableCategory category, Authentication authentication)
        {
            var tableCollection = category.GetService(typeof(ITableCollection)) as ITableCollection;
            var tableName       = RandomUtility.NextIdentifier();
            var copyData        = RandomUtility.NextBoolean();
            var tableContext    = category.GetService(typeof(ITableContext)) as ITableContext;
            var table           = await tableCollection.GetRandomTableAsync(item => item.TemplatedParent == null && item.Parent == null);

            return(await table.InheritAsync(authentication, tableName, category.Path, copyData));
        }
예제 #4
0
        public void Move(ITableCategory category, TaskContext context)
        {
            category.Dispatcher.Invoke(() =>
            {
                if (category.Parent == null)
                {
                    return;
                }
                var categories   = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
                var categoryPath = categories.Random().Path;
                if (Verify(categoryPath) == false)
                {
                    return;
                }
                category.Move(context.Authentication, categoryPath);
            });

            bool Verify(string categoryPath)
            {
                if (context.AllowException == true)
                {
                    return(true);
                }
                if (categoryPath.StartsWith(category.Path) == true)
                {
                    return(false);
                }
                if (category.Parent.Path == categoryPath)
                {
                    return(false);
                }
                return(true);
            }
        }
예제 #5
0
 public NewTableViewModel(Authentication authentication, ITableCategory category, ITableTemplate template)
     : base(authentication, template, true)
 {
     this.category = category;
     this.category.Dispatcher.VerifyAccess();
     this.tableContext = category.GetService(typeof(ITableContext)) as ITableContext;
     this.DisplayName  = Resources.Title_NewTable;
 }
예제 #6
0
        public static ITable AddRandomDerivedTable(this ITableCategory category, Authentication authentication)
        {
            var tableName    = RandomUtility.NextIdentifier();
            var copyData     = RandomUtility.NextBoolean();
            var tableContext = category.GetService(typeof(ITableContext)) as ITableContext;
            var table        = tableContext.Tables.Random(item => item.TemplatedParent == null && item.Parent == null);

            return(table.Inherit(authentication, tableName, category.Path, copyData));
        }
        public static async Task <ITable> GenerateStandardTableAsync(this ITableCategory category, Authentication authentication, string prefix, IEnumerable <string> keyTypes, IEnumerable <string> columnTypes)
        {
            var tables    = category.GetService(typeof(ITableCollection)) as ITableCollection;
            var tableName = string.Join("_", EnumerableUtility.Friends(prefix, keyTypes));

            if (tables.Contains(tableName) == true)
            {
                return(null);
            }

            var template = await category.AddNewTableAsync(authentication);

            await template.SetTableNameAsync(authentication, tableName);

            foreach (var item in keyTypes)
            {
                await template.AddKeyAsync(authentication, item, item);
            }

            foreach (var item in columnTypes)
            {
                await template.AddColumnAsync(authentication, item, item);
            }

            try
            {
                await template.EndEditAsync(authentication);

                return(template.Target as ITable);
            }
            catch
            {
                await template.CancelEditAsync(authentication);

                return(null);
            }

            //var table = template.Table;
            //var content = table.Content;

            //content.BeginEdit(authentication);
            //content.EnterEdit(authentication);
            //try
            //{
            //    content.GenerateRowsAsync(authentication, RandomUtility.Next(10, 1000));
            //    content.LeaveEdit(authentication);
            //    content.EndEdit(authentication);
            //}
            //catch
            //{
            //    content.CancelEdit(authentication);
            //}

            //return table;
        }
예제 #8
0
        public static void MoveTest(this ITableCategory category, Authentication authentication)
        {
            Assert.AreNotEqual(null, category.Parent);
            var categories  = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
            var descendants = EnumerableUtility.Descendants(category, item => item.Categories);
            var target      = categories.Random(item => descendants.Contains(item) == false && item != category && item != category.Parent);

            if (target == null)
            {
                Assert.Inconclusive();
            }
            category.Move(authentication, target.Path);
        }
 public static void MoveParentFailTest <T>(ICremaHost cremaHost, ITableCategory category, Authentication authentication) where T : Exception
 {
     cremaHost.Dispatcher.Invoke(() =>
     {
         try
         {
             var categories = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
             category.Parent.Move(authentication, categories.Root.Path);
             Assert.Fail("Move");
         }
         catch (T)
         {
         }
     });
 }
예제 #10
0
 public static void MoveFailTest <T>(ITableCategory category, Authentication authentication) where T : Exception
 {
     Assert.AreNotEqual(null, category.Parent);
     category.Dispatcher.Invoke(() =>
     {
         try
         {
             var categories  = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
             var descendants = EnumerableUtility.Descendants(category, item => item.Categories);
             var target      = categories.Random(item => descendants.Contains(item) == false && item != category.Parent);
             category.Move(authentication, target.Path);
             Assert.Fail("MoveFailTest");
         }
         catch (T)
         {
         }
     });
 }
예제 #11
0
        public async Task MoveAsync(ITableCategory category, TaskContext context)
        {
            var authentication = context.Authentication;
            var categories     = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
            var categoryPath   = await categories.Dispatcher.InvokeAsync(() => categories.Random().Path);

            if (context.AllowException == false)
            {
                if (await VerifyAsync() == false)
                {
                    return;
                }
            }
            await category.MoveAsync(authentication, categoryPath);

            async Task <bool> VerifyAsync()
            {
                if ((await category.GetAllTablesAsync(item => item.TableState != TableState.None)).Any() == true)
                {
                    return(false);
                }
                return(await category.Dispatcher.InvokeAsync(() =>
                {
                    if (category.Parent == null)
                    {
                        return false;
                    }
                    if (categoryPath.StartsWith(category.Path) == true)
                    {
                        return false;
                    }
                    if (category.Parent.Path == categoryPath)
                    {
                        return false;
                    }
                    if (categoryPath.StartsWith(category.Path) == true)
                    {
                        return false;
                    }
                    return true;
                }));
            }
        }
예제 #12
0
 public void RemoveAccessMember(ITableCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         if (category.Parent == null)
         {
             return;
         }
         var userContext = category.GetService(typeof(IUserContext)) as IUserContext;
         var memberID    = userContext.Dispatcher.Invoke(() => userContext.Select(item => item.Path).Random());
         if (NameValidator.VerifyItemPath(memberID) == true)
         {
             category.RemoveAccessMember(context.Authentication, new ItemName(memberID).Name);
         }
         else
         {
             category.RemoveAccessMember(context.Authentication, memberID);
         }
     });
 }
예제 #13
0
        //[TaskMethod(Weight = 10)]
        public async Task AddAccessMemberAsync(ITableCategory category, TaskContext context)
        {
            var authentication = context.Authentication;

            if (category.Parent == null)
            {
                return;
            }
            var userContext = category.GetService(typeof(IUserContext)) as IUserContext;
            var memberID    = await userContext.Dispatcher.InvokeAsync(() => userContext.Select(item => item.Path).Random());

            var accessType = RandomUtility.NextEnum <AccessType>();

            if (NameValidator.VerifyItemPath(memberID) == true)
            {
                await category.AddAccessMemberAsync(authentication, new ItemName(memberID).Name, accessType);
            }
            else
            {
                await category.AddAccessMemberAsync(authentication, memberID, accessType);
            }
        }
예제 #14
0
        public static async Task <ITable> GenerateTableAsync(this ITableCategory tableCategory, Authentication authentication, params string[] typeNames)
        {
            var tableCollection = tableCategory.GetService(typeof(ITableCollection)) as ITableCollection;
            var newName         = await tableCollection.GenerateNewTableNameAsync("table");

            var template = await tableCategory.AddNewTableAsync(authentication);

            await template.SetTableNameAsync(authentication, newName);

            foreach (var item in typeNames)
            {
                var columnName = await template.GenerateNewColumnNameAsync();

                var comment = RandomUtility.NextString();
                await template.AddColumnAsync(authentication, columnName, item, comment);
            }
            await template.AddRandomColumnsAsync(authentication);

            await template.EndEditAsync(authentication);

            return(template.Target as ITable);

            throw new NotImplementedException();
        }
 public void GetService()
 {
     Console.Write(category.GetService(typeof(ICremaHost)));
 }
예제 #16
0
        private void MoveTableCategory(Authentication authentication, ITableCategory sourceCategory, string newPath)
        {
            var destPath   = new DataBasePath(newPath);
            var destObject = this.GetObject(authentication, destPath.Path);

            this.CremaHost.Dispatcher.Invoke(MoveTableCategory);

            void MoveTableCategory()
            {
                var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase;
                var tables   = sourceCategory.GetService(typeof(ITableCollection)) as ITableCollection;

                if (destPath.DataBaseName != dataBase.Name)
                {
                    throw new InvalidOperationException($"cannot move to : {destPath}");
                }
                if (destPath.Context != CremaSchema.TableDirectory)
                {
                    throw new InvalidOperationException($"cannot move to : {destPath}");
                }
                if (destObject is ITable)
                {
                    throw new InvalidOperationException($"cannot move to : {destPath}");
                }

                using (DataBaseUsing.Set(dataBase, authentication))
                {
                    if (destObject is ITableCategory destCategory)
                    {
                        if (sourceCategory.Parent != destCategory)
                        {
                            sourceCategory.Move(authentication, destCategory.Path);
                        }
                    }
                    else
                    {
                        if (NameValidator.VerifyCategoryPath(destPath.ItemPath) == true)
                        {
                            throw new InvalidOperationException($"cannot move to : {destPath}");
                        }
                        var itemName   = new ItemName(destPath.ItemPath);
                        var categories = sourceCategory.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
                        if (categories.Contains(itemName.CategoryPath) == false)
                        {
                            throw new InvalidOperationException($"cannot move to : {destPath}");
                        }
                        if (sourceCategory.Name != itemName.Name && tables.Contains(itemName.Name) == true)
                        {
                            throw new InvalidOperationException($"cannot move to : {destPath}");
                        }
                        if (sourceCategory.Parent.Path != itemName.CategoryPath)
                        {
                            sourceCategory.Move(authentication, itemName.CategoryPath);
                        }
                        if (sourceCategory.Name != itemName.Name)
                        {
                            sourceCategory.Rename(authentication, itemName.Name);
                        }
                    }
                }
            }
        }