Exemplo n.º 1
0
 private static void Server_OnClientConnected(string clientIP)
 {
     _transferMetrics = new Metrics();
     ClientIP         = clientIP;
     byte[] receivedData = server.GetData();
     if (receivedData == null)
     {
         return;
     }
     if (receivedData[0] == (byte)Functions.QueryTransfer)
     {
         int    numberOfFiles = BitConverter.ToInt32(receivedData, 1);
         long   transferSize  = BitConverter.ToInt64(receivedData, 5);
         int    nameLen       = receivedData[13];
         string senderDevice  = Encoding.ASCII.GetString(receivedData, 14, nameLen);
         FilePaths = new string[numberOfFiles];
         if (File == null)
         {
             File = new FileOperations();
         }
         File.CalculateFileSize(transferSize);
         string fileSizeString = File.FileSize.ToString("0.00") + " " + File.FileSizeUnit.ToString();
         Debug.WriteLine("numberOfFiles: " + numberOfFiles + " transfer size: " + fileSizeString + " device Name: " + senderDevice);
         IsSending = false;
         if (OnClientRequested != null)
         {
             OnClientRequested(fileSizeString, senderDevice);
         }
         else
         {
             ResponseToTransferRequest(false);
         }
         _transferMetrics.TotalDataSizeAsBytes = transferSize;
     }
 }
Exemplo n.º 2
0
 private static void UpdateTransferMetrics(long byteCounter, double elapsedTime)
 {
     lock (Lck_TransferMetrics)
     {
         _transferMetrics.TotalBytesSent   += byteCounter;
         _transferMetrics.TransferSpeed     = (_transferMetrics.TransferSpeed * 0.9 + 0.1 * (byteCounter / (MB * elapsedTime)));
         _transferMetrics.Progress          = ((double)_transferMetrics.TotalBytesSent / (double)_transferMetrics.TotalDataSizeAsBytes) * 100.0;
         _transferMetrics.TotalElapsedTime += elapsedTime;
         _transferMetrics.EstimatedTime     = (_transferMetrics.TotalDataSizeAsBytes - _transferMetrics.TotalBytesSent) / (_transferMetrics.TotalBytesSent / _transferMetrics.TotalElapsedTime);
         var file = new FileOperations();
         file.CalculateFileSize(_transferMetrics.TotalDataSizeAsBytes);
         _transferMetrics.TotalDataSize = file.FileSize;
         _transferMetrics.SizeUnit      = file.FileSizeUnit;
         file.CalculateFileSize(_transferMetrics.TotalBytesSent);
         _transferMetrics.TotalDataSent = file.FileSize;
         _transferMetrics.SentSizeUnit  = file.FileSizeUnit;
     }
 }