Example #1
0
        private void MoveUserCategory(Authentication authentication, IUserCategory sourceCategory, string destPath)
        {
            var destObject = this.GetObject(destPath);

            this.UserContext.Dispatcher.Invoke(MoveUserCategory);

            void MoveUserCategory()
            {
                //var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase;
                var users = sourceCategory.GetService(typeof(IUserCollection)) as IUserCollection;

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

                if (destObject is IUserCategory destCategory)
                {
                    if (sourceCategory.Parent != destCategory)
                    {
                        sourceCategory.Move(authentication, destCategory.Path);
                    }
                }
                else
                {
                    if (NameValidator.VerifyCategoryPath(destPath) == true)
                    {
                        throw new InvalidOperationException($"cannot move to : {destPath}");
                    }
                    var itemName   = new ItemName(destPath);
                    var categories = sourceCategory.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection;
                    if (categories.Contains(itemName.CategoryPath) == false)
                    {
                        throw new InvalidOperationException($"cannot move to : {destPath}");
                    }
                    if (sourceCategory.Name != itemName.Name && users.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);
                    }
                }
            }
        }
Example #2
0
        public void Move(IUserCategory category, TaskContext context)
        {
            category.Dispatcher.Invoke(() =>
            {
                if (category.Parent == null)
                {
                    return;
                }
                var categories   = category.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection;
                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.Path == categoryPath)
                {
                    return(false);
                }
                return(true);
            }
        }
Example #3
0
 public void Move()
 {
     category.Move(authentication, PathUtility.Separator);
 }