public void HandleTransferRequest(TransferRequestMessage request)
 {
     string[] filePaths = FileOperations.GetFilteredFilePaths(logsSourcePath,
                                                              request.TimeRangeLocal, request.FullCategories);
     if (filePaths.Length == 0)
     {
         SendResponseMessage(ResponseCode.Error,
                             "No files found that match request");
         return;
     }
     // send response
     SendResponseMessage(ResponseCode.Ok);
     // transfer files
     logger.Log("Transferring files...");
     for (int i = 0; i < filePaths.Length; i++)
     {
         string path = filePaths[i];
         logger.Log("Transferring: " + path);
         string fileName            = Path.GetFileName(path);
         byte[] fileBytes           = File.ReadAllBytes(path);
         byte[] fileBytesCompressed = ByteCompression.GZipCompress(fileBytes);
         var    message             = new TransferOperationMessage(
             i + 1, filePaths.Length, fileName, fileBytesCompressed);
         client.Writer.Write(message);
     }
     logger.Log("Transfer operation complete");
 }
Beispiel #2
0
        private async void ReceivingAndDecodingWork(object state)
        {
            while (!doneReceiving)
            {
                string message = await Client.AwaitMessageAsync();

                Console.WriteLine("Received file message. Decoding...");
                TransferOperationMessage msgDecoded =
                    Decoder.DecodeMessage <TransferOperationMessage>(message);
                Console.WriteLine("Decoded file: " + msgDecoded.FileName);
                operationMessageQueue.Enqueue(msgDecoded);
                if (msgDecoded.NumFilesCompleted == msgDecoded.NumTotalFiles)
                {
                    doneReceiving = true;
                }
                autoEvent.Set();
            }
        }