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 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 #3
0
 public void Move()
 {
     category.Move(authentication, PathUtility.Separator);
 }
Example #4
0
        private void MoveTypeCategory(Authentication authentication, ITypeCategory sourceCategory, string newPath)
        {
            var destPath   = new DataBasePath(newPath);
            var destObject = this.GetObject(authentication, destPath.Path);

            this.CremaHost.Dispatcher.Invoke(MoveTypeCategory);

            void MoveTypeCategory()
            {
                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 (DataBaseUsing.Set(dataBase, authentication))
                {
                    if (destObject is ITypeCategory 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(ITypeCategoryCollection)) as ITypeCategoryCollection;
                        if (categories.Contains(itemName.CategoryPath) == false)
                        {
                            throw new InvalidOperationException($"cannot move to : {destPath}");
                        }
                        if (sourceCategory.Name != itemName.Name && types.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);
                        }
                    }
                }
            }
        }