public void AddFileSliceSender(FileSliceSender fileSliceSender)
 {
     TransferStatus.Add(fileSliceSender.UniqueKey, new FileTransferStatus
     {
         NextSlice     = 0,
         SlicesCount   = fileSliceSender.SlicesCount,
         LastSliceSize = fileSliceSender.LastSliceSize,
         SliceMaxSize  = sliceMaxSize,
     });
 }
Ejemplo n.º 2
0
        private async Task InitFileReceiveEndpoints(IWebServer server, FileSendInfo fileInfo, FileSendProgressCalculator transferProgress)
        {
            await fileInfo.InitSlicingAsync();

            fileSliceSender = new FileSliceSender(fileInfo);
            transferProgress.AddFileSliceSender(fileSliceSender);
            fileSliceSender.SliceRequested += transferProgress.SliceRequestReceived;

            for (int i = 0; i < fileInfo.SlicesCount; i++)
            {
                server.AddResponseUrl($"/{fileInfo.UniqueKey}/{i}/", (Func <IWebServer, RequestDetails, Task <byte[]> >)fileSliceSender.GetFileSlice);
            }
        }
        internal void SliceRequestReceived(FileSliceSender sender, SliceRequestedEventArgs e)
        {
            if (!TransferStatus.ContainsKey(sender.UniqueKey))
            {
                throw new KeyNotFoundException($"FileSliceSender '{sender.UniqueKey}' was not registered in FileSendProgressCalculator.");
            }

            var nextSlice = e.RequestedSlice + 1;

            if (TransferStatus[sender.UniqueKey].NextSlice < nextSlice)
            {
                TransferStatus[sender.UniqueKey].NextSlice = nextSlice;
            }

            TransferStarted            = true;
            timeoutCountSinceLastSlice = 0;
            UpdateTimer();
            InvokeProgressEvent();
        }