當前位置: 首頁>>代碼示例>>C#>>正文


C# BackgroundTransferRequest類代碼示例

本文整理匯總了C#中BackgroundTransferRequest的典型用法代碼示例。如果您正苦於以下問題:C# BackgroundTransferRequest類的具體用法?C# BackgroundTransferRequest怎麽用?C# BackgroundTransferRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BackgroundTransferRequest類屬於命名空間,在下文中一共展示了BackgroundTransferRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Create

        public static TransferMonitorViewModel Create(BackgroundTransferRequest request)
        {
            var vm = new TransferMonitorViewModel(new TransferMonitor(request));
            vm.CreateJobData(request);

            return vm;
        }
開發者ID:gep13,項目名稱:Emby.WindowsPhone,代碼行數:7,代碼來源:TransferMonitorViewModel.cs

示例2: Button_Click_1

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string mp3uri = "http://www.nmgwxc.com/m/yldcj.mp3";

            if (BackgroundTransferService.Requests.Count() >= 25)
            {
                MessageBox.Show("已經超過最大請求數量,請稍後");
                return;
            }
            if (BackgroundTransferService.Requests.Any(p => p.RequestUri.AbsoluteUri == mp3uri))
            {
                MessageBox.Show("文件已經在下載的請求中");
                return;
            }
            BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(new Uri(mp3uri, UriKind.Absolute));
            transferRequest.Method = "GET";
            transferRequest.TransferPreferences = TransferPreferences.None;
            transferRequest.TransferStatusChanged += transferRequest_TransferStatusChanged;
            transferRequest.TransferProgressChanged += transferRequest_TransferProgressChanged;
            transferRequest.Tag = "yldcj.mp3";
            transferRequest.DownloadLocation = new Uri("shared/transfers/yldcj.mp3", UriKind.Relative);
            try
            {
                BackgroundTransferService.Add(transferRequest);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
開發者ID:peepo3663,項目名稱:WindowsPhone8,代碼行數:30,代碼來源:MainPage.xaml.cs

示例3: PersistRequestToStorage

 private void PersistRequestToStorage(BackgroundTransferRequest request)
 {
     var requestUri = request.RequestUri;
     var requestUriHash = CryptoUtils.GetHash(requestUri.ToString());
     var trackerDir = FileUtils.GetDowloadTrackerDirectory(false, true);
     FileUtils.WriteFile(string.Format("{0}\\{1}", trackerDir, requestUriHash), request.RequestId);
 }
開發者ID:hubaishan,項目名稱:quran-phone,代碼行數:7,代碼來源:WindowsPhoneDownloadManager.cs

示例4: Download_Click

        private void Download_Click(object sender, EventArgs e)
        {
            try
            {
                // Sichergehen, dass der Download-Ordner existiert
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isoStore.DirectoryExists(TransfersFolder))
                    {
                        isoStore.CreateDirectory(TransfersFolder);
                    }
                }

                var request = new BackgroundTransferRequest(new Uri("http://ralfe-software.net/Wildlife.wmv", UriKind.Absolute))
                    {
                        DownloadLocation = new Uri(DownloadLocation, UriKind.Relative),
                        Method = "GET",
                        TransferPreferences = TransferPreferences.AllowBattery
                    };
                BackgroundTransferService.Add(request);

                DownloadButton.IsEnabled = false;
                DeleteButton.IsEnabled = true;
                UpdateUI();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
開發者ID:GregOnNet,項目名稱:WP8BookSamples,代碼行數:30,代碼來源:MainPage.xaml.cs

示例5: ResumeOneDownload

        /// <summary>
        /// 繼續一個下載任務
        /// </summary>
        /// <param name="info"></param>
        protected bool ResumeOneDownload(DownloadInfo info)
        {
            if (string.IsNullOrEmpty(info.RequestId)) return false;

            var transferRequest = BackgroundTransferService.Find(info.RequestId);
            if (transferRequest != null
                && transferRequest.TransferStatus == TransferStatus.Transferring)
            {
                try
                {
                    _isDownloading = true;
                    info.DownloadState = DownloadState.Downloading;
                    HandleDownload(transferRequest, info, false);
                    return true;
                }
                catch (Exception ex)
                {
                    DownloadFailture(info, ex.Message);
                    _isDownloading = false;
                }
            }
            else
            {
                _isDownloading = true;
                info.DownloadState = DownloadState.Downloading;
                transferRequest = new BackgroundTransferRequest(new Uri(info.DownloadUri), new Uri(info.LocalFileName, UriKind.Relative));
                HandleDownload(transferRequest, info, true);
                return true;
            }
            return false;
        }
開發者ID:uvbs,項目名稱:MyProjects,代碼行數:35,代碼來源:DownloadBase.cs

示例6: DownloadAsyncViaBackgroundTranfer

        private ITransferRequest DownloadAsyncViaBackgroundTranfer(Uri serverUri, Uri phoneUri)
        {
            try
            {
                var request = new BackgroundTransferRequest(serverUri, phoneUri);
                request.Tag = serverUri.ToString();
                request.TransferPreferences = TransferPreferences.AllowCellularAndBattery;

                int count = 0;
                foreach (var r in BackgroundTransferService.Requests)
                {
                    count++;
                    if (r.RequestUri == serverUri)
                        return new WindowsTransferRequest(r);
                    if (r.TransferStatus == TransferStatus.Completed)
                    {
                        BackgroundTransferService.Remove(r);
                        count--;
                    }
                    // Max 5 downloads
                    if (count >= 5)
                        return null;
                }
                BackgroundTransferService.Add(request);
                PersistRequestToStorage(request);
                return new WindowsTransferRequest(request);
            }
            catch (InvalidOperationException)
            {
                return GetRequest(serverUri.ToString());
            }
        }
開發者ID:hubaishan,項目名稱:quran-phone,代碼行數:32,代碼來源:WindowsPhoneDownloadManager.cs

示例7: DownloadItemBackgroundViewModel

 public DownloadItemBackgroundViewModel(BackgroundTransferRequest backgroundTransferRequest)
 {
     this.BackgroundTransferRequest = backgroundTransferRequest;
     this.ProcessTransfer(backgroundTransferRequest);
     this.WatchTransfer();
     this.ProcessTransfer(backgroundTransferRequest);
 }
開發者ID:rlecole,項目名稱:SaveAndPlay,代碼行數:7,代碼來源:DownloadItemBackgroundViewModel.cs

示例8: ConvertTransferStatusChangedToTask

        /// <summary>
        /// Attaches a BackgroundUploadCompletedEventAdapter to the given BackgroundTransferRequest.
        /// This is to convert a BackgroundTransferRequest's status changes to a LiveOperationResult.
        /// </summary>
        /// <param name="request">Request to attach to.</param>
        /// <returns>A Task&lt;LiveOperationResult&gt; converted over from a BackgroundTransferEventArgs.</returns>
        public Task<LiveOperationResult> ConvertTransferStatusChangedToTask(BackgroundTransferRequest request)
        {
            var completedEventHandler =
                new BackgroundUploadCompletedEventAdapter(this.backgroundTransferService, this.tcs);
            completedEventHandler.BackgroundTransferRequestCompleted += this.OnBackgroundTransferRequestCompleted;

            return completedEventHandler.ConvertTransferStatusChangedToTask(request);
        }
開發者ID:d20021,項目名稱:LiveSDK-for-Windows,代碼行數:14,代碼來源:BackgroundUploadEventAdapter.cs

示例9: CreateJobData

        private void CreateJobData(BackgroundTransferRequest request)
        {
            var json = request.Tag;
            var jobData = JsonConvert.DeserializeObject<JobData>(json);
            JobData = jobData;

            Monitor.Name = jobData.Name;
        }
開發者ID:gep13,項目名稱:Emby.WindowsPhone,代碼行數:8,代碼來源:TransferMonitorViewModel.cs

示例10: WindowsTransferRequest

 public WindowsTransferRequest(BackgroundTransferRequest request)
 {
     this.request = request;
     if (this.request != null)
     {
         this.request.TransferProgressChanged += request_TransferProgressChanged;
         this.request.TransferStatusChanged += request_TransferStatusChanged;
     }
 }
開發者ID:hubaishan,項目名稱:quran-phone,代碼行數:9,代碼來源:WindowsPhoneTransferRequest.cs

示例11: StartOneDownload

        /// <summary>
        /// 開始下載一個新任務,此方法為後台線程調用
        /// </summary>
        /// <param name="info"></param>
        protected void StartOneDownload(DownloadInfo info)
        {
            _isDownloading = true;

            var destinationPath = string.Format("/shared/transfers/{0}", info.LocalFileName);
            var destinationFile = new Uri(destinationPath, UriKind.Relative);
            var transferRequest = new BackgroundTransferRequest(new Uri(info.DownloadUri), destinationFile);
            info.LocalFileName = transferRequest.DownloadLocation.OriginalString;
            HandleDownload(transferRequest, info, true);
        }
開發者ID:uvbs,項目名稱:MyProjects,代碼行數:14,代碼來源:DownloadBase.cs

示例12: startAsync

        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));
            }
        }
開發者ID:AndreasNogler,項目名稱:Emby.Mobile,代碼行數:55,代碼來源:BackgroundDownload.cs

示例13: GetProgressInfo

 public ProgressInfo GetProgressInfo(BackgroundTransferRequest e)
 {
     P.FileProgress = (float)e.BytesReceived / (float)e.TotalBytesToReceive;
     string[] splitted_tag = e.Tag.Split('|');
     ts = DateTime.Now - last_time;
     P.Speed = (float)(e.BytesReceived - BytesTransferredLast) / (float)ts.TotalSeconds/1024;
     P.Title = splitted_tag[1];
     BytesTransferredLast = e.BytesReceived;
     last_time = DateTime.Now;
     return P;
 }
開發者ID:ahmeda8,項目名稱:audio-youtube-wp7,代碼行數:11,代碼來源:ProgressReporter.cs

示例14: LivePendingDownload

        internal LivePendingDownload(
            IBackgroundTransferService backgroundTransferService, 
            BackgroundTransferRequest request)
        {
            Debug.Assert(backgroundTransferService != null);
            Debug.Assert(request != null);
            Debug.Assert(BackgroundTransferHelper.IsDownloadRequest(request));

            this.request = request;
            this.backgroundTransferService = backgroundTransferService;
        }
開發者ID:d20021,項目名稱:LiveSDK-for-Windows,代碼行數:11,代碼來源:LivePendingDownload.cs

示例15: ConvertTransferStatusChangedToTask

        /// <summary>
        /// Attaches a BackgroundDownloadCompletedEventAdapter to the given BackgroundTransferRequest.
        /// This is to convert a BackgroundTransferRequest's status changes to a LiveOperationResult.
        /// </summary>
        /// <param name="request">Request to attach to.</param>
        /// <returns>A Task&lt;LiveOperationResult&gt; converted over from a BackgroundTransferEventArgs.</returns>
        public Task<LiveOperationResult> ConvertTransferStatusChangedToTask(BackgroundTransferRequest request)
        {
            Debug.Assert(request != null);

            var completedEventAdapter =
                new BackgroundDownloadCompletedEventAdapter(this.backgroundTransferService, this.tcs);

            completedEventAdapter.BackgroundTransferRequestCompleted +=
                this.OnBackgroundTransferRequestCompletedEventAdapter;
            return completedEventAdapter.ConvertTransferStatusChangedToTask(request);
        }
開發者ID:harunpehlivan,項目名稱:LiveSDK-for-Windows,代碼行數:17,代碼來源:BackgroundDownloadEventAdapter.cs


注:本文中的BackgroundTransferRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。