当前位置: 首页>>代码示例>>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;未经允许,请勿转载。