static async Task <List <Service> > ConsumeOwlAsync(string url) { string content = string.Empty; string jObject = "query= PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX : <http://www.semanticweb.org/ca.mendoza968/ontologies/services#>SELECT ?URI ?methodValue (group_concat(?bodyLabel) as ?bodyLabels) (group_concat(?dataTypeLabel) as ?dataTypes)WHERE { ?service a :Service; :aboutProperty ?property . ?service :hasAPIURL ?URL; :hasMethod ?method . ?URL :hasStringValue ?URI . ?method a :Read; :hasStringValue ?methodValue; :hasBodyField ?bodyField . ?bodyField rdfs:label ?bodyLabel; :hasDataType ?dataType . ?dataType rdfs:label ?dataTypeLabel .}GROUP BY ?URI ?methodValue"; var stringContent = new StringContent(jObject, Encoding.UTF8, "application/x-www-form-urlencoded"); HttpResponseMessage response = await client.PostAsync(url, stringContent); if (response.EnsureSuccessStatusCode().IsSuccessStatusCode) { content = await response.Content.ReadAsStringAsync(); } List <Service> listServices = new List <Service>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(content); GettingStarted data = GettingStarted.FromJson(JsonConvert.SerializeXmlNode(xmlDoc)); foreach (Result item in data.Sparql.Results.Result) { Service itemService = new Service(); foreach (Binding detail in item.Binding) { if (detail.Name.Equals("URI")) { itemService.url = detail.Literal; } if (detail.Name.Equals("methodValue")) { itemService.methodValue = detail.Literal; } if (detail.Name.Equals("dataTypes")) { itemService.dataTypes = detail.Literal; } if (detail.Name.Equals("bodyLabels")) { itemService.bodyLabels = detail.Literal; } itemService.method = "GET"; } listServices.Add(itemService); } return(listServices); }
public override Task <List <ArticleModel> > EvaluateFeed(FeedModel feedModel) { return(ExecuteSafe(async() => { //find customer key first if (CustomerKey == null) { await GetCustomerKey(); } var articlelist = new List <ArticleModel>(); var json = await DownloadAsync(new Uri(feedModel.Source.LogicBaseUrl + feedModel.Url.Replace("CUSTOMERKEY", CustomerKey))); if (json == null) { return articlelist; } var feed = GettingStarted.FromJson(json); if (feed == null) { LogHelper.Instance.Log(LogLevel.Error, "ZwanzigMinHelper.EvaluateFeed 20 min channel is null after deserialisation", this); } else { foreach (var item in feed.Content.Items.Item) { var model = FeedToArticleModel(item, feedModel); if (model != null) { articlelist.Add(model); } } } return articlelist; })); }
static async Task <bool> ConsumeOwlAsync(string url, string method, Int32 maxSelected, string service) { string finalMethod = string.Empty; string filter = string.Empty; switch (method.ToUpper().Trim()) { case "GET": finalMethod = "Read"; break; default: finalMethod = "Read"; break; } if (!string.IsNullOrEmpty(service) || !service.Contains("*")) { filter = string.Format("FILTER (?methodValue = \"{0}\") .", service); } string jObject = "query= PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX : <http://www.semanticweb.org/ca.mendoza968/ontologies/services#> SELECT ?URI ?methodValue (group_concat(?bodyLabel) as ?bodyLabels) (group_concat(?dataTypeLabel) as ?dataTypes) WHERE { ?service a :Service; :aboutProperty ?property. ?service :hasAPIURL ?URL; :hasMethod ?method . ?URL :hasStringValue ?URI.?method a :" + finalMethod + "; :hasStringValue ?methodValue; :hasBodyField ?bodyField . ?bodyField rdfs:label ?bodyLabel; :hasDataType ?dataType . ?dataType rdfs:label ?dataTypeLabel . " + filter + "} GROUP BY ?URI ?methodValue"; var stringContent = new StringContent(jObject, Encoding.UTF8, "application/x-www-form-urlencoded"); HttpResponseMessage response = await client.PostAsync(url, stringContent); if (response.EnsureSuccessStatusCode().IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); List <Service> listServices = new List <Service>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(content); GettingStarted data = GettingStarted.FromJson(JsonConvert.SerializeXmlNode(xmlDoc)); foreach (Result item in data.Sparql.Results.Result) { Service itemService = new Service(); foreach (Binding detail in item.Binding) { if (detail.Name.Equals("URI")) { itemService.url = detail.Literal; } if (detail.Name.Equals("methodValue")) { itemService.methodValue = detail.Literal; } if (detail.Name.Equals("dataTypes")) { itemService.dataTypes = detail.Literal; } if (detail.Name.Equals("bodyLabels")) { itemService.bodyLabels = detail.Literal; } } listServices.Add(itemService); } List <Service> distinctValues = new List <Service>(); if (maxSelected == 1) { distinctValues = listServices.GroupBy(c => c.methodValue, (key, c) => c.FirstOrDefault()).ToList(); } else { var finalTrans = listServices.GroupBy(c => c.methodValue, (key, c) => c.Take(maxSelected)); ////Convertir de Ienumerable a List. foreach (var item in finalTrans) { foreach (var serviceItem in item) { distinctValues.Add(serviceItem); } } } try { JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer(); string json = jsonSerialiser.Serialize(distinctValues); File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\" + "config.txt", json); } catch (Exception) { return(false); } return(true); } return(false); }
private async Task EvaluateSources(ConcurrentStack <SourceEntity> input) { try { while (input.TryPop(out var source)) { if ((int)source.Source >= 20 && (int)source.Source <= 40) { //tamedia sources var resp = await _httpService.DownloadAsync(new Uri(source.LogicBaseUrl + "navigations?client=webapp")); var json = await resp.GetResponseAsStringAsync(); var model = TamediaNavigation.FromJson(json); var existing = source.Feeds.ToList(); var newList = new List <FeedEntity>(); foreach (var navigation in model.Navigations) { if (navigation.CategoryPreview != null) { var found = FindAndRemove(existing, navigation.CategoryPreview.Name) ?? new FeedEntity() { Guid = Guid.NewGuid(), Name = navigation.CategoryPreview.Name }; //correct category found.Url = "categories/" + navigation.CategoryPreview.Id; newList.Add(found); } } //skip adding of front because currently it cannot be processed if (false) { //add / correct special front navigation var front = FindAndRemove(existing, "Front") ?? new FeedEntity() { Guid = Guid.NewGuid(), Name = "Front" }; //correct category front.Url = "fronts/mobile"; newList.Insert(0, front); } //to output source.Feeds.Clear(); foreach (var feedEntity in newList) { source.Feeds.Add(feedEntity); } } else if (source.Source == Sources.ZwanzigMin) { var resp = await _httpService.DownloadAsync(new Uri("http://api.20min.ch/feed/sitemap?&key=" + TwentyMinCustomerKey + "&json&host=m.20min.ch&lang=de")); var json = await resp.GetResponseAsStringAsync(); var feedDic = new Dictionary <string, FeedEntity>(); foreach (var sourceFeed in source.Feeds) { feedDic.Add(sourceFeed.Name, sourceFeed); } source.Feeds.Clear(); source.LogicBaseUrl = "http://api.20min.ch/feed"; var logicLength = source.LogicBaseUrl.Length; var model = GettingStarted.FromJson(json); foreach (var contentItem in model.Content.Items.Item.Where(c => !string.IsNullOrEmpty(c.Category) && c.Type == "view")) { FeedEntity item = null; if (feedDic.ContainsKey(contentItem.Category)) { item = feedDic[contentItem.Category]; } else { item = new FeedEntity { Name = contentItem.Category, Guid = Guid.NewGuid() }; } item.Url = contentItem.FeedFullContentUrl.Substring(logicLength).Replace(TwentyMinCustomerKey, "CUSTOMERKEY"); source.Feeds.Add(item); } } } } catch (Exception e) { Console.WriteLine(e); } }