示例#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;
            }
        }
示例#2
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;
            }
        }
        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;
        }
示例#4
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;
        }