void factory_FileRequestReceived(object sender, FileRequestEventArgs e)
 {
     if (FileRequestReceived != null)
     {
         FileRequestReceived(sender, e);
     }
 }
 void _rebuilderService_NextChunkRequested(object sender, FileRequestEventArgs e)
 {
     ClientFactory.OnNextFileChunkRequested(e);
 }
        internal void RequestFile(FileDescriptor file, long chunkIndex, Action<FileDescriptor, FileRequestMode> sendResponseCallback, Action<FileDescriptor, FileChunkMessage> sendChunkCallback)
        {
            FileRequestEventArgs e = new FileRequestEventArgs(file);

            //This is giving a chance for the Server application to globally block a file - it has nothing to do with the client's desire to server the file
            if (FileRequested != null)
            {
                FileRequested(this, e);
            }

            if (!e.Allow)
            {
                sendResponseCallback(file, FileRequestMode.NotAvailable);
                return;
            }

            if (ServerFactory.Protocols.Count(p => p.Files.Contains(file)) == 0)
            {
                sendResponseCallback(file, FileRequestMode.NotAvailable);
                return;
            }

            //Negotiate File Transfer
            _activeNegotiators.Add(
                new FileServerNegotiator(ServerFactory, file, sendResponseCallback, sendChunkCallback));

            _activeNegotiators[_activeNegotiators.Count - 1].TimedOut += new EventHandler(FileServiceNegotiator_TimedOut);
            _activeNegotiators[_activeNegotiators.Count - 1].Settings = _settings;
            _activeNegotiators[_activeNegotiators.Count - 1].Negotiate(chunkIndex);
        }
 void event_FileRequestReceived(object sender, FileRequestEventArgs e)
 {
     if (_fileRequestReceivedCallback != null)
     {
         _fileRequestReceivedCallback(e);
     }
 }
Example #5
0
        /// <summary>
        /// Will assume file is allowed unless FileRequestReceived event is not handled.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Service_FileRequestReceived(object sender, FileRequestEventArgs e)
        {
            //Check first whether file actually is available
            if (!_localFiles.Contains(e.File))
            {
                e.Allow = false;
                return;
            }

            if (FileRequestReceived != null)
            {
                FileRequestReceived(sender, e);
            }
        }
        private bool WriteChunkToFile(FileChunkMessage chunk)
        {
            if (_host == null) throw new InvalidOperationException("Service not started");

            if (chunk.IsStartChunk)
            {
                PrepareForTransfer(chunk.Header.Hash);
            }

            if (!_fileBuilders.ContainsKey(chunk.Header.Hash))
            {
                return false;
            }

            FileRebuilder builder = _fileBuilders[chunk.Header.Hash];

            builder.ReceiveChunk(chunk);

            if (chunk.IsEndChunk && TransferCompleted != null)
            {
                FileTransferCompletedEventArgs args = new FileTransferCompletedEventArgs(chunk.Header.Hash, builder.FileName);

                //Close so subscribers can move file
                _fileBuilders[chunk.Header.Hash].Close();

                TransferCompleted(this, args);

                _fileBuilders[chunk.Header.Hash].Dispose();
                _fileBuilders.Remove(chunk.Header.Hash);
            }
            else
            {
                if (NextChunkRequested != null)
                {
                    FileRequestEventArgs args = new FileRequestEventArgs(null);
                    args.Hash = chunk.Header.Hash;
                    args.ChunkIndex = chunk.ChunkIndex + 1;

                    NextChunkRequested(this, args);
                }
            }

            return true;
        }
Example #7
0
 void ServerService_FileRequested(object sender, FileRequestEventArgs e)
 {
     if (FileRequested != null)
     {
         FileRequested(sender, e);
     }
 }
        private void HandleRequestedFileMessage(FileRequestMessage requestMessage)
        {
            FileRequestEventArgs e = new FileRequestEventArgs(requestMessage.RequestedFile);

            if (FileRequestReceived != null)
            {
                FileRequestReceived(this, e);
            }

            ClientProtocol.SendFileRequestResponse(requestMessage.RequestedFile, e.Allow);
        }
        internal void OnNextFileChunkRequested(FileRequestEventArgs e)
        {
            if (!_requestedFiles.ContainsKey(e.Hash))
            {
                throw new InvalidOperationException(string.Format("Next chunk requested for unknown file {0)", e.Hash));
            }

            e.File = _requestedFiles[e.Hash];

            if (FileNextChunkRequestReceived != null)
            {
                FileNextChunkRequestReceived(this, new FileRequestEventArgs(e.File));
            }

            SendFileRequest(e.File, e.ChunkIndex);
        }