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