public ConfirmRecoveryWordsViewModel(List <RecoveryWordViewModel> mnemonicWords, KeyManager keyManager)
    {
        var confirmationWordsSourceList = new SourceList <RecoveryWordViewModel>();

        _isSkipEnable = Services.WalletManager.Network != Network.Main || System.Diagnostics.Debugger.IsAttached;

        var nextCommandCanExecute =
            confirmationWordsSourceList
            .Connect()
            .ObserveOn(RxApp.MainThreadScheduler)
            .WhenValueChanged(x => x.IsConfirmed)
            .Select(_ => confirmationWordsSourceList.Items.All(x => x.IsConfirmed));

        EnableBack = true;

        NextCommand = ReactiveCommand.Create(() => OnNext(keyManager), nextCommandCanExecute);

        if (_isSkipEnable)
        {
            SkipCommand = ReactiveCommand.Create(() => NextCommand.Execute(null));
        }

        CancelCommand = ReactiveCommand.Create(OnCancel);

        confirmationWordsSourceList
        .Connect()
        .ObserveOn(RxApp.MainThreadScheduler)
        .OnItemAdded(x => x.Reset())
        .Sort(SortExpressionComparer <RecoveryWordViewModel> .Ascending(x => x.Index))
        .Bind(out _confirmationWords)
        .Subscribe();

        // Select random words to confirm.
        confirmationWordsSourceList.AddRange(mnemonicWords.OrderBy(_ => new Random().NextDouble()).Take(3));
    }
Exemplo n.º 2
0
        public LoginViewModel()
        {
            IsLoading = Visibility.Collapsed;

            Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.PressEnterToLoginToken, act =>
            {
                NextCommand.Execute(null);
            });
        }
Exemplo n.º 3
0
        private void MetroWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && NextCommand.CanExecute(null))
            {
                NextCommand.Execute(null);
            }

            else if (e.Key == Key.Escape)
            {
                Close();
            }
        }
Exemplo n.º 4
0
        public LoginViewModel()
        {
            IsLoading = false;

            Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.PressEnterToLoginToken, act =>
            {
                NextCommand.Execute(null);
            });

#if DEBUG
            TempEmail     = "*****@*****.**";
            InputPassword = "******";
#endif
        }
 public override void Execute(Test test)
 {
     if (test.Command.StartsWith(Resource.checkLinkPresentByHref))
     {
         if (test.FirstParam != null)
         {
             pageTester.CheckLinkPresentByHref(test);
         }
     }
     else if (NextCommand != null)
     {
         NextCommand.Execute(test);
     }
 }
Exemplo n.º 6
0
        public void Creates_the_correct_first_tag_for_a_specific_label()
        {
            var git = new Mock <IGit>();

            git.Setup(x => x.GetTags()).Returns(new List <Tag>());

            var nextMajorVersionCommand = new NextCommand(Place.Version, git.Object);

            nextMajorVersionCommand.Execute(new [] { "rc" });

            git.Verify(x => x.NewTag("0.0.1-RC.1", null));
            git.Verify(x => x.Push());
            git.Verify(x => x.PushTag("0.0.1-RC.1"));
        }
Exemplo n.º 7
0
        public void Creates_the_correct_first_tag(Place place, string expectedTag)
        {
            var git = new Mock <IGit>();

            git.Setup(x => x.GetTags()).Returns(new List <Tag>());

            var nextMajorVersionCommand = new NextCommand(place, git.Object);

            nextMajorVersionCommand.Execute(Array.Empty <string>());

            git.Verify(x => x.NewTag(expectedTag, null));
            git.Verify(x => x.Push());
            git.Verify(x => x.PushTag(expectedTag));
        }
        public override void Execute(Test test)
        {
            if (test.Command.StartsWith(Resource.checkPageContains))
            {
                if (test.FirstParam != null)
                {
                    pageTester.CheckPageContains(test);
                }
            }

            else if (NextCommand != null)
            {
                NextCommand.Execute(test);
            }
        }
Exemplo n.º 9
0
        public override void Execute(Test test)
        {
            if (test.Command.StartsWith(Resource.open))
            {
                if (test.FirstParam != null)
                {
                    pageTester.Open(test);
                }
            }

            else if (NextCommand != null)
            {
                NextCommand.Execute(test);
            }
        }
Exemplo n.º 10
0
        public void Creates_the_correct_tag_for_a_patch_version_when_there_is_a_major_tag_present()
        {
            var git = new Mock <IGit>();

            git.Setup(x => x.GetTags()).Returns(new List <Tag>
            {
                new Tag(1, 0, 0, null, null)
            });

            var nextMajorVersionCommand = new NextCommand(Place.Patch, git.Object);

            nextMajorVersionCommand.Execute(Array.Empty <string>());

            git.Verify(x => x.NewTag("1.0.1", null));
            git.Verify(x => x.Push());
            git.Verify(x => x.PushTag("1.0.1"));
        }
Exemplo n.º 11
0
        public void Creates_a_tag_for_a_given_label()
        {
            var git = new Mock <IGit>();

            git.Setup(x => x.GetTags()).Returns(new List <Tag>
            {
                new Tag(1, 0, 0, null, null),
                new Tag(0, 1, 0, null, null),
                new Tag(0, 1, 0, "RC", 1)
            });

            var nextMajorVersionCommand = new NextCommand(Place.Version, git.Object);

            nextMajorVersionCommand.Execute(new [] { "test", "rc" });

            git.Verify(x => x.NewTag("1.1.0-TEST.1", "0.1.0-RC.1"));
            git.Verify(x => x.Push());
            git.Verify(x => x.PushTag("1.1.0-TEST.1"));
        }
Exemplo n.º 12
0
        public void Creates_the_correct_tag_for_a_label_when_a_major_tag_is_the_latest_tag_and_a_new_major_version_should_be_created()
        {
            var git = new Mock <IGit>();

            git.Setup(x => x.GetTags()).Returns(new List <Tag>
            {
                new Tag(1, 0, 0, null, null),
                new Tag(0, 1, 0, null, null),
                new Tag(0, 1, 0, "RC", 1)
            });

            var nextMajorVersionCommand = new NextCommand(Place.Version, git.Object);

            nextMajorVersionCommand.Execute(new [] { "rc", "-X" });

            git.Verify(x => x.NewTag("2.0.0-RC.1", null));
            git.Verify(x => x.Push());
            git.Verify(x => x.PushTag("2.0.0-RC.1"));
        }
Exemplo n.º 13
0
 private void StopAndPlayNext()
 {
     MusicPlayHelper.Stop();
     ConfigInfo.PlayStatus = PlayStatus.Pause;
     NextCommand.Execute(null);
 }
        public MainViewModel()
        {
            CurrentScreen = ScreenType.ApiKey;

            ApiKey    = Properties.Settings.Default.challonge_apikey;
            Subdomain = Properties.Settings.Default.challonge_subdomain;

            //Observable.Start(() =>
            //{
            //    try
            //    {
            //        //I'm considering doing an http request to smashboards to find if a new version is released. I think smashboard's anti-DDOS protection is preventing it from working
            //        WebRequest request = WebRequest.Create(ThreadUrl);
            //        request.Credentials = CredentialCache.DefaultCredentials;

            //        WebResponse response = request.GetResponse();
            //        if (((HttpWebResponse)response).StatusDescription == "OK")
            //        {
            //            Stream dataStream = response.GetResponseStream();
            //            StreamReader reader = new StreamReader(dataStream);
            //            string responseFromServer = reader.ReadToEnd();
            //            reader.Close();
            //        }
            //        response.Close();
            //    }
            //    catch { /* ignore */ }
            //});

            //Modify ViewModel state when an action is initiated
            Action startAction = () =>
            {
                ErrorMessage = null;
                IsBusy       = true;
            };

            //Modify ViewModel state when an action is completed
            Action endAction = () =>
            {
                IsBusy = false;
            };

            //Modify ViewModel state when an action comes back with an exception
            Action <Exception> errorHandler = ex =>
            {
                if (ex.InnerException is ChallongeApiException)
                {
                    var cApiEx = (ChallongeApiException)ex.InnerException;

                    if (cApiEx.Errors != null)
                    {
                        ErrorMessage = cApiEx.Errors.Aggregate((one, two) => one + "\r\n" + two);
                    }
                    else
                    {
                        ErrorMessage = string.Format("Error with ResponseStatus \"{0}\" and StatusCode \"{1}\". {2}", cApiEx.RestResponse.ResponseStatus,
                                                     cApiEx.RestResponse.StatusCode, cApiEx.RestResponse.ErrorMessage);
                    }
                }
                else
                {
                    ErrorMessage = ex.NewLineDelimitedMessages();
                }

                IsBusy = false;
            };

            var dispatcher = System.Threading.SynchronizationContext.Current;

            //Handle next button press
            NextCommand = Command.CreateAsync(() => true, () =>
            {
                switch (CurrentScreen)
                {
                case ScreenType.ApiKey:
                    var subdomain = string.IsNullOrWhiteSpace(Subdomain) ? null : Subdomain;
                    Portal        = new ChallongePortal(ApiKey, subdomain);

                    //Load list of tournaments that match apikey/subdomain
                    TournamentCollection = Portal.GetTournaments().OrderByDescending(t => t.CreatedAt).ToArray();

                    try
                    {
                        //This is a silly method for checking whether a new application version exists without me having my own website.
                        //I manage the most recent version number in the description of a tournament hosted on challonge. This code fetches that number
                        var versionCheckPortal = new ChallongePortal(ApiKey, "fizzitestorg");
                        MostRecentVersion      = versionCheckPortal.GetTournaments().Where(t => t.Name == "CMDVersionTest").Select(t =>
                        {
                            //Modifying the description seems to put some html formatting into the result. This filters the description for
                            //just the version number by itself
                            var versionResult = string.Concat(t.Description.Where(c => char.IsDigit(c) || c == '.'));
                            return(versionResult);
                        }).First();

                        //Check both version numbers to determine if current version is older than recent version
                        var versionCompareResult = Version.Split('.').Zip(MostRecentVersion.Split('.'), (v, mrv) =>
                        {
                            return(int.Parse(v).CompareTo(int.Parse(mrv)));
                        }).FirstOrDefault(i => i != 0);

                        //If app version is older than most recent version, show message
                        IsVersionOutdatedVisible = versionCompareResult < 0;
                    }
                    catch (Exception)
                    {
                        //If version check fails simply ignore the problem and move on
                        System.Diagnostics.Debug.WriteLine("Version check failed.");
                    }

                    break;

                case ScreenType.TournamentSelection:
                    if (Context != null)
                    {
                        Context.Dispose();
                    }
                    if (matchesChangedHandler != null)
                    {
                        Context.Tournament.PropertyChanged -= matchesChangedHandler;
                    }

                    //Create tournament context from selected tournament
                    Context = new TournamentContext(Portal, SelectedTournament.Id);
                    Context.StartSynchronization(TimeSpan.FromMilliseconds(500), 6);

                    //Create TO View Model
                    OrgViewModel = new OrganizerViewModel(this, dispatcher);

                    //Load up matches into display matches. This is done to allow ordering of assigned matches over unassigned matches without having to refresh the view
                    DisplayMatches = Context.Tournament.Matches.Select(kvp => new DisplayMatch(OrgViewModel, kvp.Value, DisplayMatch.DisplayType.Assigned))
                                     .Concat(Context.Tournament.Matches.Select(kvp => new DisplayMatch(OrgViewModel, kvp.Value, DisplayMatch.DisplayType.Unassigned))).ToList();

                    //This handler is used to keep matches display matches in sync with tournament context matches. If the matches in the context change, re-generate the display matches
                    matchesChangedHandler = new PropertyChangedEventHandler((sender, e) =>
                    {
                        if (e.PropertyName == "Matches")
                        {
                            if (Context.Tournament.Matches == null)
                            {
                                DisplayMatches = null;
                            }
                            else
                            {
                                DisplayMatches = Context.Tournament.Matches.Select(kvp => new DisplayMatch(OrgViewModel, kvp.Value, DisplayMatch.DisplayType.Assigned))
                                                 .Concat(Context.Tournament.Matches.Select(kvp => new DisplayMatch(OrgViewModel, kvp.Value, DisplayMatch.DisplayType.Unassigned))).ToList();
                            }
                        }

                        if (e.PropertyName == "ProgressMeter")
                        {
                            if (Context.Tournament.ProgressMeter == 100)
                            {
                            }
                        }
                    });
                    Context.Tournament.PropertyChanged += matchesChangedHandler;

                    break;
                }

                CurrentScreen = (ScreenType)((int)CurrentScreen + 1);
            }, startAction, endAction, errorHandler);

            Back = Command.CreateAsync(() => true, () =>
            {
                switch (CurrentScreen)
                {
                case ScreenType.TournamentSelection:
                    ApiKey = Properties.Settings.Default.challonge_apikey;
                    break;

                case ScreenType.PendingMatchView:
                    if (OrgViewModel != null)
                    {
                        OrgViewModel.Dispose();
                        OrgViewModel = null;
                    }
                    break;
                }
                CurrentScreen = (ScreenType)((int)CurrentScreen - 1);
            }, startAction, endAction, errorHandler);

            IgnoreVersionNotification = Command.Create(() => true, () => IsVersionOutdatedVisible = false);


            if (ApiKey != "")
            {
                NextCommand.Execute(null);
            }
        }
Exemplo n.º 15
0
 public void GoToNextFromMediaWebSocket()
 {
     NextCommand.Execute();
 }