Exemplo n.º 1
0
        protected override void OnSetPath(Authentication authentication, string path)
        {
            var dataBaseName = this.DataBaseName;
            var dataBasePath = new DataBasePath(path);

            this.CremaHost.Dispatcher.Invoke(() =>
            {
                if (dataBaseName != string.Empty && dataBasePath.DataBaseName != dataBaseName)
                {
                    var dataBase       = this.CremaHost.DataBases[dataBaseName];
                    dataBase.Unloaded -= DataBase_Unloaded;
                    if (dataBase.IsLoaded == true)
                    {
                        dataBase.Leave(authentication);
                    }
                }

                if (dataBasePath.DataBaseName != string.Empty && dataBasePath.DataBaseName != dataBaseName)
                {
                    var dataBase = this.CremaHost.DataBases[dataBasePath.DataBaseName];
                    if (dataBase.IsLoaded == false)
                    {
                        dataBase.Load(authentication);
                    }
                    dataBase.Enter(authentication);
                    dataBase.Unloaded += DataBase_Unloaded;
                }
            });
            this.dataBasePath = dataBasePath;
        }
Exemplo n.º 2
0
 private string GetCurrentDirectory()
 {
     if (this.CommandContext.Drive is DataBasesConsoleDrive root)
     {
         var dataBasePath = new DataBasePath(this.CommandContext.Path);
         return(dataBasePath.ItemPath);
     }
     return(PathUtility.Separator);
 }
Exemplo n.º 3
0
        protected override void OnCreate(Authentication authentication, string path, string name)
        {
            var target = this.GetObject(authentication, path);

            if (target is ITableCategory tableCategory)
            {
                this.CremaHost.Dispatcher.Invoke(() =>
                {
                    var dataBase = tableCategory.GetService(typeof(IDataBase)) as IDataBase;
                    using (DataBaseUsing.Set(dataBase, authentication))
                    {
                        tableCategory.AddNewCategory(authentication, name);
                    }
                });
            }
            else if (target is ITypeCategory typeCategory)
            {
                this.CremaHost.Dispatcher.Invoke(() =>
                {
                    var dataBase = typeCategory.GetService(typeof(IDataBase)) as IDataBase;
                    using (DataBaseUsing.Set(dataBase, authentication))
                    {
                        typeCategory.AddNewCategory(authentication, name);
                    }
                });
            }
            else if (path == PathUtility.Separator)
            {
                var comment = this.CommandContext.ReadString("comment:");
                this.CremaHost.Dispatcher.Invoke(() =>
                {
                    this.CremaHost.DataBases.AddNewDataBase(authentication, name, comment);
                });
            }
            else
            {
                var dataBasePath = new DataBasePath(path);
                if (dataBasePath.Context == string.Empty)
                {
                    throw new PermissionDeniedException();
                }
                throw new CategoryNotFoundException(path);
            }
        }
Exemplo n.º 4
0
 void IPartImportsSatisfiedNotification.OnImportsSatisfied()
 {
     this.CremaHost.Closed += (s, e) => this.dataBasePath = null;
 }
Exemplo n.º 5
0
        public override object GetObject(Authentication authentication, string path)
        {
            return(this.CremaHost.Dispatcher.Invoke(GetObject));

            object GetObject()
            {
                var dataBasePath = new DataBasePath(path);

                if (dataBasePath.DataBaseName == string.Empty)
                {
                    return(null);
                }

                var dataBase = this.CremaHost.DataBases[dataBasePath.DataBaseName];

                if (dataBase == null)
                {
                    throw new DataBaseNotFoundException(dataBasePath.DataBaseName);
                }

                if (dataBasePath.Context == string.Empty)
                {
                    return(dataBase);
                }

                if (dataBasePath.ItemPath == string.Empty)
                {
                    return(null);
                }

                if (dataBase.IsLoaded == false)
                {
                    dataBase.Load(authentication);
                }

                if (dataBasePath.Context == CremaSchema.TableDirectory)
                {
                    if (NameValidator.VerifyCategoryPath(dataBasePath.ItemPath) == true)
                    {
                        return(dataBase.TableContext[dataBasePath.ItemPath]);
                    }
                    var item = dataBase.TableContext[dataBasePath.ItemPath + PathUtility.Separator];
                    if (item != null)
                    {
                        return(item);
                    }
                    return(dataBase.TableContext[dataBasePath.ItemPath]);
                }
                else if (dataBasePath.Context == CremaSchema.TypeDirectory)
                {
                    if (NameValidator.VerifyCategoryPath(dataBasePath.ItemPath) == true)
                    {
                        return(dataBase.TypeContext[dataBasePath.ItemPath]);
                    }
                    var item = dataBase.TypeContext[dataBasePath.ItemPath + PathUtility.Separator];
                    if (item != null)
                    {
                        return(item);
                    }
                    return(dataBase.TypeContext[dataBasePath.ItemPath]);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 6
0
        private void MoveTable(Authentication authentication, ITable sourceTable, string newPath)
        {
            var destPath   = new DataBasePath(newPath);
            var destObject = this.GetObject(authentication, destPath.Path);

            this.CremaHost.Dispatcher.Invoke(MoveTable);

            void MoveTable()
            {
                var dataBase = sourceTable.GetService(typeof(IDataBase)) as IDataBase;
                var tables   = sourceTable.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 (sourceTable.Category != destCategory)
                        {
                            sourceTable.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 = sourceTable.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection;
                        if (categories.Contains(itemName.CategoryPath) == false)
                        {
                            throw new InvalidOperationException($"cannot move to : {destPath}");
                        }
                        if (sourceTable.Name != itemName.Name && tables.Contains(itemName.Name) == true)
                        {
                            throw new InvalidOperationException($"cannot move to : {destPath}");
                        }
                        if (sourceTable.Category.Path != itemName.CategoryPath)
                        {
                            sourceTable.Move(authentication, itemName.CategoryPath);
                        }
                        if (sourceTable.Name != itemName.Name)
                        {
                            sourceTable.Rename(authentication, itemName.Name);
                        }
                    }
                }
            };
        }