Beispiel #1
0
        public void Test_All()
        {
            int tenantId = 1;

            Dictionary <string, int> connections = new Dictionary <string, int>();

            for (int i = 0; i < 100; i++)
            {
                connections.Add(MakeNewConnectionId(), i + 1);
            }

            foreach (var pair in connections)
            {
                _clientManager.Add(new OnlineClient(pair.Key, "127.0.0.1", tenantId, pair.Value));
            }

            var testId = connections.Keys.ToList()[5];

            _clientManager.GetAllClients().Count.ShouldBe(connections.Count);
            _clientManager.GetAllByUserId(new UserIdentifier(tenantId, connections[testId])).Count.ShouldBe(1);
            _clientManager.GetByConnectionIdOrNull(testId).ShouldNotBeNull();
            _clientManager.Remove(testId).ShouldBeTrue();
            _clientManager.GetAllClients().Count.ShouldBe(connections.Count - 1);
            _clientManager.GetByConnectionIdOrNull(testId).ShouldBeNull();
            _clientManager.GetAllByUserId(new UserIdentifier(tenantId, connections[testId])).Count.ShouldBe(0);
        }
Beispiel #2
0
        public void JobForProjectForceSubmit(Guid projectId)
        {
            var singleprojectmodel = _singleProjectInfoRepository.FirstOrDefault(r => r.Id == projectId);

            if (singleprojectmodel == null)
            {
                return;
            }
            var query = _projectSupplementRepository.GetAll().Where(r => r.ProjectBaseId == projectId && r.HasSupplement == false);
            var count = query.Count();

            if (count > 0)
            {
                Debug.Assert(singleprojectmodel.CreatorUserId != null, "CreatorUserId != null");
                var projectModel = _projectBaseRepository.Get(singleprojectmodel.ProjectId);
                var link         = $"/DataAdd?id={projectId}&appraisalTypeId={projectModel.AppraisalTypeId}";
                //var link = $"/Mpa/Project/DataChange?instanceId={projectId}&appTypeId={projectmodel.AppraisalTypeId}&notInAudit=1";

                var onlineclients =
                    _onlineClientManager.GetAllClients().Where(r => r.UserId == singleprojectmodel.CreatorUserId).ToList();
                var signalrNoticeService = Abp.AbpBootstrapper.Create <Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve <ISignalrNoticeAppService>();

                signalrNoticeService.SendNoticeToClient(onlineclients, projectId.ToString(), "补充资料提示", $"项目{singleprojectmodel.SingleProjectName}缺少{count}处资料,请及时补充", link);
            }
            else
            {
                _backgroudWorkJobWithHangFire.RemoveIfExistsJobForProjectForceSubmit(projectId);
            }
        }
        /// <summary>
        /// 获取用户列表(并且判断是否在线)
        /// </summary>
        /// <returns></returns>
        public virtual async Task <List <OnlineClientExtension> > GetAllClients()
        {
            //查询用户列表排除自己
            var userData = await _userInfoRepository.GetAllListAsync(g => g.Id != AbpSessionExtens.UserId.Value);

            //
            var onlineClients = _onlineClientManager.GetAllClients();
            //
            List <OnlineClientExtension> onlineClientList = new List <OnlineClientExtension>();

            foreach (var item in userData)
            {
                OnlineClientExtension onlineClientEx = new OnlineClientExtension();
                //
                var oC = onlineClients.Where(w => w.UserId == item.Id);
                if (oC.Any())
                {
                    onlineClientEx.ConnectionId = oC.ToList()[0].ConnectionId;
                    onlineClientEx.ConnectTime  = oC.ToList()[0].ConnectTime;
                    onlineClientEx.IpAddress    = oC.ToList()[0].IpAddress;
                    onlineClientEx.TenantId     = oC.ToList()[0].TenantId;
                }
                onlineClientEx.UserId     = item.Id;
                onlineClientEx.IsOnline   = oC.Any();
                onlineClientEx.UserCode   = item.UserCode;
                onlineClientEx.UserNameCn = item.UserNameCn;
                onlineClientEx.ImageUrl   = item.ImageUrl;

                onlineClientList.Add(onlineClientEx);
            }
            return(onlineClientList);
        }
Beispiel #4
0
        public static int GetOnlineCount()
        {
            IOnlineClientManager   OnlineClientManager   = IocManager.Instance.Resolve <IOnlineClientManager>();
            IInfrastructureSession InfrastructureSession = IocManager.Instance.Resolve <IInfrastructureSession>();

            return(OnlineClientManager.GetAllClients().WhereIf(InfrastructureSession.TenantId.HasValue, model => model.TenantId == InfrastructureSession.TenantId).Count());
        }
        public static IReadOnlyList <IOnlineClient> GetAllByUserId(
            [NotNull] this IOnlineClientManager onlineClientManager,
            [NotNull] IUserIdentifier user)
        {
            Check.NotNull(onlineClientManager, nameof(onlineClientManager));
            Check.NotNull(user, nameof(user));

            return(onlineClientManager.GetAllClients()
                   .Where(c => (c.UserId == user.UserId && c.TenantId == user.TenantId))
                   .ToImmutableList());
        }
        public IViewComponentResult Invoke()
        {
            var onlineUserIds = _onlineClientManager.GetAllClients().Select(o => o.UserId.Value).ToList();

            var users = _userRepository.Query().Where(u =>
                                                      onlineUserIds.Contains(u.Id)).Select(u =>
                                                                                           new SelectListItem
            {
                Text  = u.UserName,
                Value = u.Id.ToString()
            }).ToList();

            var vm = new TestNotificationVm
            {
                OnlineUsers = users
            };

            return(View(this.GetViewPath(), vm));
        }
Beispiel #7
0
        /// <summary>
        /// higefire定时器工作项时间到后调用
        /// </summary>
        /// <param name="taskId">这里的taskid为上一步的id  需要找到下一步的id</param>
        public void TimeOut(Guid instancId, Guid taskId)
        {
            var task = _workFlowTaskRepository.GetAll().FirstOrDefault(ite => ite.PrevID == taskId);

            if (task == null)
            {
                //throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "未找到当前待办。");
                return;
            }
            task.Status = 0;
            _workFlowTaskRepository.Update(task);
            var process = _repository.Get(instancId);
            var project = _projectRepository.Get(process.ProjectBaseId);
            // s ignalr 提醒
            var link          = $"/dynamicpage?fid={task.FlowID}&instanceID={task.InstanceID}&stepID={task.StepID}&groupID={task.GroupID}&taskID={task.Id}";// $"/Mpa/Project/DataChange?instanceId={projectId}&appTypeId={projectmodel.AppraisalTypeId}&notInAudit=1";
            var onlineclients =
                _onlineClientManager.GetAllClients().Where(r => r.UserId == task.ReceiveID).ToList();
            var signalrNoticeService = Abp.AbpBootstrapper.Create <Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve <ISignalrNoticeAppService>();

            signalrNoticeService.SendNoticeToClient(onlineclients, task.InstanceID.ToString(), "项目进度提醒", $"项目{project.ProjectName}评审阶段【{project.ProjectStatus.ToString()}】计划时间已到,请确认进度。", link);
            _backgroudWorkJobWithHangFire.RemoveProjectProgressTask(instancId);
        }
Beispiel #8
0
        public async Task <ActionResult> OnlineClients()
        {
            var clients = _onlineClientManager.GetAllClients();
            List <OnlineUser> onlineUsers = new EditableList <OnlineUser>();

            foreach (var onlineClient in clients)
            {
                var user = await _userManager.Users.FirstOrDefaultAsync(p => p.Id == onlineClient.UserId);

                if (user != null)
                {
                    onlineUsers.Add(new OnlineUser()
                    {
                        Ipaddress = onlineClient.IpAddress,
                        ClientId  = onlineClient.ConnectionId,
                        Name      = user.Name
                    });
                }
            }

            return(View(onlineUsers));
        }
        protected override async Task PublishAsync(NotificationInfo notification, IEnumerable <UserIdentifier> identifiers, CancellationToken cancellationToken = default)
        {
            if (identifiers?.Count() == 0)
            {
                var groupName = notification.TenantId?.ToString() ?? "Global";

                var singalRGroup = _hubContext.Clients.Group(groupName);
                if (singalRGroup == null)
                {
                    Logger.LogDebug("Can not get group " + groupName + " from SignalR hub!");
                    return;
                }
                // 租户通知群发
                Logger.LogDebug($"Found a singalr group, begin senging notifications");
                await singalRGroup.SendAsync("getNotification", notification, cancellationToken);
            }
            else
            {
                var onlineClients             = _onlineClientManager.GetAllClients(client => identifiers.Any(ids => client.UserId == ids.UserId));
                var onlineClientConnectionIds = onlineClients.Select(client => client.ConnectionId).ToImmutableArray();
                try
                {
                    var signalRClients = _hubContext.Clients.Clients(onlineClientConnectionIds);
                    if (signalRClients == null)
                    {
                        Logger.LogDebug("Can not get users connection from SignalR hub!");
                        return;
                    }
                    Logger.LogDebug($"Found a singalr client, begin senging notifications");
                    await signalRClients.SendAsync("getNotification", notification, cancellationToken);
                }
                catch (Exception ex)
                {
                    Logger.LogWarning("Could not send notifications to all users");
                    Logger.LogWarning("Send to user notifications error: {0}", ex.Message);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 培训前通知参训人员
        /// </summary>
        /// <param name="eventParams"></param>
        public void SendMessageForJoinUser(Guid guid)
        {
            var train = _repository.Get(guid);

            if (train != null && (train.CreatorUserId ?? 0) != 0)
            {
                var signalrNoticeService = Abp.AbpBootstrapper.Create <Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve <ISignalrNoticeAppService>();
                var users     = train.JoinUser.Split(',');
                var longUsers = new List <long?>();
                foreach (var item in users)
                {
                    var uid = Convert.ToInt64(item.Replace("u_", ""));
                    if (_trainLeaveRepository.GetAll().Any(x => x.TrainId == train.Id && x.UserId == uid && x.Status == -1 && x.StartTime == train.StartTime && x.EndTime == train.EndTime))
                    {
                        continue;
                    }
                    longUsers.Add(uid);
                }
                var link          = "/pxgl/pxxq?id=" + train.Id;
                var onlineclients =
                    _onlineClientManager.GetAllClients().Where(r => longUsers.Contains(r.UserId)).ToList();
                signalrNoticeService.SendNoticeToClient(onlineclients, train.Id.ToString(), train.Title + "将在:" + train.StartTime.ToString("yyyy/MM/dd HH:mm") + "开始,请准时参加。", link);
            }
        }
Beispiel #11
0
        protected async Task CreateNotice(NoticePublishInput input, List <long> users = null)
        {
            if (input.Id.HasValue)
            {
            }
            var userId = AbpSession.GetUserId();

            var textId = await _noticeTextRepository.InsertAndGetIdAsync(new NoticeTexts
            {
                CreationTime        = DateTime.Now,
                ExpireTime          = new DateTime(2099, 09, 09),
                MsgConent           = input.Content,
                NoticeType          = input.NoticeType,
                ProjectId           = null,
                Title               = input.Title,
                SendUserId          = userId,
                NoticeDepartmentIds = input.NoticeDepartmentIds,
                NoticeGroupIds      = input.NoticeGroupIds,
                NoticeUserIds       = input.NoticeUserIds,
                NoticeAllUserIds    = users == null ? null : string.Join(",", users)
            });

            if (input.NoticeType == (int)SystemNoticeType.通知公告 && users.Count == 0)
            {
                input.IsAllRecive = true;
            }

            if (input.NoticeType == (int)SystemNoticeType.公司新闻)
            {
                await _noticeLogRepository.InsertAsync(new NoticeLogs
                {
                    TextId       = textId,
                    ReceiveId    = userId,
                    Status       = 1,
                    NoticeType   = input.NoticeType,
                    CreationTime = DateTime.Now
                });
            }
            else if (input.NoticeType == (int)SystemNoticeType.通知公告)
            {
                if (input.IsAllRecive)
                {
                    await _noticeLogRepository.InsertAsync(new NoticeLogs
                    {
                        TextId       = textId,
                        ReceiveId    = userId,
                        Status       = 1,
                        NoticeType   = input.NoticeType,
                        CreationTime = DateTime.Now
                    });
                }
                else
                {
                    if (users.Count > 0)
                    {
                        foreach (var item in users)
                        {
                            await _noticeLogRepository.InsertAsync(new NoticeLogs
                            {
                                TextId       = textId,
                                ReceiveId    = item,
                                Status       = 1,
                                NoticeType   = input.NoticeType,
                                CreationTime = DateTime.Now
                            });
                        }
                    }
                }
            }
            else
            {
            }


            //日志功能暂时屏蔽
            //var logservice = Abp.AbpBootstrapper.Create<Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve<Logapp.ILogAppService>();
            //await logservice.CreateOrUpdateLogV2("发布公告", string.Format("发布公告,标题:{0}", input.Title), SystemLogTypes.日常办公.ToString());
            await CurrentUnitOfWork.SaveChangesAsync();


            var onlineClients = new List <IOnlineClient>();

            if (input.NoticeType == (int)SystemNoticeType.通知公告 && !input.IsAllRecive)
            {
                onlineClients = _onlineClientManager.GetAllClients().Where(p => p.UserId != userId && users.Contains(p.UserId.Value)).ToList();
            }
            else
            {
                onlineClients = _onlineClientManager.GetAllClients().Where(p => p.UserId != userId).ToList();
            }

            _noticeCommunicator.SendNoticeToClient(onlineClients, null, input.Title, string.Empty);
        }
Beispiel #12
0
 public object GetAllClient()
 {
     return(_onlineClientManager.GetAllClients());
 }
Beispiel #13
0
 public static IReadOnlyList <IOnlineClient> GetAllByUserId(this IOnlineClientManager onlineClientManager, IUserIdentifier user)
 {
     return(onlineClientManager.GetAllClients()
            .Where(c => c.UserId == user.UserId && c.TenantId == user.TenantId)
            .ToImmutableList());
 }
Beispiel #14
0
 public static IOnlineClient GetByUserIdOrNull(this IOnlineClientManager onlineClientManager, IUserIdentifier user)
 {
     return(onlineClientManager
            .GetAllClients()
            .FirstOrDefault(c => c.UserId == user.UserId && c.TenantId == user.TenantId));
 }
Beispiel #15
0
 /// <summary>
 /// 取所有当前建立连接用户
 /// </summary>
 /// <returns></returns>
 public IReadOnlyList <IOnlineClient> GetAllClients()
 {
     return(_onlineclientManager.GetAllClients());
 }
Beispiel #16
0
        public void SendNoticeToClientV2(long userId, string instanceId, string title, string content, string link = "")
        {
            var onlineClient = _onlineClientManager.GetAllClients().Where(p => p.UserId == userId).ToList();

            SendNoticeToClient(onlineClient, instanceId, title, content, link);
        }