Esempio n. 1
0
        public void downloadFile(MyChatBubble chatBubble, string msisdn)
        {
            Uri downloadUriSource = new Uri(Uri.EscapeUriString(HikeConstants.FILE_TRANSFER_BASE_URL + "/" + chatBubble.FileAttachment.FileKey),
                                            UriKind.RelativeOrAbsolute);

            string relativeFilePath = "/" + msisdn + "/" + Convert.ToString(chatBubble.MessageId);
            string destinationPath  = "shared/transfers" + "/" + Convert.ToString(chatBubble.MessageId);
            Uri    destinationUri   = new Uri(destinationPath, UriKind.RelativeOrAbsolute);

            BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(downloadUriSource);

            // Set the transfer method. GET and POST are supported.
            transferRequest.Tag    = relativeFilePath;
            transferRequest.Method = "GET";
            transferRequest.TransferStatusChanged   += new EventHandler <BackgroundTransferEventArgs>(transfer_TransferStatusChanged);
            transferRequest.TransferProgressChanged += new EventHandler <BackgroundTransferEventArgs>(transfer_TransferProgressChanged);
            transferRequest.DownloadLocation         = destinationUri;
            try
            {
                transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
                BackgroundTransferService.Add(transferRequest);
                requestIdChatBubbleMap.Add(transferRequest.RequestId, chatBubble as ReceivedChatBubble);
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(AppResources.FileTransfer_ErrorMsgBoxText + ex.Message);
            }
            catch (Exception e)
            {
                MessageBox.Show(AppResources.FileTransfer_ErrorMsgBoxText);
            }
        }
Esempio n. 2
0
 public static void addUploadingOrDownloadingMessage(long messageId, MyChatBubble chatBubble)
 {
     if (messageId == -1)
     {
         return;
     }
     lock (lockObj)
     {
         if (!uploadingOrDownloadingMessages.ContainsKey(messageId))
         {
             uploadingOrDownloadingMessages.Add(messageId, chatBubble);
         }
     }
 }