public void Move(ITableCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } var categories = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; 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.Parent.Path == categoryPath) { return(false); } return(true); } }
public static void MoveTest(this ITableCategory category, Authentication authentication) { Assert.AreNotEqual(null, category.Parent); 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 && item != category.Parent); if (target == null) { Assert.Inconclusive(); } category.Move(authentication, target.Path); }
public static void MoveFailTest <T>(ICremaHost cremaHost, ITableCategory category, Authentication authentication) where T : Exception { cremaHost.Dispatcher.Invoke(() => { try { var categories = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; category.Move(authentication, categories.Root.Path); Assert.Fail("Move"); } catch (T) { } }); }
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 void Move() { category.Move(authentication, PathUtility.Separator); }
private void MoveTableCategory(Authentication authentication, ITableCategory sourceCategory, string newPath) { var destPath = new DataBasePath(newPath); var destObject = this.GetObject(authentication, destPath.Path); this.CremaHost.Dispatcher.Invoke(MoveTableCategory); void MoveTableCategory() { var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase; var tables = sourceCategory.GetService(typeof(ITableCollection)) as ITableCollection; if (destPath.DataBaseName != dataBase.Name) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destPath.Context != CremaSchema.TableDirectory) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destObject is ITable) { throw new InvalidOperationException($"cannot move to : {destPath}"); } using (DataBaseUsing.Set(dataBase, authentication)) { if (destObject is ITableCategory 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(ITableCategoryCollection)) as ITableCategoryCollection; if (categories.Contains(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Name != itemName.Name && tables.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); } } } } }