Exemplo n.º 1
0
        public static T Get <T>(this ITailSettingService service, string name, T defaultValue = default(T))
        {
            var value = service.Get(name);

            if (value != null)
            {
                var converter = TypeDescriptor.GetConverter(typeof(T));
                return((T)converter.ConvertFromInvariantString(value));
            }
            return(defaultValue);
        }
Exemplo n.º 2
0
        public SettingsViewModel(ITailProviderService service, ITailSettingService settingsService, GeneralSettingsViewModel generalSettings)
        {
            _settingsService = settingsService;
            _viewModels      = new Dictionary <Type, ITailSettings>();
            _providers       = new List <TailProviderInfo>();

            var types = service.GetProviderTypes();

            foreach (var type in types)
            {
                var viewModel = service.CreateSettings(type);
                if (viewModel != null)
                {
                    var displayName = service.GetDisplayName(type);
                    if (!string.IsNullOrWhiteSpace(displayName))
                    {
                        // Load the settings for the view model.
                        viewModel.Load(_settingsService);

                        // Add the settings to the collection.
                        _viewModels.Add(viewModel.GetType(), viewModel);
                        _providers.Add(new TailProviderInfo(displayName, viewModel.GetType()));
                    }
                }
            }

            // Sort all providers by name.
            _providers = _providers.OrderBy(x => x.Name).ToList();

            // Insert the general settings.
            _viewModels.Add(typeof(GeneralSettingsViewModel), generalSettings);
            _providers.Insert(0, new TailProviderInfo("General", typeof(GeneralSettingsViewModel)));

            // Select the first provider in the list.
            if (_providers.Count > 0)
            {
                SelectedProvider = Providers[0];
                ToggleProvider(Providers[0]);
            }

            DisplayName = "Settings";
        }
 public void Save(ITailSettingService service)
 {
 }
 public void Load(ITailSettingService service)
 {
 }
Exemplo n.º 5
0
 public void Save(ITailSettingService service)
 {
 }
Exemplo n.º 6
0
 public void Load(ITailSettingService service)
 {
 }
 public void Save(ITailSettingService service)
 {
     service.Set("Example.DoMagic", _doMagic);
 }
 public void Load(ITailSettingService service)
 {
     _doMagic = service.Get("Example.DoMagic", false);
 }
Exemplo n.º 9
0
        public static void Set <T>(this ITailSettingService service, string name, T value)
        {
            var converter = TypeDescriptor.GetConverter(typeof(T));

            service.Set(name, converter.ConvertToInvariantString(value));
        }