Exemple #1
0
 public void Download(string url, AsyncCallback DownloadCallback)
 {
     url          = url.Replace("https", "http");
     BTR_Download = new BackgroundTransferRequest(new Uri(url));
     using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
     {
         if (!iso.DirectoryExists(TRANSFER_FOLDER))
         {
             iso.CreateDirectory(TRANSFER_FOLDER);
         }
     }
     BTR_Download.DownloadLocation         = new Uri(DOWNLOAD_LOCATION, UriKind.Relative);
     BTR_Download.TransferStatusChanged   += BTR_Download_TransferStatusChanged;
     BTR_Download.TransferProgressChanged += BTR_Download_TransferProgressChanged;
     if (!Downloading)
     {
         foreach (BackgroundTransferRequest req in BackgroundTransferService.Requests)
         {
             if (req.DownloadLocation == BTR_Download.DownloadLocation)
             {
                 BackgroundTransferService.Remove(req);
             }
         }
         BackgroundTransferService.Add(BTR_Download);
         Downloading = true;
         _downloadProgressChangeCallback = DownloadCallback;
     }
 }
Exemple #2
0
 void BTR_TransferStatusChanged(object sender, BackgroundTransferEventArgs e)
 {
     if (e.Request.TransferStatus == TransferStatus.Completed)
     {
         Uploading = false;
         if (e.Request.StatusCode == 200)
         {
             using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
             {
                 if (iso.FileExists(SAVE_RESPONSE_LOCATION))
                 {
                     IsolatedStorageFileStream fs = new IsolatedStorageFileStream(SAVE_RESPONSE_LOCATION, System.IO.FileMode.Open, iso);
                     //byte[] buffer = new byte[fs.Length];
                     //fs.Read(buffer, 0, (int)fs.Length);
                     StreamReader str  = new StreamReader(fs);
                     string       resp = str.ReadToEnd();
                     fs.Close();
                     JsonObject jobj = (JsonObject)SimpleJson.DeserializeObject(resp);
                     string     userid;
                     IsolatedStorageSettings.ApplicationSettings.TryGetValue("userid", out userid);
                     if (userid != null)
                     {
                         _heroku.AddBackup(jobj["key"].ToString(), jobj["url"].ToString(), userid);
                     }
                     iso.DeleteFile(SAVE_RESPONSE_LOCATION);
                     _uploadCallback.Invoke(new AsyncCallbackEvent("success"));
                 }
             }
         }
         BackgroundTransferService.Remove(e.Request);
     }
     Debug.WriteLine(e.Request.TransferStatus);
 }
Exemple #3
0
        void BTR_Download_TransferStatusChanged(object sender, BackgroundTransferEventArgs e)
        {
            if (e.Request.TransferStatus == TransferStatus.Completed)
            {
                Downloading = false;
                if (e.Request.StatusCode == 200)
                {
                    using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (iso.FileExists(DOWNLOAD_LOCATION))
                        {
                            iso.CopyFile(DOWNLOAD_LOCATION, "/cars.sdf", true);
                        }
                    }
                    string DBConnectionString = "Data Source=isostore:/cars.sdf";
                    App.ViewModel.Database.Dispose();

                    /*
                     * App.ViewModel.Database.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,App.ViewModel.Database.carInfo);
                     * App.ViewModel.Database.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, App.ViewModel.Database.fuelInfo);
                     * App.ViewModel.Database.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, App.ViewModel.Database.maintInfo);
                     * App.ViewModel.Database.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, App.ViewModel.Database.settingsInfo);
                     */
                    App.ViewModel = new Data(DBConnectionString);
                }
                BackgroundTransferService.Remove(e.Request);
            }
            Debug.WriteLine(e.Request.TransferStatus);
            Debug.WriteLine("downloaded-" + e.Request.BytesReceived);
        }
Exemple #4
0
        void OnBackgroundTransferStatusChanged(object sender, BackgroundTransferEventArgs e)
        {
            if (e.Request.TransferStatus == TransferStatus.Completed)
            {
                BackgroundTransferService.Remove(e.Request);

                if (_idMapping.ContainsKey(e.Request.RequestId))
                {
                    _idMapping[e.Request.RequestId].Invoke(e.Request);
                    _idMapping.Remove(e.Request.RequestId);
                }

                // Check if there are pending downloads, if there are then queue them up with background transfer service now.
                if (_requests.Count > 0)
                {
                    try
                    {
                        BackgroundTransferService.Add(_requests[0]);
                        _requests.RemoveAt(0);
                    }
                    catch (InvalidOperationException)
                    {
                    }
                }
            }
        }
Exemple #5
0
 public static void RemoveAllRequests()
 {
     foreach (var request in BackgroundTransferService.Requests)
     {
         BackgroundTransferService.Remove(request);
     }
 }
Exemple #6
0
        public void Upload(AsyncCallback UploadCallback, AsyncCallback uploadProgressCallback)
        {
            string upload_uri = FILEPICKER_BASEURL + "/api/store/S3?key=" + FILEPICKER_APIKEY;

            BTR = new BackgroundTransferRequest(new Uri(upload_uri));
            BTR.TransferStatusChanged   += BTR_TransferStatusChanged;
            BTR.TransferProgressChanged += BTR_TransferProgressChanged;
            BTR.Method = "POST";

            using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!iso.DirectoryExists(TRANSFER_FOLDER))
                {
                    iso.CreateDirectory(TRANSFER_FOLDER);
                }
                iso.CopyFile("/cars.sdf", TRANSFER_FOLDER + "/cars.sdf", true);
            }
            BTR.DownloadLocation = new Uri(SAVE_RESPONSE_LOCATION, UriKind.Relative);
            BTR.UploadLocation   = new Uri(TRANSFER_FOLDER + "/cars.sdf", UriKind.Relative);
            if (!Uploading)
            {
                Uploading = true;
                foreach (BackgroundTransferRequest req in BackgroundTransferService.Requests)
                {
                    if (req.UploadLocation == BTR.UploadLocation)
                    {
                        BackgroundTransferService.Remove(req);
                    }
                }
                BackgroundTransferService.Add(BTR);
                _uploadCallback = UploadCallback;
                _uplaodProgressChangeCallback = uploadProgressCallback;
            }
        }
        //=================================== blob 相关函数定义

        private void downloadECG(string filename)
        {
            if (_currentRequest != null)
            {
                BackgroundTransferService.Remove(_currentRequest);
            }


            //解析文件名,赋给SAVE_LOCATION
            //    filename = "634708322772702206";
            SAVE_LOCATION = SAVE_LOCATION + filename;
            Uri saveLocationUri = new Uri(SAVE_LOCATION, UriKind.RelativeOrAbsolute);


            //向服务器请求sas
            // string patient

            var    http = new Http();
            long   A    = System.DateTime.Today.Ticks;
            string uri  = "http://echelper.cloudapp.net/Service.svc/doctor/liaomin/downloadrequest?" + A;

            http.StartRequest(@uri,
                              result =>
            {
                //    A = result;
                //    x = 1;

                //    getfinished = false;
                Dispatcher.BeginInvoke(() => GetSas(result));
            });
        }
        void current_request_TransferStatusChanged(object sender, BackgroundTransferEventArgs e)
        {
            switch (e.Request.TransferStatus)
            {
            case TransferStatus.Completed:
                if (e.Request.StatusCode != 0)
                {
                    string[] filename = e.Request.Tag.Split('|');
                    ISOHelper.MoveFileOverwrite(e.Request.DownloadLocation.OriginalString, filename[0]);
                    BackgroundTransferService.Remove(e.Request);
                }
                long totaldata    = 0;
                long session_data = 0;

                IsolatedStorageSettings.ApplicationSettings.TryGetValue("total_data", out totaldata);
                totaldata += e.Request.BytesReceived / 1024 / 1024;
                IsolatedStorageSettings.ApplicationSettings["total_data"] = totaldata;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue("session_data", out session_data);
                session_data += e.Request.BytesReceived / 1024 / 1024;
                IsolatedStorageSettings.ApplicationSettings["session_data"] = session_data;
                IsolatedStorageSettings.ApplicationSettings.Save();
                if (!Cancelled)
                {
                    //RaiseCompleted(new FileDownloadEvntArgs("Completed"));
                    Message.SetMessage("Downloading complete");
                }
                if (SOURCES.Count == 0)
                {
                    //RaiseSyncChange(new FileDownloadEvntArgs("Completed"));
                    Message.SetMessage("Downloading complete");
                }
                break;
            }
        }
        private void DeleteRequest(object o)
        {
            var download = o as BackgroundDownload;

            if (download == null)
            {
                return;
            }

            try
            {
                BackgroundTransferRequest transferToRemove = BackgroundTransferService.Find(download.Id);
                if (transferToRemove == null)
                {
                    return;
                }

                // Try to remove the transfer from the background transfer service.
                BackgroundTransferService.Remove(transferToRemove);

                // Remove the request from the UI
                Requests.Remove(download);
                TxtNothingToDownload.Visibility = Requests.Any() ? Visibility.Collapsed : Visibility.Visible;
            }
            catch (Exception ex)
            {
                App.TrackException(ex);
            }
        }
        private async void DownloadLatestBackupFile()
        {
            //
            //

            try
            {
                bBackup.IsEnabled  = false;
                bRestore.IsEnabled = false;
                pbProgress.Value   = 0;
                var progressHandler = new Progress <LiveOperationProgress>(
                    (e) =>
                {
                    pbProgress.Value = e.ProgressPercentage;

                    pbProgress.Visibility = Visibility.Visible;
                    lblLastBackup.Text    =
                        string.Format(
                            StringResources
                            .BackupAndRestorePage_Messages_DwnlProgress,
                            e.BytesTransferred, e.TotalBytes);
                });
                _ctsDownload = new CancellationTokenSource();
                _client      = new LiveConnectClient(App.LiveSession);
                var reqList = BackgroundTransferService.Requests.ToList();
                foreach (var request in reqList)
                {
                    if (request.DownloadLocation.Equals(new Uri(@"\shared\transfers\restore.zip", UriKind.Relative)))
                    {
                        BackgroundTransferService.Remove(BackgroundTransferService.Find(request.RequestId));
                    }
                }
                var token = await _client.DownloadAsync(_newestFile + "/Content", _ctsDownload.Token, progressHandler);

                lblLastBackup.Text = StringResources.BackupAndRestorePage_Messages_Restoring;
                RestoreFromFile(token.Stream);
            }
            catch (TaskCanceledException)
            {
                lblLastBackup.Text = "Download Cancelled.";
            }
            catch (LiveConnectException ee)
            {
                lblLastBackup.Text = string.Format("Error Downloading: {0}", ee.Message);
            }
            catch (Exception e)
            {
                lblLastBackup.Text = e.Message;
            }
            finally
            {
                bBackup.IsEnabled     = true;
                bRestore.IsEnabled    = true;
                pbProgress.Value      = 0;
                pbProgress.Visibility = Visibility.Collapsed;
            }
        }
        private void GetSas(string result)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(string));

            result = "<root>" + result + "</root>";
            XDocument document = XDocument.Parse(result);

            sas = document.Root.Value;
            //  ECGName = "634708322772702206";

            string fileDownload = "https://echelperspace.blob.core.windows.net/" + Patientid + "/" + ECGName + "/" + sas;
            // Uri fileDownloadUri = new Uri("https://echelperspace.blob.core.windows.net/{patientuser}/{filename}+{sas}");

            Uri fileDownloadUri = new Uri(fileDownload);



            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!isoStore.DirectoryExists("shared/transfers"))
                {
                    isoStore.CreateDirectory("shared/transfers");
                }
            }
            //解析文件名,赋给SAVE_LOCATION
            //       SAVE_LOCATION = SAVE_LOCATION + filename;
            Uri saveLocationUri = new Uri(SAVE_LOCATION, UriKind.RelativeOrAbsolute);

            using (IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (userStore.FileExists(SAVE_LOCATION))
                {
                    userStore.DeleteFile(SAVE_LOCATION);
                }
            }


            _currentRequest        = new BackgroundTransferRequest(fileDownloadUri, saveLocationUri);
            _currentRequest.Method = "GET";
            _currentRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
            // try
            //{
            foreach (BackgroundTransferRequest request in BackgroundTransferService.Requests)
            {
                BackgroundTransferService.Remove(request);
            }

            BackgroundTransferService.Add(_currentRequest);

            InitializeTransferRequestEventHandlers();
            // }
            ////catch (InvalidOperationException)
            //{
            //    textBlock_Status.Text = "wocao";
            //}
            //sas = (string)serializer.Deserialize(document.CreateReader());
        }
Exemple #12
0
        protected void CancelAll()
        {
            var requests = BackgroundTransferService.Requests;

            foreach (var request in requests)
            {
                BackgroundTransferService.Remove(request);
                request.Dispose();
            }
        }
Exemple #13
0
 public void Dispose()
 {
     foreach (var request in BackgroundTransferService.Requests)
     {
         if (request.TransferStatus == TransferStatus.Completed)
         {
             BackgroundTransferService.Remove(request);
         }
     }
 }
 public void CancellAll()
 {
     //RaiseSyncChange(new FileDownloadEvntArgs("Syncing Cancelled"));
     foreach (var t in BackgroundTransferService.Requests)
     {
         BackgroundTransferService.Remove(t);
     }
     Cancelled = true;
     Message.SetMessage("Downloading cancelled.");
 }
Exemple #15
0
 internal void FinalizeRequests()
 {
     foreach (var request in BackgroundTransferService.Requests)
     {
         if (request.TransferStatus == TransferStatus.Completed)
         {
             BackgroundTransferService.Remove(request);
         }
     }
 }
Exemple #16
0
        private void HandleDownload(BackgroundTransferRequest transferRequest, DownloadInfo info, bool isAddQueue)
        {
            transferRequest.TransferStatusChanged += (o, e) =>
            {
                switch (e.Request.TransferStatus)
                {
                case TransferStatus.Completed:
                    if (e.Request.StatusCode == 200 || e.Request.StatusCode == 206)
                    {
                        DownloadCompleted(info);
                        BackgroundTransferService.Remove(e.Request);
                        e.Request.Dispose();
                    }
                    break;

                case TransferStatus.WaitingForWiFi:
                case TransferStatus.WaitingForNonVoiceBlockingNetwork:
                    info.DownloadState = DownloadState.WaitingForWiFi;
                    Utils.TileUtils.CreateBasicToast("需要在WiFi环境下才能下载");
                    break;

                case TransferStatus.WaitingForExternalPower:
                case TransferStatus.WaitingForExternalPowerDueToBatterySaverMode:
                    info.DownloadState = DownloadState.WaitingForExternalPower;
                    Utils.TileUtils.CreateBasicToast("需要外接电源才能下载");
                    break;

                default:
                    break;
                }
            };
            transferRequest.TransferProgressChanged += (o, e) =>
            {
                DownloadProgress(e.Request, info);
            };

            if (isAddQueue)
            {
                transferRequest.Method = "GET";
                info.RequestId         = transferRequest.RequestId;

                try
                {
                    if (BackgroundTransferService.Find(info.RequestId) == null)
                    {
                        BackgroundTransferService.Add(transferRequest);
                    }
                }
                catch (Exception ex)
                {
                    _isDownloading = false;
                    DownloadFailture(info, ex.Message);
                }
            }
        }
Exemple #17
0
        public void startAsync(string options)
        {
            try
            {
                var optStings = JSON.JsonHelper.Deserialize <string[]>(options);

                var uriString = optStings[0];
                var filePath  = optStings[1];


                if (_activDownloads.ContainsKey(uriString))
                {
                    return;
                }

                _activDownloads.Add(uriString, new Download(uriString, filePath, optStings[2]));


                var requestUri = new Uri(uriString);

                BackgroundTransferRequest transfer = FindTransferByUri(requestUri);

                if (transfer == null)
                {
                    // "shared\transfers" is the only working location for BackgroundTransferService download
                    // we use temporary file name to download content and then move downloaded file to the requested location
                    var downloadLocation = new Uri(@"\shared\transfers\" + Guid.NewGuid(), UriKind.Relative);

                    transfer = new BackgroundTransferRequest(requestUri, downloadLocation);

                    // Tag is used to make sure we run single background transfer for this file
                    transfer.Tag = uriString;

                    BackgroundTransferService.Add(transfer);
                }

                if (transfer.TransferStatus == TransferStatus.Completed)
                {
                    // file was already downloaded while we were in background and we didn't report this
                    MoveFile(transfer);
                    BackgroundTransferService.Remove(transfer);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
                }
                else
                {
                    transfer.TransferProgressChanged += ProgressChanged;
                    transfer.TransferStatusChanged   += TransferStatusChanged;
                }
            }
            catch (Exception ex)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
            }
        }
Exemple #18
0
        public bool Abort()
        {
            BackgroundTransferRequest request = BackgroundTransferService.Find(requestId);

            if (request != null)
            {
                isAborted = true;
                BackgroundTransferService.Remove(request);
            }

            return(request != null);
        }
 public override void Cancel()
 {
     try
     {
         BackgroundTransferService.Remove(Request);
         Request.Dispose();
     }
     catch (InvalidOperationException)
     {
         // request is alreadty completed/ cancelled
     }
 }
 internal void Remove(BackgroundTransferRequest request)
 {
     // Check if the request is in Background service before removing to
     // avoid Object aready disposed exception.
     if (BackgroundTransferService.Find(request.RequestId) != null)
     {
         request.TransferProgressChanged -= onTransferProgressChanged;
         request.TransferStatusChanged   -= onTransferStatusChanged;
         BackgroundTransferService.Remove(request);
         request.Dispose();
     }
 }
Exemple #21
0
 private static void SafeRemoveRequest(BackgroundTransferRequest request)
 {
     try
     {
         BackgroundTransferService.Remove(request);
     }
     catch { }
     try
     {
         request.Dispose();
     }
     catch { }
 }
Exemple #22
0
 private void RemoveTransferRequest(BackgroundTransferRequest transfer)
 {
     Debug.WriteLine("Removing transfer request with id: " + transfer.RequestId);
     // Try to remove the transfer from the background transfer service.
     try
     {
         BackgroundTransferService.Remove(transfer);
     }
     catch (Exception e)
     {
         Debug.WriteLine("ERROR: Cannot remove transfer request. Error: " + e.Message);
     }
 }
        public async Task MoveCompleted(BackgroundTransferRequest request)
        {
            var item             = JsonConvert.DeserializeObject <JobData>(request.Tag);
            var finalFile        = item.Location;
            var downloadLocation = string.Format(Constants.AnyTime.DownloadLocation, item.Id);

            await _storageService.MoveFileIfExists(downloadLocation, finalFile, true);

            await _storageService.DeleteFileIfExists(downloadLocation);

            BackgroundTransferService.Remove(request);

            _messengerService.SendSyncNotification(Constants.Messages.SyncJobFinishedMsg, item.Id, item.ItemType);
        }
Exemple #24
0
        private void RemoveTransferRequest(string transferID)
        {
            // Use Find to retrieve the transfer request with the specified ID.
            BackgroundTransferRequest transferToRemove = BackgroundTransferService.Find(transferID);

            // try to remove the transfer from the background transfer service.
            try
            {
                BackgroundTransferService.Remove(transferToRemove);
            }
            catch (Exception)
            {
            }
        }
Exemple #25
0
 private void RemoveTransferRequest(BackgroundTransferRequest request)
 {
     try
     {
         request.TransferProgressChanged -= MainPage_TransferProgressChanged;
         request.TransferStatusChanged   -= MainPage_TransferStatusChanged;
         BackgroundTransferService.Remove(request);
     }
     catch (ObjectDisposedException) { }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #26
0
        private void OnDownloadFinished(BackgroundTransferRequest request)
        {
            //Move downloaded file to its final location
            Storage.MoveFile(downloadPath, targetPath);

            //Notify listeners (UI) about download complete
            if (DownloadFinished != null)
            {
                DownloadFinished(this, EventArgs.Empty);
            }

            //Remove the request from the queue
            BackgroundTransferService.Remove(request);
        }
Exemple #27
0
        public BackgroundTransfer()
        {
            this._requests = new List <BackgroundTransferRequest>();

            this._idMapping = new Dictionary <string, OnTransferCompleted>();

            foreach (BackgroundTransferRequest request in BackgroundTransferService.Requests)
            {
                if (request.TransferStatus == TransferStatus.Completed)
                {
                    BackgroundTransferService.Remove(request);
                }
            }
        }
        /// <summary>
        /// Uploader notre base de données sur OneDrive
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public async static Task <int> ExportDB(CancellationToken ct, Progress <LiveOperationProgress> uploadProgress)
        {
            int log = 0;

            if (LiveClient == null)
            {
                log = await LogClient();
            }

            // Prepare for download, make sure there are no previous requests
            var reqList = BackgroundTransferService.Requests.ToList();

            foreach (var req in reqList)
            {
                if (req.UploadLocation.Equals(new Uri(@"\shared\transfers\" + AppResources.DBFileName, UriKind.Relative)) ||
                    req.UploadLocation.Equals(new Uri(@"\shared\transfers\" + AppResources.DBFileName + ".json", UriKind.Relative)))
                {
                    BackgroundTransferService.Remove(BackgroundTransferService.Find(req.RequestId));
                }
            }

            IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

            iso.CopyFile(AppResources.DBFileName, "/shared/transfers/" + AppResources.DBFileName, true);

            //  create a folder
            string folderID = await GetFolderID("checkmapp");

            if (string.IsNullOrEmpty(folderID))
            {
                //  return error
                return(0);
            }

            //  upload local file to OneDrive
            LiveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowCellularAndBattery;
            try
            {
                await LiveClient.BackgroundUploadAsync(folderID, new Uri("/shared/transfers/" + AppResources.DBFileName, UriKind.RelativeOrAbsolute), OverwriteOption.Overwrite, ct, uploadProgress);
            }
            catch (TaskCanceledException exception)
            {
                Console.WriteLine("Exception occured while uploading file to OneDrive : " + exception.Message);
            }
            catch (Exception e)
            {
            }
            return(1);
        }
        private async Task CreateDownload(string source, IApiClient client, LocalItem localItem)
        {
            var existingRequest = BackgroundTransferService.Requests.FirstOrDefault(x => x.Tag != null && x.Tag.Contains(localItem.Id));

            if (existingRequest != null)
            {
                return;
            }

            await _storageService.CreateDirectoryIfNotThere("AnyTime");

            await _storageService.CreateDirectoryIfNotThere("Shared\\Transfers");

            await _storageService.CreateDirectoryIfNotThere("Shared\\Transfers\\Sync");

            var stringVersion = ApplicationManifest.Current.App.Version;

            var downloader = new BackgroundTransferRequest(new Uri(source, UriKind.Absolute));

            downloader.Headers.Add("X-MediaBrowser-Token", client.AccessToken);
            var authorization = string.Format("MediaBrowser UserId=\"{0}\", Client=\"{1}\", Device=\"{2}\", DeviceId=\"{3}\", Version=\"{4}\"", client.CurrentUserId, client.ClientName, client.DeviceName, client.DeviceId, stringVersion);

            downloader.Headers.Add("Authorization", authorization);
            downloader.Method = "GET";
            downloader.Tag    = JsonConvert.SerializeObject(new JobData(localItem.Id, localItem.LocalPath, localItem.Item.Name, localItem.Item.Type));

            var downloadLocation = new Uri(string.Format(Constants.AnyTime.DownloadLocation, localItem.Id), UriKind.RelativeOrAbsolute);

            downloader.DownloadLocation       = downloadLocation;
            downloader.TransferStatusChanged += DownloaderOnTransferStatusChanged;

            if (BackgroundTransferService.Requests.Count() == 25)
            {
                // TODO: error or something
                var i = 1;
            }

            var complete = BackgroundTransferService.Requests.Where(x => x.TransferStatus == TransferStatus.Completed).ToList();

            if (!complete.IsNullOrEmpty())
            {
                foreach (var request in complete)
                {
                    BackgroundTransferService.Remove(request);
                }
            }

            _transferService.Add(downloader);
        }
        private void RemoveTransferRequest(string transferID)
        {
            requestIdChatBubbleMap.Remove(transferID);
            // Use Find to retrieve the transfer request with the specified ID.
            BackgroundTransferRequest transferToRemove = BackgroundTransferService.Find(transferID);

            try
            {
                BackgroundTransferService.Remove(transferToRemove);
            }
            catch (Exception e)
            {
                // Handle the exception.
            }
        }