private void Attach() { if (this.descriptor != null) { if (this.descriptor is INotifyPropertyChanged) { (this.descriptor as INotifyPropertyChanged).PropertyChanged += Descriptor_PropertyChanged; } var typePath = this.descriptor.TypeInfo.CategoryPath + this.descriptor.TypeInfo.Name; var tableBrowser = this.tableBrowser.Value; var tables = EnumerableUtility.Descendants <TreeViewItemViewModel, TableTreeViewItemViewModel>(tableBrowser.Items, item => item.Items) .Where(item => item.TableInfo.Columns.Any(i => i.DataType == typePath)) .Select(item => new TableListBoxItemViewModel(item)) .ToArray(); foreach (var item in tables) { this.compositionService.SatisfyImportsOnce(item); } this.Tables = tables; } this.NotifyOfPropertyChange(nameof(this.IsVisible)); this.NotifyOfPropertyChange(nameof(this.SelectedObject)); }
/// <summary> /// 폴더내에 모든 테이블과 상속된 테이블을 읽어들입니다. /// </summary> public CremaDataSet ReadAllData(Authentication authentication) { try { var dataSet = CremaDataSet.Create(new SignatureDateProvider(authentication.ID)); var tables = EnumerableUtility.Descendants <IItem, Table>(this as IItem, item => item.Childs).ToArray(); var typeFiles = tables.SelectMany(item => item.GetTypes()) .Select(item => item.SchemaPath) .Distinct() .ToArray(); var tableFiles = tables.SelectMany(item => EnumerableUtility.Friends(item, item.DerivedTables)) .Select(item => item.XmlPath) .Distinct() .ToArray(); dataSet.ReadMany(typeFiles, tableFiles); dataSet.AcceptChanges(); return(dataSet); } catch (Exception e) { this.CremaHost.Error(e); throw; } }
public CremaDataSet ReadData(Authentication authentication, bool recursive) { try { var dataSet = CremaDataSet.Create(new SignatureDateProvider(authentication.ID)); var types = CollectTypes(); var typeFiles = types.Select(item => item.SchemaPath).ToArray(); dataSet.ReadMany(typeFiles, new string[] { }); dataSet.AcceptChanges(); return(dataSet); Type[] CollectTypes() { if (recursive == true) { return(EnumerableUtility.Descendants <IItem, Type>(this as IItem, item => item.Childs).ToArray()); } return(this.Types.ToArray()); } } catch (Exception e) { this.CremaHost.Error(e); throw; } }
public void Delete(IUserCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } if (Verify() == false) { return; } category.Delete(context.Authentication); context.Complete(category); }); bool Verify() { if (context.AllowException == true) { return(true); } if (category.Parent == null) { return(false); } if (EnumerableUtility.Descendants <IUserItem, IUser>(category as IUserItem, item => item.Childs).Any() == true) { return(false); } return(true); } }
public void ValidateMove(_C parent) { if (parent == null) { return; } if (parent == this) { throw new ArgumentException(Resources.Exception_CannotBeSetItSelfAsParent, nameof(parent)); } if (this.name == null) { throw new InvalidOperationException(Resources.Exception_UnnamedFolderCannotHaveParent); } if (EnumerableUtility.Descendants(this, item => item.Categories).Contains(parent) == true) { throw new ArgumentException(Resources.Exception_ChildFolderCannotBeSetAsParent, nameof(parent)); } if (parent.Categories.ContainsKey(this.Name) == true && parent.categories[this.Name] != this) { throw new ArgumentException(Resources.Exception_SameFolderInParent, nameof(parent)); } if (parent.Items.ContainsKey(this.Name) == true) { throw new ArgumentException(Resources.Exception_SameItemInParent, nameof(parent)); } }
/// <summary> /// 폴더내에 모든 타입과 타입이 사용하고 있는 테이블, 상속된 테이블을 읽어들입니다. /// </summary> public CremaDataSet ReadAllData(Authentication authentication, bool recursive) { var dataSet = CremaDataSet.Create(new SignatureDateProvider(authentication.ID)); var types = CollectTypes(); var tables = CollectTables(); var typeFiles = types.Select(item => item.SchemaPath).ToArray(); var tableFiles = tables.Select(item => item.Parent ?? item) .Select(item => item.XmlPath) .Distinct() .ToArray(); dataSet.ReadMany(typeFiles, tableFiles); dataSet.AcceptChanges(); return(dataSet); Type[] CollectTypes() { if (recursive == true) { return(EnumerableUtility.Descendants <IItem, Type>(this as IItem, item => item.Childs).ToArray()); } return(this.Types.ToArray()); } Table[] CollectTables() { var tableContext = this.GetService(typeof(TableContext)) as TableContext; var query = from table in EnumerableUtility.Descendants <IItem, Table>(tableContext.Root as IItem, item => item.Childs) from type in types where table.IsTypeUsed(type.Path) select table; return(query.ToArray()); } }
public override void SelectObject(object obj) { this.descriptor = obj as ITableDescriptor; if (this.descriptor != null) { var items = EnumerableUtility.Descendants <TreeViewItemViewModel, ITableDescriptor>(this.Browser.Items, item => item.Items) .Where(item => item.TableInfo.TemplatedParent == this.descriptor.Name) .ToArray(); var viewModelList = new List <TableListBoxItemViewModel>(); foreach (var item in items) { var table = item.Target; if (table.ExtendedProperties.ContainsKey(this) == true) { var descriptor = table.ExtendedProperties[this] as TableDescriptor; viewModelList.Add(descriptor.Host as TableListBoxItemViewModel); } else { var viewModel = new TableListBoxItemViewModel(this.authenticator, item, this); viewModelList.Add(viewModel); } } this.Tables = viewModelList.ToArray(); } else { this.Tables = new TableListBoxItemViewModel[] { }; } this.NotifyOfPropertyChange(nameof(this.IsVisible)); this.NotifyOfPropertyChange(nameof(this.SelectedObject)); }
private void ValidateUsingTables(IAuthentication authentication) { var tables = this.GetService(typeof(TableCollection)) as TableCollection; var types = EnumerableUtility.Descendants <IItem, Type>(this as IItem, item => item.Childs).ToArray(); { var query = from Table item in tables from type in types where item.IsTypeUsed(type.Path) && item.VerifyAccessType(authentication, AccessType.Master) == false select item; if (query.Any() == true) { throw new PermissionDeniedException(string.Format(Resources.Exception_ItemsPermissionDenined_Format, string.Format(", ", query))); } } { var query = from Table item in tables from type in types where item.IsTypeUsed(type.Path) && item.TableState != TableState.None select item.Name; if (query.Any() == true) { throw new InvalidOperationException(string.Format(Resources.Exception_TableIsBeingEdited_Format, string.Join(", ", query))); } } }
public override void OnValidateDelete(IAuthentication authentication, object target) { base.OnValidateDelete(authentication, target); if (this.templateList.Any() == true) throw new CremaException("새로운 타입을 생성중일때는 삭제할 수 없습니다."); var types = EnumerableUtility.Descendants<IItem, Type>(this as IItem, item => item.Childs).ToArray(); if (types.Any() == true) throw new CremaException("타입이 있는 폴더는 삭제할 수 없습니다."); this.ValidateUsingTables(authentication); }
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); }
public void ValidateDelete(Authentication authentication) { if (authentication.Types.HasFlag(AuthenticationType.Administrator) == false) { throw new PermissionDeniedException(); } base.ValidateDelete(); if (EnumerableUtility.Descendants <IItem, IUser>(this as IItem, item => item.Childs).Any() == true) { throw new CremaException("폴더 또는 하위 폴더내에 사용자 항목이 존재하므로 삭제할 수 없습니다."); } }
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); } }
public void ValidateDelete(Authentication authentication) { if (authentication.Types.HasFlag(AuthenticationType.Administrator) == false) { throw new PermissionDeniedException(); } base.ValidateDelete(); if (EnumerableUtility.Descendants <IItem, IUser>(this as IItem, item => item.Childs).Any() == true) { throw new InvalidOperationException(Resources.Exception_CannotDeletePathWithItems); } }
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; }
public override void OnValidateMove(IAuthentication authentication, object target, string oldPath, string newPath) { base.OnValidateMove(authentication, target, oldPath, newPath); if (this.templateList.Any() == true) { throw new CremaException("새로운 테이블을 생성중일때는 이동할 수 없습니다."); } var tables = EnumerableUtility.Descendants <IItem, Table>(this as IItem, item => item.Childs); if (tables.Where(item => item.TableState != TableState.None).Any() == true) { throw new CremaException("편집 또는 설정중인 테이블이 있기 때문에 이동할 수 없습니다."); } var categoryName = new CategoryName(Regex.Replace(this.Path, $"^{oldPath}", newPath)); this.Context.ValidateCategoryPath(categoryName); }
public override void OnValidateMove(IAuthentication authentication, object target, string oldPath, string newPath) { base.OnValidateMove(authentication, target, oldPath, newPath); if (this.templateList.Any() == true) { throw new InvalidOperationException(Resources.Exception_CannotMoveOnCreateTable); } var tables = EnumerableUtility.Descendants <IItem, Table>(this as IItem, item => item.Childs); if (tables.Where(item => item.TableState != TableState.None).Any() == true) { throw new InvalidOperationException(string.Format(Resources.Exception_TableIsBeingEdited_Format, string.Join(", ", tables.Select(item => item.Name)))); } var categoryName = new CategoryName(Regex.Replace(this.Path, $"^{oldPath}", newPath)); this.Context.ValidateCategoryPath(categoryName); }
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) { } }); }
public async Task DeleteAsync(IUserCategory category, TaskContext context) { var authentication = context.Authentication; if (context.AllowException == false) { if (await category.Dispatcher.InvokeAsync(() => category.Parent) == null) { return; } if (await category.Dispatcher.InvokeAsync(() => EnumerableUtility.Descendants <IUserItem, IUser>(category as IUserItem, item => item.Childs).Any()) == true) { return; } } await category.DeleteAsync(authentication); context.Complete(category); }
public static void TableCategoryDeleteTest(this IDataBase dataBase, Authentication authentication) { dataBase.Dispatcher.Invoke(() => { var tableContext = dataBase.TableContext; var category = tableContext.Categories.RandomOrDefault(item => item != tableContext.Root); if (category == null) { return; } var tables = EnumerableUtility.Descendants <IItem, ITable>(category as IItem, item => item.Childs).ToArray(); if (tables.Any() == true) { return; } category.Delete(authentication); }); }
public override void SelectObject(object obj) { this.descriptor = obj as ITableDescriptor; if (this.descriptor != null) { var types = EnumerableUtility.Descendants <TreeViewItemViewModel, ITypeDescriptor>(this.Browser.Items, item => item.Items); var query = from column in this.descriptor.TableInfo.Columns join type in types on column.DataType equals(type.TypeInfo.CategoryPath + type.TypeInfo.Name) select type; var descriptors = query.Distinct().ToArray(); var viewModelList = new List <TypeListBoxItemViewModel>(); foreach (var item in descriptors) { var type = item.Target; if (type.ExtendedProperties.ContainsKey(this) == true) { var descriptor = type.ExtendedProperties[this] as TypeDescriptor; viewModelList.Add(descriptor.Host as TypeListBoxItemViewModel); } else { var viewModel = new TypeListBoxItemViewModel(this.authenticator, item, this); this.compositionService.SatisfyImportsOnce(viewModel); viewModelList.Add(viewModel); } } this.Types = viewModelList.ToArray(); } else { this.Types = new TypeListBoxItemViewModel[] { }; } this.NotifyOfPropertyChange(nameof(this.IsVisible)); this.NotifyOfPropertyChange(nameof(this.SelectedObject)); }
public override void SelectObject(object obj) { if (this.descriptor != null) { if (this.descriptor is INotifyPropertyChanged) { (this.descriptor as INotifyPropertyChanged).PropertyChanged -= Table_PropertyChanged; } } this.descriptor = obj as ITableDescriptor; if (this.descriptor != null) { if (this.descriptor is INotifyPropertyChanged) { (this.descriptor as INotifyPropertyChanged).PropertyChanged += Table_PropertyChanged; } var browser = this.browser.Value; var types = EnumerableUtility.Descendants <TreeViewItemViewModel, TypeTreeViewItemViewModel>(browser.Items, item => item.Items); var query = from item in this.descriptor.TableInfo.Columns join type in types on item.DataType equals(type.TypeInfo.CategoryPath + type.TypeInfo.Name) select type; var typeItems = query.Distinct() .Select(item => new TypeListBoxItemViewModel(item)) .ToArray(); foreach (var item in typeItems) { compositionService.SatisfyImportsOnce(item); } this.Types = typeItems; } this.NotifyOfPropertyChange(nameof(this.IsVisible)); this.NotifyOfPropertyChange(nameof(this.SelectedObject)); }
public static void TypeCategoryMoveTest(this IDataBase dataBase, Authentication authentication) { dataBase.Dispatcher.Invoke(() => { var typeContext = dataBase.TypeContext; var category = typeContext.Categories.RandomOrDefault(item => item != typeContext.Root && item.VerifyAccessType(authentication, AccessType.Master)); if (category == null) { return; } var descendants = EnumerableUtility.Descendants(category, item => item.Categories); var parent = typeContext.Categories.Random(item => descendants.Contains(item) == false && item.VerifyAccessType(authentication, AccessType.Master)); if (category == parent || category.Parent == parent) { return; } category.Move(authentication, parent.Path); }); }
private void ValidateUsingTables(IAuthentication authentication) { var tables = this.GetService(typeof(TableCollection)) as TableCollection; var types = EnumerableUtility.Descendants<IItem, Type>(this as IItem, item => item.Childs).ToArray(); { var query = from Table item in tables from type in types where item.IsTypeUsed(type.Path) && item.VerifyAccessType(authentication, AccessType.Master) == false select item; if (query.Any() == true) throw new PermissionDeniedException("사용되고 있는 테이블의 접근권한이 없습니다."); } { var query = from Table item in tables from type in types where item.IsTypeUsed(type.Path) && item.TableState != TableState.None select item; if (query.Any() == true) throw new CremaException("사용되고 있는 테이블이 편집중입니다."); } }
private void Category_CategoriesChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { foreach (_C item in e.NewItems) { var categories = EnumerableUtility.Descendants(item, i => i.Categories).ToArray(); var items = categories.SelectMany(i => i.Items).ToArray(); if (item.Container == null) { this.AddBase(item); this.AddBase(categories); this.ItemContainer.AddInternal(item.Items); this.ItemContainer.AddInternal(items); } else { this.ReplaceKeyBase(item); this.ReplaceKeyBase(categories.Reverse()); this.ItemContainer.MoveInternal(item.Items.Reverse()); this.ItemContainer.MoveInternal(items.Reverse()); } } } break; case NotifyCollectionChangedAction.Remove: { foreach (_C item in e.OldItems) { if (item.IsDisposing == true) { var categories = EnumerableUtility.Descendants(item, i => i.Categories).ToArray(); var items = categories.SelectMany(i => i.Items); this.ItemContainer.RemoveInternal(items); this.ItemContainer.RemoveInternal(item.Items); this.RemoveBase(categories.Reverse()); this.RemoveBase(item); } } } break; case NotifyCollectionChangedAction.Replace: { foreach (_C item in e.NewItems) { var categories = EnumerableUtility.Descendants(item, i => i.Categories).ToArray(); var items = categories.SelectMany(i => i.Items).ToArray(); this.ReplaceKeyBase(item); this.ReplaceKeyBase(categories.Reverse()); this.ItemContainer.MoveInternal(item.Items.Reverse()); this.ItemContainer.MoveInternal(items.Reverse()); } } break; case NotifyCollectionChangedAction.Reset: { var categories = sender as CategoryBase <_I, _C, _IC, _CC, _CT> .CategoryCollection; var query = from item in this where item.Parent == categories.Category select item; this.RemoveBase(query); foreach (_C item in query) { item.parent = null; } } break; } }
public ITypeDescriptor[] GetDescriptors() { return(EnumerableUtility.Descendants <TreeViewItemViewModel, ITypeDescriptor>(this.typeBrowser.Items.OfType <TreeViewItemViewModel>(), item => item.Items).ToArray()); }
public static IEnumerable <TreeViewItemViewModel> Descendants(TreeViewItemViewModel viewModel) { return(EnumerableUtility.Descendants <TreeViewItemViewModel>(viewModel, item => item.Items)); }