public CompareOptionsViewModel(ISchedulers schedulers, CompareOptions compareOptions) { ContextLinesInput = new IntegerInputViewModel(schedulers, compareOptions.ContextLines, 0) .DisposeWith(_disposable); InterhunkLinesInput = new IntegerInputViewModel(schedulers, compareOptions.InterhunkLines, 0) .DisposeWith(_disposable); DiffAlgorithm = new EnumViewModel <DiffAlgorithm>(compareOptions.Algorithm) .DisposeWith(_disposable); IndentHeuristic = new ViewSubject <bool>(compareOptions.IndentHeuristic) .DisposeWith(_disposable); SimilarityOptions = new SimilarityOptionsViewModel(schedulers, compareOptions.Similarity) .DisposeWith(_disposable); CompareOptionsObservable = Observable .CombineLatest(ContextLinesInput.Value, InterhunkLinesInput.Value, DiffAlgorithm.Value, IndentHeuristic, SimilarityOptions.SimilarityObservable, (contextLines, interhunkLines, algorithm, indentHeuristic, similarityOptions) => new CompareOptions() { ContextLines = contextLines, InterhunkLines = interhunkLines, Similarity = similarityOptions, IncludeUnmodified = false, Algorithm = algorithm, IndentHeuristic = indentHeuristic, }); }
public DiffViewModel( ISchedulers schedulers, IObservable <DiffViewModelInput> input) { TreeDiff = new ViewSubject <Variant <List <TreeEntryChanges>, Unexpected> >(new Unexpected(NoCommitSelectedMessage)) .DisposeWith(_disposables); SelectionInfo = new ViewSubject <TSelectionInfo>( new TSelectionInfo(NoCommitSelectedMessage)) .DisposeWith(_disposables); IndexSelected = new ViewSubject <bool>(false) .DisposeWith(_disposables); var focusChangedCommand = ReactiveCommand .Create <bool, bool>(indexSelected => indexSelected, schedulers.Dispatcher) .DisposeWith(_disposables); FocusChangedCommand = focusChangedCommand; focusChangedCommand .Merge(input .Where(d => d.OldCommit is null) .Where(d => d.NewCommit is null || !d.NewCommit.Is <DiffTargets>()) .Select(_ => false)) .Subscribe(IndexSelected) .DisposeWith(_disposables);
public IEnumerable <ViewSubject> GetAll() { var result = from s in context.Subjects join e in context.Exams on s.Exam.Id equals e.Id select new { s.SubjectID, s.SubjectName, s.Status, s.CreatedDate, e.NameExam }; List <ViewSubject> list = new List <ViewSubject>(); foreach (var item in result) { ViewSubject viewSubject = new ViewSubject(); viewSubject.SubjectID = item.SubjectID; viewSubject.SubjectName = item.SubjectName; viewSubject.CreatedDate = item.CreatedDate; viewSubject.Status = item.Status; viewSubject.NameExam = item.NameExam; list.Add(viewSubject); } return(list); }
private void viewSubjectsToolStripMenuItem_Click(object sender, EventArgs e) { MainPanel.Controls.Clear(); if (viewSubj != null) { viewSubj.Close(); } viewSubj = new ViewSubject(); FormSetUp(viewSubj); }
public RefSelectionViewModel(string friendlyName, string canonicalName, bool selected, ISchedulers schedulers) { Selected = new ViewSubject <bool>(selected) .DisposeWith(_disposables); CanonicalName = canonicalName; FriendlyName = friendlyName; SelectCommand = ReactiveCommand.Create <bool, bool>(p => p, schedulers.Dispatcher) .DisposeWith(_disposables); RefSelectionObservable = SelectCommand .Select(s => new RefSelection(canonicalName, friendlyName, s)) .StartWith(new RefSelection(canonicalName, friendlyName, selected)); }
public IntegerInputViewModel(ISchedulers schedulers, int value, int min = int.MinValue, int max = int.MaxValue) { if (value > max || value < min) { throw new ArgumentException($"{nameof(value)} out of bounds: {value}.", nameof(value)); } Text = new ViewSubject <string>(value.ToString()) .DisposeWith(_disposable); Value = Text .Select(text => int.TryParse(text, out int res) ? (int?)res : null) .SkipNull(); Valid = new ViewSubject <bool>(false) .DisposeWith(_disposable); Text .Select(text => int.TryParse(text, out var _)) .Subscribe(Valid) .DisposeWith(_disposable); var increase = ReactiveCommand.Create <object, object>( canExecute: Value .Select(newVal => newVal < max), execute: (param) => param, scheduler: schedulers.Dispatcher) .DisposeWith(_disposable); Increase = increase; increase .WithLatestFrom(Value, (_, newVal) => (newVal + 1).ToString()) .Subscribe(Text) .DisposeWith(_disposable); var decrease = ReactiveCommand.Create <object, object>( canExecute: Value .Select(newVal => newVal > min), execute: (param) => param, scheduler: schedulers.Dispatcher) .DisposeWith(_disposable); Decrease = decrease; decrease .WithLatestFrom(Value, (_, newVal) => (newVal - 1).ToString()) .Subscribe(Text) .DisposeWith(_disposable); }
public RefsViewModel(List <RefSelectionViewModel> refs, string?headCanonicalName, ISchedulers schedulers) { Refs = refs; var selectAllRefsCommand = ReactiveCommand.Create <bool?, bool?>(isChecked => isChecked, schedulers.Dispatcher); SelectAllRefsCommand = selectAllRefsCommand; AllRefsSelected = new ViewSubject <bool?>(refs.All(r => r.Selected.Value) ? true : (refs.Any(r => r.Selected.Value) ? null : (bool?)false)); var singleSelections = refs .Select((r, i) => r.RefSelectionObservable .Select(rs => new { rs, i })) .Merge() .Select(s => new Variant <Tuple <RefSelection, int>, SelectAllType>(Tuple.Create(s.rs, s.i))) .Merge(selectAllRefsCommand .StartWith(AllRefsSelected.Value) .Select(sa => new Variant <Tuple <RefSelection, int>, SelectAllType>(!sa.HasValue ? SelectAllType.Undetermined : sa.Value?SelectAllType.AllSelected: SelectAllType.NoneSelected))) .Scan( Tuple.Create(refs.Select(_ => (RefSelection?)null).ToList(), SelectAllType.Undetermined), (last, current) => current.Visit( newSelection => { var res = last.Item2 == SelectAllType.Undetermined ? last.Item1.ToList() : last.Item1.Select(rs => rs is null ? null : new RefSelection(rs.CanonicalName, rs.FriendlyName, last.Item2 == SelectAllType.AllSelected)).ToList(); res[newSelection.Item2] = newSelection.Item1; return(Tuple.Create(res, SelectAllType.Undetermined)); }, sa => Tuple.Create(last.Item1, sa == SelectAllType.Undetermined && last.Item1.All(r => r?.Selected ?? false) ? SelectAllType.NoneSelected : sa))) .Select(x => x.Item1.ToList()) .SkipManyNull <RefSelection, List <RefSelection?>, List <RefSelection> >(); var selections = singleSelections .StartWith(refs .Select(r => new RefSelection(r.CanonicalName, r.FriendlyName, r.Selected.Value)) .ToList()) .Merge(selectAllRefsCommand .WithLatestFrom(singleSelections, (isChecked, refSelections) => new { isChecked, refSelections }) .Select(d => { var isChecked = (d.isChecked is bool) ? d.isChecked : (d.refSelections.All(r => r.Selected) ? false : d.isChecked); return(d.refSelections.Select(@ref => new RefSelection(@ref.CanonicalName, @ref.FriendlyName, isChecked is null ? @ref.Selected : (bool)isChecked)).ToList()); }));
public Subscription(ViewSubject <T> subject, IObserver <T> observer) { _subject = subject; _observer = observer; }
public EnumViewModel(TEnum value) { Values = Enum.GetValues(typeof(TEnum)).Cast <TEnum>().ToList(); Value = new ViewSubject <TEnum>(value); }
public LogGraph(ISchedulers schedulers, IObservable <LogGraphInput> input) { const int chunkSize = 1000; var scrolledBottom = ReactiveCommand.Create <object?, object?>(p => p, schedulers.Dispatcher); ScrolledBottom = scrolledBottom; LogGraphNodes = new ViewSubject <Variant <GraphType, Unexpected> >(new GraphType()) .DisposeWith(_disposable); SelectedNode = new ViewSubject <LogGraphNode?>(null) .DisposeWith(_disposable); SecondarySelectedNode = new ViewSubject <LogGraphNode?>(null) .DisposeWith(_disposable); input .Select(d => new LogGraphInput(d.Repository, d.SelectedBranches.Where(branch => branch.Selected).ToList())) .WithLatestFrom(LogGraphNodes, (d, oldNodes) => { var firstChunk = oldNodes.Visit( graph => Math.Max(chunkSize, graph.Count), _ => chunkSize); return(CreateGraph(d.Repository, d.SelectedBranches !) .ToObservable(schedulers.ThreadPool) .Select((node, i) => new { node, i }) .GroupBy(data => data.i < firstChunk) .Select(g => g.Buffer(g.Key ? firstChunk : chunkSize)) .Switch() .Zip(Observable.Return <object?>(null).Concat(scrolledBottom), (data, _) => data.Select(data => data.node).ToList()) .Scan( new NodesData() { Index = 0, Batch = new GraphType() }, (last, current) => new NodesData() { Index = last.Index + 1, Batch = current }) .Select(data => new Variant <NodesData, string>(data)) .Catch((Exception e) => Observable.Return(new Variant <NodesData, string>(e.Message))) .ObserveOn(schedulers.Dispatcher)); }) .Switch() .Subscribe(var => var.Visit( data => { if (data.Index == 1) { LogGraphNodes.OnNext(new GraphType(data.Batch)); } else { foreach (var node in data.Batch) { LogGraphNodes.Value.First.Add(node); } } }, error => LogGraphNodes.OnNext(new Unexpected(error)))) .DisposeWith(_disposable); }