public ProcessViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { _workingDirectory = "."; _filePath = "cmd.exe"; _args = "/c nslookup invalidname"; _outputQueue = new ConcurrentQueue <ProcessData>(); _errorQueue = new ConcurrentQueue <ProcessErrorData>(); _output = new ObservableCollection <ProcessData>(); _errors = new ObservableCollection <ProcessErrorData>(); Output = new ReadOnlyObservableCollection <ProcessData>(_output); Errors = new ReadOnlyObservableCollection <ProcessErrorData>(_errors); _timer = new DispatcherTimer(); _timer.Tick += OnTimerTick; _timer.Interval = TimeSpan.FromMilliseconds(500); _startCommand = commandBuilder.Create(Start, CanStart) .WithAsyncCancellation() .WithBusyNotification(BusyStack) .Build(); }
public DirectoriesViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { var progress = new Progress <int>(); _progress = progress; Log = new LogViewModel(commandBuilder); Excludes = new Patterns(commandBuilder, this); Includes = new Patterns(commandBuilder, this); ProgressViewModel = new ProgressViewModel(commandBuilder, progress, this); _syncCommand = commandBuilder .Create(Synchronize, CanSync) .WithSingleExecution() .WithBusyNotification(BusyStack) .WithCancellation() .Build(); StartTimedSynchronizationCommand = commandBuilder .Create(StartTimedSynchronization, CanStartTimedSynchronization) .WithSingleExecution() .WithBusyNotification(BusyStack) .WithCancellation() .Build(); ExcludeCommand = commandBuilder .Create(Exclude, CanExclude) .WithSingleExecution() .Build(); }
public NavigationViewModel(SynchronizationContext synchronizationContext, IScarletCommandBuilder commandBuilder, LocalizationsViewModel localizationsViewModel) : base(commandBuilder, localizationsViewModel) { var dataGridViewModel = new DataGridViewModel(commandBuilder, synchronizationContext); Add("Lazy Loading / Data-Virtualization", new DataEntriesViewModel(CommandBuilder)); Add("Image Loading + Drag and Drop", new ProcessingImagesViewModel(commandBuilder, new ImageFactory(CommandBuilder))); Add("ConcurrentCommands and state changes", new AsyncStateListViewModel(commandBuilder)); Add("MVVM Live Sorting and Grouping in bound collections", dataGridViewModel); Add("Progress, -notification and dispatcher throtteling", new ProgressViewModel(commandBuilder)); Add("FileSystemBrowser", new FileSystemViewModel(commandBuilder, new FileSystemViewModelFactory(commandBuilder), FileSystemOptionsViewModel.Default)); Add("State changes in a tree structure", new BusyViewModel(commandBuilder)); Add("Geometry rendering", new GeometryRenderViewModel(commandBuilder)); Add("Binding Passwordbox", new PasswordViewModel()); Add("MVVM Grouping", GroupingViewModel.Create(commandBuilder, dataGridViewModel.Items)); Add("Dialog-ViewModel", new DialogViewModel(commandBuilder)); Add("MVVM Terminal/Console", new ProcessViewModel(commandBuilder)); var contextMenu = new ContextMenuViewModels(); var menuitem = new ContextMenuViewModel(); menuitem.Items.Add(new ContextMenuViewModel()); menuitem.Items.Add(new ContextMenuViewModel()); contextMenu.Items[0].Items.Add(menuitem); Add("MVVM ContextMenus", contextMenu); Add("Binding Enum values", new EnumViewModel()); Add("MVVM Toast-Notification", new ToastsViewModel(commandBuilder)); }
public Image(IScarletCommandBuilder commandBuilder, Assembly assembly) : base(commandBuilder) { LoadCommand = commandBuilder.Create(Load, () => true) .WithSingleExecution() .Build(); _assembly = assembly ?? throw new ArgumentNullException(nameof(assembly)); }
public ObservableBusyViewModel(IScarletCommandBuilder commandBuilder, IScarletDispatcher dispatcher) { _observableBusyStack = new ObservableBusyStack(hasItems => { IsBusy = hasItems; Debug.WriteLine("ObservableBusyViewModel is busy: " + hasItems); }); BeBusyCommand = commandBuilder.Create(BeBusyInternal, () => !IsBusy) .WithBusyNotification(_observableBusyStack) .WithSingleExecution() .Build(); }
public DataGridViewModel(IScarletCommandBuilder commandBuilder, SynchronizationContext synchronizationContext) : base(commandBuilder, synchronizationContext, vm => vm.Name, new DataGridDataProvider(commandBuilder, 2000, 50)) { Groups = GroupingViewModel.Create(Items); Filter = IsMatch; PageSize = 50; TotalPageCount = 2000; CurrentPage = 1; }
protected DialogResultViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { CloseCommand = commandBuilder .Create(Close, CanClose) .WithSingleExecution() .WithBusyNotification(BusyStack) .WithCancellation() .Build(); }
public ProgressViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { Maximum = 100; _progress = new DispatcherProgress <double>(Dispatcher, killTheUIWithWork, TimeSpan.FromMilliseconds(50)); _uiBlockingProgress = new Progress <double>(killTheUIWithWork); /// overwhelms the dispatcher and the UI thread with property changed notifications void killTheUIWithWork(double i) => Dispatcher.Invoke(() => Percentage = i).ConfigureAwait(false); }
protected ViewModelBase(IScarletCommandBuilder commandBuilder) : base((commandBuilder?.Messenger) !) { CommandBuilder = commandBuilder ?? throw new ArgumentNullException(nameof(commandBuilder)); Dispatcher = commandBuilder.Dispatcher ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.Dispatcher)); CommandManager = commandBuilder.CommandManager ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.CommandManager)); Exit = commandBuilder.Exit ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.Exit)); WeakEventManager = commandBuilder.WeakEventManager ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.WeakEventManager)); BusyStack = new ObservableBusyStack((hasItems) => IsBusy = hasItems); }
public GroupViewModel(IScarletCommandBuilder commandBuilder, PropertyInfo propertyInfo) : base(commandBuilder) { if (propertyInfo is null) { throw new System.ArgumentNullException(nameof(propertyInfo)); } _name = propertyInfo.Name; GroupDescription = new PropertyGroupDescription(propertyInfo.Name); }
public DialogViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { RunCommand = CommandBuilder.Create(Run, CanRun) .WithBusyNotification(BusyStack) .WithSingleExecution() .WithAsyncCancellation() .Build(); DialogResult = new BoolDialogResultViewModel(commandBuilder); }
public ScarletFile(FileInfo info, IFileSystemParent parent, IScarletCommandBuilder commandBuilder) : base(commandBuilder) { _name = info.Name ?? throw new ArgumentException(nameof(info.Name)); _fullName = info.FullName ?? throw new ArgumentException(info.FullName); _parent = parent ?? throw new ArgumentNullException(nameof(parent)); IsContainer = false; Set(info); }
public Pattern(IScarletCommandBuilder commandBuilder, IScarletCommandManager commandManager, DirectoriesViewModel directoriesViewModel, string value) : base(commandBuilder) { _directoriesViewModel = directoriesViewModel ?? throw new ArgumentNullException(nameof(directoriesViewModel)); Value = value ?? throw new ArgumentNullException(nameof(value)); UpdatePreviewCommand = commandBuilder .Create(UpdatePreview, CanUpdatePreview) .WithSingleExecution() .Build(); }
public Patterns(IScarletCommandBuilder commandBuilder, DirectoriesViewModel directoriesViewModel) : base(commandBuilder) { _directoriesViewModel = directoriesViewModel ?? throw new ArgumentNullException(nameof(directoriesViewModel)); AddCommand = commandBuilder .Create(Add, CanAdd) .WithSingleExecution() .Build(); Messenger.Subscribe <ViewModelListBaseSelectionChanged <Pattern> >(OnSelectionChanged, OnSelectionChangedReceived); }
public GeometryRenderViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { _typeface = new Typeface("Tahoma"); _numberSubstitution = new NumberSubstitution(); _geomtries = Enumerable.Range(0, 5000) .Select(c => (c % (97 - 32)) + 32) .Select(c => (char)c) .Select(c => new GeometryContainer(BuildGeometry(new string(c, 1), _typeface, _numberSubstitution))) .ToArray(); }
public ScarletDrive(DriveInfo info, IScarletCommandBuilder commandBuilder, IFileSystemViewModelFactory factory, IReadOnlyCollection <FileAttributes> fileAttributes, IReadOnlyCollection <FileAttributes> folderAttributes) : base(commandBuilder) { _factory = factory ?? throw new ArgumentNullException(nameof(factory)); _name = info.Name ?? throw new ArgumentException(nameof(info.Name)); _fullName = info.Name; _fileAttributes = fileAttributes; _folderAttributes = folderAttributes; IsContainer = true; Set(info); }
public DataEntriesViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { AddCommand = CommandBuilder.Create(AddNew, CanAddNew) .WithSingleExecution() .WithBusyNotification(BusyStack) .WithCancellation() .Build(); AddRangeCommand = CommandBuilder .Create(AddRange, CanAddRange) .WithSingleExecution() .WithBusyNotification(BusyStack) .Build(); }
public ToastsViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { ShowToastCommand = commandBuilder .Create(ShowToastImpl) .Build(); ShowManyToastsCommand = commandBuilder .Create(ShowManyToastsImpl) .Build(); _title = "Toast-Title"; _body = "Toast-Body"; _toastType = ToastType.Success; }
public BusyViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { _disposables = new Dictionary <INotifyPropertyChanged, IDisposable>(); AddChildCommand = CommandBuilder .Create(InternalAddChildAsync, CanAddChild) .WithBusyNotification(BusyStack) .WithSingleExecution() .Build(); AddContainerCommand = CommandBuilder .Create(InternalAddContainerAsync, CanAddChild) .WithBusyNotification(BusyStack) .WithSingleExecution() .Build(); }
public ProgressViewModel(IScarletCommandBuilder commandBuilder, Progress <int> progress, DirectoriesViewModel directoriesViewModel) : base(commandBuilder) { _directoriesViewModel = directoriesViewModel ?? throw new ArgumentNullException(nameof(directoriesViewModel)); _progress = progress ?? throw new ArgumentNullException(nameof(progress)); _observable = Observable.FromEventPattern <int>( fsHandler => _progress.ProgressChanged += fsHandler, fsHandler => _progress.ProgressChanged -= fsHandler); _disposable = _observable .Publish(ps => ps.Buffer(() => ps.Throttle(TimeSpan.FromSeconds(1)))) .Subscribe(x => ProgressChanged(x.Sum(p => p.EventArgs))); //_disposable = _observable // .Window(TimeSpan.FromSeconds(1)) // .Count() // .Subscribe(ProgressChanged); }
public AsyncStateListViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { for (var i = 0; i < 10; i++) { AddUnchecked(new AsyncStateViewModel(commandBuilder) { DisplayName = "Test " + i, }); } SelectedItem = Items[0]; Filter = ObjectFilter; _timer = new Timer(new TimerCallback(OnTimerElapsed), this, Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(1)); EnableGenerationCommand = new RelayCommand(() => _timer.Change(TimeSpan.Zero, TimeSpan.FromSeconds(1))); DisableGenerationCommand = new RelayCommand(() => _timer.Change(Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(1))); }
public SyncsViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { var dbFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FS"); Directory.CreateDirectory(dbFolder); _connectionString = Path.Combine(dbFolder, "FS.db"); AddCommand = commandBuilder .Create(Add, CanAdd) .WithSingleExecution() .WithBusyNotification(BusyStack) .Build(); CloneCommand = commandBuilder .Create(Clone, CanClone) .WithSingleExecution() .WithBusyNotification(BusyStack) .WithCancellation() .Build(); }
private GroupingViewModel(IScarletCommandBuilder commandBuilder, Func <ListCollectionView> collectionViewFactory, Type type) : base(commandBuilder) { _type = type ?? throw new ArgumentNullException(nameof(type)); _filterCollection = new ConcurrentDictionary <string, GroupViewModel>(); _collectionViewFactory = collectionViewFactory ?? throw new ArgumentNullException(nameof(collectionViewFactory)); AddCommand = commandBuilder.Create(Add, CanAdd) .WithBusyNotification(BusyStack) .WithSingleExecution() .WithCancellation() .Build(); RemoveCommand = commandBuilder .Create <GroupsViewModel>((p, t) => Remove(p, t), (p) => CanRemove(p)) .WithSingleExecution() .WithBusyNotification(BusyStack) .WithCancellation() .Build(); Messenger.Register <GroupingViewModel, ViewModelListBaseSelectionChanging <GroupViewModel> >(this, (r, m) => { if (m.Value is null) { return; } r._filterCollection.TryAdd(m.Value.Name, m.Value); }); Messenger.Register <GroupingViewModel, ViewModelListBaseSelectionChanged <GroupViewModel> >(this, (r, m) => { if (m.Value is null) { return; } r._filterCollection.TryRemove(m.Value.Name, out var _); }); }
public DataGridDataProvider(IScarletCommandBuilder scarletCommandBuilder, int pageCount, int pageSize) { _cache = new List <DataGridRowViewModel>(pageCount * pageSize); _scarletCommandBuilder = scarletCommandBuilder ?? throw new ArgumentNullException(nameof(scarletCommandBuilder)); var page = 1; for (var i = 0; i < pageCount * pageSize; i++) { if (i % pageSize == 0) { page++; } _cache.Add(new DataGridRowViewModel(_scarletCommandBuilder, page) { Id = i, CreatedOn = DateTime.Now, Name = Guid.NewGuid().ToString(), Color = $"#cc{i * 2:X2}{i * 3:X2}", }); } }
public LogViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { }
public BoolDialogResultViewModel(IScarletCommandBuilder commandBuilder, bool model) : base(commandBuilder, model) { }
public DerivedViewModelListBase(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { }
public static GroupingViewModel Create <T>(IScarletCommandBuilder commandBuilder, Func <ListCollectionView> collectionViewFactory) where T : class, INotifyPropertyChanged { return(new GroupingViewModel(commandBuilder, collectionViewFactory, typeof(T))); }
public ImageFactory(IScarletCommandBuilder commandBuilder) { _commandBuilder = commandBuilder ?? throw new System.ArgumentNullException(nameof(commandBuilder)); }
public static GroupingViewModel Create <T>(IScarletCommandBuilder commandBuilder, IEnumerable <T> collection) where T : class, INotifyPropertyChanged { return(new GroupingViewModel(commandBuilder, () => (ListCollectionView)CollectionViewSource.GetDefaultView(collection), typeof(T))); }