private void RaiseRejectRequest()
        {
            InnerItem.AccountState = (int)AccountState.Rejected;

            ApproveCommand.RaiseCanExecuteChanged();
            RejectCommand.RaiseCanExecuteChanged();
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        public void ReceiveLoginMsg(string json)
        {
            var msg = JsonConvert.DeserializeObject <MinerLoginMsg>(json);

            if (msg == null)
            {
                return;
            }

            LogHelper.Info("Receive LoginMsg");

            if (msg.ServerId == Setting.PoolId)
            {
                return;
            }

            var miner = PoolCache.WorkingMiners.FirstOrDefault(x => x.SerialNo == msg.SN || x.WalletAddress == msg.Account);

            if (miner == null)
            {
                return;
            }

            TcpState tcpState = new TcpState()
            {
                Client = miner.Client, Stream = miner.Stream, Address = miner.ClientAddress
            };

            StopCommand.Send(tcpState, new StopMsg
            {
                BlockHeight = PoolCache.CurrentTask.CurrentBlockHeight,
                Result      = false,
                StartTime   = PoolCache.CurrentTask.StartTime,
                StopTime    = Time.EpochTime
            });
            RejectCommand.Send(tcpState);
            PoolCache.WorkingMiners.Remove(miner);
        }
Exemplo n.º 3
0
        public PullRequestViewModel(
            string username, string repository, int pullRequestId,
            IMarkdownService markdownService     = null, IApplicationService applicationService = null,
            IActionMenuService actionMenuService = null)
        {
            _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            markdownService     = markdownService ?? Locator.Current.GetService <IMarkdownService>();
            actionMenuService   = actionMenuService ?? Locator.Current.GetService <IActionMenuService>();

            Title         = $"Pull Request #{pullRequestId}";
            Username      = username;
            Repository    = repository;
            PullRequestId = pullRequestId;

            Comments = _comments.CreateDerivedCollection(x =>
            {
                var name   = x.User.DisplayName ?? x.User.Username ?? "Unknown";
                var avatar = new Avatar(x.User.Links?.Avatar?.Href);
                return(new CommentItemViewModel(name, avatar, x.CreatedOn.Humanize(), x.Content.Html));
            });

            Comments.Changed.Subscribe(_ => CommentCount = Comments.Count);

            LoadCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                PullRequest = await applicationService.Client.PullRequests.Get(username, repository, pullRequestId);
                _comments.Clear();
                await applicationService
                .Client.ForAllItems(
                    x => x.PullRequests.GetComments(username, repository, pullRequestId),
                    y =>
                {
                    var items = y.Where(x => !string.IsNullOrEmpty(x.Content.Raw) && x.Inline == null)
                                .OrderBy(x => (x.CreatedOn));
                    _comments.Reset(items);
                });
            });

            GoToCommitsCommand = ReactiveCommand.CreateFromTask(t =>
            {
                if (PullRequest?.Source?.Repository == null)
                {
                    throw new Exception("The author has deleted the source repository for this pull request.");
                }

                var viewModel = new PullRequestCommitsViewModel(username, repository, pullRequestId);
                NavigateTo(viewModel);
                return(Task.FromResult(Unit.Default));
            });

            var canMerge = this.WhenAnyValue(x => x.PullRequest)
                           .Select(x => string.Equals(x?.State, "open", StringComparison.OrdinalIgnoreCase));

            canMerge.ToProperty(this, x => x.IsOpen, out _open);

            MergeCommand = ReactiveCommand.Create(() => { }, canMerge);

            RejectCommand = ReactiveCommand.CreateFromTask(
                t => applicationService.Client.PullRequests.Decline(username, repository, pullRequestId),
                canMerge);

            RejectCommand.Subscribe(x => PullRequest = x);

            GoToUserCommand = ReactiveCommand.Create <string>(user => NavigateTo(new UserViewModel(user)));

            ToggleApproveButton = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (Approved)
                {
                    await applicationService.Client.PullRequests.Unapprove(username, repository, pullRequestId);
                }
                else
                {
                    await applicationService.Client.PullRequests.Approve(username, repository, pullRequestId);
                }

                PullRequest = await applicationService.Client.PullRequests.Get(username, repository, pullRequestId);
            });

            //ToggleApproveButton.ThrownExceptions
            //    .Subscribe(x => DisplayAlert("Unable to approve commit: " + x.Message).ToBackground());


            var participantObs = this.WhenAnyValue(x => x.PullRequest.Participants)
                                 .Select(x => x ?? Enumerable.Empty <PullRequestParticipant>());

            var currentUsername = applicationService.Account.Username;

            participantObs
            .Select(x => x.FirstOrDefault(y => string.Equals(y.User.Username,
                                                             currentUsername, StringComparison.OrdinalIgnoreCase))?.Approved ?? false)
            .ToProperty(this, x => x.Approved, out _approved);

            participantObs
            .Select(x => new int?(x.Count()))
            .ToProperty(this, x => x.ParticipantCount, out _participants);

            participantObs
            .Select(x => new int?(x.Count(y => y.Approved)))
            .ToProperty(this, x => x.ApprovalCount, out _approvalCount);

            this.WhenAnyValue(x => x.PullRequest.Description)
            .Select(x => string.IsNullOrEmpty(x) ? null : markdownService.ConvertMarkdown(x))
            .ToProperty(this, x => x.Description, out _description);

            this.WhenAnyValue(x => x.PullRequest.Participants)
            .Select(participants =>
            {
                return((participants ?? Enumerable.Empty <PullRequestParticipant>())
                       .Where(x => x.Approved)
                       .Select(x =>
                {
                    var avatar = new Avatar(x.User?.Links?.Avatar?.Href);
                    var vm = new UserItemViewModel(x.User?.Username, x.User?.DisplayName, avatar);
                    vm.GoToCommand
                    .Select(_ => new UserViewModel(x.User))
                    .Subscribe(NavigateTo);
                    return vm;
                }));
            })
            .Select(x => x.ToArray())
            .ToProperty(this, x => x.Approvals, out _approvals, new UserItemViewModel[0]);

            ShowMenuCommand = ReactiveCommand.CreateFromTask(sender =>
            {
                var menu = actionMenuService.Create();
                menu.AddButton("Show in Bitbucket", _ =>
                {
                    NavigateTo(new WebBrowserViewModel(PullRequest?.Links?.Html?.Href));
                });
                return(menu.Show(sender));
            });
        }