public PollingNodeNoticeHandler(NodeNotice notice, NodeConnection nodeConnection, IPollsService pollsService, INodeRequestSender nodeRequestSender)
 {
     this.notice            = (PollingNodeNotice)notice;
     this.nodeConnection    = nodeConnection;
     this.pollsService      = pollsService;
     this.nodeRequestSender = nodeRequestSender;
 }
 public DeleteAllUserMessagesNodeNoticeHandler(NodeNotice notice, NodeConnection nodeConnection, IDeleteMessagesService deleteMessagesService, ILoadUsersService loadUsersService)
 {
     this.notice                = (DeleteAllUserMessagesNodeNotice)notice;
     this.nodeConnection        = nodeConnection;
     this.deleteMessagesService = deleteMessagesService;
     this.loadUsersService      = loadUsersService;
 }
 public ChannelUsersNodeNoticeHandler(NodeNotice notice, NodeConnection current, ICreateChannelsService createChannelsService, INodeRequestSender nodeRequestSender, ICrossNodeService crossNodeService)
 {
     this.notice  = (ChannelUsersNodeNotice)notice;
     this.current = current;
     this.createChannelsService = createChannelsService;
     this.nodeRequestSender     = nodeRequestSender;
     this.crossNodeService      = crossNodeService;
 }
 public MessagesUpdatedNodeNoticeHandler(NodeNotice notice,
                                         NodeConnection nodeConnection,
                                         IConversationsNoticeService conversationsNoticeService,
                                         IUpdateMessagesService updateMessagesService,
                                         IAttachmentsService attachmentsService)
 {
     this.notice                     = (MessagesUpdatedNodeNotice)notice;
     this.nodeConnection             = nodeConnection;
     this.conversationsNoticeService = conversationsNoticeService;
     this.updateMessagesService      = updateMessagesService;
     this.attachmentsService         = attachmentsService;
 }
Ejemplo n.º 5
0
 public ConversationActionNodeNoticeHandler(
     NodeNotice notice,
     NodeConnection nodeConnection,
     IConversationsService conversationsService,
     IConversationsNoticeService conversationsNoticeService,
     ILoadDialogsService loadDialogsService,
     ISystemMessagesService systemMessagesService)
 {
     this.notice                     = (ConversationActionNodeNotice)notice;
     this.nodeConnection             = nodeConnection;
     this.conversationsService       = conversationsService;
     this.conversationsNoticeService = conversationsNoticeService;
     this.loadDialogsService         = loadDialogsService;
     this.systemMessagesService      = systemMessagesService;
 }
Ejemplo n.º 6
0
 public MessagesDeletedNoticeHandler(
     NodeNotice notice,
     IConversationsNoticeService conversationsNoticeService,
     IDeleteMessagesService deleteMessagesService,
     ILoadChatsService loadChatsService,
     ILoadDialogsService loadDialogsService,
     ILoadChannelsService loadChannelsService)
 {
     this.notice = (MessagesDeletedNodeNotice)notice;
     this.conversationsNoticeService = conversationsNoticeService;
     this.deleteMessagesService      = deleteMessagesService;
     this.loadChatsService           = loadChatsService;
     this.loadDialogsService         = loadDialogsService;
     this.loadChannelsService        = loadChannelsService;
 }
 public ChannelNodeNoticeHandler(
     NodeNotice notice,
     NodeConnection current,
     IConversationsNoticeService conversationsNoticeService,
     ICreateChannelsService createChannelsService,
     ILoadChannelsService loadChannelsService,
     ISystemMessagesService systemMessagesService)
 {
     this.notice  = (ChannelNodeNotice)notice;
     this.current = current;
     this.conversationsNoticeService = conversationsNoticeService;
     this.createChannelsService      = createChannelsService;
     this.loadChannelsService        = loadChannelsService;
     this.systemMessagesService      = systemMessagesService;
 }
Ejemplo n.º 8
0
 public MessagesReadNoticeHandler(NodeNotice notice,
                                  NodeConnection current,
                                  IConversationsNoticeService conversationsNoticeService,
                                  IUpdateMessagesService updateMessagesService,
                                  IUpdateChatsService updateChatsService,
                                  ILoadDialogsService loadDialogsService,
                                  IUpdateChannelsService updateChannelsService)
 {
     this.notice  = (MessagesReadNodeNotice)notice;
     this.current = current;
     this.conversationsNoticeService = conversationsNoticeService;
     this.updateMessagesService      = updateMessagesService;
     this.updateChatsService         = updateChatsService;
     this.loadDialogsService         = loadDialogsService;
     this.updateChannelsService      = updateChannelsService;
 }
 public AddUsersChatNoticeHandler(NodeNotice notice,
                                  NodeConnection node,
                                  IConversationsNoticeService conversationsNoticeService,
                                  IUpdateChatsService updateChatsService,
                                  INodeRequestSender nodeRequestSender,
                                  ICrossNodeService crossNodeService,
                                  ISystemMessagesService systemMessagesService)
 {
     this.notice = (AddUsersChatNodeNotice)notice;
     this.node   = node;
     this.conversationsNoticeService = conversationsNoticeService;
     this.updateChatsService         = updateChatsService;
     this.nodeRequestSender          = nodeRequestSender;
     this.crossNodeService           = crossNodeService;
     this.systemMessagesService      = systemMessagesService;
 }
Ejemplo n.º 10
0
        private async Task SendNoticeToNodesAsync(NodeNotice notice, IEnumerable <long> nodesIds = null)
        {
            List <NodeConnection> nodesConnections;

            if (nodesIds == null || !nodesIds.Any())
            {
                var nodes = await _nodesService.GetAllNodesInfoAsync().ConfigureAwait(false);

                nodesIds = nodes.Select(opt => opt.Id);
            }
            if (nodesIds != null && nodesIds.Any())
            {
                nodesConnections = _connectionsService.GetNodeConnections(nodesIds);
                IEnumerable <long> notConnectedNodesIds;
                if (nodesConnections != null && nodesConnections.Any())
                {
                    notConnectedNodesIds = nodesIds.Where(id => !nodesConnections.Any(node => node?.Node?.Id == id));
                }
                else
                {
                    notConnectedNodesIds = nodesIds;
                }

                if (notConnectedNodesIds != null && notConnectedNodesIds.Any())
                {
                    foreach (var nodeId in notConnectedNodesIds)
                    {
                        await _pendingMessagesService.AddNodePendingMessageAsync(nodeId, notice, TimeSpan.FromDays(10)).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                nodesConnections = _connectionsService.GetNodeConnections();
            }
            await SendNoticeToNodesAsync(nodesConnections, notice).ConfigureAwait(false);
        }
Ejemplo n.º 11
0
        private async Task SendNoticeToNodesAsync(IEnumerable <NodeConnection> nodes, NodeNotice notice)
        {
            try
            {
                foreach (var node in nodes)
                {
                    if (node.NodeWebSocket.State != WebSocketState.Open && node.Node != null)
                    {
                        await _pendingMessagesService.AddNodePendingMessageAsync(node.Node.Id, notice, TimeSpan.FromDays(10)).ConfigureAwait(false);

                        continue;
                    }
                    try
                    {
                        byte[] noticeData;
                        if (node.IsEncryptedConnection)
                        {
                            noticeData = Encryptor.SymmetricDataEncrypt(
                                ObjectSerializer.ObjectToByteArray(notice),
                                NodeData.Instance.NodeKeys.SignPrivateKey,
                                node.SymmetricKey,
                                MessageDataType.Notice,
                                NodeData.Instance.NodeKeys.Password);
                        }
                        else
                        {
                            noticeData = ObjectSerializer.ObjectToByteArray(notice);
                        }
                        await node.NodeWebSocket.SendAsync(
                            noticeData,
                            WebSocketMessageType.Binary,
                            true,
                            CancellationToken.None).ConfigureAwait(false);
                    }
                    catch (WebSocketException)
                    {
                        Logger.WriteLog("Connection was closed.");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex, notice.ToString());
            }
        }
 public ProxyUsersNotificationsNodeNoticeHandler(NodeNotice notice, NodeConnection nodeConnection, IConnectionsService connectionsService)
 {
     this.notice             = (ProxyUsersNotificationsNodeNotice)notice;
     this.nodeConnection     = nodeConnection;
     this.connectionsService = connectionsService;
 }
 public UsersRemovedFromUserBlacklistNoticeHandler(NodeNotice notice, NodeConnection current, IUpdateUsersService updateUsersService)
 {
     this.notice             = (UsersRemovedFromUserBlacklistNodeNotice)notice;
     this.current            = current;
     this.updateUsersService = updateUsersService;
 }
Ejemplo n.º 14
0
 public ClientDisconnectedNoticeHandler(NodeNotice notice, IConnectionsService connectionsService)
 {
     this.notice             = (ClientDisconnectedNodeNotice)notice;
     this.connectionsService = connectionsService;
 }
        private async void HandleNotice(NodeNotice notice)
        {
            try
            {
                ICommunicationHandler noticeHandler = null;
                switch (notice.NoticeCode)
                {
                case NodeNoticeCode.NewBlocks:
                {
                    noticeHandler = new NewBlocksNoticeHandler(notice, nodeConnection, appServiceProvider.KeysService);
                }
                break;

                case NodeNoticeCode.NewNodes:
                {
                    noticeHandler = new NewNodesNoticeHandler(notice, nodeConnection, appServiceProvider.CrossNodeService);
                }
                break;

                case NodeNoticeCode.EditNodes:
                {
                    noticeHandler = new EditNodesNoticeHandler(notice, nodeConnection, appServiceProvider.CrossNodeService);
                }
                break;

                case NodeNoticeCode.NewUsers:
                {
                    noticeHandler = new NewUsersNoticeHandler(notice, nodeConnection, appServiceProvider.CrossNodeService);
                }
                break;

                case NodeNoticeCode.EditUsers:
                {
                    noticeHandler = new EditUsersNoticeHandler(notice, nodeConnection, appServiceProvider.CrossNodeService);
                }
                break;

                case NodeNoticeCode.DeleteUsers:
                {
                    noticeHandler = new DeleteUsersNoticeHandler(notice, nodeConnection, appServiceProvider.DeleteUsersService);
                }
                break;

                case NodeNoticeCode.NewChats:
                {
                    noticeHandler = new NewChatsNoticeHandler(notice, nodeConnection, appServiceProvider.NodeNoticeService, appServiceProvider.ConversationsNoticeService, appServiceProvider.CrossNodeService);
                }
                break;

                case NodeNoticeCode.DeleteConversations:
                {
                    noticeHandler = new DeleteConversationsNoticeHandler(
                        notice,
                        appServiceProvider.DeleteChatsService,
                        appServiceProvider.LoadChatsService,
                        appServiceProvider.LoadDialogsService,
                        appServiceProvider.DeleteDialogsService,
                        appServiceProvider.LoadChannelsService,
                        appServiceProvider.DeleteChannelsService);
                }
                break;

                case NodeNoticeCode.EditChats:
                {
                    noticeHandler = new EditChatsNoticeHandler(
                        notice,
                        nodeConnection,
                        appServiceProvider.NodeNoticeService,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.LoadChatsService,
                        appServiceProvider.CrossNodeService,
                        appServiceProvider.SystemMessagesService);
                }
                break;

                case NodeNoticeCode.NewFiles:
                {
                    noticeHandler = new NewFilesNoticeHandler(notice, nodeConnection, appServiceProvider.FilesService);
                }
                break;

                case NodeNoticeCode.DeleteFiles:
                {
                    noticeHandler = new DeleteFilesNoticeHandler(notice, nodeConnection, appServiceProvider.FilesService);
                }
                break;

                case NodeNoticeCode.NewMessagesNotice:
                {
                    noticeHandler = new NewMessagesNoticeHandler(
                        notice,
                        nodeConnection,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.AttachmentsService,
                        appServiceProvider.CreateMessagesService,
                        appServiceProvider.CreateChannelsService,
                        appServiceProvider.NodeRequestSender,
                        appServiceProvider.CrossNodeService,
                        appServiceProvider.LoadDialogsService);
                }
                break;

                case NodeNoticeCode.AddUsersChat:
                {
                    noticeHandler = new AddUsersChatNoticeHandler(
                        notice,
                        nodeConnection,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.UpdateChatsService,
                        appServiceProvider.NodeRequestSender,
                        appServiceProvider.CrossNodeService,
                        appServiceProvider.SystemMessagesService);
                }
                break;

                case NodeNoticeCode.ChangeUsersChat:
                {
                    noticeHandler = new ChangeUsersChatNoticeHandler(
                        notice,
                        nodeConnection,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.UpdateChatsService,
                        appServiceProvider.LoadChatsService,
                        appServiceProvider.NodeRequestSender,
                        appServiceProvider.CrossNodeService,
                        appServiceProvider.SystemMessagesService);
                }
                break;

                case NodeNoticeCode.MessagesRead:
                {
                    noticeHandler = new MessagesReadNoticeHandler(
                        notice,
                        nodeConnection,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.UpdateMessagesService,
                        appServiceProvider.UpdateChatsService,
                        appServiceProvider.LoadDialogsService,
                        appServiceProvider.UpdateChannelsService);
                }
                break;

                case NodeNoticeCode.BlockSegments:
                {
                    noticeHandler = new BlockSegmentsNoticeHandler(notice, nodeConnection);
                }
                break;

                case NodeNoticeCode.MessagesDeleted:
                {
                    noticeHandler = new MessagesDeletedNoticeHandler(
                        notice,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.DeleteMessagesService,
                        appServiceProvider.LoadChatsService,
                        appServiceProvider.LoadDialogsService,
                        appServiceProvider.LoadChannelsService);
                }
                break;

                case NodeNoticeCode.UsersAddedToUserBlacklist:
                {
                    noticeHandler = new UsersAddedToUserBlacklistNoticeHandler(notice, nodeConnection, appServiceProvider.UpdateUsersService);
                }
                break;

                case NodeNoticeCode.UsersRemovedFromUserBlacklist:
                {
                    noticeHandler = new UsersRemovedFromUserBlacklistNoticeHandler(notice, nodeConnection, appServiceProvider.UpdateUsersService);
                }
                break;

                case NodeNoticeCode.NewUserKeys:
                {
                    noticeHandler = new NewUserKeysNodeNoticeHandler(notice, nodeConnection, appServiceProvider.KeysService);
                }
                break;

                case NodeNoticeCode.DeleteUserKeys:
                {
                    noticeHandler = new DeleteUserKeysNodeNoticeHandler(notice, nodeConnection, appServiceProvider.KeysService);
                }
                break;

                case NodeNoticeCode.Channels:
                {
                    noticeHandler = new ChannelNodeNoticeHandler(notice, nodeConnection, appServiceProvider.ConversationsNoticeService, appServiceProvider.CreateChannelsService, appServiceProvider.LoadChannelsService, appServiceProvider.SystemMessagesService);
                }
                break;

                case NodeNoticeCode.ChannelsUsers:
                {
                    noticeHandler = new ChannelUsersNodeNoticeHandler(notice, nodeConnection, appServiceProvider.CreateChannelsService, appServiceProvider.NodeRequestSender, appServiceProvider.CrossNodeService);
                }
                break;

                case NodeNoticeCode.ClientDisconnected:
                {
                    noticeHandler = new ClientDisconnectedNoticeHandler(notice, appServiceProvider.ConnectionsService);
                }
                break;

                case NodeNoticeCode.UserNodeChanged:
                {
                    noticeHandler = new UserNodeChangedNodeNoticeHandler(notice, nodeConnection, appServiceProvider.UpdateUsersService);
                }
                break;

                case NodeNoticeCode.Polling:
                {
                    noticeHandler = new PollingNodeNoticeHandler(notice, nodeConnection, appServiceProvider.PollsService, appServiceProvider.NodeRequestSender);
                }
                break;

                case NodeNoticeCode.Proxy:
                {
                    noticeHandler = new ProxyUsersNotificationsNodeNoticeHandler(notice, nodeConnection, appServiceProvider.ConnectionsService);
                }
                break;

                case NodeNoticeCode.MessagesUpdated:
                {
                    noticeHandler = new MessagesUpdatedNodeNoticeHandler(
                        notice,
                        nodeConnection,
                        appServiceProvider.ConversationsNoticeService,
                        appServiceProvider.UpdateMessagesService,
                        appServiceProvider.AttachmentsService);
                }
                break;

                case NodeNoticeCode.NewNodeKeys:
                {
                    noticeHandler = new NewNodeKeysNodeNoticeHandler(notice, nodeConnection);
                }
                break;

                case NodeNoticeCode.AllMessagesDeleted:
                {
                    noticeHandler = new DeleteAllUserMessagesNodeNoticeHandler(notice, nodeConnection, appServiceProvider.DeleteMessagesService, appServiceProvider.LoadUsersService);
                }
                break;

                case NodeNoticeCode.ConversationAction:
                {
                    noticeHandler = new ConversationActionNodeNoticeHandler(notice, nodeConnection, appServiceProvider.ConversationsService, appServiceProvider.ConversationsNoticeService, appServiceProvider.LoadDialogsService,
                                                                            appServiceProvider.SystemMessagesService);
                }
                break;

                default:
                {
                    throw new ArgumentException($"Unknown NoticeCode: {notice.NoticeCode}");
                }
                }
                try
                {
                    if (noticeHandler.IsObjectValid())
                    {
                        await noticeHandler.HandleAsync().ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(ex, notice);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
 public UserNodeChangedNodeNoticeHandler(NodeNotice notice, NodeConnection current, IUpdateUsersService updateUsersService)
 {
     this.notice             = (UserNodeChangedNodeNotice)notice;
     this.current            = current;
     this.updateUsersService = updateUsersService;
 }
 public DeleteUserKeysNodeNoticeHandler(NodeNotice notice, NodeConnection current, IKeysService keysService)
 {
     this.notice      = (DeleteUserKeysNodeNotice)notice;
     this.current     = current;
     this.keysService = keysService;
 }
Ejemplo n.º 18
0
 private async Task SendNoticeToNodeAsync(NodeConnection nodeConnection, NodeNotice notice)
 {
     await SendNoticeToNodesAsync(new List <NodeConnection> {
         nodeConnection
     }, notice).ConfigureAwait(false);
 }
Ejemplo n.º 19
0
 public BlockSegmentsNoticeHandler(NodeNotice notice, NodeConnection current)
 {
     this.notice  = (BlockSegmentsNotice)notice;
     this.current = current;
 }
Ejemplo n.º 20
0
 public NewNodeKeysNodeNoticeHandler(NodeNotice notice, NodeConnection nodeConnection)
 {
     this.notice         = (NewNodeKeysNodeNotice)notice;
     this.nodeConnection = nodeConnection;
 }