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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes a passed command using the current ChromeCommandExecutor
        /// </summary>
        /// <param name="driverCommand">command to execute</param>
        /// <param name="parameters">parameters of command being executed</param>
        /// <returns>response to the command (a Response wrapping a null value if none)</returns>
        public ChromeResponse Execute(DriverCommand driverCommand, params object[] parameters)
        {
            ChromeCommand command = new ChromeCommand(
                new SessionId(
                    "[No sessionId]"),
                new Context("[No context]"),
                driverCommand,
                parameters);
            ChromeResponse commandResponse = null;
            try
            {
                commandResponse = executor.Execute(command);
            }
            catch (NotSupportedException nse)
            {
                string message = nse.Message.ToLowerInvariant();
                if (message.Contains("cannot toggle a") || message.Contains("cannot unselect a single element select"))
                {
                    throw new NotImplementedException();
                }

                throw;
            }
            catch (ArgumentException)
            {
                // Exceptions may leave the extension hung, or in an
                // inconsistent state, so we restart Chrome
                StopClient();
                StartClient();
            }
            catch (FatalChromeException)
            {
                // Exceptions may leave the extension hung, or in an
                // inconsistent state, so we restart Chrome
                StopClient();
                StartClient();
            }

            return commandResponse;
        }