Task chaining

This commit is contained in:
Sergey Chebotar 2021-11-29 16:36:04 +03:00
parent 198e5c886f
commit e9ec1df01b
2 changed files with 7 additions and 4 deletions

View File

@ -17,12 +17,12 @@ namespace Rehau.Sku.Assist
return await httpClient.GetStringAsync(uri); return await httpClient.GetStringAsync(uri);
} }
public async static Task<IDocument> GetDocument(string source) public async static Task<IDocument> GetDocument(Task<string> source)
{ {
IConfiguration config = Configuration.Default; IConfiguration config = Configuration.Default;
IBrowsingContext context = BrowsingContext.New(config); IBrowsingContext context = BrowsingContext.New(config);
return await context.OpenAsync(req => req.Content(source)); return await context.OpenAsync(req => req.Content(source.Result));
} }
public static IProduct GetProductFromDocument(IDocument document) public static IProduct GetProductFromDocument(IDocument document)

View File

@ -1,4 +1,4 @@
using System; using AngleSharp.Dom;
using ExcelDna.Integration; using ExcelDna.Integration;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,7 +12,10 @@ namespace Rehau.Sku.Assist
[ExcelFunction] [ExcelFunction]
public static async Task<string> RAUNAME(string request) public static async Task<string> RAUNAME(string request)
{ {
throw new NotImplementedException(); Task<string> contentTask = Task.Run(() => SkuAssist.GetContent(request, httpClient));
Task<IDocument> documentTask = await contentTask.ContinueWith(content => SkuAssist.GetDocument(content));
IProduct product = await documentTask.ContinueWith(doc => SkuAssist.GetProductFromDocument(doc.Result));
return product.ToString();
} }
} }
} }