public UserUnbanArguments(User user)
        {
            var items     = EnumerableUtility.One(user).ToArray();
            var userInfo  = user.UserInfo;
            var userPath  = user.Path;
            var lockPaths = new[] { userPath };

            this.UserID    = userInfo.ID;
            this.UserName  = userInfo.Name;
            this.Items     = items;
            this.UserInfo  = userInfo;
            this.UserPath  = userPath;
            this.LockPaths = lockPaths;
        }
示例#2
0
        public override void OnValidateDelete(IAuthentication authentication, object target)
        {
            base.OnValidateDelete(authentication, target);
            if (this.templateList.Any() == true)
            {
                throw new CremaException("새로운 테이블을 생성중일때는 삭제할 수 없습니다.");
            }
            var tables = EnumerableUtility.Descendants <IItem, Table>(this as IItem, item => item.Childs).ToArray();

            if (tables.Any() == true)
            {
                throw new CremaException("테이블이 있는 폴더는 삭제할 수 없습니다.");
            }
        }
示例#3
0
        public override void OnValidateDelete(IAuthentication authentication, object target)
        {
            base.OnValidateDelete(authentication, target);
            if (this.templateList.Any() == true)
            {
                throw new InvalidOperationException(Resources.Exception_CannotDeleteOnCreateTable);
            }
            var tables = EnumerableUtility.Descendants <IItem, Table>(this as IItem, item => item.Childs).ToArray();

            if (tables.Any() == true)
            {
                throw new InvalidOperationException(Resources.Exception_CannotDeletePathWithItems);
            }
        }
示例#4
0
        public void ValidateLeave(Authentication authentication)
        {
            if (this.table.Parent != null)
            {
                throw new CremaException();
            }

            var items = EnumerableUtility.Friends(this, this.Childs);

            foreach (var item in items)
            {
                item.OnValidateLeave(authentication, this);
            }
        }
示例#5
0
        public void Delete(Authentication authentication)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Delete), this);
            base.ValidateDelete(authentication);
            this.Sign(authentication);
            var items     = EnumerableUtility.One(this).ToArray();
            var oldPaths  = items.Select(item => item.Path).ToArray();
            var container = this.Container;

            container.InvokeCategoryDelete(authentication, this);
            base.Delete(authentication);
            container.InvokeCategoriesDeletedEvent(authentication, items, oldPaths);
        }
示例#6
0
        protected override void OnEndEdit(Authentication authentication, CremaTemplate template)
        {
            this.Container.InvokeTableEndTemplateEdit(authentication, this.table, this.TemplateSource);
            base.OnEndEdit(authentication, template);
            this.table.UpdateTemplate(template.TableInfo);
            this.table.UpdateTags(template.Tags);
            this.table.UpdateComment(template.Comment);
            this.table.SetTableState(TableState.None);

            var items = EnumerableUtility.One(this.table).ToArray();

            this.Container.InvokeTablesStateChangedEvent(authentication, items);
            this.Container.InvokeTablesTemplateChangedEvent(authentication, items, this.TemplateSource.TargetTable.DataSet);
        }
示例#7
0
        public void Move(Authentication authentication, string parentPath)
        {
            this.Dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(Move), this, parentPath);

            var items          = EnumerableUtility.One(this).ToArray();
            var oldPaths       = items.Select(item => item.Path).ToArray();
            var oldParentPaths = items.Select(item => item.Parent.Path).ToArray();
            var result         = this.Service.MoveUserItem(this.Path, parentPath);

            result.Validate(authentication);
            this.Parent = this.Container[parentPath];
            this.Container.InvokeCategoriesMovedEvent(authentication, items, oldPaths, oldParentPaths);
        }
示例#8
0
        public void Delete(Authentication authentication)
        {
            this.Dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(Delete), this);

            var items     = EnumerableUtility.One(this).ToArray();
            var oldPaths  = items.Select(item => item.Path).ToArray();
            var container = this.Container;
            var result    = this.Service.DeleteUserItem(this.Path);

            result.Validate(authentication);
            this.Dispose();
            container.InvokeCategoriesDeletedEvent(authentication, items, oldPaths);
        }
示例#9
0
        public void ValidateBeginEdit(Authentication authentication)
        {
            if (this.table.Parent != null)
            {
                throw new CremaException("자식 테이블은 편집을 시작할 수 없습니다.");
            }
            var isAdmin = authentication.Types.HasFlag(AuthenticationType.Administrator);
            var items   = EnumerableUtility.Friends(this, this.Childs);

            foreach (var item in items)
            {
                item.OnValidateBeginEdit(authentication, this);
            }
        }
示例#10
0
        public void Rename(Authentication authentication, string name)
        {
            this.Dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(Rename), this, name);

            var items    = EnumerableUtility.One(this).ToArray();
            var oldNames = items.Select(item => item.Name).ToArray();
            var oldPaths = items.Select(item => item.Path).ToArray();
            var result   = this.Service.RenameUserItem(this.Path, name);

            result.Validate(authentication);
            base.Name = name;
            this.Container.InvokeCategoriesRenamedEvent(authentication, items, oldNames, oldPaths);
        }
 public TableEditorViewModel(Authentication authentication, TableDescriptor descriptor)
 {
     this.authentication          = authentication;
     this.authentication.Expired += (s, e) => this.Dispatcher.InvokeAsync(() => this.Tables.Clear());
     this.descriptor              = descriptor;
     this.contentDescriptor       = descriptor.ContentDescriptor;
     this.AttachEvent();
     this.DisplayName = descriptor.DisplayName;
     this.Target      = descriptor.Target;
     foreach (var item in EnumerableUtility.FamilyTree(this.descriptor, item => item.Childs))
     {
         this.Tables.Add(new TableItemViewModel(this.authentication, item, this));
     }
     this.Initialize();
 }
示例#12
0
        public void Move(Authentication authentication, string categoryPath)
        {
            this.Dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(Move), this, categoryPath);
            var result = this.Service.MoveUserItem(this.Path, categoryPath);

            this.Sign(authentication, result);
            var items            = EnumerableUtility.One(this).ToArray();
            var oldPaths         = items.Select(item => item.Path).ToArray();
            var oldCategoryPaths = items.Select(item => item.Category.Path).ToArray();

            this.Container.InvokeUserMove(authentication, this, categoryPath);
            base.Move(authentication, categoryPath);
            this.Container.InvokeUsersMovedEvent(authentication, items, oldPaths, oldCategoryPaths);
        }
示例#13
0
        public void Rename(Authentication authentication, string name)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Rename), this, name);
            base.ValidateRename(authentication, name);
            this.Sign(authentication);
            var items    = EnumerableUtility.One(this).ToArray();
            var oldNames = items.Select(item => item.Name).ToArray();
            var oldPaths = items.Select(item => item.Path).ToArray();
            var dataSet  = this.ReadAllData(authentication, true);

            this.Container.InvokeCategoryRename(authentication, this, name, dataSet);
            base.Rename(authentication, name);
            this.Container.InvokeCategoriesRenamedEvent(authentication, items, oldNames, oldPaths, dataSet);
        }
示例#14
0
 public FindResultInfo[] Find(Authentication authentication, string text, FindOptions options)
 {
     this.DataBase.ValidateAsyncBeginInDataBase(authentication);
     this.CremaHost.DebugMethod(authentication, this, nameof(Find), this, text, options);
     var items = this.Dispatcher.Invoke(() =>
     {
         this.ValidateAccessType(authentication, AccessType.Guest);
         this.Sign(authentication);
         var descendants = EnumerableUtility.Descendants<ITypeItem>(this, item => item.Childs);
         return EnumerableUtility.Friends(this, descendants).Select(item => item.Path).ToArray();
     });
     var service = this.GetService(typeof(DataFindService)) as DataFindService;
     var result = service.Dispatcher.Invoke(() => service.FindFromType(this.DataBase.ID, items, text, options));
     return result;
 }
示例#15
0
文件: Type.cs 项目: teize001/Crema
        public void Rename(Authentication authentication, string name)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Rename), this, name);
            var result = this.Context.Service.RenameTypeItem(base.Path, name);

            this.Sign(authentication, result);
            var items    = EnumerableUtility.One(this).ToArray();
            var oldNames = items.Select(item => item.Name).ToArray();
            var oldPaths = items.Select(item => item.Path).ToArray();

            this.Container.InvokeTypeRename(authentication, this, name);
            base.Rename(authentication, name);
            this.Container.InvokeTypesRenamedEvent(authentication, items, oldNames, oldPaths);
        }
        public UserResetPasswordArguments(User user)
        {
            var items     = EnumerableUtility.One(user).ToArray();
            var userInfo  = user.UserInfo;
            var userPath  = user.Path;
            var lockPaths = new[] { userPath };

            this.UserID    = userInfo.ID;
            this.UserName  = userInfo.Name;
            this.Password  = $"{userInfo.Authority}".ToLower().ToSecureString();
            this.Items     = items;
            this.UserInfo  = userInfo;
            this.UserPath  = userPath;
            this.LockPaths = lockPaths;
        }
示例#17
0
文件: Table.cs 项目: sedrion/Crema
        public void Move(Authentication authentication, string categoryPath)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Move), this, categoryPath);
            var result = this.Service.MoveTableItem(base.Path, categoryPath);

            this.Sign(authentication, result);
            var items            = EnumerableUtility.Friends(this, this.Childs).ToArray();
            var oldPaths         = items.Select(item => item.Path).ToArray();
            var oldCategoryPaths = items.Select(item => item.Category.Path).ToArray();

            this.Container.InvokeTableMove(authentication, this, categoryPath);
            base.Move(authentication, categoryPath);
            this.Container.InvokeTablesMovedEvent(authentication, items, oldPaths, oldCategoryPaths);
        }
示例#18
0
        public void Move(Authentication authentication, string parentPath)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Move), this, parentPath);
            base.ValidateMove(authentication, parentPath);
            this.Sign(authentication);
            var items          = EnumerableUtility.One(this).ToArray();
            var oldPaths       = items.Select(item => item.Path).ToArray();
            var oldParentPaths = items.Select(item => item.Parent.Path).ToArray();
            var dataSet        = this.ReadAllData(authentication, true);

            this.Container.InvokeCategoryMove(authentication, this, parentPath, dataSet);
            base.Move(authentication, parentPath);
            this.Container.InvokeCategoriesMovedEvent(authentication, items, oldPaths, oldParentPaths, dataSet);
        }
示例#19
0
文件: Table.cs 项目: sedrion/Crema
        public void ReadAll(Authentication authentication, CremaDataSet dataSet)
        {
            if (this.Parent != null)
            {
                this.Parent.ReadAll(authentication, dataSet);
                return;
            }

            var types      = this.GetService(typeof(TypeCollection)) as TypeCollection;
            var typeFiles  = (from Type item in types select item.SchemaPath).ToArray();
            var tableFiles = EnumerableUtility.Friends(this, this.DerivedTables).Select(item => item.XmlPath).ToArray();

            dataSet.ReadMany(typeFiles, tableFiles);
            dataSet.AcceptChanges();
        }
示例#20
0
        /// <summary>
        /// Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the <paramref name="source"/>.
        /// </summary>
        /// <param name="source">The source type to locate ancestor-and-descendant-or-self types from.</param>
        /// <param name="assemblies">The assemblies to search for the <paramref name="source"/>.</param>
        /// <returns>An <see cref="IEnumerable{Type}"/> holding the ancestor-and-descendant-or-self types from the <paramref name="source"/>.</returns>
        public static IEnumerable <Type> GetAncestorAndDescendantsOrSelfTypes(Type source, params Assembly[] assemblies)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }
            IEnumerable <Type> ancestorOrSelfTypes = GetAncestorOrSelfTypes(source);
            IEnumerable <Type> derivedOrSelfTypes  = GetDescendantOrSelfTypes(source, assemblies);

            return(EnumerableUtility.SortDescending(EnumerableUtility.Concat(derivedOrSelfTypes, ancestorOrSelfTypes).Distinct(), new ReferenceComparer <Type>()));
        }
示例#21
0
        public UserDeleteArguments(User user)
        {
            var items      = EnumerableUtility.One(user).ToArray();
            var oldPaths   = items.Select(item => item.Path).ToArray();
            var userInfo   = user.UserInfo;
            var targetName = new ItemName(userInfo.Path);

            var(userPath, lockPaths) = GetPathForData(user.Path, targetName);
            this.UserID    = userInfo.ID;
            this.Items     = items;
            this.OldPaths  = oldPaths;
            this.UserInfo  = userInfo;
            this.UserPath  = userPath;
            this.LockPaths = lockPaths;
        }
示例#22
0
        private void CancelContent(Authentication authentication)
        {
            var items = EnumerableUtility.Friends(this.table, this.table.Childs);

            foreach (var item in items.Select(i => i.Content))
            {
                item.domain     = null;
                item.isModified = false;
                item.dataSet    = null;
                item.dataTable  = null;
                item.table.SetTableState(TableState.None);
            }

            this.Container.InvokeTablesStateChangedEvent(authentication, items.ToArray());
        }
 static IEnumerable <string> QueryParents(string path)
 {
     return(EnumerableUtility.Ancestors(path, item =>
     {
         if (item == PathUtility.Separator)
         {
             return null;
         }
         if (NameValidator.VerifyItemPath(item) == true)
         {
             return new ItemName(item).CategoryPath;
         }
         return new CategoryName(item).ParentPath;
     }));
 }
        protected static (string[] userPaths, string[] lockPaths) GetPathForData(UserCategory uesrCategory, CategoryName targetName)
        {
            var targetPaths = new string[]
            {
                targetName.ParentPath,
                targetName,
            };
            var items     = EnumerableUtility.FamilyTree(uesrCategory as IUserItem, item => item.Childs);
            var users     = items.Where(item => item is User).Select(item => item as User).ToArray();
            var userPaths = users.Select(item => item.Path).ToArray();
            var itemPaths = items.Select(item => item.Path).ToArray();
            var lockPaths = itemPaths.Concat(targetPaths).Distinct().OrderBy(item => item).ToArray();

            return(userPaths, lockPaths);
        }
示例#25
0
        private void CreateTables(CremaDataSet dataSet, string[] names)
        {
            var tableCollection = this.dataBase.TableContext.Tables;
            var tableList       = new List <ITable>(names.Length);

            foreach (var item in names)
            {
                if (tableCollection.Contains(item) == false)
                {
                    throw new TableNotFoundException(item);
                }
                tableList.Add(tableCollection[item]);
            }

            var tables = tableList.ToArray();

            var types = from item in tables
                        from i in EnumerableUtility.Friends(item, item.Childs)
                        from c in i.TableInfo.Columns
                        where c.DataType.StartsWith("/")
                        select c.DataType;

            var types1 = types.Distinct().ToArray();

            dataSet.BeginLoad();
            foreach (var item in types1)
            {
                var typeItem = dataBase.TypeContext[item];
                if (typeItem is IType == false)
                {
                    continue;
                }

                var type = typeItem as IType;

                dataSet.Types.Add(type.TypeInfo);
            }
            dataSet.EndLoad();
            foreach (var item in tables)
            {
                if (item.Parent != null)
                {
                    continue;
                }

                this.CreateTable(dataSet, item);
            }
        }
示例#26
0
        public void LockedTableFailTest()
        {
            var tableContext = this.dataBase.TableContext;
            var table        = tableContext.Tables.RandomSample();
            var child        = table.Childs.Random();
            var category     = EnumerableUtility.Ancestors(table as IItem).Random(item => item.Parent != null) as ITableCategory;

            table.Lock(this.admin, string.Empty);

            try
            {
                this.InvokeFail <PermissionException>(() => table.SetPublic(this.member));
                this.InvokeFail <PermissionDeniedException>(() => table.SetPrivate(this.member));
                this.InvokeFail <PermissionException>(() => table.AddAccessMember(this.member, this.someone.UserID, AccessType.ReadWrite));
                this.InvokeFail <PermissionException>(() => table.RemoveAccessMember(this.member, this.someone.UserID));
                this.InvokeFail <PermissionException>(() => table.Lock(this.member, RandomUtility.NextString()));
                this.InvokeFail <PermissionDeniedException>(() => table.Unlock(this.member));
                this.InvokeFail <PermissionDeniedException>(() => table.RenameTest(this.member));
                this.InvokeFail <PermissionDeniedException>(() => table.MoveTest(this.member));
                this.InvokeFail <PermissionDeniedException>(() => table.Delete(this.member));
                this.InvokeFail <PermissionDeniedException>(() => table.NewTable(this.member));
                this.InvokeFail <PermissionDeniedException>(() => table.Revert(this.member, 0));

                this.InvokeFail <CremaException>(() => category.SetPublic(this.member));
                this.InvokeFail <CremaException>(() => category.SetPrivate(this.member));
                this.InvokeFail <CremaException>(() => category.AddAccessMember(this.member, this.someone.UserID, AccessType.ReadWrite));
                this.InvokeFail <CremaException>(() => category.RemoveAccessMember(this.member, this.someone.UserID));
                this.InvokeFail <CremaException>(() => category.Lock(this.member, RandomUtility.NextString()));
                this.InvokeFail <CremaException>(() => category.Unlock(this.member));
                this.InvokeFail <CremaException>(() => category.RenameTest(this.member));
                this.InvokeFail <CremaException>(() => category.MoveTest(this.member));
                this.InvokeFail <CremaException>(() => category.Delete(this.member));

                this.InvokeFail <PermissionException>(() => child.SetPublic(this.member));
                this.InvokeFail <PermissionDeniedException>(() => child.SetPrivate(this.member));
                this.InvokeFail <PermissionException>(() => child.AddAccessMember(this.member, this.someone.UserID, AccessType.ReadWrite));
                this.InvokeFail <PermissionException>(() => child.RemoveAccessMember(this.member, this.someone.UserID));
                this.InvokeFail <PermissionException>(() => child.Lock(this.member, RandomUtility.NextString()));
                this.InvokeFail <PermissionException>(() => child.Unlock(this.member));
                this.InvokeFail <PermissionDeniedException>(() => child.RenameTest(this.member));
                this.InvokeFail <PermissionDeniedException>(() => child.MoveTest(this.member));
                this.InvokeFail <PermissionDeniedException>(() => child.Delete(this.member));
            }
            finally
            {
                table.Unlock(this.admin);
            }
        }
示例#27
0
文件: Table.cs 项目: sedrion/Crema
        public void Delete(Authentication authentication)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Delete), this, base.Path);
            var result = this.Service.DeleteTableItem(base.Path);

            this.Sign(authentication, result);
            var items = this.Parent == null?EnumerableUtility.Friends(this, this.Childs).ToArray() : EnumerableUtility.Friends(this, this.DerivedTables).ToArray();

            var oldPaths  = items.Select(item => item.Path).ToArray();
            var container = this.Container;

            container.InvokeTableDelete(authentication, this);
            base.Delete(authentication);
            container.InvokeTablesDeletedEvent(authentication, items, oldPaths);
        }
示例#28
0
文件: Table.cs 项目: sedrion/Crema
        public void Rename(Authentication authentication, string name)
        {
            this.DataBase.ValidateBeginInDataBase(authentication);
            this.CremaHost.DebugMethod(authentication, this, nameof(Rename), this, name);
            base.ValidateRename(authentication, name);
            this.Sign(authentication);
            var items = this.Parent == null?EnumerableUtility.Friends(this, this.Childs).ToArray() : EnumerableUtility.Friends(this, this.DerivedTables).ToArray();

            var oldNames = items.Select(item => item.Name).ToArray();
            var oldPaths = items.Select(item => item.Path).ToArray();
            var dataSet  = this.ReadAll(authentication);

            this.Container.InvokeTableRename(authentication, this, name, dataSet);
            base.Rename(authentication, name);
            this.Container.InvokeTablesRenamedEvent(authentication, items, oldNames, oldPaths, dataSet);
        }
示例#29
0
    private List <Vector3> allDirections()
    {
        List <Vector3> res = new List <Vector3>();

        foreach (int i in EnumerableUtility.Range(-1, 2))
        {
            foreach (int j in EnumerableUtility.Range(-1, 2))
            {
                if (!(i == 0 && j == 0))
                {
                    res.Add(new Vector3(i, j, 0));
                }
            }
        }
        return(res);
    }
示例#30
0
        public void SelectRecursiveDepthFirst_Nested()
        {
            var item0a = new RecursiveItem();
            var item0b = new RecursiveItem();
            var item0c = new RecursiveItem();
            var item1a = new RecursiveItem(item0a, item0b);
            var item1b = new RecursiveItem();
            var item1c = new RecursiveItem(item0c);
            var item2a = new RecursiveItem(item1a);
            var item2b = new RecursiveItem(item1b, item1c);
            var item3  = new RecursiveItem(item2a, item2b);

            var result = EnumerableUtility.SelectRecursiveDepthFirst(item3, i => i.Children).ToArray();

            Assert.That(result, Is.EqualTo(new[] { item3, item2a, item1a, item0a, item0b, item2b, item1b, item1c, item0c }));
        }