/// <summary> /// Private constructor for initializing <b>server side</b> sessions. /// </summary> /// <param name="router">The message router.</param> /// <param name="msg">The <see cref="ReliableTransferMsg" /> that initiated this session.</param> /// <param name="direction">The transfer direction supported by the server.</param> /// <param name="stream">The input or output stream.</param> /// <exception cref="InvalidOperationException"> /// Thrown if the client requested transfer direction does not match the /// direction implied by this method. /// </exception> private StreamTransferSession(MsgRouter router, ReliableTransferMsg msg, TransferDirection direction, EnhancedStream stream) { if (direction != msg.Direction) { throw new InvalidOperationException(string.Format("Transfer direction [{0}] is not supported.", msg.Direction)); } ReliableTransferHandler handler; reliableSession = msg.Session; reliableSession.SessionHandler = handler = new ReliableTransferHandler(reliableSession); handler.BeginTransferEvent += new ReliableTransferDelegate(OnBeginTransfer); handler.EndTransferEvent += new ReliableTransferDelegate(OnEndTransfer); if (direction == TransferDirection.Upload) { handler.ReceiveEvent += new ReliableTransferDelegate(OnReceive); } else { handler.SendEvent += new ReliableTransferDelegate(OnSend); } this.router = router; this.direction = direction; this.args = msg.Args; this.stream = stream; this.started = false; this.closed = false; this.arTransfer = null; this.simError = false; this.simCancel = false; this.delay = 0; }
/// <summary> /// Generates a clone of this message instance, generating a new /// <see cref="Msg._MsgID" /> property if the original ID is /// not empty. /// </summary> /// <returns>The cloned message.</returns> public override Msg Clone() { ReliableTransferMsg clone; clone = new ReliableTransferMsg(Stub.Param); clone.CopyBaseFields(this, true); return(clone); }
/// <summary> /// /// </summary> /// <param name="router">The <see cref="MsgRouter" /> to associate with the session.</param> /// <param name="msg">The <see cref="ReliableTransferMsg" /> that initiated this session.</param> /// <param name="input">The input stream whose data is to be downloaded.</param> /// <returns>The new <see cref="StreamTransferSession" /> instance.</returns> /// <remarks> /// The application will need to <see cref="BeginTransfer" /> to initiate the transfer. /// </remarks> /// <exception cref="InvalidOperationException"> /// Thrown if the client requested transfer direction does not match the /// direction implied by this method. /// </exception> public static StreamTransferSession ServerDownload(MsgRouter router, ReliableTransferMsg msg, EnhancedStream input) { return(new StreamTransferSession(router, msg, TransferDirection.Download, input)); }
/// <summary> /// /// </summary> /// <param name="router">The <see cref="MsgRouter" /> to associate with the session.</param> /// <param name="msg">The <see cref="ReliableTransferMsg" /> that initiated this session.</param> /// <param name="inputPath">The path of the file to be downloaded.</param> /// <returns>The new <see cref="StreamTransferSession" /> instance.</returns> /// <remarks> /// The application will need to <see cref="BeginTransfer" /> to initiate the transfer. /// </remarks> /// <exception cref="InvalidOperationException"> /// Thrown if the client requested transfer direction does not match the /// direction implied by this method. /// </exception> public static StreamTransferSession ServerDownload(MsgRouter router, ReliableTransferMsg msg, string inputPath) { return(ServerDownload(router, msg, new EnhancedFileStream(inputPath, FileMode.Open, FileAccess.Read))); }
/// <summary> /// /// </summary> /// <param name="router">The <see cref="MsgRouter" /> to associate with the session.</param> /// <param name="msg">The <see cref="ReliableTransferMsg" /> that initiated this session.</param> /// <param name="outputPath">Path of the output file where the uploaded data will be written.</param> /// <returns>The new <see cref="StreamTransferSession" /> instance.</returns> /// <remarks> /// The application will need to <see cref="BeginTransfer" /> to initiate the transfer. /// </remarks> /// <exception cref="InvalidOperationException"> /// Thrown if the client requested transfer direction does not match the /// direction implied by this method. /// </exception> public static StreamTransferSession ServerUpload(MsgRouter router, ReliableTransferMsg msg, string outputPath) { return(ServerUpload(router, msg, new EnhancedFileStream(outputPath, FileMode.Create, FileAccess.ReadWrite))); }