Exemplo n.º 1
0
        public async Task LoadRolesFromJsonAsync(string json)
        {
            IDictionary <string, Category> categories =
                await db.Categories.ToDictionaryAsync(x => x.Name);

            IDictionary <string, OperationKey> operationKeys =
                await db.OperationKeys.ToDictionaryAsync(x => x.Name);

            JsonSchema schema = await JsonSchema.FromFileAsync(RolesSchemaPath);

            RolesFromJsonLoader rolesFromJsonLoader = new RolesFromJsonLoader(categories, operationKeys, schema);


            rolesFromJsonLoader.Seed(json);

            try
            {
                db.BeginTransaction();
                await UpdateRoles(rolesFromJsonLoader.roles);
                await ClearAccessesAsync();
                await CopyToDb(rolesFromJsonLoader);

                db.CommitTransaction();
            }
            catch (Exception e)
            {
                db.RollbackTransaction();
                throw e;
            }
        }
Exemplo n.º 2
0
        private void CopyToDb(RolesFromJsonLoader fromJsonLoader)
        {
            BulkCopyOptions options = new BulkCopyOptions
            {
                CheckConstraints = false,
                BulkCopyType     = BulkCopyType.Default,
                KeepIdentity     = true
            };

            db.BulkCopy(options, fromJsonLoader.categoryAccesses);
            db.UpdateSequence("CategoryAccesses", "Id");
            db.BulkCopy(options, fromJsonLoader.categoryOperationAccesses);
        }
Exemplo n.º 3
0
        public async Task LoadRolesFromJsonAsync(string json)
        {
            IDictionary <string, Category> categories =
                await db.Categories.ToDictionaryAsync(x => x.Name);

            IDictionary <string, OperationKey> operationKeys =
                await db.OperationKeys.ToDictionaryAsync(x => x.Name);

            JsonSchema schema = await JsonSchema.FromFileAsync(RolesSchemaPath);

            RolesFromJsonLoader rolesFromJsonLoader;

            try
            {
                rolesFromJsonLoader = new RolesFromJsonLoader(categories, operationKeys, schema);
                rolesFromJsonLoader.Seed(json);
            }
            catch (Exception e)
            {
                throw new SunErrorException(new Error
                {
                    Code        = "PermissionsJsonUploadParseError",
                    Description = "Error in parsing uploaded json",
                    Message     = e.Message,
                });
            }

            try
            {
                db.BeginTransaction();
                await UpdateRoles(rolesFromJsonLoader.roles);
                await ClearAccessesAsync();

                CopyToDb(rolesFromJsonLoader);
                db.CommitTransaction();
            }
            catch
            {
                db.RollbackTransaction();
                throw;
            }
        }
Exemplo n.º 4
0
        private void SeedRoles()
        {
            Console.WriteLine("Roles");

            string     pathToUserGroupsConfig = Path.GetFullPath(Path.Combine(configDir, "Roles.json"));
            string     pathToUserGroupsSchema = Path.GetFullPath("Resources/Roles.schema.json");
            JsonSchema schema = JsonSchema.FromFileAsync(pathToUserGroupsSchema).GetAwaiter().GetResult();


            RolesFromJsonLoader fromJsonLoader =
                new RolesFromJsonLoader(dataContainer.Categories.ToDictionary(x => x.Name),
                                        dataContainer.OperationKeys.ToDictionary(x => x.Name), schema);

            var json = File.ReadAllText(pathToUserGroupsConfig);

            fromJsonLoader.Seed(json);

            dataContainer.Roles                     = fromJsonLoader.roles;
            dataContainer.CategoryAccesses          = fromJsonLoader.categoryAccesses;
            dataContainer.CategoryOperationAccesses = fromJsonLoader.categoryOperationAccesses;
        }
Exemplo n.º 5
0
        private void SeedRoles()
        {
            Console.WriteLine("Roles");

            string pathToUserGroupsConfig = Path.Combine(configInitDir, SeederPathsNames.RolesJsonFile);
            string resourcesPath          = pathService.GetPath(PathNames.ResourcesDirName);
            string pathToUserGroupsSchema = Path.Combine(resourcesPath, SeederPathsNames.RolesSchemaJsonFile);

            JsonSchema schema = JsonSchema.FromFileAsync(pathToUserGroupsSchema).GetAwaiter().GetResult();

            RolesFromJsonLoader fromJsonLoader =
                new RolesFromJsonLoader(dataContainer.Categories.ToDictionary(x => x.Name),
                                        dataContainer.OperationKeys.ToDictionary(x => x.Name), schema);

            var json = File.ReadAllText(pathToUserGroupsConfig);

            fromJsonLoader.Seed(json);

            dataContainer.Roles                     = fromJsonLoader.roles;
            dataContainer.CategoryAccesses          = fromJsonLoader.categoryAccesses;
            dataContainer.CategoryOperationAccesses = fromJsonLoader.categoryOperationAccesses;
        }