/// <summary> /// Initializes a new instance of the <see cref="Terradue.OpenSearch.Request.MemoryOpenSearchRequest"/> class. /// </summary> /// <param name="url">URL.</param> /// <param name="contentType">Content type.</param> public MemoryOpenSearchRequest(OpenSearchUrl url, string contentType) : base(url, contentType) { this.parameters = HttpUtility.ParseQueryString(url.Query); memStream = new MemoryStream(); originalParameters = HttpUtility.ParseQueryString(url.Query); }
public void TestFedeo() { XmlSerializer ser = new XmlSerializer(typeof(OpenSearchDescription)); var osd = (OpenSearchDescription)ser.Deserialize(XmlReader.Create(new FileStream("../Samples/fedeo-osdd.xml", FileMode.Open, FileAccess.Read))); GenericOpenSearchable os = new GenericOpenSearchable(osd, new OpenSearchEngine()); OpenSearchEngine ose = new OpenSearchEngine(); ose.LoadPlugins(); var url = new OpenSearchUrl("http://fedeo.esa.int/opensearch/request/?httpAccept=application/atom%2Bxml&parentIdentifier=urn:eop:DLR:EOWEB:Geohazard.Supersite.TerraSAR-X_SSC&startDate=2014-01-01T00:00:00Z&endDate=2015-04-20T00:00:00Z&recordSchema=om"); NameValueCollection parameters = new NameValueCollection(); parameters.Set("maximumRecords", "1"); NameValueCollection nvc; if (url != null) nvc = HttpUtility.ParseQueryString(url.Query); else nvc = new NameValueCollection(); parameters.AllKeys.SingleOrDefault(k => { nvc.Set(k, parameters[k]); return false; }); var request = OpenSearchRequest.Create(os, os.GetQuerySettings(ose), nvc); }
public CachedOpenSearchRequest(OpenSearchUrl url, IOpenSearchResponse response, NameValueCollection originalParameters, TimeSpan elapsed) : base(url, response.ContentType) { base.OpenSearchUrl = url; this.response = response; this.OriginalParameters = originalParameters; }
public UrlBasedOpenSearchable(IfyContext context, OpenSearchDescription osd, OpenSearchUrl url, OpenSearchableFactorySettings settings) { this.context = context; this.osd = osd; this.url = url; this.settings = settings; }
private static SandboxOpenSearchInformation GetSandboxOpenSearchInformation(OpenSearchUrl url) { SandboxOpenSearchInformation sosi = new SandboxOpenSearchInformation(); //check if the url ends with /search or /description //if so it can be queried using opensearch, otherise it means that it points to an AtomFeed file if (url.AbsolutePath.EndsWith("/search") || url.AbsolutePath.EndsWith("/description")) { System.Text.RegularExpressions.Regex r; System.Text.RegularExpressions.Match m; //GET Workflow / RunId for Terradue VMs if (url.AbsolutePath.StartsWith("/sbws/wps")) { r = new System.Text.RegularExpressions.Regex(@"^\/sbws\/wps\/(?<workflow>[a-zA-Z0-9_\-]+)\/(?<runid>[a-zA-Z0-9_\-]+)\/results"); m = r.Match(url.AbsolutePath); if (m.Success) { sosi.Workflow = m.Result("${workflow}"); sosi.RunId = m.Result("${runid}"); sosi.Hostname = url.Host; var replacementUrl = url.AbsoluteUri.Replace("/sbws/wps/" + sosi.Workflow + "/" + sosi.RunId + "/results", "/sbws/production/run/" + sosi.Workflow + "/" + sosi.RunId + "/products"); //TEMPORARY: if T2 sandbox (/sbws), use new path (/sbws/production) //if url exists we replace the value try { var request = (HttpWebRequest)WebRequest.Create(replacementUrl); using (var response = (HttpWebResponse)request.GetResponse()) { url = new OpenSearchUrl(replacementUrl); } } catch (Exception) { } } } else if (url.AbsolutePath.StartsWith("/sbws/production/run")) { r = new System.Text.RegularExpressions.Regex(@"^\/sbws\/production\/run\/(?<workflow>[a-zA-Z0-9_\-]+)\/(?<runid>[a-zA-Z0-9_\-]+)\/products"); m = r.Match(url.AbsolutePath); if (m.Success) { sosi.Hostname = m.Result("${hostname}"); sosi.Workflow = m.Result("${workflow}"); sosi.RunId = m.Result("${runid}"); } } //Get hostname of the run VM r = new System.Text.RegularExpressions.Regex(@"^https?:\/\/(?<hostname>[a-zA-Z0-9_\-\.]+)\/"); m = r.Match(url.AbsoluteUri); if (m.Success) { sosi.Hostname = m.Result("${hostname}"); } } sosi.Url = url; return(sosi); }
/// <summary> /// Initializes a new instance of the <see cref="Terradue.OpenSearch.HttpOpenSearchRequest"/> class. /// </summary> /// <param name="url">the HTTP URL.</param> internal HttpOpenSearchRequest(OpenSearchUrl url, string contentType = null) : base(url, contentType) { this.contentType = contentType; if (!url.Scheme.StartsWith("http")) throw new InvalidOperationException("A http scheme is expected for this kind of request"); this.OpenSearchUrl = url; this.originalParameters = HttpUtility.ParseQueryString(url.Query); }
/// <summary> /// Initializes a new instance of the <see cref="Terradue.OpenSearch.Request.MultiAtomOpenSearchRequest"/> class. /// </summary> /// <param name="ose">Instance of OpenSearchEngine, preferably with the AtomOpenSearchEngineExtension registered</param> /// <param name="entities">IOpenSearchable entities to be searched.</param> /// <param name="type">contentType of the .</param> /// <param name="url">URL.</param> public MultiAtomGroupedOpenSearchRequest(OpenSearchEngine ose, IOpenSearchable[] entities, string type, OpenSearchUrl url, bool concurrent) : base(url, type) { this.concurrent = concurrent; this.ose = ose; this.type = type; this.parameters = HttpUtility.ParseQueryString(url.Query); this.entities = entities; }
public void CanBindTemplate() { // Arrange ILinkTemplate template = new OpenSearchUrl { Template = "http://search.com/?q={terms}", MediaType = "application/atom+xml", RelationType = "results" }; // Act Request request = Session.Bind(template, new { terms = "abc" }); // Assert Assert.IsNotNull(request); Assert.AreEqual("http://search.com/?q=abc", request.Url.AbsoluteUri); }
public void GenericOpenSearchableTest() { AddinManager.Initialize(); AddinManager.Registry.Update(null); OpenSearchEngine ose = new OpenSearchEngine(); ose.LoadPlugins(); OpenSearchUrl url = new OpenSearchUrl("http://catalogue.terradue.int/catalogue/search/MER_FRS_1P/rdf?startIndex=0&q=MER_FRS_1P&start=1992-01-01&stop=2014-10-24&bbox=-72,47,-57,58"); IOpenSearchable entity = new GenericOpenSearchable(url, ose); var osr = ose.Query(entity, new System.Collections.Specialized.NameValueCollection(), "rdf"); //Assert.AreEqual(15, osr.TotalResults); Assert.That(osr.Links.Count > 0); }
public object Post(TypeImportRequest request) { OpenSearchEngine ose = new OpenSearchEngine(); ose.LoadPlugins(); ose.DefaultTimeOut = 60000; OpenSearchUrl url = new OpenSearchUrl(request.url); IOpenSearchable entity = new GenericOpenSearchable(url, ose); IOpenSearchableElasticType type = ecf.GetOpenSearchableElasticTypeByNameOrDefault(request.IndexName, request.TypeName); IOpenSearchResultCollection osres = ose.Query(entity, new NameValueCollection()); OpenSearchFactory.RemoveLinksByRel(ref osres, "alternate"); OpenSearchFactory.RemoveLinksByRel(ref osres, "via"); OpenSearchFactory.RemoveLinksByRel(ref osres, "self"); OpenSearchFactory.RemoveLinksByRel(ref osres, "search"); IElasticCollection documents = type.FromOpenSearchResultCollection(osres); BulkRequest bulkRequest = new BulkRequest() { Refresh = true, Consistency = Consistency.One, Index = request.IndexName }; foreach (var doc in documents.Items) { bulkRequest.Operations.Add(new BulkIndexOperation <IElasticItem>((IElasticItem)doc) { Id = doc.Id }); } var response = client.Bulk(bulkRequest); return(response); }
public void CanBindRequestFromLinkTemplateWithoutExplicitSession() { // Arrange string url = ResolveTestUrl(Constants.CatPath).AbsoluteUri; ILinkTemplate template = new OpenSearchUrl { Template = url, MediaType = "application/json", RelationType = "results" }; // Act using (var response = template.Bind(new { name = "Petra" }).AcceptJson().Get <Cat>()) { var body = response.Body; // Assert Assert.IsNotNull(body); Assert.AreEqual("Petra", body.Name); } }
protected override void SetUp() { base.SetUp(); Url1 = new OpenSearchUrl { RelationType = "tv", MediaType = "text/html", Template = "http://search.com?q={searchTerms}" }; Url2 = new OpenSearchUrl { RelationType = "home", MediaType = "text/html", Template = "http://search.com?q={searchTerms}" }; Url3 = new OpenSearchUrl { RelationType = "tv", MediaType = "application/atom+xml", Template = "http://search.com?q={searchTerms}" }; Url4 = new OpenSearchUrl { RelationType = "home", MediaType = "application/atom+xml", Template = "http://search.com?q={searchTerms}" }; Urls = new List <OpenSearchUrl>(); Urls.Add(Url1); Urls.Add(Url2); Urls.Add(Url3); Urls.Add(Url4); SearchDescription = new OpenSearchDescription { Urls = Urls }; }
public FedeoOpenSearchable(OpenSearchUrl url, IOpenSearchableFactory factory) : base(url, factory.Settings) { }
public SmartGenericOpenSearchable(OpenSearchUrl url, OpenSearchEngine ose) : base(new OpenSearchDescription(), ose) { base.url = url; base.ose = ose; base.osd = FindSmartOpenSearchDescription(); }
/// <summary> /// Initializes a new instance of the <see cref="Terradue.OpenSearch.Request.MemoryOpenSearchRequest"/> class. /// </summary> /// <param name="url">URL.</param> /// <param name="contentType">Content type.</param> public AtomOpenSearchRequest(OpenSearchUrl url, Func<NameValueCollection, AtomFeed> FeedGenerator) : base(url, "application/atom+xml") { this.feedGenerator = FeedGenerator; this.parameters = HttpUtility.ParseQueryString(url.Query); }
/// <summary> /// Initializes a new instance of the <see cref="Terradue.OpenSearch.OpenSearchRequest"/> class. /// </summary> /// <param name="url">URL.</param> protected OpenSearchRequest(OpenSearchUrl url, string contentType) { this.url = url; this.contentType = contentType; }
/// <summary> /// Create an IOpenSearchable from an OpenSearchUrl /// </summary> /// <param name="url">URL to either a search or a description</param> public IOpenSearchable Create(OpenSearchUrl url) { return new GenericOpenSearchable(url, this); }
public IOpenSearchable Create(OpenSearchDescription osd, OpenSearchUrl url = null) { return(new UrlBasedOpenSearchable(context, osd, url, Settings)); }
public static SandboxOpenSearchable CreateSandboxOpenSearchable(OpenSearchUrl osUrl, OpenSearchableFactorySettings settings) { var sosi = GetSandboxOpenSearchInformation(osUrl); return(new SandboxOpenSearchable(sosi, settings)); }
public OpenSearchResponseCacheItem(OpenSearchUrl url, IOpenSearchResponse clonedResponse) : base(url.ToString(),clonedResponse) { created = DateTime.UtcNow; }
public FedeoOpenSearchable(OpenSearchUrl url, OpenSearchEngine ose) : base(url, ose) { }
/// <summary> /// Loads an OpenSearchDescription document from an Url. /// </summary> /// <returns>The open search description document.</returns> /// <param name="url">URL.</param> public OpenSearchDescription LoadOpenSearchDescriptionDocument(OpenSearchUrl url) { OpenSearchDescription osd; OpenSearchRequest request = OpenSearchRequest.Create(url); ApplyPreSearchFilters(ref request); IOpenSearchResponse response = request.GetResponse(); ApplyPostSearchFilters(request, ref response); if (response.ObjectType != typeof(byte[])) throw new InvalidOperationException("The OpenSearch Description document did not return byte[] body"); try { XmlSerializer ser = new XmlSerializer(typeof(OpenSearchDescription)); Stream stream = new MemoryStream((byte[])response.GetResponseObject()); osd = (OpenSearchDescription)ser.Deserialize(XmlReader.Create(stream)); stream.Flush(); stream.Close(); } catch (Exception e) { throw new Exception("Exception querying OpenSearch description at " + url.ToString() + " : " + e.Message, e); } return osd; }
public IOpenSearchable Create(OpenSearchUrl url) { return(new UrlBasedOpenSearchable(context, url, Settings)); }
/// <summary> /// Initializes a new instance of the <see cref="Terradue.OpenSearch.HttpOpenSearchRequest"/> class. /// </summary> /// <param name="url">the HTTP URL.</param> internal FileOpenSearchRequest(OpenSearchUrl url, string mimeType) : base(url, mimeType) { if (!url.Scheme.StartsWith("file")) throw new InvalidOperationException("A file scheme is expected for this kind of request"); this.OpenSearchUrl = url; }
public static OpenSearchRequest Create(OpenSearchUrl queryUrl) { OpenSearchRequest request = null; switch (queryUrl.Scheme) { case "http": case "https": request = new HttpOpenSearchRequest(queryUrl); break; case "file": request = new FileOpenSearchRequest(queryUrl, ""); break; } return request; }
/// <summary> /// Try to discover the OpenSearchDescription from an URL. /// </summary> /// <returns>An OpenSearchDescription</returns> /// <param name="url">URL.</param> public OpenSearchDescription AutoDiscoverFromQueryUrl(OpenSearchUrl url) { OpenSearchDescription osd = null; OpenSearchUrl descriptionUrl = null; OpenSearchRequest request = OpenSearchRequest.Create(url); ApplyPreSearchFilters(ref request); IOpenSearchResponse response = request.GetResponse(); ApplyPostSearchFilters(request, ref response); string contentType = response.ContentType; if (contentType.Contains(";")) contentType = contentType.Split(';')[0]; if (contentType == "application/opensearchdescription+xml") { osd = this.LoadOpenSearchDescriptionDocument(url); descriptionUrl = url; } else { IOpenSearchEngineExtension osee = GetExtensionByContentTypeAbility(contentType); if (osee == null) throw new ImpossibleSearchException("No registered extension is able to read content of type " + response.ContentType); descriptionUrl = osee.FindOpenSearchDescriptionUrlFromResponse(response); if (descriptionUrl == null) throw new ImpossibleSearchException("No Opensearch Description link found in results of " + url.ToString()); osd = LoadOpenSearchDescriptionDocument(descriptionUrl); } osd.Originator = descriptionUrl; if (contentType == "application/opensearchdescription+xml") contentType = "application/atom+xml"; osd.DefaultUrl = osd.Url.FirstOrDefault(u => u.Type.StartsWith(contentType)); return osd; }