public Task <ContentProviderResult> ExtractResource(string url) { Uri resultUrl; if (Uri.TryCreate(url, UriKind.Absolute, out resultUrl)) { var request = new ContentProviderHttpRequest(resultUrl); return(ExtractContent(request)); } return(TaskAsyncHelper.FromResult <ContentProviderResult>(null)); }
protected override Task <ContentProviderResult> GetCollapsibleContent(ContentProviderHttpRequest request) { var args = ExtractParameters(request.RequestUri); if (args == null || !args.Any()) { return(TaskAsyncHelper.FromResult <ContentProviderResult>(null)); } return(TaskAsyncHelper.FromResult(new ContentProviderResult() { Content = String.Format(MediaFormatString, args.ToArray()), Title = request.RequestUri.AbsoluteUri })); }
public virtual Task <ContentProviderResult> GetContent(ContentProviderHttpRequest request) { return(GetCollapsibleContent(request).Then(result => { if (IsCollapsible && result != null) { result.Content = String.Format(CultureInfo.InvariantCulture, ContentFormat, IsPopOut ? @"<div class='collapsible_pin'></div>" : "", result.Title, result.Content); } return result; })); }
private Task <ContentProviderResult> ExtractContent(ContentProviderHttpRequest request) { var contentProviders = _contentProviders.Value; var validProviders = contentProviders.Where(c => c.IsValidContent(request.RequestUri)) .ToList(); if (validProviders.Count == 0) { return(TaskAsyncHelper.FromResult <ContentProviderResult>(null)); } var tasks = validProviders.Select(c => c.GetContent(request)).ToArray(); var tcs = new TaskCompletionSource <ContentProviderResult>(); Task.Factory.ContinueWhenAll(tasks, completedTasks => { var faulted = completedTasks.FirstOrDefault(t => t.IsFaulted); if (faulted != null) { tcs.SetException(faulted.Exception); } else if (completedTasks.Any(t => t.IsCanceled)) { tcs.SetCanceled(); } else { ContentProviderResult result = completedTasks.Select(t => t.Result) .FirstOrDefault(content => content != null); tcs.SetResult(result); } }); return(tcs.Task); }
protected abstract Task <ContentProviderResult> GetCollapsibleContent(ContentProviderHttpRequest request);