Ejemplo n.º 1
0
        /// <summary>
        /// Returns feature friendly name.
        /// </summary>
        /// <param name="feature">Feature.</param>
        /// <returns>Feature name.</returns>
        public string GetFeatureName(KnownFeature feature)
        {
            var attribs = typeof(KnownFeature).GetField(feature.ToString())?.GetCustomAttributes(typeof(DescriptionAttribute), false);
            var name    = (attribs == null) || (attribs.Length == 0) ? feature.ToString() : ((DescriptionAttribute)attribs[0]).Description;

            return(name);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Custom: logs feature message and exception.
        /// </summary>
        public static void LogMessage(this ILog log, KnownFeature feature, string message, Exception ex)
        {
            var featureMessage = feature.ToString() + Log.INDENT;

            message = string.IsNullOrEmpty(message) ? featureMessage : featureMessage + message;

            log.LogMessage(message, ex);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves feature options to the storage.
        /// </summary>
        /// <param name="feature">Feature.</param>
        /// <param name="options">Options.</param>
        public void SaveOptions(KnownFeature feature, IDictionary <string, object> options)
        {
            if (options == null)
            {
                return;
            }

            RegistryKey featureKey;

            try
            {
                featureKey = _packageService.GetUserRegistryRootKey(feature.ToString());
            }
            catch
            {
                featureKey = null;
            }
            if (featureKey == null)
            {
                _log.LogMessage($"Failed to saved {feature} options", LOG_CATEGORY);
                return;
            }

            using (featureKey)
            {
                // Delete existing values first
                foreach (var value in featureKey.GetValueNames())
                {
                    featureKey.DeleteValue(value);
                }

                foreach (var option in options.Keys)
                {
                    var customValue = options[option];
                    if (customValue != null)
                    {
                        featureKey.SetValue(option, customValue);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads feature options from the storage.
        /// </summary>
        /// <param name="feature">Feature.</param>
        /// <returns>Options.</returns>
        public IDictionary <string, object> LoadOptions(KnownFeature feature)
        {
            RegistryKey featureKey;

            try
            {
                featureKey = _packageService.GetUserRegistryRootKey(feature.ToString());
            }
            catch
            {
                featureKey = null;
            }

            var options = new Dictionary <string, object>(4, StringComparer.OrdinalIgnoreCase);

            if (featureKey != null)
            {
                using (featureKey)
                {
                    var names = featureKey.GetValueNames();
                    for (int index = 0; index < names.Length; index++)
                    {
                        var name        = names[index];
                        var customValue = featureKey.GetValue(name);
                        if (customValue != null)
                        {
                            options.Add(name, customValue);
                        }
                    }
                }
            }
            else
            {
                _log.LogMessage($"No {feature} options to load", LOG_CATEGORY);
            }

            return(options);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes all feature options from the storage.
        /// </summary>
        /// <param name="feature">Feature.</param>
        public void DeleteOptions(KnownFeature feature)
        {
            RegistryKey featureKey;

            try
            {
                featureKey = _packageService.GetUserRegistryRootKey(feature.ToString(), false);
            }
            catch
            {
                featureKey = null;
            }

            if (featureKey != null)
            {
                using (featureKey)
                {
                    foreach (var value in featureKey.GetValueNames())
                    {
                        featureKey.DeleteValue(value);
                    }
                }
            }
        }