示例#1
0
 void onException(object _sender, Receiver.AsyncEventArgs _args)
 {
     if (null != OnException)
     {
         OnException(this, newArgs(_args, _args.msg));
     }
 }
示例#2
0
        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, ""));
            }
        }
示例#3
0
 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;
 }
示例#4
0
 void onNetError(object _sender, Receiver.AsyncEventArgs _args)
 {
     if (null != OnError)
     {
         OnError(this, newArgs(_args, _args.msg));
     }
 }
示例#5
0
 void onClientDisconnected(object _sender, Receiver.AsyncEventArgs _args)
 {
     if (null != OnFinish)
     {
         OnFinish(this, newArgs(_args, ""));
     }
     handleClientDisconnected(_args);
 }
示例#6
0
 void onClientConnected(object _sender, Receiver.AsyncEventArgs _args)
 {
     handleClientConnected(_args);
     if (null != this.OnReady)
     {
         OnReady(this, newArgs(_args, ""));
     }
 }
示例#7
0
        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);
        }
示例#8
0
        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);
            }
        }
示例#9
0
 protected abstract void handleClientDisconnected(Receiver.AsyncEventArgs _args);
示例#10
0
 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));
 }
示例#11
0
 protected override void handleClientConnected(Receiver.AsyncEventArgs _args)
 {
     _args.state.writer.guid   = Guid.NewGuid().ToString();
     _args.state.writer.stream = new MemoryStream();
 }