public MainWindow(IInteractionService interactions) { InitializeComponent(); ViewModel = new MainViewModel(); this.interactions = interactions ?? Locator.Current.GetService<IInteractionService>(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this .Events() .Closing .Subscribe(async e => await this.interactions .WindowClosing.Handle(Unit.Default)) .DisposeWith(disposables); this .OneWayBind(ViewModel, vm => vm.Router, v => v.ViewHost.Router) .DisposeWith(disposables); }); }
public ConnectionView() { InitializeComponent(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this // ViewModel.From.ConnectionPoint -> Arrow.From .Bind(ViewModel, vm => vm.From.ConnectionPoint, v => v.Arrow.From) .DisposeWith(disposables); this // ViewModel.To.ConnectionPoint -> Arrow.To .Bind(ViewModel, vm => vm.To.ConnectionPoint, v => v.Arrow.To) .DisposeWith(disposables); }); }
public static IDisposalContinuation DisposeAfer( this IDisposable disposable, TimeSpan duration) { var cancellationTokenSource = new CancellationTokenSource(duration); return(disposable.DisposeWith(cancellationTokenSource.Token)); }
public override void Execute() { Result = Observable.Interval(TimeSpan.FromSeconds(Seconds)).Subscribe(_ => { Tick(); }).DisposeWith(System); if (DisposeWith != null) { Result.DisposeWith(DisposeWith); } }
public override void Execute() { Result = Observable.Interval(new TimeSpan(0, 0, Minutes, Seconds, 0)).Subscribe(_ => { Tick(); }).DisposeWith(System); if (DisposeWith != null) { Result.DisposeWith(DisposeWith); } }
public void DisposeWith_ShouldAddSutToComposite( CompositeDisposable compositeDisposable, IDisposable sut) { //arrange //act sut.DisposeWith(compositeDisposable); //assert compositeDisposable.Should().Contain(sut); }
public ConnectorView() { InitializeComponent(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this // ViewModel.IsEnabled -> IsEnabled .OneWayBind(ViewModel, vm => vm.IsEnabled, v => v.IsEnabled) .DisposeWith(disposables); this // ViewModel.IsConnected -> ConnectorButton.Content .WhenAnyValue(v => v.ViewModel.IsConnected) .Select(ic => ic ? "\xECCC" : string.Empty) .BindTo(this, v => v.ConnectorButton.Content) .DisposeWith(disposables); this // ViewModel.ConnectorCommand -> ConnectorButton.Command .OneWayBind(ViewModel, vm => vm.ConnectorCommand, v => v.ConnectorButton.Command) .DisposeWith(disposables); this // Transform coordinates of the connector to the coordinates of the container .Events() .LayoutUpdated .Where(_ => Container != null) // while Container is set .Where(_ => Container.IsAncestorOf(this)) // while it's still the ancestor .Select(_ => this.TransformToAncestor(Container) // get transform to Container .Transform(new Point(ActualWidth / 2, // transform the center ActualHeight / 2))) .BindTo(this, v => v.ConnectionPoint) // set ConnectionPoint .DisposeWith(disposables); this // ViewModel.ConnectionPoint <-> ConnectionPoint .Bind(ViewModel, vm => vm.ConnectionPoint, v => v.ConnectionPoint) .DisposeWith(disposables); }); }
/// <summary> /// Binds the overlay. /// </summary> protected void BindOverlay() { InitOverlayLoop(); overlayDisposable?.Dispose(); overlayDisposable = overlayProgressHandler.Message.Subscribe(s => { QueueOverlay(s); }); if (Disposables != null) { overlayDisposable.DisposeWith(Disposables); } }
public ProxyView() { InitializeComponent(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this .BindCommand(ViewModel, vm => vm.StartCommand, v => v.StartButton) .DisposeWith(disposables); this .BindCommand(ViewModel, vm => vm.StopCommand, v => v.StopButton) .DisposeWith(disposables); this .WhenAnyValue(v => v.ViewModel.IsStarted) .Select(v => v ? Visibility.Visible : Visibility.Hidden) .BindTo(this, v => v.GoofySvg.Visibility) .DisposeWith(disposables); this .WhenAnyValue(v => v.ViewModel.IsStarted) .Select(v => v ? Visibility.Hidden : Visibility.Visible) .BindTo(this, v => v.HappySvg.Visibility) .DisposeWith(disposables); }); }
public OperationDialog() { InitializeComponent(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // Operation -> AdditionRadioButton.IsChecked .WhenAnyValue(v => v.Operation) .Select(o => o == OperationType.Addition) .BindTo(this, v => v.AdditionRadioButton.IsChecked) .DisposeWith(disposables); this // Operation -> SubtractionRadioButton.IsChecked .WhenAnyValue(v => v.Operation) .Select(o => o == OperationType.Subtraction) .BindTo(this, v => v.SubtractionRadioButton.IsChecked) .DisposeWith(disposables); this // AdditionRadioButton.IsChecked -> Operation .WhenAnyValue(v => v.AdditionRadioButton.IsChecked) .Where(v => v == true) .Select(_ => OperationType.Addition) .BindTo(this, v => v.Operation) .DisposeWith(disposables); this // SubtractionRadioButton.IsChecked -> Operation .WhenAnyValue(v => v.SubtractionRadioButton.IsChecked) .Where(v => v == true) .Select(_ => OperationType.Subtraction) .BindTo(this, v => v.Operation) .DisposeWith(disposables); }); }
public NodeControl() { IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // Make sure node X stays within bounds .WhenAnyValue(v => v.ViewModel.X, // node X changed v => v.ActualWidth, // node width changed v => v.Container.ActualWidth, // container resized (a, b, c) => new { X = a, Width = b, ContainerWidth = c }) .Select(e => e.X > 0 ? e.X + e.Width > e.ContainerWidth ? e.ContainerWidth - e.Width : e.X : 0) .BindTo(ViewModel, vm => vm.X) .DisposeWith(disposables); this // Make sure node Y stays within bounds .WhenAnyValue(v => v.ViewModel.Y, // node Y changed v => v.ActualHeight, // node height changed v => v.Container.ActualHeight, // container resized (a, b, c) => new { Y = a, Height = b, ContainerHeight = c }) .Select(e => e.Y > 0 ? e.Y + e.Height > e.ContainerHeight ? e.ContainerHeight - e.Height : e.Y : 0) .BindTo(ViewModel, vm => vm.Y) .DisposeWith(disposables); }); }
public OperationNodeView(IMixerViewModel mixer = null) { InitializeComponent(); this.mixer = mixer ?? Locator.Current.GetService <IMixerViewModel>(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this // ViewModel.Title -> TitleTextBlock.Text .OneWayBind(ViewModel, vm => vm.Title, v => v.TitleTextBlock.Text) .DisposeWith(disposables); this // ViewModel.Width <-> Thumb.Width .Bind(ViewModel, vm => vm.Width, v => v.Thumb.Width) .DisposeWith(disposables); this // ViewModel.Height <-> Thumb.Height .Bind(ViewModel, vm => vm.Height, v => v.Thumb.Height) .DisposeWith(disposables); this // ViewModel.InputA -> InputAConnector.ViewModel .WhenAnyValue(v => v.ViewModel.InputA) .BindTo(this, v => v.InputAConnector.ViewModel) .DisposeWith(disposables); this // ViewModel.InputB -> InputBConnector.ViewModel .WhenAnyValue(v => v.ViewModel.InputB) .BindTo(this, v => v.InputBConnector.ViewModel) .DisposeWith(disposables); this // ViewModel.Output -> OutputConnector.ViewModel .WhenAnyValue(v => v.ViewModel.Output) .BindTo(this, v => v.OutputConnector.ViewModel) .DisposeWith(disposables); Thumb // Thumb.DragDelta.HorizontalChange -> ViewModel.X .Events() .DragDelta .Select(e => ViewModel.X + e.HorizontalChange) .BindTo(ViewModel, vm => vm.X) .DisposeWith(disposables); Thumb // Thumb.DragDelta.VerticalChange -> ViewModel.Y .Events() .DragDelta .Select(e => ViewModel.Y + e.VerticalChange) .BindTo(ViewModel, vm => vm.Y) .DisposeWith(disposables); this // ViewModel.EditNodeCommand -> EditNodeButton.Command .OneWayBind(ViewModel, vm => vm.EditNodeCommand, v => v.EditNodeButton.Command) .DisposeWith(disposables); this // ViewModel.DeleteNodeCommand -> DeleteNodeButton.Command .OneWayBind(ViewModel, vm => vm.DeleteNodeCommand, v => v.DeleteNodeButton.Command) .DisposeWith(disposables); this // Make Thumb click-through when a node or connection is being added .WhenAnyValue(v => v.mixer.IsNodeBeingAdded, v => v.mixer.ConnectingConnector, (a, b) => !a && b == null) .BindTo(this, v => v.Thumb.IsHitTestVisible) .DisposeWith(disposables); }); }
public MixerView(IInteractionService interactions = null) { InitializeComponent(); this.interactions = interactions ?? Locator.Current.GetService <IInteractionService>(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this // ViewModel.Nodes -> Nodes.ItemsSource .OneWayBind(ViewModel, vm => vm.Nodes, v => v.Nodes.ItemsSource) .DisposeWith(disposables); this // ViewModel.Connections -> Connections.ItemsSource .OneWayBind(ViewModel, vm => vm.Connections, v => v.Connections.ItemsSource) .DisposeWith(disposables); this // ViewModel.AddColorNodeCommand -> AddColorNodeButton.Command .OneWayBind(ViewModel, vm => vm.AddColorNodeCommand, v => v.AddColorNodeButton.Command) .DisposeWith(disposables); this // ViewModel.AddOperationNodeCommand -> AddOperationNodeButton.Command .OneWayBind(ViewModel, vm => vm.AddOperationNodeCommand, v => v.AddOperationNodeButton.Command) .DisposeWith(disposables); this // ViewModel.AddResultNodeCommand -> AddResultNodeButton.Command .OneWayBind(ViewModel, vm => vm.AddResultNodeCommand, v => v.AddResultNodeButton.Command) .DisposeWith(disposables); this // Handle new node point request by ViewModel .interactions .GetNewNodePoint .RegisterHandler(i => HandleNewNodePointRequest(i)) .DisposeWith(disposables); this // Show an arrow following mouse pointer when a connection is being created .WhenAnyValue(v => v.ViewModel.ConnectingConnector) .Select(c => c == null ? Visibility.Hidden : Visibility.Visible) .Delay(TimeSpan.FromMilliseconds(150), RxApp.MainThreadScheduler) .BindTo(this, v => v.Arrow.Visibility) .DisposeWith(disposables); this // Set the point where the arrow should start from .WhenAnyValue(v => v.ViewModel.ConnectingConnector.ConnectionPoint) .BindTo(this, v => v.Arrow.From) .DisposeWith(disposables); Nodes // Make the arrow follow mouse pointer .Events() .MouseMove .Where(_ => ViewModel.ConnectingConnector != null) .Select(e => e.GetPosition(Nodes)) .BindTo(this, v => v.Arrow.To) .DisposeWith(disposables); this // Cancel connection creating on right mouse button click .WhenAnyValue(v => v.ViewModel.ConnectingConnector, v => v.ViewModel.ConnectedConnector, (from, to) => new { From = from, To = to }) .Where(c => c.From != null && c.To == null) .SelectMany(_ => Nodes.Events().MouseRightButtonDown) .Select(_ => default(IConnector)) .BindTo(ViewModel, vm => vm.ConnectingConnector) .DisposeWith(disposables); this // Cancel connection creating on Escape button press .WhenAnyValue(v => v.ViewModel.ConnectingConnector, v => v.ViewModel.ConnectedConnector, (from, to) => new { From = from, To = to }) .Where(c => c.From != null && c.To == null) .SelectMany(_ => ViewModel.MainWindowKeyDown .Where(e => e.Key == Key.Escape)) .Select(_ => default(IConnector)) .BindTo(ViewModel, vm => vm.ConnectingConnector) .DisposeWith(disposables); }); }
public Arrow() { InitializeComponent(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // Sets the margin of the arrow box .WhenAnyValue(v => v.From, v => v.To, (from, to) => new Thickness { Left = Math.Min(from.X, to.X), Top = Math.Min(from.Y, to.Y), Right = LineArrow.Margin.Right, Bottom = LineArrow.Margin.Bottom }) .BindTo(this, v => v.LineArrow.Margin) .DisposeWith(disposables); this // Sets the bend amount of the arrow .WhenAnyValue(v => v.From, v => v.To, (from, to) => from.X > to.X ? from.Y > to.Y ? -0.5 : 0.5 : from.Y > to.Y ? 0.5 : -0.5) .BindTo(this, v => v.LineArrow.BendAmount) .DisposeWith(disposables); this // Sets the start corner of the arrow .WhenAnyValue(v => v.From, v => v.To, (from, to) => from.X > to.X ? from.Y > to.Y ? CornerType.BottomRight : CornerType.TopRight : from.Y > to.Y ? CornerType.BottomLeft : CornerType.TopLeft) .BindTo(this, v => v.LineArrow.StartCorner) .DisposeWith(disposables); this // Sets the width of the arrow box .WhenAnyValue(v => v.From, v => v.To, (from, to) => Math.Abs(to.X - from.X)) .BindTo(this, v => v.LineArrow.Width) .DisposeWith(disposables); this // Sets the height of the arrow box .WhenAnyValue(v => v.From, v => v.To, (from, to) => Math.Abs(to.Y - from.Y)) .BindTo(this, v => v.LineArrow.Height) .DisposeWith(disposables); }); }
public static void DisposeWith <T>(this IDisposable disposable, BaseController <T> controller) where T : class, new() { disposable.DisposeWith(controller.ControllerDisposable); }
public MainWindow(IInteractionService interactions) { InitializeComponent(); ViewModel = Application.Current // get the bootstrapper from App resources .FindResource("MainWindowViewModel") as IMainWindowViewModel; this.interactions = interactions ?? Locator.Current.GetService <IInteractionService>(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // ViewModel -> DataContext .WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this // KeyDown -> ViewModel.KeyDown .WhenAnyValue(v => v.ViewModel) .Select(_ => this.Events().KeyDown) .BindTo(ViewModel, vm => vm.KeyDown) .DisposeWith(disposables); this // Handle GetNodeColor interaction .interactions .GetNodeColor .RegisterHandler(async interaction => { var dialog = new ColorDialog { Color = interaction.Input // dialog edits what the node sent here }; await this.ShowMetroDialogAsync(dialog); var isAccepted = await dialog.WaitUntilClosedAsync(); await this.HideMetroDialogAsync(dialog); if (isAccepted) { interaction.SetOutput(dialog.Color); // return new color } else { interaction.SetOutput(interaction.Input); // return old color } }) .DisposeWith(disposables); this .interactions .GetNodeOperation .RegisterHandler(async interaction => { var dialog = new OperationDialog { Operation = interaction.Input // dialog edits what the node sent here }; await this.ShowMetroDialogAsync(dialog); var isAccepted = await dialog.WaitUntilClosedAsync(); await this.HideMetroDialogAsync(dialog); if (isAccepted) { interaction.SetOutput(dialog.Operation); // return new operation } else { interaction.SetOutput(interaction.Input); // return old operation } }) .DisposeWith(disposables); }); }
public ColorDialog() { InitializeComponent(); IDisposable activation = null; activation = this.WhenActivated(disposables => { activation .DisposeWith(disposables); this // Color -> ColorRectangle.Fill .WhenAnyValue(v => v.Color) .Select(c => new SolidColorBrush(c)) .BindTo(this, v => v.ColorRectangle.Fill) .DisposeWith(disposables); this // Color.R -> RedSlider.Value .WhenAnyValue(v => v.Color, c => c.R) .BindTo(this, v => v.RedSlider.Value) .DisposeWith(disposables); this // Color.G -> GreenSlider.Value .WhenAnyValue(v => v.Color, c => c.G) .BindTo(this, v => v.GreenSlider.Value) .DisposeWith(disposables); this // Color.B -> BlueSlider.Value .WhenAnyValue(v => v.Color, c => c.B) .BindTo(this, v => v.BlueSlider.Value) .DisposeWith(disposables); this // Color.R -> RedValue.Content .WhenAnyValue(v => v.Color, c => c.R) .BindTo(this, v => v.RedValue.Content) .DisposeWith(disposables); this // Color.G -> RedValue.Content .WhenAnyValue(v => v.Color, c => c.G) .BindTo(this, v => v.GreenValue.Content) .DisposeWith(disposables); this // Color.B -> RedValue.Content .WhenAnyValue(v => v.Color, c => c.B) .BindTo(this, v => v.BlueValue.Content) .DisposeWith(disposables); this // RedSlider.Value, GreenSlider.Value, BlueSlider.Value -> Color .WhenAnyValue(v => v.RedSlider.Value, v => v.GreenSlider.Value, v => v.BlueSlider.Value, (r, g, b) => new { R = (byte)r, G = (byte)g, B = (byte)b }) .Select(c => new Color { R = c.R, G = c.G, B = c.B, A = 255 }) .BindTo(this, v => v.Color) .DisposeWith(disposables); }); }
public MainWindow() { InitializeComponent(); ViewModel = Locator.Current.GetService <MainWindowViewModel>(); _logServices = CreateLogService(); this.WhenActivated(d => { ViewModel.DisposeWith(d); this.Bind(ViewModel, vm => vm.Config.RoomId, v => v.RoomIdTextBox.Text, x => $@"{x}", x => long.TryParse(x, out var v) ? v : 732).DisposeWith(d); RoomIdTextBox.Events().KeyUp.Subscribe(args => { if (args.Key != Key.Enter) { return; } ViewModel.TriggerLiveRecordListQuery = !ViewModel.TriggerLiveRecordListQuery; }).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.ImageUri, v => v.FaceImage.Source, url => url == null ? null : new BitmapImage(new Uri(url))).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.Name, v => v.NameTextBlock.Text).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.Uid, v => v.UIdTextBlock.Text, i => $@"UID: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.Level, v => v.LvTextBlock.Text, i => $@"Lv{i}").DisposeWith(d); this.Bind(ViewModel, vm => vm.Config.MainDir, v => v.MainDirTextBox.Text).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.DiskUsageProgressBarText, v => v.DiskUsageProgressBarTextBlock.Text).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.DiskUsageProgressBarValue, v => v.DiskUsageProgressBar.Value).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.DiskUsageProgressBarValue, v => v.DiskUsageProgressBar.Foreground, p => p > 90 ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Color.FromRgb(38, 160, 218))).DisposeWith(d); this.BindCommand(ViewModel, viewModel => viewModel.SelectMainDirCommand, view => view.SelectMainDirButton).DisposeWith(d); this.BindCommand(ViewModel, viewModel => viewModel.OpenMainDirCommand, view => view.OpenMainDirButton).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.RoomId, v => v.RoomIdTextBlock.Text, i => $@"房间号: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.ShortRoomId, v => v.ShortRoomIdTextBlock.Text, i => $@"短号: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.RecordCount, v => v.RecordCountTextBlock.Text, i => $@"列表总数: {i}").DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.IsLiveRecordBusy, v => v.LiveRecordBusyIndicator.IsActive).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.LiveRecordList, v => v.LiveRecordListDataGrid.ItemsSource).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.CopyLiveRecordDownloadUrlCommand, v => v.CopyLiveRecordDownloadUrlMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.OpenLiveRecordUrlCommand, v => v.OpenLiveRecordUrlMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.DownLoadCommand, v => v.DownLoadMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.OpenDirCommand, v => v.OpenDirMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.ShowWindowCommand, v => v.NotifyIcon, nameof(NotifyIcon.TrayLeftMouseUp)).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.ShowWindowCommand, v => v.ShowMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.ExitCommand, v => v.ExitMenuItem).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.TaskList, v => v.TaskListDataGrid.ItemsSource).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.StopTaskCommand, v => v.StopTaskMenuItem).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.ClearAllTasksCommand, v => v.RemoveTaskMenuItem).DisposeWith(d); this.Bind(ViewModel, vm => vm.Config.DownloadThreads, v => v.ThreadsTextBox.Value, x => x, Convert.ToByte).DisposeWith(d); this.Bind(ViewModel, vm => vm.Config.IsCheckUpdateOnStart, v => v.IsCheckUpdateOnStartSwitch.IsOn).DisposeWith(d); this.Bind(ViewModel, vm => vm.Config.IsCheckPreRelease, v => v.IsCheckPreReleaseSwitch.IsOn).DisposeWith(d); this.BindCommand(ViewModel, vm => vm.CheckUpdateCommand, v => v.CheckUpdateButton).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.UpdateStatus, v => v.UpdateStatusTextBlock.Text).DisposeWith(d); Observable.FromEventPattern(LogTextBox, nameof(LogTextBox.TextChanged)).Subscribe(_ => { if (LogTextBox.LineCount > 2000) { _logServices?.Dispose(); LogTextBox.Clear(); _logServices = CreateLogService(); } }).DisposeWith(d); _logServices?.DisposeWith(d); #region CloseReasonHack AddCloseReasonHook(); this.Events().Closing.Subscribe(e => { if (CloseReason == CloseReason.UserClosing) { Hide(); e.Cancel = true; } }).DisposeWith(d); #endregion }); }