Example #1
0
        public void Move(ITypeCategory category, TaskContext context)
        {
            category.Dispatcher.Invoke(() =>
            {
                var categories   = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection;
                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 (category.Parent == null || category.Path == categoryPath)
                {
                    return(false);
                }
                return(true);
            }
        }
Example #2
0
        public void Rename(ITypeCategory category, TaskContext context)
        {
            category.Dispatcher.Invoke(() =>
            {
                var categoryName = RandomUtility.NextIdentifier();
                if (Verify() == false)
                {
                    return;
                }
                category.Rename(context.Authentication, categoryName);
            });

            bool Verify()
            {
                if (context.AllowException == true)
                {
                    return(true);
                }
                if (category.Parent == null)
                {
                    return(false);
                }
                return(true);
            }
        }
Example #3
0
 public PreviewTypeCategoryViewModel(Authentication authentication, ITypeCategory category, long revision)
 {
     this.authentication = authentication;
     this.category       = category;
     this.revision       = revision;
     this.Initialize();
 }
 public async Task FindAsync(ITypeCategory category, TaskContext context)
 {
     var authentication = context.Authentication;
     var text           = RandomUtility.NextWord();
     var option         = RandomUtility.NextEnum <FindOptions>();
     await category.FindAsync(authentication, text, option);
 }
Example #5
0
        public void SetPrivate(ITypeCategory category, TaskContext context)
        {
            category.Dispatcher.Invoke(() =>
            {
                if (category.Parent == null)
                {
                    return;
                }
                if (Verify() == false)
                {
                    return;
                }
                category.SetPrivate(context.Authentication);
            });

            bool Verify()
            {
                if (context.AllowException == true)
                {
                    return(true);
                }
                if (category.IsPrivate == false)
                {
                    return(false);
                }
                return(true);
            }
        }
        public async Task DeleteAsync(ITypeCategory category, TaskContext context)
        {
            var authentication = context.Authentication;

            if (context.AllowException == false)
            {
                if (await VerifyAsync() == true)
                {
                    return;
                }
            }
            await category.DeleteAsync(authentication);

            context.Pop(category);

            async Task <bool> VerifyAsync()
            {
                if ((await category.GetAllTypesAsync(item => true)).Any() == true)
                {
                    return(false);
                }
                return(await category.Dispatcher.InvokeAsync(() =>
                {
                    if (category.Parent == null)
                    {
                        return false;
                    }
                    return true;
                }));
            }
        }
        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);
        }
        public async Task RemoveAccessMemberAsync(ITypeCategory category, TaskContext context)
        {
            var authentication = context.Authentication;

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

            if (NameValidator.VerifyItemPath(memberID) == true)
            {
                await category.RemoveAccessMemberAsync(authentication, new ItemName(memberID).Name);
            }
            else
            {
                await category.RemoveAccessMemberAsync(authentication, memberID);
            }
        }
 private DeleteTypeCategoryViewModel(Authentication authentication, ITypeCategory category)
 {
     this.authentication = authentication;
     this.category       = category;
     this.category.Dispatcher.VerifyAccess();
     this.DisplayName = Resources.Title_DeleteTypeFolder;
 }
Example #10
0
 public void GetAccessType(ITypeCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         category.GetAccessType(context.Authentication);
     });
 }
Example #11
0
        //[TaskMethod]
        //public async Task VerifyReadAsync(ITypeCategory category, TaskContext context)
        //{
        //    category.Dispatcher.Invoke(() =>
        //    {
        //        category.VerifyRead(authentication);
        //    });
        //}

        //[TaskMethod]
        //public async Task VerifyOwnerAsync(ITypeCategory category, TaskContext context)
        //{
        //    category.Dispatcher.Invoke(() =>
        //    {
        //        category.VerifyOwner(authentication);
        //    });
        //}

        //[TaskMethod]
        //public async Task VerifyMemberAsync(ITypeCategory category, TaskContext context)
        //{
        //    category.Dispatcher.Invoke(() =>
        //    {
        //        category.VerifyMember(authentication);
        //    });
        //}

        //[TaskMethod(Weight = 10)]
        public async Task LockAsync(ITypeCategory category, TaskContext context)
        {
            var authentication = context.Authentication;
            var comment        = RandomUtility.NextString();

            if (context.AllowException == false)
            {
                if (category.Parent == null)
                {
                    return;
                }
                if (string.IsNullOrEmpty(comment) == true)
                {
                    return;
                }
                var lockInfo = await category.Dispatcher.InvokeAsync(() => category.LockInfo);

                if (lockInfo.IsLocked == true || lockInfo.IsInherited == true)
                {
                    return;
                }
            }

            await category.LockAsync(authentication, comment);
        }
Example #12
0
 public NewTypeViewModel(Authentication authentication, ITypeCategory category, ITypeTemplate template)
     : base(authentication, template, true)
 {
     this.Category       = category;
     this.typeCollection = category.GetService(typeof(ITypeCollection)) as ITypeCollection;
     this.DisplayName    = Resources.Title_NewType;
 }
Example #13
0
 public void Preview(ITypeCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         category.GetDataSet(context.Authentication, -1);
     });
 }
Example #14
0
 private void Category_Deleted(object sender, EventArgs e)
 {
     this.category = null;
     this.Dispatcher.InvokeAsync(() =>
     {
         this.OnDisposed(EventArgs.Empty);
     });
 }
Example #15
0
 //[TaskMethod]
 public Task GetAccessTypeAsync(ITypeCategory category, TaskContext context)
 {
     throw new NotImplementedException();
     //category.Dispatcher.Invoke(() =>
     //{
     //    category.GetAccessType(authentication);
     //});
 }
Example #16
0
        public void Initialize()
        {
            var dataBase    = cremaHost.PrimaryDataBase;
            var typeContext = dataBase.TypeContext;

            this.guest    = users.Where(item => item.Key.Authority == Authority.Guest).Random().Value;
            this.category = typeContext.Categories.RandomOrDefault(item => item.IsLocked == false && item.Parent != null);
        }
Example #17
0
 public void NewType(ITypeCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         var template = category.NewType(context.Authentication);
         context.Push(template);
     });
 }
Example #18
0
 public void AddNewCategory(ITypeCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         var categoryNanme = RandomUtility.NextIdentifier();
         category.AddNewCategory(context.Authentication, categoryNanme);
     });
 }
Example #19
0
        public static IType AddRandomType(this ITypeCategory category, Authentication authentication)
        {
            var template = category.NewType(authentication);

            template.InitializeRandom(authentication);
            template.EndEdit(authentication);
            return(template.Type);
        }
 private MoveTypeCategoryViewModel(Authentication authentication, ITypeCategory category, string[] targetPaths)
     : base(category, currentPath: category.Path, targetPaths: targetPaths)
 {
     this.authentication = authentication;
     this.category       = category;
     this.category.Dispatcher.VerifyAccess();
     this.DisplayName = Resources.Title_MoveTypeFolder;
 }
Example #21
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 #22
0
 public static Task <string> GenerateNewCategoryNameAsync(this ITypeCategory typeCategory, string name)
 {
     return(typeCategory.Dispatcher.InvokeAsync(() =>
     {
         var names = typeCategory.Categories.Select(item => item.Name);
         return NameUtility.GenerateNewName(name, names);
     }));
 }
Example #23
0
 public void Find(ITypeCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         var text   = RandomUtility.NextWord();
         var option = RandomUtility.NextEnum <FindOptions>();
         category.Find(context.Authentication, text, option);
     });
 }
Example #24
0
        private async Task MoveTypeCategoryAsync(Authentication authentication, ITypeCategory 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 types    = sourceCategory.GetService(typeof(ITypeCollection)) as ITypeCollection;

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

            using (await UsingDataBase.SetAsync(dataBase, authentication))
            {
                if (destObject is ITypeCategory 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(ITypeCategoryCollection)) as ITypeCategoryCollection;
                    if (await categories.ContainsAsync(itemName.CategoryPath) == false)
                    {
                        throw new InvalidOperationException($"cannot move to : {destPath}");
                    }
                    if (sourceCategory.Name != itemName.Name && await types.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);
                    }
                }
            }
        }
Example #25
0
 public static Task <IType[]> GetAllTypesAsync(this ITypeCategory category, Func <IType, bool> predicate)
 {
     return(category.Dispatcher.InvokeAsync(() =>
     {
         var query = from item in EnumerableUtility.FamilyTree <ITypeItem, IType>(category as ITypeItem, item => item.Childs)
                     where predicate(item)
                     select item;
         return query.ToArray();
     }));
 }
Example #26
0
 public void Lock(ITypeCategory category, TaskContext context)
 {
     category.Dispatcher.Invoke(() =>
     {
         if (category.Parent == null)
         {
             return;
         }
         var comment = RandomUtility.NextString();
         category.Lock(context.Authentication, comment);
     });
 }
Example #27
0
        //public static Task<ITable[]> GetAllRelationTablesAsync(this ITableCategory category, Func<ITable, bool> predicate)
        //{
        //    return category.Dispatcher.InvokeAsync(() =>
        //    {
        //        var tables = from item in EnumerableUtility.FamilyTree<ITableItem, ITable>(category as ITableItem, item => item.Childs)
        //                     select item;
        //        var allTables = tables.SelectMany(item => TableExtensions.GetAllRelationTables(item)).Distinct().OrderBy(item => item.Name);
        //        var query = from item in allTables
        //                    where predicate(item)
        //                    select item;
        //        return query.ToArray();
        //    });
        //}

        public static Task <ITable[]> GetAllUsingTablesAsync(this ITypeCategory category, Func <ITable, bool> predicate)
        {
            return(category.Dispatcher.InvokeAsync(() =>
            {
                var types = EnumerableUtility.FamilyTree <ITypeItem, IType>(category as ITypeItem, item => item.Childs);
                var tables = types.SelectMany(item => TypeExtensions.GetTables(item)).Distinct();
                var query = from item in tables
                            where predicate(item)
                            select item;
                return query.ToArray();
            }));
        }
Example #28
0
        public async Task MoveAsync(ITypeCategory category, TaskContext context)
        {
            var authentication = context.Authentication;
            var categories     = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection;
            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.GetAllTypesAsync(item => item.TypeState != TypeState.None)).Any() == true)
                {
                    return(false);
                }

                if ((await category.GetAllUsingTablesAsync(item => item.TableState != TableState.None)).Any() == true)
                {
                    return(false);
                }

                return(await category.Dispatcher.InvokeAsync(() =>
                {
                    if (category.Parent == null)
                    {
                        return false;
                    }
                    if (category.Parent.Path == categoryPath)
                    {
                        return false;
                    }
                    if (category.Path == categoryPath)
                    {
                        return false;
                    }
                    if (categoryPath.StartsWith(category.Path) == true)
                    {
                        return false;
                    }
                    if (category.VerifyAccessType(authentication, AccessType.Master) == false)
                    {
                        return false;
                    }
                    return true;
                }));
            }
        }
Example #29
0
        public static void MoveTest(this ITypeCategory category, Authentication authentication)
        {
            Assert.AreNotEqual(null, category.Parent);
            var categories  = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection;
            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);
        }
Example #30
0
        public async Task AddNewCategoryAsync(ITypeCategory category, TaskContext context)
        {
            var authentication = context.Authentication;
            var categoryNanme  = RandomUtility.NextIdentifier();

            if (context.AllowException == false)
            {
                if (category.GetAccessType(authentication) < AccessType.Master)
                {
                    return;
                }
            }
            await category.AddNewCategoryAsync(authentication, categoryNanme);
        }