Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            _manager = SettingsManager.Instance;
            _manager.Initialize(SettingsManager.SettingsInitialization.IncludeDisplayConfiguration);

            _displayConfiguration = _manager.GetSettingsDisplayConfiguration();

            _sections = new Dictionary<string, SectionViewModel>();

            foreach (SettingDescriptor descriptor in _manager)
            {
                SectionViewModel svm = null;
                if (!_sections.TryGetValue(descriptor.Identifier, out svm))
                {
                    svm = new SectionViewModel(_displayConfiguration.GetIdentifier(descriptor.Identifier));
                    svm.Identifier = descriptor.Identifier;
                    _sections.Add(svm.Identifier, svm);
                }

                SettingInfo setting = _displayConfiguration.GetSetting(descriptor.Identifier, descriptor.SettingItem.Name);
                if (setting == null)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingNotFoundInDisplayConfiguration, descriptor.SettingItem.Name, descriptor.Identifier);
                    continue;
                }
                svm.Add(descriptor, setting);
            }

            // TODO: Sort the list afterwards
        }
        internal GroupedSectionViewModel(SectionViewModel section)
        {
            Children = new List <GroupedSectionViewModel>();

            if (section != null)
            {
                Section = section;

                Identifier = Section.Identifier;
                Header     = Section.DisplayText;
                Order      = section.Order;
            }
        }
        internal GroupedSectionViewModel(SectionViewModel section)
        {
            Children = new List<GroupedSectionViewModel>();

            if (section != null)
            {
                Section = section;

                Identifier = Section.Identifier;
                Header = Section.DisplayText;
                Order = section.Order;
            }
        }
        internal GroupedSectionViewModel(SectionViewModel section)
        {
            Children = new ObservableCollection<GroupedSectionViewModel>();

            ICollectionView view = CollectionViewSource.GetDefaultView(Children);
            view.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));

            if (section != null)
            {
                Section = section;

                Identifier = Section.Identifier;
                Header = Section.DisplayText;
                Order = section.Order;
            }
        }
        internal GroupedSectionViewModel(SectionViewModel section)
        {
            Children = new ObservableCollection <GroupedSectionViewModel>();

            ICollectionView view = CollectionViewSource.GetDefaultView(Children);

            view.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));

            if (section != null)
            {
                Section = section;

                Identifier = Section.Identifier;
                Header     = Section.DisplayText;
                Order      = section.Order;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            _manager = SettingsManager.Instance;
            _manager.Initialize();

            _sections = new Dictionary<string, SectionViewModel>();

            foreach (SettingDescriptor descriptor in _manager)
            {
                SectionViewModel svm = null;
                if (!_sections.TryGetValue(descriptor.Identifier, out svm))
                {
                    svm = new SectionViewModel();
                    svm.Identifier = descriptor.Identifier;
                    _sections.Add(svm.Identifier, svm);
                }

                svm.SettingItems.Add(new SettingItemViewModel(descriptor));
            }
        }
Esempio n. 7
0
        private void BuildSectionsTree(ISettingsService settings)
        {
            Dictionary <string, SectionViewModel> sectionsTemp   = new Dictionary <string, SectionViewModel>();
            Dictionary <string, string>           sectionParents = new Dictionary <string, string>();

            foreach (IdentifierInfo identifier in _displayConfiguration.Identifiers)
            {
                SectionViewModel svm = null;
                if (!sectionsTemp.TryGetValue(identifier.Name, out svm))
                {
                    sectionParents[identifier.Name] = identifier.Parent;

                    svm = new SectionViewModel(identifier);
                    sectionsTemp.Add(svm.Identifier, svm);
                }

                foreach (SettingInfo info in identifier.Settings)
                {
                    SettingItem setting = settings.GetSetting(info.CreateSettingKey());
                    svm.Add(info, setting);
                }
            }

            _sections = new List <GroupedSectionViewModel>();
            // Create hierarchy, starting with the sections that don't have parents
            foreach (var kvp in sectionParents.OrderBy(k => k.Value))
            {
                SectionViewModel section    = sectionsTemp.FirstOrDefault(s => s.Key == kvp.Key).Value;
                string           parentName = kvp.Value;
                bool             hasParent  = (parentName != null);

                // Create group for this item
                GroupedSectionViewModel group = new GroupedSectionViewModel(section);

                if (hasParent)
                {
                    // Find parent group
                    // TODO: If there is no parent group, create a dummy group
                    GroupedSectionViewModel parentGroup = GetAllSections().FirstOrDefault(s => s.Identifier == parentName);
                    if (parentGroup == null)
                    {
                        // Create a dummy group
                        parentGroup            = new GroupedSectionViewModel(null);
                        parentGroup.Identifier = parentName;
                        parentGroup.Header     = parentName;
                        _sections.Add(parentGroup);
                    }

                    parentGroup.Children.Add(group);
                }
                else
                {
                    _sections.Add(group);
                }
            }

            // Always select the "Shared" section
            _sections.First(s => s.Identifier == SectionNameShared).IsSelected = true;

            ICollectionView view = CollectionViewSource.GetDefaultView(_sections);

            view.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));
        }
        private void BuildSectionsTree(ISettingsService settings)
        {
            Dictionary<string, SectionViewModel> sectionsTemp = new Dictionary<string, SectionViewModel>();
            Dictionary<string, string> sectionParents = new Dictionary<string, string>();

            foreach (IdentifierInfo identifier in _displayConfiguration.Identifiers)
            {
                SectionViewModel svm = null;
                if (!sectionsTemp.TryGetValue(identifier.Name, out svm))
                {
                    sectionParents[identifier.Name] = identifier.Parent;

                    svm = new SectionViewModel(identifier);
                    sectionsTemp.Add(svm.Identifier, svm);
                }

                foreach (SettingInfo info in identifier.Settings)
                {
                    SettingItem setting = settings.GetSetting(info.CreateSettingKey());
                    svm.Add(info, setting);
                }
            }

            _sections = new List<GroupedSectionViewModel>();
            // Create hierarchy, starting with the sections that don't have parents
            foreach (var kvp in sectionParents.OrderBy(k => k.Value))
            {
                SectionViewModel section = sectionsTemp.FirstOrDefault(s => s.Key == kvp.Key).Value;
                string parentName = kvp.Value;
                bool hasParent = (parentName != null);

                // Create group for this item
                GroupedSectionViewModel group = new GroupedSectionViewModel(section);

                if (hasParent)
                {
                    // Find parent group
                    // TODO: If there is no parent group, create a dummy group
                    GroupedSectionViewModel parentGroup = GetAllSections().FirstOrDefault(s => s.Identifier == parentName);
                    if (parentGroup == null)
                    {
                        // Create a dummy group
                        parentGroup = new GroupedSectionViewModel(null);
                        parentGroup.Identifier = parentName;
                        parentGroup.Header = parentName;
                        _sections.Add(parentGroup);
                    }

                    parentGroup.Children.Add(group);
                }
                else
                {
                    _sections.Add(group);
                }
            }

            // Always select the "Shared" section
            _sections.First(s => s.Identifier == SectionNameShared).IsSelected = true;

            ICollectionView view = CollectionViewSource.GetDefaultView(_sections);
            view.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));
        }
Esempio n. 9
0
        private void BuildSectionsTree()
        {
            _sections = new Dictionary<string, SectionViewModel>();
            foreach (SettingDescriptor descriptor in _manager)
            {
                SectionViewModel svm = null;
                if (!_sections.TryGetValue(descriptor.Identifier, out svm))
                {
                    svm = new SectionViewModel(_displayConfiguration.GetIdentifier(descriptor.Identifier));
                    svm.Identifier = descriptor.Identifier;
                    _sections.Add(svm.Identifier, svm);
                }

                SettingInfo setting = _displayConfiguration.GetSetting(descriptor.Identifier, descriptor.SettingItem.Name);
                if (setting == null)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingNotFoundInDisplayConfiguration, descriptor.SettingItem.Name, descriptor.Identifier);
                    continue;
                }
                svm.Add(descriptor, setting);
            }

            // Apply sorting
            ICollectionView view = CollectionViewSource.GetDefaultView(this.Sections);
            view.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("DisplayText", ListSortDirection.Ascending));
        }
        /// <summary>
        /// Stores all settings at the service.
        /// </summary>
        /// <param name="parameter">An optional parameter for the command.</param>
        protected override void Execute(object parameter)
        {
            List <Dictionary <SettingKey, SettingItem> > settings = new List <Dictionary <SettingKey, SettingItem> >();
            int iFailedSettings = 0;

            App.Current.Dispatcher.Invoke((Action)(() =>
            {
                foreach (GroupedSectionViewModel gsvm in this.GetParent().GetAllSections())
                {
                    SectionViewModel svm = gsvm.Section;
                    if (svm == null)
                    {
                        continue;
                    }

                    Dictionary <SettingKey, SettingItem> sectionSettings = new Dictionary <SettingKey, SettingItem>();
                    settings.Add(sectionSettings);

                    foreach (CategoryViewModel cvm in svm.CategoryItems)
                    {
                        foreach (SettingItemViewModel sivm in cvm.SettingItems)
                        {
                            object value = null;
                            try
                            {
                                value = sivm.TypeEditor.Value;

                                sivm.Setting.Value = value;
                                sectionSettings.Add(sivm.Info.CreateSettingKey(), sivm.Setting);
                            }
                            catch (Exception ex)
                            {
                                string exMessage = ex.Message;
                                string exHint = Properties.Resources.SettingSaveError_DefaultHints;

                                ValueException vex = ex as ValueException;
                                if (vex != null)
                                {
                                    exHint = vex.Hint;
                                }

                                Logger.Instance.LogException(this, ex);

                                string message = string.Format(Properties.Resources.SettingSaveError, sivm.DisplayText, svm.DisplayText, exMessage, exHint);
                                MessageBox.Show(message, Properties.Resources.SettingSaveError_Title, MessageBoxButton.OK, MessageBoxImage.Error);
                                iFailedSettings++;
                            }
                        }
                    }
                }
            }));

            iFailedSettings += SaveSettingItems(settings);

            string          boxMessage = null;
            MessageBoxImage boxImage   = MessageBoxImage.Information;

            if (iFailedSettings == 0)
            {
                boxMessage = Properties.Resources.SavingSettingsSuccess;
            }
            else
            {
                boxMessage = Properties.Resources.SavingSettingsWithErrors;
                boxImage   = MessageBoxImage.Warning;
            }
            MessageBox.Show(boxMessage, Properties.Resources.SettingSaveFinished_Title, MessageBoxButton.OK, boxImage);
        }
Esempio n. 11
0
        private void BuildSectionsTree()
        {
            Dictionary<string, SectionViewModel> sectionsTemp = new Dictionary<string, SectionViewModel>();
            Dictionary<string, string> sectionParents = new Dictionary<string, string>();

            foreach (SettingDescriptor descriptor in _manager)
            {
                SectionViewModel svm = null;
                if (!sectionsTemp.TryGetValue(descriptor.Identifier, out svm))
                {
                    IdentifierInfo identifier = _displayConfiguration.GetIdentifier(descriptor.Identifier);
                    sectionParents[identifier.Name] = identifier.Parent;

                    svm = new SectionViewModel(identifier);
                    svm.Identifier = descriptor.Identifier;
                    sectionsTemp.Add(svm.Identifier, svm);
                }

                SettingInfo setting = _displayConfiguration.GetSetting(descriptor.Identifier, descriptor.SettingItem.Name);
                if (setting == null)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingNotFoundInDisplayConfiguration, descriptor.SettingItem.Name, descriptor.Identifier);
                    continue;
                }
                svm.Add(descriptor, setting);
            }

            _sections = new List<GroupedSectionViewModel>();
            // Create hierarchy, starting with the sections that don't have parents
            foreach (var kvp in sectionParents.OrderBy(k => k.Value))
            {
                SectionViewModel section = sectionsTemp.FirstOrDefault(s => s.Key == kvp.Key).Value;
                string parentName = kvp.Value;
                bool hasParent = (parentName != null);

                // Create group for this item
                GroupedSectionViewModel group = new GroupedSectionViewModel(section);

                if (hasParent)
                {
                    // Find parent group
                    // TODO: If there is no parent group, create a dummy group
                    GroupedSectionViewModel parentGroup = GetAllSections().FirstOrDefault(s => s.Identifier == parentName);
                    if (parentGroup == null)
                    {
                        // Create a dummy group
                        parentGroup = new GroupedSectionViewModel(null);
                        parentGroup.Identifier = parentName;
                        parentGroup.Header = parentName;
                        _sections.Add(parentGroup);
                    }

                    parentGroup.Children.Add(group);
                }
                else
                {
                    _sections.Add(group);
                }
            }

            // Always select the "Shared" section
            _sections.First(s => s.Identifier == SectionNameShared).IsSelected = true;

            // Apply sorting
            ICollectionView view = CollectionViewSource.GetDefaultView(this.Sections);
            view.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));
        }