Ejemplo n.º 1
0
 private void reportToETAgent(
     string message = default(string),
     string path    = default(string),
     EventHandler <FileTransferFinishedEventArgs> fileTransferFinishedHandler = null)
 {
     if (message != default(string))
     {
         conn.Send(agent.Channels[Tools.CHANNEL_ID], Encoding.UTF8.GetBytes(message));
         Debug.WriteLine(Tools.TAG, $"Message has been submitted on BLE. length={message.Length}");
     }
     else if (path != default(string))
     {
         OutgoingFileTransfer oft = new OutgoingFileTransfer(peer, path);
         oft.Send();
         if (fileTransferFinishedHandler == null)
         {
             oft.Finished += (s, e) => { Debug.WriteLine(Tools.TAG, $"File has been submitted on BLE. Result => {e.Result}"); }
         }
         ;
         else
         {
             oft.Finished += fileTransferFinishedHandler;
         }
     }
     log("Data uploaded");
 }
Ejemplo n.º 2
0
        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();
                }
            }
        }