public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                if (destinationType == typeof(MRSSettingsLogCollection))
                {
                    return(this.ConvertFrom(context, culture, value));
                }
                MRSSettingsLogCollection mrssettingsLogCollection = value as MRSSettingsLogCollection;

                if (mrssettingsLogCollection == null)
                {
                    throw new ArgumentException("Converted value is not of MRSSettingsLogCollection type");
                }
                if (destinationType == typeof(string))
                {
                    return(mrssettingsLogCollection.ToString());
                }
                return(base.ConvertTo(context, culture, value, destinationType));
            }
示例#2
0
        public void ProcessLogs()
        {
            if (!this.LogIsNeeded())
            {
                return;
            }
            MRSSettingsLogCollection config = ConfigBase <MRSConfigSchema> .GetConfig <MRSSettingsLogCollection>("MRSSettingsLogList");

            if (config == null)
            {
                MRSSettingsLog.PublishPeriodicExceptionNotification(string.Format("The value for {0} setting is corrupt. Check and correct setting value", "MRSSettingsLogList"));
                return;
            }
            foreach (MRSSettingsLogCollection.MRSSettingsLogElement mrssettingsLogElement in config.SettingsLogCollection)
            {
                try
                {
                    MRSSettingsData loggingStatsData;
                    if (StringComparer.OrdinalIgnoreCase.Equals(mrssettingsLogElement.SettingName, "IsJobPickupEnabled"))
                    {
                        using (IEnumerator enumerator2 = Enum.GetValues(typeof(RequestWorkloadType)).GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                object obj = enumerator2.Current;
                                RequestWorkloadType requestWorkloadType = (RequestWorkloadType)obj;
                                if (requestWorkloadType != RequestWorkloadType.None)
                                {
                                    SettingsContextBase settingsContextBase = new GenericSettingsContext("RequestWorkloadType", requestWorkloadType.ToString(), null);
                                    using (settingsContextBase.Activate())
                                    {
                                        bool config2 = ConfigBase <MRSConfigSchema> .GetConfig <bool>(mrssettingsLogElement.SettingName);

                                        loggingStatsData = new MRSSettingsData
                                        {
                                            Context      = string.Format("{0}={1}", "RequestWorkloadType", requestWorkloadType.ToString()),
                                            SettingName  = "IsJobPickupEnabled",
                                            SettingValue = Convert.ToInt32(config2).ToString()
                                        };
                                    }
                                    this.Write(loggingStatsData);
                                }
                            }
                            continue;
                        }
                    }
                    if (StringComparer.OrdinalIgnoreCase.Equals(mrssettingsLogElement.SettingName, "IgnoreHealthMonitor"))
                    {
                        List <ResourceKey> list = new List <ResourceKey>
                        {
                            ADResourceKey.Key,
                            ProcessorResourceKey.Local
                        };
                        using (List <ResourceKey> .Enumerator enumerator3 = list.GetEnumerator())
                        {
                            while (enumerator3.MoveNext())
                            {
                                ResourceKey         resourceKey          = enumerator3.Current;
                                SettingsContextBase settingsContextBase2 = new GenericSettingsContext("WlmHealthMonitor", resourceKey.ToString(), null);
                                using (settingsContextBase2.Activate())
                                {
                                    bool config3 = ConfigBase <MRSConfigSchema> .GetConfig <bool>(mrssettingsLogElement.SettingName);

                                    loggingStatsData = new MRSSettingsData
                                    {
                                        Context      = string.Format("{0}={1}", "WlmHealthMonitor", resourceKey.ToString()),
                                        SettingName  = "IgnoreHealthMonitor",
                                        SettingValue = Convert.ToInt32(config3).ToString()
                                    };
                                }
                                this.Write(loggingStatsData);
                            }
                            continue;
                        }
                    }
                    ConfigurationProperty configurationProperty;
                    if (!ConfigBase <MRSConfigSchema> .Schema.TryGetConfigurationProperty(mrssettingsLogElement.SettingName, out configurationProperty))
                    {
                        throw new MRSSettingsLog.BadConfigSettingException(string.Format("Can not find corresponding name of MRS config setting specified by string {0}. Check if the setting name and correct it if needed", mrssettingsLogElement.SettingName));
                    }
                    string settingValue = string.Empty;
                    if (configurationProperty.Type == typeof(bool))
                    {
                        settingValue = ConfigBase <MRSConfigSchema> .GetConfig <bool>(configurationProperty.Name).ToString();
                    }
                    else if (configurationProperty.Type == typeof(int))
                    {
                        settingValue = ConfigBase <MRSConfigSchema> .GetConfig <int>(configurationProperty.Name).ToString();
                    }
                    else if (configurationProperty.Type == typeof(long))
                    {
                        settingValue = ConfigBase <MRSConfigSchema> .GetConfig <long>(configurationProperty.Name).ToString();
                    }
                    else if (configurationProperty.Type == typeof(string))
                    {
                        settingValue = ConfigBase <MRSConfigSchema> .GetConfig <string>(configurationProperty.Name);
                    }
                    else
                    {
                        if (!(configurationProperty.Type == typeof(TimeSpan)))
                        {
                            throw new MRSSettingsLog.BadConfigSettingException(string.Format("Type {0} of a provided setting {1} is not supported by logging functionality. Check and correct list of the settings to be logged", configurationProperty.Type, mrssettingsLogElement.SettingName));
                        }
                        settingValue = ConfigBase <MRSConfigSchema> .GetConfig <TimeSpan>(configurationProperty.Name).ToString();
                    }
                    loggingStatsData = new MRSSettingsData
                    {
                        Context      = "Server",
                        SettingName  = configurationProperty.Name,
                        SettingValue = settingValue
                    };
                    this.Write(loggingStatsData);
                }
                catch (MRSSettingsLog.BadConfigSettingException ex)
                {
                    MRSSettingsLog.PublishPeriodicExceptionNotification(ex.Message);
                }
            }
        }