Example #1
0
        private void SetDefaultConfigurationSingleEnvironmentValues(string appId, IAppConfiguration configuration)
        {
            var configurationType = configuration.GetType();
            var properties        = configurationType.GetProperties().Where(x => x.GetCustomAttribute <SingleEnvironmentAttribute>() != null).ToArray();

            if (!properties.Any())
            {
                return;
            }

            var records = Database.Fetch <Configuration>(
                "WHERE " + nameof(Data.Dto.Configuration.AppId) + " = @0",
                appId);

            var record = records.FirstOrDefault();

            if (record == null)
            {
                return;
            }

            var recordConfiguration = JsonConvert.DeserializeObject(record.Value, configurationType) as AppConfiguration;

            foreach (var property in properties)
            {
                property.SetValue(configuration, property.GetValue(recordConfiguration));
            }
        }
Example #2
0
        public IAppConfiguration ReadConfiguration(int environmentId, string appId, IAppConfiguration defaultConfiguration = null)
        {
            if (defaultConfiguration == null)
            {
                defaultConfiguration = App <IAppConfiguration> .Create(appId).DefaultConfiguration;
            }

            return(DbContext.Instance.Configuration.Read(environmentId, appId, defaultConfiguration.GetType(),
                                                         defaultConfiguration));
        }
        /// <summary>
        /// 加载应用程序配置集
        /// </summary>
        /// <param name="appConfiguration">应用程序配置集</param>
        /// <returns>结果/returns>
        protected int LoadAppConfiguration(IAppConfiguration appConfiguration)
        {
            if (object.ReferenceEquals(null, appConfiguration))
            {
                return(-1);
            }

            object   obj  = null;
            TreeNode node = null;
            IEnumerator <PropertyInfo> enumerator = null;

            //调整:使配置单元能够自动创建
            foreach (IConfigurationUnitInfo unit in appConfiguration.ConfigUnitInfos)
            {
                unit.AutoInitWhenNonExist = true;
            }

            //处理定义的所有配置组单元
            enumerator = ConfigurationHelper.GetDeclaredSubSectionGroups(appConfiguration.GetType());
            while (enumerator.MoveNext())
            {
                obj              = enumerator.Current.GetValue(appConfiguration, null);
                node             = NewConfigurationSectionGroupNode(enumerator.Current.Name, obj);
                node.ToolTipText = GetDescription(enumerator.Current);
                treeConfig.Nodes.Add(node);
            }

            //处理定义的所有配置段单元
            enumerator = ConfigurationHelper.GetDeclaredSubSections(appConfiguration.GetType());
            while (enumerator.MoveNext())
            {
                obj              = enumerator.Current.GetValue(appConfiguration, null);
                node             = NewConfigurationSectionNode(enumerator.Current.Name, obj);
                node.ToolTipText = GetDescription(enumerator.Current);
                treeConfig.Nodes.Add(node);
            }

            return(1);
        }
Example #4
0
        private void SetSingleEnvironmentValues(IAppConfiguration configuration, int environmentId, string appId)
        {
            var configurationType = configuration.GetType();
            var properties        = configurationType.GetProperties();

            if (properties.All(x => x.GetCustomAttribute <SingleEnvironmentAttribute>() == null))
            {
                return;
            }

            var singleEnvProperties = properties
                                      .Where(x => x.GetCustomAttribute <SingleEnvironmentAttribute>() != null)
                                      .ToArray();

            var records = Database.Fetch <Configuration>(
                "WHERE " + nameof(Data.Dto.Configuration.EnvironmentId) + " != @0 AND " +
                nameof(Data.Dto.Configuration.AppId) + " = @1",
                environmentId, appId);

            foreach (var record in records)
            {
                if (!(JsonConvert.DeserializeObject(record.Value, configurationType) is AppConfiguration recordConfiguration))
                {
                    continue;
                }

                foreach (var property in singleEnvProperties)
                {
                    property.SetValue(recordConfiguration, property.GetValue(configuration));

                    record.Value = JsonConvert.SerializeObject(recordConfiguration, Formatting.None,
                                                               new JsonSerializerSettings {
                        ContractResolver = new ShouldSerializeContractResolver()
                    });
                }

                recordConfiguration.LastModified = DateTime.UtcNow;
                Database.Update(record);
            }
        }
Example #5
0
        /// <summary>
        /// ����Ӧ�ó������ü�
        /// </summary>
        /// <param name="appConfiguration">Ӧ�ó������ü�</param>
        /// <returns>���/returns>
        protected int LoadAppConfiguration(IAppConfiguration appConfiguration)
        {
            if (object.ReferenceEquals(null, appConfiguration)) return -1;

            object obj = null;
            TreeNode node = null;
            IEnumerator<PropertyInfo> enumerator = null;

            //������ʹ���õ�Ԫ�ܹ��Զ�����
            foreach (IConfigurationUnitInfo unit in appConfiguration.ConfigUnitInfos)
            {
                unit.AutoInitWhenNonExist = true;
            }

            //�����������������鵥Ԫ
            enumerator = ConfigurationHelper.GetDeclaredSubSectionGroups(appConfiguration.GetType());
            while (enumerator.MoveNext())
            {
                obj = enumerator.Current.GetValue(appConfiguration, null);
                node = NewConfigurationSectionGroupNode(enumerator.Current.Name, obj);
                node.ToolTipText = GetDescription(enumerator.Current);
                treeConfig.Nodes.Add(node);
            }

            //���������������öε�Ԫ
            enumerator = ConfigurationHelper.GetDeclaredSubSections(appConfiguration.GetType());
            while (enumerator.MoveNext())
            {
                obj = enumerator.Current.GetValue(appConfiguration, null);
                node = NewConfigurationSectionNode(enumerator.Current.Name, obj);
                node.ToolTipText = GetDescription(enumerator.Current);
                treeConfig.Nodes.Add(node);
            }

            return 1;
        }