コード例 #1
0
        private void PopulateSourcesAndSVMLookup(IEnumerable <ISource> sources)
        {
            foreach (var s in sources)
            {
                var svm = new SourceViewModel(s);
                this.sources.Add(svm);

                SVMLookup.Add(s, svm);
            }

            sourcesView        = new CollectionViewSource();
            sourcesView.Source = this.sources;

            sourcesView.SortDescriptions.Add(new SortDescription("Disabled", ListSortDirection.Ascending));
            sourcesView.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending));
        }
コード例 #2
0
        private void RemoveSource(SourceViewModel svm)
        {
            Sources.Remove(svm);
            SVMLookup.Remove(svm.Data);

            List <ItemViewModel> itemsToRemove = new List <ItemViewModel>();

            foreach (var i in items)
            {
                if (i.SourceName == svm.SourceName)
                {
                    itemsToRemove.Add(i);
                }
            }

            foreach (var i in itemsToRemove)
            {
                items.Remove(i);
            }
        }
コード例 #3
0
        private void SetOriginalSource(SourceViewModel svm)
        {
            originalSource = svm;
            RaisePropertyChanged(IDVisibilityProperty);

            var source = svm.Data;

            IDText   = source.ID.Value.ToString();
            Name     = source.SourceName;
            Url      = SourceViewModel.GetUrl(source);
            Disabled = svm.Disabled;

            CanSelectProvider = false;
            SelectedProvider  = providers.First(p => p.ProviderId == source.ProviderID);

            //TODO:ADD
            //TypeComboBox.SelectedItem = providers.First(p => p.ProviderId == source.ProviderID);
            //TypeComboBox.IsEnabled = false;

            SetSelectedColor(SourceViewModel.GetColor(source));
        }
コード例 #4
0
ファイル: ItemViewModel.cs プロジェクト: allanx2000/Watcher
 public ItemViewModel(IDataItem item, SourceViewModel sourceViewModel)
     : base(item)
 {
     svm = sourceViewModel;
     svm.PropertyChanged += ((e, args) => RefreshViewModel());
 }
コード例 #5
0
        private void ProcessParameters()
        {
            try
            {
                if (SelectedProvider == null)
                {
                    throw new Exception("No provider selected");
                }

                var meta = SelectedProvider.GetMetaFields();

                foreach (Control c in optionsGrid.Children)
                {
                    if (c.Tag != null)
                    {
                        string id    = c.Tag.ToString();
                        string value = null;

                        if (c is TextBox)
                        {
                            value = ((TextBox)c).Text;
                        }
                        else if (c is ComboBox)
                        {
                            value = ((ComboBox)c).Text;
                        }
                        else if (c is CheckBox)
                        {
                            value = ((CheckBox)c).IsChecked.ToString();
                        }
                        else
                        {
                            //Error
                        }


                        var item = meta.FirstOrDefault(x => x.ID == id);

                        if (item != null) //TODO: Disabled hack
                        {
                            item.SetValue(value);
                        }
                    }
                }

                var newSource = selectedProvider.CreateNewSource(
                    selectedProvider.HasUniqueName ? Name : null //Probably just use name
                    , null, meta);

                if (selectedProvider.HasUrlField)
                {
                    newSource.SetMetaData(new MetaDataObject(SourceViewModel.URL, SourceViewModel.URL, url));
                }

                newSource.SetMetaData(new MetaDataObject(SourceViewModel.UPDATES_COLOR, SourceViewModel.UPDATES_COLOR, SourceViewModel.SerializeColor(selectedColor)));
                newSource.SetMetaData(new MetaDataObject(SourceViewModel.DISABLED, SourceViewModel.DISABLED, disabled));

                if (originalSource != null)
                {
                    newSource.SetID(originalSource.Data.ID.Value);

                    datastore.UpdateSource(newSource);

                    originalSource.SetSource(newSource);
                }
                else
                {
                    datastore.AddSource(newSource);

                    originalSource = new SourceViewModel(newSource);
                }

                window.Close();
            }
            catch (Exception ex)
            {
                MessageBoxFactory.ShowError(ex);
            }
        }
コード例 #6
0
        public SourceEditorViewModel(Window window, Grid optionsGrid, List <IProvider> providers, IDataStore dataStore, SourceViewModel svm = null)
        {
            this.window      = window;
            this.optionsGrid = optionsGrid;

            this.Providers = providers;
            this.datastore = dataStore;

            if (svm != null)
            {
                SetOriginalSource(svm);
            }
        }