/// <summary>
		/// Initializes a new instance of the FileTransferAbortedEventArgs class.
		/// </summary>
		/// <param name="transfer">A FileTransfer object representing the file-transfer
		/// operation for which the event is being raised.</param>
		/// <exception cref="ArgumentNullException">The transfer parameter is
		/// null.</exception>
		internal FileTransferAbortedEventArgs(FileTransfer transfer) {
			transfer.ThrowIfNull("transfer");
			Transfer = transfer;
		}
		/// <summary>
		/// Initializes a new instance of the FileTransferProgressEventArgs class.
		/// </summary>
		/// <param name="transfer">A FileTransfer object representing the file-transfer
		/// operation for which the event is being raised.</param>
		/// <exception cref="ArgumentNullException">The transfer parameter is
		/// null.</exception>
		internal FileTransferProgressEventArgs(FileTransfer transfer) {
			transfer.ThrowIfNull("transfer");
			Transfer = transfer;
		}
Beispiel #3
0
 /// <summary>
 /// Cancels the specified file-transfer.
 /// </summary>
 /// <param name="transfer">The file-transfer to cancel.</param>
 /// <exception cref="ArgumentNullException">The transfer parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The specified transfer instance does
 /// not represent an active data-transfer operation.</exception>
 /// <exception cref="InvalidOperationException">The XmppClient instance is not
 /// connected to a remote host, or the XmppClient instance has not authenticated with
 /// the XMPP server.</exception>
 /// <exception cref="ObjectDisposedException">The XmppClient object has been
 /// disposed.</exception>
 public void CancelFileTransfer(FileTransfer transfer)
 {
     AssertValid();
     transfer.ThrowIfNull("transfer");
     siFileTransfer.CancelFileTransfer(transfer);
 }
 /// <summary>
 /// Invoked once the result of a pending stream-initiation operation has been
 /// received.
 /// </summary>
 /// <param name="result">The result of the stream-initiation operation. If
 /// this parameter is null, stream-initiation failed.</param>
 /// <param name="to">The JID of the XMPP user to offer the file to.</param>
 /// <param name="stream">The stream to read the file-data from.</param>
 /// <param name="name">The name of the file, as offered to the XMPP user
 /// with the specified JID.</param>
 /// <param name="size">The number of bytes to transfer.</param>
 /// <param name="cb">A callback method invoked once the other site has
 /// accepted or rejected the file-transfer request.</param>
 /// <param name="description">A description of the file so the receiver can
 /// better understand what is being sent.</param>
 /// <remarks>This is called in the context of an arbitrary thread.</remarks>
 private void OnInitiationResult(InitiationResult result, Jid to, string name,
     Stream stream, long size, string description, Action<bool, FileTransfer> cb)
 {
     FileTransfer transfer = new FileTransfer(im.Jid, to, name, size, null,
         description);
     try
     {
         // Get the instance of the data-stream extension that the other site has
         // selected.
         IDataStream ext = im.GetExtension(result.Method) as IDataStream;
         // Register the session.
         SISession session = new SISession(result.SessionId, stream, size, false,
             im.Jid, to, ext);
         siSessions.TryAdd(result.SessionId, session);
         // Store the file's meta data.
         metaData.TryAdd(result.SessionId, new FileMetaData(name, description));
         // Invoke user-provided callback.
         if (cb != null)
             cb.Invoke(true, transfer);
         // Perform the actual data-transfer.
         try
         {
             ext.Transfer(session);
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.Message + e.StackTrace + e.ToString());
             // Nothing to do here.
         }
     }
     catch
     {
         // Something went wrong. Invoke user-provided callback to let them know
         // the file-transfer can't be performed.
         if (cb != null)
             cb.Invoke(false, transfer);
     }
 }
 /// <summary>
 /// Invoked whenever a 'Stream Initiation' request for file transfers
 /// is received.
 /// </summary>
 /// <param name="from">The JID of the XMPP entity that wishes to initiate
 /// the data-stream.</param>
 /// <param name="si">The 'si' element of the request.</param>
 /// <returns>The response to the SI request or an error element to include
 /// in the IQ response.</returns>
 private XmlElement OnStreamInitiationRequest(Jid from, XmlElement si)
 {
     try
     {
         string method = SelectStreamMethod(si["feature"]);
         // If the session-id is already in use, we cannot process the request.
         string sid = si.GetAttribute("id");
         if (String.IsNullOrEmpty(sid) || siSessions.ContainsKey(sid))
             return new XmppError(ErrorType.Cancel, ErrorCondition.Conflict).Data;
         // Extract file information and hand to user.
         var file = si["file"];
         string desc = file["desc"] != null ? file["desc"].InnerText : null,
             name = file.GetAttribute("name");
         int size = int.Parse(file.GetAttribute("size"));
         FileTransfer transfer = new FileTransfer(from, im.Jid, name, size,
             sid, desc);
         string savePath = TransferRequest.Invoke(transfer);
         // User has rejected the request.
         if (savePath == null)
             return new XmppError(ErrorType.Cancel, ErrorCondition.NotAcceptable).Data;
         // Create an SI session instance.
         SISession session = new SISession(sid, File.OpenWrite(savePath),
             size, true, from, im.Jid, im.GetExtension(method) as IDataStream);
         siSessions.TryAdd(sid, session);
         // Store the file's meta data.
         metaData.TryAdd(sid, new FileMetaData(name, desc));
         // Construct and return the negotiation result.
         return Xml.Element("si", "http://jabber.org/protocol/si").Child(
             FeatureNegotiation.Create(new SubmitForm(
                 new ListField("stream-method", method))));
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine("Exception raised", e.ToString() + e.StackTrace);
         return new XmppError(ErrorType.Cancel, ErrorCondition.BadRequest).Data;
     }
 }
 /// <summary>
 /// Cancels the specified file-transfer.
 /// </summary>
 /// <param name="transfer">The file-transfer to cancel.</param>
 /// <exception cref="ArgumentNullException">The transfer parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The specified transfer instance does
 /// not represent an active data-transfer operation.</exception>
 public void CancelFileTransfer(FileTransfer transfer)
 {
     transfer.ThrowIfNull("transfer");
     SISession session = GetSession(transfer.SessionId, transfer.From,
         transfer.To);
     if (session == null)
     {
         throw new ArgumentException("The specified transfer instance does not " +
             "represent an active data-transfer operation.");
     }
     session.Extension.CancelTransfer(session);
 }
Beispiel #7
0
 private void FileTransferCallback(bool accepted, FileTransfer transfer)
 {
     uiDispatcher.multiDebug(transfer.To + " has " + (accepted == true ? "accepted " : "rejected ") +
         "the transfer of " + transfer.Name + ".");
 }
Beispiel #8
0
        /// <summary>
        /// Incoming File delegate
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">File transfer object</param>
        private string fileTransferMgt_OnFile_Delegate(FileTransfer e)
        {
            //Put a first wake lock since we are having an incoming file tranfered
            uiDispatcher.WakeLock((long)DefaultTimeOut);

            uiDispatcher.multiDebug("On File: " + e.ToString() + " " + e.Name + " " + e.SessionId + " " + e.From);

            return "filepath";
        }