Beispiel #1
0
        public async Task <List <FileInfoVm> > GetFilesInformationAsync(List <string> filesIds, long?nodeId = null)
        {
            NodeConnection nodeConnection;

            if (nodeId != null)
            {
                nodeConnection = connectionsService.GetNodeConnection(nodeId.Value);
            }
            else
            {
                nodeConnection = connectionsService.GetNodeConnections()
                                 .FirstOrDefault(opt => opt.Node?.Id != NodeSettings.Configs.Node.Id && opt.NodeWebSocket?.State == WebSocketState.Open);
            }
            if (nodeConnection != null)
            {
                GetObjectsInfoNodeRequest request = new GetObjectsInfoNodeRequest(filesIds);
                SendRequest(nodeConnection, request);
                var response = await GetResponseAsync(request).ConfigureAwait(false);

                if (response is FilesInformationResponse filesResponse)
                {
                    return(filesResponse.FilesInfo);
                }
                if (response != null)
                {
                    Console.WriteLine(response.ToJson());
                }
            }
            return(null);
        }
Beispiel #2
0
        public async Task <GetObjectsInfoNodeRequest> GetChatsInfoAsync(List <long> chatsId, NodeConnection nodeConnection)
        {
            GetObjectsInfoNodeRequest request = new GetObjectsInfoNodeRequest(chatsId, null, Enums.NodeRequestType.GetChats);

            SendRequest(nodeConnection, request);
            return(request);
        }
Beispiel #3
0
        public async Task <List <UserVm> > GetUsersInfoAsync(List <long> usersId, long?requestorUserId, NodeConnection nodeConnection)
        {
            try
            {
                GetObjectsInfoNodeRequest request = new GetObjectsInfoNodeRequest(usersId, requestorUserId, Enums.NodeRequestType.GetUsers);
                SendRequest(nodeConnection, request);
                UsersNodeResponse nodeResponse = (UsersNodeResponse) await GetResponseAsync(request).ConfigureAwait(false);

                return(nodeResponse.Users);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
                return(new List <UserVm>());
            }
        }
Beispiel #4
0
 public GetObjectsInfoNodeRequestHandler(NodeRequest request,
                                         NodeConnection nodeConnection,
                                         ILoadChatsService loadChatsService,
                                         ILoadUsersService loadUsersService,
                                         ILoadChannelsService loadChannelsService,
                                         IPrivacyService privacyService,
                                         IFilesService filesService)
 {
     this.request             = (GetObjectsInfoNodeRequest)request;
     this.nodeConnection      = nodeConnection;
     this.loadChatsService    = loadChatsService;
     this.loadUsersService    = loadUsersService;
     this.loadChannelsService = loadChannelsService;
     this.privacyService      = privacyService;
     this.filesService        = filesService;
 }
Beispiel #5
0
        public async Task <ChannelDto> GetChannelInformationAsync(long channelId, NodeConnection nodeConnection)
        {
            try
            {
                GetObjectsInfoNodeRequest request = new GetObjectsInfoNodeRequest(new List <long> {
                    channelId
                }, null, Enums.NodeRequestType.GetChannels);
                SendRequest(nodeConnection, request);
                NodeResponse response = await GetResponseAsync(request).ConfigureAwait(false);

                return(((ChannelsNodeResponse)response).Channels.FirstOrDefault());
            }
            catch
            {
                return(null);
            }
        }