本文整理汇总了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;
}
示例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);
}
}
示例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);
}
示例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());
}
}
示例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;
}
示例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());
}
}
示例7: DownloadItemBackgroundViewModel
public DownloadItemBackgroundViewModel(BackgroundTransferRequest backgroundTransferRequest)
{
this.BackgroundTransferRequest = backgroundTransferRequest;
this.ProcessTransfer(backgroundTransferRequest);
this.WatchTransfer();
this.ProcessTransfer(backgroundTransferRequest);
}
示例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<LiveOperationResult> 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);
}
示例9: CreateJobData
private void CreateJobData(BackgroundTransferRequest request)
{
var json = request.Tag;
var jobData = JsonConvert.DeserializeObject<JobData>(json);
JobData = jobData;
Monitor.Name = jobData.Name;
}
示例10: WindowsTransferRequest
public WindowsTransferRequest(BackgroundTransferRequest request)
{
this.request = request;
if (this.request != null)
{
this.request.TransferProgressChanged += request_TransferProgressChanged;
this.request.TransferStatusChanged += request_TransferStatusChanged;
}
}
示例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);
}
示例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));
}
}
示例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;
}
示例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;
}
示例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<LiveOperationResult> 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);
}