Esempio n. 1
0
        public async Task InitializeAsync()
        {
            var dataBaseContext = this.CremaHost.DataBaseContext;
            var dataBases       = await dataBaseContext.Dispatcher.InvokeAsync(() => dataBaseContext.ToArray <DataBase>());

            await this.Dispatcher.InvokeAsync(() =>
            {
                foreach (var item in dataBases)
                {
                    var categoryName  = CategoryName.Create(item.Name);
                    var category      = this.Categories.AddNew(categoryName);
                    category.DataBase = item;
                }
            });

            if (this.CremaHost.NoCache == false)
            {
                foreach (var item in dataBases)
                {
                    await this.RestoreAsync(item);
                }
            }
            await dataBaseContext.Dispatcher.InvokeAsync(() =>
            {
                dataBaseContext.ItemsCreated += DataBaseContext_ItemsCreated;
                dataBaseContext.ItemsRenamed += DataBaseContext_ItemsRenamed;
                dataBaseContext.ItemsDeleted += DataBaseContext_ItemDeleted;
            });

            this.CremaHost.Info($"{nameof(DomainContext)} Initialized");
        }
Esempio n. 2
0
        private void Initialize(IEnumerable <TypeInfo> typeInfos)
        {
            this.CremaHost.Debug("Load Types");
            var directories = DirectoryUtility.GetAllDirectories(this.BasePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.BasePath, item));
                this.Categories.Prepare(categoryName.Path);
            }

            foreach (var item in typeInfos)
            {
                var type = this.Types.AddNew(Authentication.System, item.Name, item.CategoryPath);
                type.Initialize(item);
            }

            var itemPaths = this.Serializer.GetItemPaths(this.BasePath, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);

            foreach (var item in itemPaths)
            {
                var accessInfo = (AccessSerializationInfo)this.Serializer.Deserialize(item, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);
                var tableItem  = this.GetTypeItemByItemPath(item);
                if (tableItem is Type type)
                {
                    type.SetAccessInfo((AccessInfo)accessInfo);
                }
                else if (tableItem is TypeCategory category)
                {
                    category.SetAccessInfo((AccessInfo)accessInfo);
                }
            }
            this.CremaHost.Debug("TypeLoadingCompleted.");
        }
Esempio n. 3
0
        private void Initialize(IEnumerable <TypeInfo> typeInfos)
        {
            this.CremaHost.Debug("Load Types");
            var directories = DirectoryUtility.GetAllDirectories(this.basePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.basePath, item));
                this.Categories.Prepare(categoryName.Path);
            }
            foreach (var item in typeInfos)
            {
                var type = this.Types.AddNew(Authentication.System, item.Name, item.CategoryPath);
                type.Initialize(item);
            }
            foreach (ITypeItem item in this)
            {
                var accessInfoPath = item.GetAccessInfoPath();
                try
                {
                    item.ReadAccessInfo(accessInfoPath);
                }
                catch (Exception e)
                {
                    this.CremaHost.Error(e);
                }
            }
            this.CremaHost.Debug("TypeLoadingCompleted.");
        }
Esempio n. 4
0
        public async Task InitializeAsync()
        {
            await this.Dispatcher.InvokeAsync(() =>
            {
                this.CremaHost.Debug("Load user data...");

                var directories = DirectoryUtility.GetAllDirectories(this.BasePath, "*", true);
                foreach (var item in directories)
                {
                    var relativeUri  = UriUtility.MakeRelativeOfDirectory(this.BasePath, item);
                    var segments     = StringUtility.Split(relativeUri, PathUtility.SeparatorChar, true);
                    var categoryName = CategoryName.Create(relativeUri);
                    var category     = this.Categories.Prepare(categoryName);
                    category.Guid    = Guid.NewGuid();
                }

                var settings  = ObjectSerializerSettings.Empty;
                var itemPaths = this.Serializer.GetItemPaths(this.BasePath, typeof(UserSerializationInfo), settings);
                foreach (var item in itemPaths)
                {
                    var userInfo    = (UserSerializationInfo)this.Serializer.Deserialize(item, typeof(UserSerializationInfo), settings);
                    var directory   = Path.GetDirectoryName(item);
                    var relativeUri = UriUtility.MakeRelativeOfDirectory(this.BasePath, item);
                    var segments    = StringUtility.Split(relativeUri, PathUtility.SeparatorChar, true);
                    var itemName    = ItemName.Create(segments);
                    var user        = this.Users.AddNew(userInfo.ID, itemName.CategoryPath);
                    user.Initialize((UserInfo)userInfo, (BanInfo)userInfo.BanInfo);
                    user.Password = UserContext.StringToSecureString(userInfo.Password);
                    user.Guid     = Guid.NewGuid();
                }

                this.CremaHost.Info($"{nameof(UserContext)} Initialized");
            });
        }
Esempio n. 5
0
        private CremaDataSet ReadDataSet(string path)
        {
            var dataSet = CremaDataSet.ReadFromDirectory(path);

            var dirs = DirectoryUtility.GetAllDirectories(path);

            {
                var typesPath = System.IO.Path.Combine(path, CremaSchema.TypeDirectory);
                var query     = from item in dirs
                                where item.StartsWith(typesPath)
                                let localPath = item.Substring(typesPath.Length)
                                                let segments = localPath.Split(new char[] { System.IO.Path.DirectorySeparatorChar, }, StringSplitOptions.RemoveEmptyEntries)
                                                               select CategoryName.Create(segments).Path;

                dataSet.ExtendedProperties[CremaSchema.TypeDirectory] = query.ToArray();
            }
            {
                var tablesPath = System.IO.Path.Combine(path, CremaSchema.TableDirectory);
                var query      = from item in dirs
                                 where item.StartsWith(tablesPath)
                                 let localPath = item.Substring(tablesPath.Length)
                                                 let segments = localPath.Split(new char[] { System.IO.Path.DirectorySeparatorChar, }, StringSplitOptions.RemoveEmptyEntries)
                                                                select CategoryName.Create(segments).Path;

                dataSet.ExtendedProperties[CremaSchema.TableDirectory] = query.ToArray();
            }

            return(dataSet);
        }
        public static string BuildRelativePath(TreeViewItemViewModel parent, TreeViewItemViewModel viewModel, Predicate <TreeViewItemViewModel> isCategory)
        {
            var items = CollectDisplayName(parent, viewModel).Reverse();

            if (isCategory(viewModel) == true)
            {
                return(CategoryName.Create(items.ToArray()));
            }
            return(ItemName.Create(items.ToArray()));
        }
Esempio n. 7
0
        private ITypeItem GetTypeItemByItemPath(string itemPath)
        {
            var isCategory  = itemPath.EndsWith($"{Path.DirectorySeparatorChar}");
            var directory   = Path.GetDirectoryName(itemPath);
            var relativeUri = UriUtility.MakeRelativeOfDirectory(this.BasePath, itemPath);
            var segments    = StringUtility.Split(relativeUri, PathUtility.SeparatorChar, true);
            var path        = isCategory == true ? (string)CategoryName.Create(segments) : ItemName.Create(segments);

            return(this[path] as ITypeItem);
        }
Esempio n. 8
0
        public void Add(Authentication authentication, Domain domain)
        {
            var dataBase     = this.Context.CremaHost.DataBases[domain.DataBaseID];
            var categoryName = CategoryName.Create(dataBase.Name, domain.DomainInfo.ItemType);
            var category     = this.Context.Categories.Prepare(categoryName);

            domain.Category   = category;
            domain.Dispatcher = new CremaDispatcher(domain);
            domain.Logger     = new DomainLogger(domain);
            domain.Dispatcher.InvokeAsync(() => this.InvokeDomainCreatedEvent(authentication, domain));
        }
Esempio n. 9
0
 public async Task AddAsync(Authentication authentication, Domain domain, DataBase dataBase)
 {
     await this.Dispatcher.InvokeAsync(() =>
     {
         var categoryName = CategoryName.Create(dataBase.Name, domain.DomainInfo.ItemType);
         var category     = this.Categories.Prepare(categoryName);
         domain.Category  = category;
         domain.Context   = this;
         domain.Logger    = new DomainLogger(this.Serializer, domain);
         this.Domains.InvokeDomainCreatedEvent(authentication, new Domain[] { domain });
     });
 }
Esempio n. 10
0
        public DomainContext(CremaHost cremaHost, UserContext userContext)
        {
            this.cremaHost = cremaHost;
            this.cremaHost.Debug(Resources.Message_DomainContextInitialize);
            this.userContext       = userContext;
            this.basePath          = DirectoryUtility.Prepare(cremaHost.WorkingPath, nameof(Domain).ToLower());
            this.cremaHost.Opened += CremaHost_Opened;
            this.cremaHost.Debug(Resources.Message_DomainContextIsCreated);

            foreach (var item in this.cremaHost.DataBases)
            {
                var categoryName = CategoryName.Create(item.Name);
                var category     = this.Categories.AddNew(categoryName);
                category.DataBase = item;
            }
        }
Esempio n. 11
0
        public string GetAbsolutePath(string path)
        {
            if (NameValidator.VerifyCategoryPath(path) != false && NameValidator.VerifyItemPath(path) != false)
            {
                path = this.path + path;
            }

            var isDirectory = path.EndsWith(".") || path.EndsWith("..") || path.EndsWith(PathUtility.Separator);
            var segments    = GetAbsolutePath(this.path, path);

            if (isDirectory == true)
            {
                return(CategoryName.Create(segments));
            }
            return(ItemName.Create(segments));
        }
Esempio n. 12
0
        private void DataBases_ItemsCreated(object sender, ItemsCreatedEventArgs <IDataBase> e)
        {
            var categoryList     = new List <DomainCategory>(e.Items.Length);
            var categoryNameList = new List <string>(e.Items.Length);
            var categoryPathList = new List <string>(e.Items.Length);

            for (var i = 0; i < e.Items.Length; i++)
            {
                var dataBase     = e.Items[i];
                var categoryName = CategoryName.Create(dataBase.Name);
                var category     = this.Categories.AddNew(categoryName);
                category.DataBase = dataBase;
                categoryList.Add(category);
            }
            Authentication.System.Sign();
            this.Categories.InvokeCategoriesCreatedEvent(Authentication.System, categoryList.ToArray());
        }
Esempio n. 13
0
 public void Restore(Authentication authentication, Domain domain)
 {
     try
     {
         authentication.Sign();
         var dataBase     = this.Context.CremaHost.DataBases[domain.DataBaseID];
         var categoryName = CategoryName.Create(dataBase.Name, domain.DomainInfo.ItemType);
         var category     = this.Context.Categories.Prepare(categoryName);
         domain.Category   = category;
         domain.Dispatcher = new CremaDispatcher(domain);
         domain.Dispatcher.InvokeAsync(() => this.InvokeDomainCreatedEvent(authentication, domain));
     }
     catch (Exception e)
     {
         this.CremaHost.Error(e);
         throw;
     }
 }
Esempio n. 14
0
        private void Initialize(IEnumerable <TableInfo> tableInfos)
        {
            this.CremaHost.Debug(Resources.Message_LoadTables);
            var directories = DirectoryUtility.GetAllDirectories(this.BasePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.BasePath, item));
                this.Categories.Prepare(categoryName.Path);
            }

            foreach (var item in tableInfos.OrderBy(i => i.Name))
            {
                var table = this.Tables.AddNew(Authentication.System, item.Name, item.CategoryPath);
                table.Initialize(item);
            }

            foreach (var item in tableInfos.Where(i => i.TemplatedParent != string.Empty))
            {
                var table = this.Tables[item.Name];
                table.TemplatedParent = this.Tables[item.TemplatedParent];
                if (table.TemplatedParent == null)
                {
                    throw new Exception();
                }
            }

            var itemPaths = this.Serializer.GetItemPaths(this.BasePath, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);

            foreach (var item in itemPaths)
            {
                var accessInfo = (AccessSerializationInfo)this.Serializer.Deserialize(item, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);
                var tableItem  = this.GetTableItemByItemPath(item);
                if (tableItem is Table table)
                {
                    table.SetAccessInfo((AccessInfo)accessInfo);
                }
                else if (tableItem is TableCategory category)
                {
                    category.SetAccessInfo((AccessInfo)accessInfo);
                }
            }
            this.CremaHost.Debug(Resources.Message_TableLoadingIsCompleted);
        }
Esempio n. 15
0
        public async Task RestoreAsync(DataBase dataBase)
        {
            var restorers = this.GetDomainRestorers(dataBase.ID);

            if (restorers.Any() == false)
            {
                return;
            }

            var tasks  = restorers.Select(item => item.RestoreAsync()).ToArray();
            var result = Task.WhenAll(tasks);

            try
            {
                await result;
            }
            catch
            {
                var exceptions = result.Exception.InnerExceptions;
                foreach (var item in exceptions)
                {
                    this.CremaHost.Error(item);
                }
            }
            finally
            {
                var count = await this.Dispatcher.InvokeAsync(() =>
                {
                    var domains = restorers.Where(item => item.Domain != null).Select(item => item.Domain).ToArray();
                    foreach (var item in domains)
                    {
                        var categoryName = CategoryName.Create(dataBase.Name, item.DomainInfo.ItemType);
                        var category     = this.Categories.Prepare(categoryName);
                        item.Category    = category;
                    }
                    this.Domains.InvokeDomainCreatedEvent(Authentication.System, domains);
                    return(domains.Length);
                });

                this.CremaHost.Info(string.Format(Resources.Message_RestoreResult_Format, count, restorers.Length - count));
            }
        }
Esempio n. 16
0
        private async void DataBaseContext_ItemsCreated(object sender, ItemsCreatedEventArgs <IDataBase> e)
        {
            var authentication = await this.UserContext.AuthenticateAsync(e.SignatureDate);

            await this.Dispatcher.InvokeAsync(() =>
            {
                var categoryList     = new List <DomainCategory>(e.Items.Length);
                var categoryNameList = new List <string>(e.Items.Length);
                var categoryPathList = new List <string>(e.Items.Length);
                for (var i = 0; i < e.Items.Length; i++)
                {
                    var dataBase      = e.Items[i];
                    var categoryName  = CategoryName.Create(dataBase.Name);
                    var category      = this.Categories.AddNew(categoryName);
                    category.DataBase = dataBase;
                    categoryList.Add(category);
                }
                this.Categories.InvokeCategoriesCreatedEvent(authentication, categoryList.ToArray());
            });
        }
Esempio n. 17
0
        private void Initialize(IEnumerable <TableInfo> tableInfos)
        {
            this.CremaHost.Debug(Resources.Message_LoadTables);
            var directories = DirectoryUtility.GetAllDirectories(this.basePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.basePath, item));
                this.Categories.Prepare(categoryName.Path);
            }
            foreach (var item in tableInfos.OrderBy(i => i.Name))
            {
                var table = this.Tables.AddNew(Authentication.System, item.Name, item.CategoryPath);
                table.Initialize(item);
            }

            foreach (var item in tableInfos.Where(i => i.TemplatedParent != string.Empty))
            {
                var table = this.Tables[item.Name];
                table.TemplatedParent = this.Tables[item.TemplatedParent];
                if (table.TemplatedParent == null)
                {
                    throw new Exception();
                }
            }
            foreach (ITableItem item in this)
            {
                var accessInfoPath = item.GetAccessInfoPath();
                try
                {
                    item.ReadAccessInfo(accessInfoPath);
                }
                catch (Exception e)
                {
                    this.CremaHost.Error(e);
                }
            }
            this.CremaHost.Debug(Resources.Message_TableLoadingIsCompleted);
        }
        public static string BuildPath(TreeViewItemViewModel viewModel)
        {
            var items = CollectDisplayName(null, viewModel).Reverse();

            return(CategoryName.Create(items.ToArray()));
        }