コード例 #1
0
        // Data
        private async Task SendData()
        {
            transferStopwatch = new Stopwatch();
            transferStopwatch.Start();
            int totalItemCount = 0;
            await Task.Run(() =>
            {
                // Send files info
                byte[] infoBuffer = new byte[13];
                infoBuffer[0]     = (byte)TTInstruction.Transfer_TransferInfo;

                totalItemCount = items.Count();
                foreach (var item in items)
                {
                    totalItemCount += item.GetTotalChildCount();
                }
                byte[] countBytes = BitConverter.GetBytes(totalItemCount);
                Array.Copy(countBytes, 0, infoBuffer, 1, 4);

                long totalSize = 0;
                foreach (var item in items)
                {
                    totalSize += item.GetTotalSize();
                }
                byte[] sizeBytes = BitConverter.GetBytes(totalSize);
                Array.Copy(sizeBytes, 0, infoBuffer, 1 + 4, 8);

                TrySend(infoBuffer, true);


                // Send data
                bytesSent  = 0;
                totalBytes = totalSize;
                foreach (var item in items)
                {
                    if (item.IsFolder)
                    {
                        SendFolder(item, "");
                    }
                    else
                    {
                        SendFile(item, "");
                    }
                }
            });


            transferStopwatch.Stop();
            OnRecordableEvent($"Sucessfully sent {totalItemCount} item/s ({ExplorerControl.FormatFileSize(bytesSent)}) in {TTNet.FormatTimeSpan(transferStopwatch.Elapsed)} at average { ExplorerControl.FormatFileSize(totalBytes * 1000 / transferStopwatch.ElapsedMilliseconds)}/s.", Console.ConsoleMessageType.Common);
        }
コード例 #2
0
ファイル: TransferServer.cs プロジェクト: LeaT113/TTransfer
        // Data
        private async Task ReceiveData()
        {
            transferStopwatch = new Stopwatch();
            transferStopwatch.Start();
            await Task.Run(() =>
            {
                // Receive info about transfer
                int length = 13;
                if (clientEncryptor != null)
                {
                    length = DataEncryptor.PredictAESLength(length);
                }
                CommunicationResult res = TryRead(clientIpPort, length, true);


                // Receive data
                int itemCount = 0;
                if (res.Instruction == TTInstruction.Transfer_TransferInfo)
                {
                    // Receive files individually
                    itemCount  = BitConverter.ToInt32(res.Data, 0);
                    totalBytes = BitConverter.ToInt64(res.Data, 4);

                    for (int i = 0; i < itemCount; i++)
                    {
                        ReceiveItem();
                    }
                }
                else
                {
                    throw new FailedReceivingException("Client sent wrong instruction about transfer.");
                }

                transferStopwatch.Stop();
                OnRecordableEvent($"Sucessfully received {itemCount} item/s ({Explorer.ExplorerControl.FormatFileSize(bytesReceived)}) in {TTNet.FormatTimeSpan(transferStopwatch.Elapsed)} at average { Explorer.ExplorerControl.FormatFileSize(bytesReceived * 1000 / transferStopwatch.ElapsedMilliseconds)}/s.", Console.ConsoleMessageType.Common);
            });
        }