Exemplo n.º 1
0
        /// <summary>
        /// 获取必须配置的值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="configSetting">配置节</param>
        /// <param name="name">值名</param>
        /// <returns>配置值</returns>
        public static T GetRequiredSetting <T>(this IConfigSetting configSetting, string name)
        {
            ISettingValue settingValue = null;

            if (configSetting != null)
            {
                settingValue = configSetting.Property[name];
                if (settingValue == null)
                {
                    var setting = name == null ? configSetting : configSetting[name];
                    if (setting != null)
                    {
                        var type = typeof(T);
                        if (typeof(IConfigSettingElement).IsAssignableFrom(typeof(T)))
                        {
                            return((T)setting.ToSetting(type));
                        }
                        settingValue = setting.Value;
                    }
                }
            }
            if (settingValue != null)
            {
                return(settingValue.TryToObject <T>());
            }
            throw new ConfigException(string.Format("必须配置节点 {0}", name));
        }
Exemplo n.º 2
0
        public SettingValuePropertyInfo(ISettingValue var)
            : base(var.Name, new Attribute[0])
        {
            Variable = var;

            if (Variable.SettingValueType == SettingValueType.IPAddress)
            {
                ConverterTypeName = typeof(IPAddressTypeConverter).AssemblyQualifiedName;
            }

            if (Variable.SettingValueType == SettingValueType.MacAddress)
            {
                ConverterTypeName = typeof(MacAddressTypeConverter).AssemblyQualifiedName;
            }

            if (Variable.SettingValueType == SettingValueType.Float)
            {
                ConverterTypeName = typeof(FloatTypeConverter).AssemblyQualifiedName;
            }

            if (Variable.SettingValueType == SettingValueType.WifiMode ||
                Variable.SettingValueType == SettingValueType.Wifi2GHzChannel ||
                Variable.SettingValueType == SettingValueType.Wifi5GHzChannel ||
                Variable.SettingValueType == SettingValueType.WifiAntenna ||
                Variable.SettingValueType == SettingValueType.WifiRegion ||
                Variable.SettingValueType == SettingValueType.WifiBand ||
                Variable.SettingValueType == SettingValueType.OscPassthroughMode ||
                Variable.SettingValueType == SettingValueType.CpuIdleMode)
            {
                ConverterTypeName = typeof(CustomEnumConverter).AssemblyQualifiedName;
            }
        }
Exemplo n.º 3
0
 private static void updateSetting(ISettingValue s, String val)
 {
     if ((val != null) && (s.SettingValue.ToLower() != val.ToLower()))
     {
         s.SettingValue = val;
         s.Update("SettingValue");
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Create an communication process.
        /// </summary>
        /// <param name="comms">An Connection to be used for communication.</param>
        /// <param name="reporter">Progress reporter.</param>
        /// <param name="callback">Callback callback to be processed.</param>
        /// <param name="timeout">Time out in milliseconds between each process iteration.</param>
        /// <param name="retryLimit">The maximum number of retries before failure.</param>
        internal CommunicationProcess(Connection comms, IReporter reporter, ISettingValue callback, int timeout = 100, int retryLimit = 3)
        {
            RetryLimit = retryLimit;
            Timeout    = timeout;

            Connection = comms;

            Reporter = reporter;

            AllCallbacks = new List <ISettingValue>(new ISettingValue[] { callback });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="comms"></param>
        /// <param name="reporter">Progress reporter.</param>
        /// <param name="variables"></param>
        /// <param name="timeout"></param>
        /// <param name="retryLimit"></param>
        public SettingProcess(Connection comms, IReporter reporter, ISettingValue variables,
                              int timeout    = 100,
                              int retryLimit = 3)
        {
            RetryLimit = retryLimit;
            Timeout    = timeout;
            Reporter   = reporter;

            Communicator = comms;

            allVariables = new List <ISettingValue>();
            allVariables.Add(variables);
        }
        protected override bool SetupCallback(ISettingValue callback)
        {
            if (callback.IsReadOnly == true)
            {
                return(false);
            }

            if (callback.IsValueUndefined == true)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        //------------------------------------------------------------------------------------

        public static void UpdateSettings(IList list, MvcContext ctx)
        {
            for (int i = 0; i < list.Count; i++)
            {
                ISettingValue s      = list[i] as ISettingValue;
                String        target = ctx.Post(GetInputName(s.Id));
                if (strUtil.HasText(target))
                {
                    if (s.DataType == SettingType.Bool.ToString())
                    {
                        updateSetting(s, cvt.ToBool(target).ToString());
                    }
                    else if (!(s.DataType == SettingType.Int.ToString()) || cvt.IsInt(target))
                    {
                        updateSetting(s, target);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void sendRatesGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = sendRatesGrid.Rows[e.RowIndex];

            DataGridViewSettingsValueColumn column = sendRatesGrid.Columns[e.ColumnIndex] as DataGridViewSettingsValueColumn;

            object value = row.Cells[e.ColumnIndex].Value;

            foreach (DataGridViewCell cell in selectedCells)
            {
                ISettingValue settingValue = (ISettingValue)cell.Tag;

                if (settingValue == null)
                {
                    continue;
                }

                cell.Value = value;

                float floatValue = 0f;

                if (value == null || float.TryParse(value.ToString(), out floatValue) == false)
                {
                    floatValue = (float)settingValue.GetValue();
                }

                float settingRemoteValue = (float)settingValue.GetRemoteValue();

                if (Math.Abs(floatValue - settingRemoteValue) > float.Epsilon)
                {
                    cell.Style.ApplyStyle(dataGridViewCellStyleBold);
                }
                else
                {
                    cell.Style.ApplyStyle(dataGridViewCellStyle);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取配置值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="configSetting">配置节</param>
        /// <param name="name">值名</param>
        /// <param name="defaultValue">值缺省值</param>
        /// <returns>配置值</returns>
        public static T GetSetting <T>(this IConfigSetting configSetting, string name, T defaultValue)
        {
            ISettingValue settingValue = null;

            if (configSetting != null)
            {
                settingValue = configSetting.Property[name];
                if (settingValue == null)
                {
                    var setting = name == null ? configSetting : configSetting[name];
                    if (setting != null)
                    {
                        var type = typeof(T);
                        if (typeof(IConfigSettingElement).IsAssignableFrom(typeof(T)))
                        {
                            return((T)setting.ToSetting(type));
                        }
                        settingValue = setting.Value;
                    }
                }
            }
            return(settingValue != null?settingValue.TryToObject <T>() : defaultValue);
        }
 protected override OscMessage GetMessageFor(ISettingValue var)
 {
     return(new OscMessage(var.OscAddress));
 }
 protected override bool SetupCallback(ISettingValue callback)
 {
     return(true);
 }
        public static CommunicationProcessResult WriteSingle <T>(Connection connection, IReporter reporter, int timeout, int retryLimit, ISettingValue <T> setting, T value)
        {
            setting.Value = value;

            SettingProcess process = new SettingProcess(connection, reporter, setting, timeout, retryLimit);

            CommunicationProcessResult result = process.Write();

            return(result);
        }
        public static CommunicationProcessResult WriteSingle <T>(Connection connection, IReporter reporter, ISettingValue <T> setting, T value)
        {
            setting.Value = value;

            SettingProcess process = new SettingProcess(connection, reporter, new ISettingValue[] { setting }, 100, 3);

            CommunicationProcessResult result = process.Write();

            return(result);
        }
        /// <summary>
        /// Reads a single <see cref="ISettingValue"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection">The connection.</param>
        /// <param name="reporter">The reporter.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="retryLimit">The retry limit.</param>
        /// <param name="setting">The setting.</param>
        /// <param name="value">The value.</param>
        /// <returns>ImuAsyncProcessResult.</returns>
        public static CommunicationProcessResult ReadSingle <T>(Connection connection, IReporter reporter, int timeout, int retryLimit, ISettingValue <T> setting, out T value)
        {
            SettingProcess process = new SettingProcess(connection, reporter, setting, timeout, retryLimit);

            CommunicationProcessResult result = process.Read();

            switch (result)
            {
            case CommunicationProcessResult.Success:
                value = setting.RemoteValue;
                break;

            default:
                value = default(T);
                break;
            }

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="reporter">Progress reporter.</param>
        /// <param name="muteToStart"></param>
        /// <param name="message"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static CommunicationProcessResult ReadSingle <T>(Connection connection, IReporter reporter, ISettingValue <T> setting, out T value) // bool muteToStart,
        {
            SettingProcess process = new SettingProcess(connection, reporter, new ISettingValue[] { setting }, 100, 3);                            // muteToStart

            CommunicationProcessResult result = process.Read();

            switch (result)
            {
            case CommunicationProcessResult.Success:
                value = setting.RemoteValue;
                break;

            default:
                value = default(T);
                break;
            }

            return(result);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates settings in given sectionId
        /// </summary>
        public void CreateSettings()
        {
            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSection(_sectionId);

            if (section == null)
            {
                section = ((IConfigAdmin)configProvider).CreateSection(_sectionId, _sectionId);
                Debug.WriteLine(string.Format("Section [{0}] erzeugt", _sectionId), "Settings Provider");
            }

            foreach (SettingsProperty oldSetting in _oldSettings.Properties)
            {
                if (!section.ContainsSetting(oldSetting.Name))
                {
                    if (oldSetting.PropertyType == typeof(string))
                    {
                        ISettingValue <string> newSetting = ((IConfigSectionAdmin)section).AddSetting(oldSetting.Name,
                                                                                                      oldSetting.DefaultValue.ToString());
                        if (!IsUserScopedSetting(oldSetting))
                        {
                            newSetting.Scope = ESettingScope.Application;
                        }
                    }
                    else if (oldSetting.PropertyType == typeof(bool))
                    {
                        bool defaultValue;
                        bool ok = bool.TryParse(oldSetting.DefaultValue.ToString(), out defaultValue);

                        if (ok)
                        {
                            ISettingValue <bool> newSetting = ((IConfigSectionAdmin)section).AddSetting(
                                oldSetting.Name, defaultValue);
                            if (!IsUserScopedSetting(oldSetting))
                            {
                                newSetting.Scope = ESettingScope.Application;
                            }
                        }
                    }
                    else if (oldSetting.PropertyType == typeof(int))
                    {
                        int  defaultValue;
                        bool ok = int.TryParse(oldSetting.DefaultValue.ToString(), out defaultValue);

                        if (ok)
                        {
                            ISettingValue <int> newSetting = ((IConfigSectionAdmin)section).AddSetting(oldSetting.Name,
                                                                                                       defaultValue);
                            if (!IsUserScopedSetting(oldSetting))
                            {
                                newSetting.Scope = ESettingScope.Application;
                            }
                        }
                    }
                    else if (oldSetting.PropertyType == typeof(decimal))
                    {
                        decimal defaultValue;
                        bool    ok = decimal.TryParse(oldSetting.DefaultValue.ToString(), out defaultValue);

                        if (ok)
                        {
                            ISettingValue <decimal> newSetting =
                                ((IConfigSectionAdmin)section).AddSetting(oldSetting.Name, defaultValue);
                            if (!IsUserScopedSetting(oldSetting))
                            {
                                newSetting.Scope = ESettingScope.Application;
                            }
                        }
                    }
                    else if (oldSetting.PropertyType == typeof(float))
                    {
                        float defaultValue;
                        bool  ok = float.TryParse(oldSetting.DefaultValue.ToString(), out defaultValue);

                        if (ok)
                        {
                            ISettingValue <float> newSetting = ((IConfigSectionAdmin)section).AddSetting(
                                oldSetting.Name, defaultValue);
                            if (!IsUserScopedSetting(oldSetting))
                            {
                                newSetting.Scope = ESettingScope.Application;
                            }
                        }
                    }
                    else if (oldSetting.PropertyType == typeof(Color))
                    {
                        Color defaultValue = Color.Transparent;
                        defaultValue = defaultValue.FromRgb(oldSetting.DefaultValue.ToString());

                        ISettingValue <Color> newSetting = ((IConfigSectionAdmin)section).AddSetting(oldSetting.Name,
                                                                                                     defaultValue);
                        if (!IsUserScopedSetting(oldSetting))
                        {
                            newSetting.Scope = ESettingScope.Application;
                        }
                    }
                }
                else
                {
                    Debug.WriteLine(string.Format("Setting [{0}] existiert schon", oldSetting.Name), "Settings Provider");
                }
            }

            configProvider.SaveSection(section);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Get an OSC callback for a callback object this callback is the one sent to the remote.
 /// Inheriting classes should implement this method for the type of callback that is used.
 /// </summary>
 /// <param name="callback">A callback object.</param>
 /// <returns>The OSC callback to be sent.</returns>
 protected abstract OscMessage GetMessageFor(ISettingValue callback);
 protected override OscMessage GetMessageFor(ISettingValue var)
 {
     return(var.Message);
 }
 public Setting(string section, string key, ISettingValue value)
 {
     Section = section;
     Key     = key;
     Value   = value;
 }
Exemplo n.º 20
0
        public static ISettingValue AddOrUpdateTenantSettingValue(this ISettingGroup group, ISettingValue value,
                                                                  int?tenantId)
        {
            using (var db = new AppDbContext())
            {
                var scopes      = SettingScopes.Tenant;
                var theTenantId = tenantId == null ? WeiChatApplicationContext.Current.TenantId : tenantId.Value;
                var groupInfo   = db.App_SettingGroups.FirstOrDefault(p => (p.Name == group.Name) && (p.Scopes == scopes));

                if (groupInfo == null)
                {
                    throw new Exception("名称为" + group.Name + "的配置组不存在。");
                }
                var settingValue =
                    db.App_SettingValues.FirstOrDefault(p => (p.Name == value.Name) && (p.Scopes == scopes));
                var isAdd = settingValue == null;
                if (settingValue == null)
                {
                    settingValue = new App_SettingValue();
                }
                settingValue.IsVisibleToClients = value.IsVisibleToClients;
                settingValue.Scopes             = scopes;
                settingValue.UpdateTime         = DateTime.Now;
                settingValue.DisplayName        = value.DisplayName;
                settingValue.Name        = value.Name;
                settingValue.Description = value.Description;
                settingValue.CreateBy    = WeiChatApplicationContext.Current.UserId;
                settingValue.Value       = value.Value;
                settingValue.GroupId     = groupInfo.Id;
                settingValue.CustomData  = value.CustomData;
                settingValue.TenantId    = theTenantId;
                if (isAdd)
                {
                    db.App_SettingValues.Add(settingValue);
                }
                db.SaveChanges();

                ConcurrentDictionary <string, ISettingValue> settings = null;
                if (SettingManager.Current.TenantSettings.ContainsKey(theTenantId))
                {
                    settings = SettingManager.Current.TenantSettings[theTenantId];
                }
                else
                {
                    settings = new ConcurrentDictionary <string, ISettingValue>();
                    {
                        var tenantSettings =
                            db.App_SettingValues.Where(p => (p.Scopes == scopes) && (p.TenantId == theTenantId));
                        foreach (var item in tenantSettings)
                        {
                            settings.TryAdd(item.Name, item);
                        }
                        SettingManager.Current.TenantSettings.TryAdd(theTenantId, settings);
                    }
                }
                settings.AddOrUpdate(settingValue.Name, settingValue, (tKey, existingVal) => { return(settingValue); });
                return(settingValue);
            }
        }
Exemplo n.º 21
0
        public static ISettingValue AddOrUpdateApplicationSettingValue(this ISettingGroup group, ISettingValue value)
        {
            using (var db = new AppDbContext())
            {
                var scopes    = SettingScopes.Application;
                var groupInfo = db.App_SettingGroups.FirstOrDefault(p => (p.Name == group.Name) && (p.Scopes == scopes));

                if (groupInfo == null)
                {
                    throw new Exception("名称为" + group.Name + "的配置组不存在。");
                }
                var settingValue =
                    db.App_SettingValues.FirstOrDefault(p => (p.Name == value.Name) && (p.Scopes == scopes));
                var isAdd = settingValue == null;
                if (settingValue == null)
                {
                    settingValue = new App_SettingValue();
                }
                settingValue.IsVisibleToClients = value.IsVisibleToClients;
                settingValue.Scopes             = scopes;
                settingValue.UpdateTime         = DateTime.Now;
                settingValue.DisplayName        = value.DisplayName;
                settingValue.Name        = value.Name;
                settingValue.Description = value.Description;
                settingValue.CreateBy    = WeiChatApplicationContext.Current.UserId;
                settingValue.Value       = value.Value;
                settingValue.GroupId     = groupInfo.Id;
                if (isAdd)
                {
                    db.App_SettingValues.Add(settingValue);
                }
                db.SaveChanges();
                SettingManager.Current.ApplicationSettings.AddOrUpdate(value.Name, settingValue,
                                                                       (tKey, existingVal) => { return(settingValue); });
                return(settingValue);
            }
        }
Exemplo n.º 22
0
 private static void updateSetting( ISettingValue s, String val ) {
     if ((val != null) && (s.SettingValue.ToLower() != val.ToLower())) {
         s.SettingValue = val;
         s.Update( "SettingValue" );
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// Setup a single callback, this method is called for each callback prior to the start of the process.
 /// Inheriting classes should implement this method for the type of callback that is used.
 /// </summary>
 /// <param name="callback">A callback object.</param>
 /// <returns>True if the callback should be included in the process.</returns>
 protected abstract bool SetupCallback(ISettingValue callback);