void onException(object _sender, Receiver.AsyncEventArgs _args) { if (null != OnException) { OnException(this, newArgs(_args, _args.msg)); } }
void onDataReceived(object _sender, Receiver.AsyncEventArgs _args) { int currentBlockSize = _args.state.currentBlockSize; int fileBlockSize = currentBlockSize; int fileReceivedSize = currentBlockSize; int offset = 0; if (_args.state.writer.stream.Position == 0) { if (_args.state.currentBlockSize >= Header.Size) { _args.state.writer.size = Convert.BytesToInt64(_args.state.Buffer, 0); int nameLength = Convert.BytesToInt32(_args.state.Buffer, 8); _args.state.writer.filename = Encoding.UTF8.GetString(_args.state.Buffer, 8 + 4, nameLength); fileBlockSize = _args.state.currentBlockSize - Header.Size; fileReceivedSize = _args.state.currentBlockSize - Header.Size; offset = Header.Size; } } _args.state.writer.stream.Write(_args.state.Buffer, offset, fileBlockSize); _args.state.receivedSize += fileReceivedSize; if (null != OnReceive) { OnReceive(this, newArgs(_args, "")); } }
protected override void handleClientDisconnected(Receiver.AsyncEventArgs _args) { _args.state.writer.stream.Flush(); _args.state.writer.stream.Close(); _args.state.writer.stream.Dispose(); _args.state.writer = null; }
void onNetError(object _sender, Receiver.AsyncEventArgs _args) { if (null != OnError) { OnError(this, newArgs(_args, _args.msg)); } }
void onClientDisconnected(object _sender, Receiver.AsyncEventArgs _args) { if (null != OnFinish) { OnFinish(this, newArgs(_args, "")); } handleClientDisconnected(_args); }
void onClientConnected(object _sender, Receiver.AsyncEventArgs _args) { handleClientConnected(_args); if (null != this.OnReady) { OnReady(this, newArgs(_args, "")); } }
protected override void handleClientConnected(Receiver.AsyncEventArgs _args) { if (!Directory.Exists(directory)) { throw new DirectoryNotFoundException(directory); } _args.state.writer.guid = Guid.NewGuid().ToString(); string file = Path.Combine(directory, _args.state.writer.guid + ".tmp"); _args.state.writer.stream = File.Open(file, FileMode.Create, FileAccess.Write); }
protected override void handleClientDisconnected(Receiver.AsyncEventArgs _args) { _args.state.writer.stream.Flush(); bool isComplete = _args.state.writer.stream.Length + Header.Size == _args.state.writer.size; _args.state.writer.stream.Close(); _args.state.writer.stream.Dispose(); string tmpFile = Path.Combine(directory, _args.state.writer.guid + ".tmp"); string distFile = Path.Combine(directory, _args.state.writer.filename); if (isComplete) { File.Move(tmpFile, distFile); } else { File.Delete(tmpFile); } }
protected abstract void handleClientDisconnected(Receiver.AsyncEventArgs _args);
private AsyncEventArgs newArgs(Receiver.AsyncEventArgs _args, string _message) { return(new AsyncEventArgs(_args.state.writer.filename, _args.state.writer.size - Header.Size, _message, _args.state.writer.stream)); }
protected override void handleClientConnected(Receiver.AsyncEventArgs _args) { _args.state.writer.guid = Guid.NewGuid().ToString(); _args.state.writer.stream = new MemoryStream(); }