Esempio n. 1
0
 public SectionsAdminManager(
     ICheckRoles checkRoles,
     SectionTypes sectionTypes,
     DataBaseConnection db) : base(db)
 {
     this.sectionTypes = sectionTypes;
     this.checkRoles   = checkRoles;
 }
Esempio n. 2
0
        public static void SectionProcess(Section section, SectionTypes sectionTypes, ICheckRoles checkRoles)
        {
            section.Options = section.Options?.MakeJsonTextNotNull();

            if (checkRoles != null)
            {
                section.Roles = checkRoles.CheckAndSetRoles(section.Roles);
            }

            var options = new Dictionary <string, object>();

            if (sectionTypes.SectionServerTypes.TryGetValue(section.Type, out Type sectionServerType))
            {
                AddFields(section.Options, sectionServerType, options);
            }
            if (sectionTypes.SectionClientTypes.TryGetValue(section.Type, out Type sectionClientType))
            {
                AddFields(section.Options, sectionClientType, options);
            }

            section.Options = JsonSerializer.Serialize(options);

            void AddFields(string optionsJson, Type sectionType, Dictionary <string, object> optionsToAdd)
            {
                var dataObject = JsonSerializer.Deserialize(optionsJson, sectionType);
                var properties = sectionType.GetProperties();

                foreach (var propertyInfo in properties)
                {
                    ConfigItemAttribute configItemAttribute = propertyInfo.GetCustomAttribute <ConfigItemAttribute>();

                    string name     = propertyInfo.Name;
                    string typeName = configItemAttribute.ConfigItemType.Name.Split(".")[^ 1].Replace("Item", "");