Ejemplo n.º 1
0
        public TabReportOut GetReportItemByTaskId(IDbConnection connection, int currentUserId, int taskId)
        {
            var userId     = currentUserId;
            var task       = _uTaskService.GetByTaskId(connection, taskId, true);
            var reportItem = _uReportService.GetUserReportByTaskId(connection, userId, taskId, i => i);
            var reportInfo = SetReportItem(userId, new List <UserTaskDataModel> {
                task
            })(reportItem);

            if (reportItem == null)
            {
                throw new Exception(Error.NoData);
            }
            TabReportOut.InitComplexBtnItem(reportInfo);

            return(reportInfo);
        }
Ejemplo n.º 2
0
        public void NotyfyTaskFinished(UserTaskDataModel finishedTask, UserReportDataModel report = null, int?newTotalWinnerUserCc = null)
        {
            IDbConnection connection = null; // коннекшен для этого метода не нужен, это часть интерфейса

            if (!finishedTask.TaskEnd)
            {
                throw new NotImplementedException("NotyfyTaskFinished: finishedTask.TaskEnd = false");
            }
            IList <ConnectionUser> hubUsers;

            if (finishedTask.IsTransfer)
            {
                hubUsers = _hubCache.LocalFind(connection, (key, val) => val.UserId == finishedTask.SourceUserId);
                if (hubUsers == null || hubUsers.Count != 1 || !hubUsers[0].Connected)
                {
                    return;
                }
                _hub.Clients.Client(hubUsers[0].ConnectionId).InvokeAsync("journalOnTaskFinished", new
                {
                    Task         = finishedTask,
                    TabReportOut = 0
                });
                return;
            }
            if (report == null)
            {
                return;
            }

            hubUsers = _hubCache.LocalFind(connection, (key, val) =>
                                           val.UserId == report.AtackerUserId || val.UserId == report.DefenderUserId);
            if (hubUsers == null || hubUsers.All(i => !i.Connected))
            {
                return;
            }
            var            atakerUsers   = hubUsers.Where(i => i.UserId == report.AtackerUserId).ToList();
            var            defendorUsers = hubUsers.Where(i => i.UserId == report.DefenderUserId).ToList();
            ConnectionUser ataker        = null;
            ConnectionUser defendor      = null;

            if (atakerUsers.Any() && atakerUsers.Count == 1 && atakerUsers[0].Connected)
            {
                ataker = atakerUsers[0];
            }
            if (defendorUsers.Any() && defendorUsers.Count == 1 && defendorUsers[0].Connected)
            {
                defendor = defendorUsers[0];
            }


            if (ataker != null)
            {
                var client = _hub.Clients.Client(ataker.ConnectionId);
                if (client != null)
                {
                    L10N.SetCulture(ataker.Lang);
                    var atakerReport =
                        _journalOut.SetReportItem(report.AtackerUserId, new List <UserTaskDataModel> {
                        finishedTask
                    })(
                            report.CloneDeep());
                    TabReportOut.InitComplexBtnItem(atakerReport);
                    client.InvokeAsync("journalOnTaskFinished", new
                    {
                        Task                 = finishedTask,
                        TabReportOut         = atakerReport,
                        NewTotalWinnerUserCc = newTotalWinnerUserCc != null && !atakerReport.IsLose
                            ? newTotalWinnerUserCc
                            : null
                    });
                }
            }
            if (defendor != null)
            {
                var client = _hub.Clients.Client(defendor.ConnectionId);
                if (client != null)
                {
                    L10N.SetCulture(defendor.Lang);
                    var defendorReport = _journalOut.SetReportItem(report.DefenderUserId,
                                                                   new List <UserTaskDataModel> {
                        finishedTask
                    })(report.CloneDeep());
                    TabReportOut.InitComplexBtnItem(defendorReport);

                    client.InvokeAsync("journalOnTaskFinished", new
                    {
                        Task                 = finishedTask,
                        TabReportOut         = defendorReport,
                        NewTotalWinnerUserCc = newTotalWinnerUserCc != null && !defendorReport.IsLose
                            ? newTotalWinnerUserCc
                            : null
                    });
                }
            }
        }