protected override void ProcessNewChannel(string object_path, uint initiator_handle, uint target_handle, ChannelDetails c) { Console.WriteLine("Processing new channel for file transfer"); string filename = (string)c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Filename"]; string content_type = (string)c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".ContentType"]; ulong size = (ulong)c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Size"]; Contact contact = Connection.Roster.GetContact(target_handle); FileTransferChannel ft = null; FileTransfer transfer = null; try { ft = new FileTransferChannel(this.Connection, object_path, initiator_handle, target_handle, filename, content_type, (long)size); if (initiator_handle != Connection.SelfHandle) { transfer = new IncomingFileTransfer(contact, ft); } else { transfer = new OutgoingFileTransfer(contact, ft); } if (transfer != null) { DispatchManager dm = Connection.DispatchManager; dm.Add(contact, transfer.OriginalFilename, transfer); } } catch (Exception e) { Console.WriteLine(e.ToString()); if (transfer != null) { transfer.Dispose(); } else if (ft != null) { ft.Dispose(); } } }
protected override void Dispose(bool disposing) { if (IsDisposed) { return; } if (disposing) { if (Channel != null) { if (state != TransferState.Idle) { this.Close(); } FileTransferChannel ft = Channel as FileTransferChannel; if (ft != null) { ft.ChannelReady -= OnChannelReady; ft.Closed -= OnTransferClosed; ft.IFileTransfer.TransferredBytesChanged -= OnTransferredBytesChanged; ft.Dispose(); Channel = null; } } if (socket != null) { try { socket.Close(); } catch (Exception) {} } socket = null; } base.Dispose(disposing); }
protected override void ProcessNewChannel(string object_path, uint initiator_handle, uint target_handle, ChannelDetails c) { Console.WriteLine ("Processing new channel for file transfer"); string filename = (string) c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Filename"]; string content_type = (string) c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".ContentType"]; ulong size = (ulong) c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Size"]; Contact contact = Connection.Roster.GetContact (target_handle); FileTransferChannel ft = null; FileTransfer transfer = null; try { ft = new FileTransferChannel (this.Connection, object_path, initiator_handle, target_handle, filename, content_type, (long) size); if (initiator_handle != Connection.SelfHandle) { transfer = new IncomingFileTransfer (contact, ft); } else { transfer = new OutgoingFileTransfer (contact, ft); } if (transfer != null) { DispatchManager dm = Connection.DispatchManager; dm.Add (contact, transfer.OriginalFilename, transfer); } } catch (Exception e) { Console.WriteLine (e.ToString ()); if (transfer != null) { transfer.Dispose (); } else if (ft != null) { ft.Dispose (); } } }