public ProviderPackage(string text, EventCaller caller, int priority) { Text = text; Caller = caller; Type = ContentType.TextOnly; Priority = priority; }
public ProviderPackage(Stream imageStream, EventCaller caller, int priority) { Caller = caller; ImageStream = imageStream; Type = ContentType.ImageOnly; Priority = priority; }
public ProviderPackage(string text, Stream imageStream, EventCaller caller, int priority) { Caller = caller; Text = text; ImageStream = imageStream; Type = ContentType.TextWithImage; Priority = priority; }
public Task<ProviderPackage> GetAsync(EventCaller caller, string inputContent) { return Task.Run(() => { var htmlTree = new HtmlDocument(); htmlTree.LoadHtml(inputContent); var node = htmlTree.DocumentNode.QuerySelector(".MSNJVData .b_imagePair"); if (node != null) return new ProviderPackage(string.Format("{0}", node.InnerText), caller, Priority); return ProviderPackage.ReturnNotAvailablePackage(); }); }
public Task<ProviderPackage> GetAsync(EventCaller caller, string inputContent) { return Task.Run(() => { var htmlTree = new HtmlDocument(); htmlTree.LoadHtml(inputContent); var node = htmlTree.DocumentNode.QuerySelector(".b_anno"); return node != null ? new ProviderPackage(node.InnerText, caller, Priority) : ProviderPackage.ReturnNotAvailablePackage(); }); }
public async Task TestBingReq() { var caller = new EventCaller() { Id = 0, CallerId = 0, CallerFirstName = "Ben" }; var textContent = "你好"; textContent = textContent.Substring(textContent.IndexOf(' ') + 1); var bingContent = await CortanaBot.Networking.BingContent.GetAsync(caller, textContent, RequestTemplate.Lang); Assert.AreNotEqual("", bingContent,"Request failed"); }
public Task<ProviderPackage> GetAsync(EventCaller caller, string inputContent) { return Task.Run(() => { var htmlTree = new HtmlDocument(); htmlTree.LoadHtml(inputContent); var node = htmlTree.DocumentNode.QuerySelector(".b_anno"); var stockNode = htmlTree.DocumentNode.QuerySelector(".b_hPanel"); var trendMap = htmlTree.DocumentNode.QuerySelector("svg"); if (node != null && stockNode != null) { if (trendMap != null) { var w = trendMap.Attributes["width"]; var h = trendMap.Attributes["height"]; var trendMapContent = string.Format("<svg width=\"{0}\" height=\"{1}\">{2}</svg>", w.Value, h.Value, trendMap.InnerHtml); var trendMapXml = new XmlDocument(); trendMapXml.LoadXml(trendMapContent); var reader = new SvgReader(new StringReader(trendMapContent)); var graphic = reader.Graphic; var c = Platforms.Current.CreateImageCanvas( new NGraphics.Size(double.Parse(w.Value), double.Parse(h.Value)), scale: 1); graphic.Draw(c); var trendMapImageStream = new MemoryStream(); c.GetImage().SaveAsPng(trendMapImageStream); // Send Package return new ProviderPackage(string.Format("{0} : {1}", node.InnerText, stockNode.InnerText) , trendMapImageStream, caller, Priority); } return new ProviderPackage(string.Format("{0} : {1}", node.InnerText, stockNode.InnerText), caller, Priority); } return ProviderPackage.ReturnNotAvailablePackage(); }); }
public async static Task<string> GetAsync(EventCaller caller, string queryString, string lang) { // Send request to Bing var httpClient = new HttpClient(); // Encode the content var reqContent = HttpUtility.UrlEncode(queryString); var requestUrl = string.Format(RequestTemplate.RequestUrl, reqContent, lang); // Remote header httpClient.DefaultRequestHeaders.Add("X-Search-MobileClientType", "Hose"); httpClient.DefaultRequestHeaders.Add("X-Search-AppId", "D41D8CD98F00B204E9800998ECF8427E09AA4958"); httpClient.DefaultRequestHeaders.Add("X-BM-Client", "BingWP/2.1/assistant"); httpClient.DefaultRequestHeaders.Add("X-BM-Theme", "000000;1BA1E2"); httpClient.DefaultRequestHeaders.Add("X-BM-DateFormat", "yyyy/M/d"); httpClient.DefaultRequestHeaders.Add("X-BM-RegionalSettings", "zh-CN"); httpClient.DefaultRequestHeaders.Add("X-BM-DeviceOrientation", "0"); httpClient.DefaultRequestHeaders.Add("X-COMMON-PARTNERCODE", "NOKMSB"); httpClient.DefaultRequestHeaders.Add("X-BM-MO", "000-HK"); httpClient.DefaultRequestHeaders.Add("X-BM-CBT", "1435931517761"); httpClient.DefaultRequestHeaders.Add("X-BM-Bandwidth", "High"); httpClient.DefaultRequestHeaders.Add("X-BM-Theme", "000000;1BA1E2"); httpClient.DefaultRequestHeaders.Add("X-Search-Location", "lat:30.281360;long:120.123233;ts:1435931517;re:124.000000"); httpClient.DefaultRequestHeaders.Add("X-BM-DeviceDpi", "96"); httpClient.DefaultRequestHeaders.Add("X-BM-DeviceScale", "1.000000"); httpClient.DefaultRequestHeaders.Add("X-BM-DeviceDimensionsLogical", "480x800"); httpClient.DefaultRequestHeaders.Add("X-DeviceId", "1CB009C462E00B208FAFE968E04058C07D2CD3DFC9E2DF7F0985563621B90E35"); httpClient.DefaultRequestHeaders.Add("X-BM-NetworkType", "Wi-Fi"); httpClient.DefaultRequestHeaders.Add("X-BM-BuildNumber", " Windows Phone 6.3.0.0.9651"); httpClient.DefaultRequestHeaders.Add("X-BM-UserDisplayName", caller.CallerName); httpClient.DefaultRequestHeaders.Add("AppContext", "{\"Stores\":\"Zest:NOKIA\",\"CatalogCountry\":\"CN\",\"OverrideCountry\":\"CN\",\"DisplayLanguageLocale\":\"zh-CN\",\"DeviceConfig\":\"268481538\",\"DeviceTypeStr\":\"winphone8.10\",\"DeviceModel\":\"RM-1019_1027\",\"SafeSearchRating\":\"99:1\"}"); httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530 Dual SIM) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537"); httpClient.DefaultRequestHeaders.Add("UA-CPU", "ARM"); // Get var bingContent = await httpClient.GetAsync(new Uri(requestUrl)); httpClient.Dispose(); if (bingContent.IsSuccessStatusCode) { return await bingContent.Content.ReadAsStringAsync(); } return null; }