public MainWindowViewModel() { EdgeLocalStateFilePath.SetValidateNotifyError(IsExitisFile); EdgeCookiesFilePath.SetValidateNotifyError(IsExitisFile); ChromeLocalStateFilePath.SetValidateNotifyError(IsExitisFile); ChromeCookiesFilePath.SetValidateNotifyError(IsExitisFile); ObsCookiesFilePath.SetValidateNotifyError(IsExitisFile); EdgeCommand = new[] { EdgeLocalStateFilePath.ObserveHasErrors, EdgeCookiesFilePath.ObserveHasErrors, ObsCookiesFilePath.ObserveHasErrors }.CombineLatestValuesAreAllFalse().ToReactiveCommand <Models.CommandParameter>(); ChromeCommand = new[] { ChromeLocalStateFilePath.ObserveHasErrors, ChromeCookiesFilePath.ObserveHasErrors, ObsCookiesFilePath.ObserveHasErrors }.CombineLatestValuesAreAllFalse().ToReactiveCommand <Models.CommandParameter>(); LocalStateFilePath.SetValidateNotifyError(IsExitisFile); SrcCookieFilePath.SetValidateNotifyError(IsExitisFile); DestCookieFilePath.SetValidateNotifyError(IsExitisFile); HostKey.SetValidateNotifyError(host => { if (String.IsNullOrWhiteSpace(host)) { return("Empty"); } return(null); }); ParamCommand = new[] { LocalStateFilePath.ObserveHasErrors, SrcCookieFilePath.ObserveHasErrors, HostKey.ObserveHasErrors, DestCookieFilePath.ObserveHasErrors }.CombineLatestValuesAreAllFalse().ToReactiveCommand <Models.CommandParameter>(); EdgeCommand.Subscribe(ExecuteCommand.Execute); ChromeCommand.Subscribe(ExecuteCommand.Execute); ParamCommand.Subscribe(ExecuteCommand.Execute); OkCommand.Subscribe(async _ => { Executing.Value = true; try { await System.Threading.Tasks.Task.Run(() => { CookieManager.Converter.Convert(Environment.ExpandEnvironmentVariables(Param.LocalStateFilePath), Environment.ExpandEnvironmentVariables(Param.SrcCookieFilePath), Param.HostKey, Environment.ExpandEnvironmentVariables(Param.DestCookieFilePath)); }); } catch { IsErrorDialogOpen.Value = true; } Executing.Value = false; IsDialogOpen.Value = false; } ); ExecuteCommand.Subscribe(param => { IsDialogOpen.Value = true; Param = param; }); CancelCommand.Subscribe(_ => IsDialogOpen.Value = false); ErrorOkCommand.Subscribe(_ => IsErrorDialogOpen.Value = false); }
//************************************************************************* // Method: RunAnEdgeCommand() // /// <summary> /// Runs an edge command. /// </summary> /// /// <param name="oCommandBarButton"> /// CommandBarButton whose Parameter property contains an edge ID. /// </param> /// /// <param name="eEdgeCommand"> /// Edge command to run. /// </param> //************************************************************************* protected void RunAnEdgeCommand( CommandBarButton oCommandBarButton, EdgeCommand eEdgeCommand ) { Debug.Assert(oCommandBarButton != null); AssertValid(); RunEdgeCommandEventHandler oRunEdgeCommand = this.RunEdgeCommand; if (oRunEdgeCommand == null) { // There is no event handler, so the command can't be run. return; } // Retrieve the ID of the edge that was right-clicked. This can be // NoRowID. Int32 iClickedEdgeID = CommandBarButtonToClickedID(oCommandBarButton); oRunEdgeCommand( this, new RunEdgeCommandEventArgs(iClickedEdgeID, eEdgeCommand) ); }
RunAnEdgeCommand ( CommandBarButton oCommandBarButton, EdgeCommand eEdgeCommand ) { Debug.Assert(oCommandBarButton != null); AssertValid(); // Retrieve the ID of the edge that was right-clicked. This can be // NoRowID. Int32 iClickedEdgeID = CommandBarButtonToClickedID(oCommandBarButton); CommandDispatcher.SendCommand( this, new RunEdgeCommandEventArgs(iClickedEdgeID, eEdgeCommand) ); }