The engine for making OpenSearch request
Inheritance: IOpenSearchableFactory
        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);
        }
Esempio n. 2
0
        public QuerySettings GetQuerySettings(Terradue.OpenSearch.Engine.OpenSearchEngine ose)
        {
            IOpenSearchEngineExtension osee = new AtomOpenSearchEngineExtension();

            originalReadNativeFunctionToExtend = osee.ReadNative;
            return(new QuerySettings(osee.DiscoveryContentType, Sentinel1QcReadNative));
        }
        public virtual IOpenSearchable CreateOpenSearchable(IEnumerable<Uri> baseUrls, string queryFormatArg, OpenSearchEngine ose, IEnumerable<NetworkCredential> netCreds, bool lax)
        {
            List<IOpenSearchable> entities = new List<IOpenSearchable>();
            foreach (var url in baseUrls) {
                if (string.IsNullOrEmpty(queryFormatArg))
                    try {
                        entities.Add(OpenSearchFactory.FindOpenSearchable(ose, url, null, lax));
                    } catch (Exception e) {
                        throw e;
                    } else {
                    var e = OpenSearchFactory.FindOpenSearchable(ose, url, ose.GetExtensionByExtensionName(queryFormatArg).DiscoveryContentType, lax);
                    entities.Add(e);
                }
            }

            IOpenSearchable entity;

            if (entities.Count > 1) {
                entity = new MultiGenericOpenSearchable(entities, ose);
            } else {
                entity = entities[0];
            }

            return entity;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Terradue.OpenSearch.Filters.OpenSearchCorrelationFilter"/> class.
 /// </summary>
 /// <param name="ose">Ose.</param>
 /// <param name="factory">Factory.</param>
 public OpenSearchCorrelationFilter(OpenSearchEngine ose, IOpenSearchableFactory factory = null)
 {
     this.ose = ose;
     if (factory != null) {
         this.factory = factory;
     } else {
         this.factory = ose;
     }
 }
 /// <summary>
 /// Creates a <see cref="cdabtesttools.Target.TargetSiteWrapper"/> instance.
 /// </summary>
 /// <param name="name">A name for the target site.</param>
 /// <param name="targetSiteConfig">The object representing the target site node from the configuration YAML file.</param>
 public TargetSiteWrapper(string name, TargetSiteConfiguration targetSiteConfig)
 {
     Name = name;
     this.targetSiteConfig = targetSiteConfig;
     ose = new Terradue.OpenSearch.Engine.OpenSearchEngine();
     ose.LoadPlugins();
     wrapper     = CreateDataAccessWrapper(targetSiteConfig);
     target_type = InitType();
 }
        public override IOpenSearchable CreateOpenSearchable(IEnumerable<Uri> baseUrls, string queryFormatArg, OpenSearchEngine ose, IEnumerable<NetworkCredential> netCreds, bool lax)
        {
            SciHubOpenSearchable entity = new SciHubOpenSearchable(baseUrls.First(), netCreds.First());
            if (queryFormatArg == "eop") {
                entity.DefaultMimeType = "application/atom+xml; profile=http://earth.esa.int/eop/2.1";
            }

            return entity;
        }
        public override IOpenSearchable CreateOpenSearchable(IEnumerable<Uri> baseUrls, string queryFormatArg, OpenSearchEngine ose, IEnumerable<NetworkCredential> netCreds, bool lax)
        {
            List<IOpenSearchable> entities = new List<IOpenSearchable>();

            IOpenSearchEngineExtension ext;

            if (string.IsNullOrEmpty(queryFormatArg)) {
                ext = ose.GetExtensionByExtensionName("atom");
            } else {
                ext = ose.GetExtensionByExtensionName(queryFormatArg);
            }

            foreach (var url in baseUrls) {
                IOpenSearchable e = null;
                // QC Sentinel1 case
                if (url.Host == "qc.sentinel1.eo.esa.int")
                {
                    log.DebugFormat("QC Sentinel1 source. Trying to get the earthobservation profile");
                    e = new Sentinel1QcOpenSearchable(url, ose);
                    entities.Add(e);
                    continue;
                }
                e = OpenSearchFactory.FindOpenSearchable(ose, url, ext.DiscoveryContentType, lax);
                if (!e.DefaultMimeType.Contains("profile=http://earth.esa.int/eop")) {
                    try {
                        e = OpenSearchFactory.FindOpenSearchable(ose, url, "application/atom+xml; profile=http://earth.esa.int/eop/2.1", lax);
                    } catch (InvalidOperationException){
                        e = OpenSearchFactory.FindOpenSearchable(ose, url, "application/atom+xml", lax);
                    }
                    if (!e.DefaultMimeType.Contains("xml"))
                        throw new InvalidOperationException("No Url in the OpenSearch Description Document that could fit the EOP data model");
                }
                // Fedeo case
                if (url.Host == "fedeo.esa.int" && e.DefaultMimeType == "application/atom+xml" && e is Terradue.OpenSearch.GenericOpenSearchable) {
                    log.DebugFormat("Fedeo source. Trying to get the earthobservation profile");
                    e = FedeoOpenSearchable.CreateFrom(url, ose);
                }
                // Cwic case
                if (url.Host == "cwic.wgiss.ceos.org" && e.DefaultMimeType == "application/atom+xml" && e is Terradue.OpenSearch.GenericOpenSearchable) {
                    log.DebugFormat("Cwic source. Trying to get the earthobservation profile");
                    e = CwicOpenSearchable.CreateFrom((Terradue.OpenSearch.GenericOpenSearchable)e, ose);
                }

                entities.Add(e);
            }

            IOpenSearchable entity;

            if (entities.Count > 1) {
                entity = new MultiGenericOpenSearchable(entities, ose);
            } else {
                entity = entities[0];
            }

            return entity;
        }
        /// <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;
        }
Esempio n. 9
0
        //        [Test]
        public void TestAtom1()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            OpenSearchEngine ose = new OpenSearchEngine();
            ose.LoadPlugins();

            GenericOpenSearchable entity = new GenericOpenSearchable(new OpenSearchUrl("https://ngeopro.magellium.fr/remote/S1_SAR_IW_SINGLE_POL/description"), ose);
            NameValueCollection nvc = new NameValueCollection();

            var osr = ose.Query(entity, nvc, "atom");
        }
Esempio n. 10
0
        public void RunBeforeTests()
        {
            XmlConfigurator.Configure(new FileInfo("../Log4Net.config"));

            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            ose = new OpenSearchEngine();
            ose.LoadPlugins();

            OpenSearchMemoryCache cache = new OpenSearchMemoryCache();

            ose.RegisterPreSearchFilter(cache.TryReplaceWithCacheRequest);
            ose.RegisterPostSearchFilter(cache.CacheResponse);
        }
        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 void DiscoverDescription()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            var ose = new OpenSearchEngine();
            ose.LoadPlugins();

            GenericOpenSearchable entity = new GenericOpenSearchable(new OpenSearchUrl("https://catalog.terradue.com/noa-cosmoskymed/search?uid=CSKS4_SCS_B_HI_09_HH_RA_SF_20150911040406_20150911040413&format=json"), ose);

            var results = ose.Query(entity, new System.Collections.Specialized.NameValueCollection(), "json");
            FeatureCollectionResult col = (FeatureCollectionResult)results;

            var properties = col.FeatureResults.First().Properties;

            Assert.That(col.Features[0].Geometry != null);
            Assert.That(!string.IsNullOrEmpty(col.Features[0].ToWkt()));

            results = ose.Query(entity, new System.Collections.Specialized.NameValueCollection(), "atom");
        }
 public QuerySettings GetQuerySettings(OpenSearchEngine ose)
 {
     IOpenSearchEngineExtension osee = ose.GetExtensionByContentTypeAbility(this.DefaultMimeType);
     if (osee == null)
         return null;
     return new QuerySettings(this.DefaultMimeType, osee.ReadNative);
 }
 public QuerySettings GetQuerySettings(OpenSearchEngine ose)
 {
     IOpenSearchEngineExtension osee = new AtomOpenSearchEngineExtension();
     return new QuerySettings(osee.DiscoveryContentType, osee.ReadNative);
 }
Esempio n. 15
0
        private void LoadStaticObject()
        {
            OpenSearchEngine = new OpenSearchEngine();
            OpenSearchEngine.LoadPlugins();

            NameValueCollection cacheSettings = new NameValueCollection();
            cacheSettings.Add("SlidingExpiration", "600");

            AppHost.searchCache = new OpenSearchMemoryCache("cache", cacheSettings);
            OpenSearchEngine.RegisterPreSearchFilter(AppHost.searchCache.TryReplaceWithCacheRequest);
            OpenSearchEngine.RegisterPostSearchFilter(AppHost.searchCache.CacheResponse);

            ElasticCasFactory.LoadPlugins(this);
        }
 public UrlBasedOpenSearchableFactory(OpenSearchEngine ose, bool soft = false)
 {
     this.soft = soft;
     this.ose = ose;
 }
 void LoadOpenSearchEngineExtensions(OpenSearchEngine ose)
 {
     ose.LoadPlugins();
     return;
 }
 public Terradue.OpenSearch.Engine.OpenSearchEngine GetOpenSearchEngine(System.Collections.Specialized.NameValueCollection nvc)
 {
     OpenSearchEngine ose = new OpenSearchEngine();
     ose.LoadPlugins();
     foreach (var ext in ose.Extensions.ToList()) {
         if (ext.Value.DiscoveryContentType == "application/json")
             ose.Extensions.Remove(ext.Key);
     }
     ose.RegisterExtension(new GenericJsonOpenSearchEngineExtension());
     return ose;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Terradue.OpenSearch.MultiGenericOpenSearchable"/> class.
 /// </summary>
 /// <param name="entities">Entities.</param>
 /// <param name="ose">Ose.</param>
 public MultiGenericOpenSearchable(List<IOpenSearchable> entities, OpenSearchEngine ose, bool concurrent = false)
 {
     this.concurrent = concurrent;
     this.ose = ose;
     this.entities = new List<IOpenSearchable>(entities);
 }
 public static CwicOpenSearchable CreateFrom(GenericOpenSearchable e, OpenSearchEngine ose)
 {
     return new CwicOpenSearchable(e.GetOpenSearchDescription(), ose);
 }
 public CwicOpenSearchable(OpenSearchDescription osd, OpenSearchEngine ose)
     : base(osd, ose)
 {
 }
Esempio n. 22
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 Terradue.OpenSearch.Schema.OpenSearchDescription GetOpenSearchDescription()
        {
            OpenSearchDescription osd = new OpenSearchDescription();

            osd.ShortName = "Elastic Catalogue";
            osd.Attribution = "Terradue";
            osd.Contact = "*****@*****.**";
            osd.Developer = "Terradue GeoSpatial Development Team";
            osd.SyndicationRight = "open";
            osd.AdultContent = "false";
            osd.Language = "en-us";
            osd.OutputEncoding = "UTF-8";
            osd.InputEncoding = "UTF-8";
            osd.Description = "This Search Service performs queries in the available dataset catalogue. There are several URL templates that return the results in different formats (GeoJson, RDF, ATOM or KML). This search service is in accordance with the OGC 10-032r3 specification.";

            OpenSearchEngine ose = new OpenSearchEngine();
            ose.LoadPlugins();

            var searchExtensions = ose.Extensions;
            List<OpenSearchDescriptionUrl> urls = new List<OpenSearchDescriptionUrl>();

            NameValueCollection parameters = GetOpenSearchParameters(this.DefaultMimeType);

            UriBuilder searchUrl = new UriBuilder(string.Format("es://elasticsearch/{0}/{1}/search", this.index.Name, this.Type.Name));
            NameValueCollection queryString = HttpUtility.ParseQueryString("?format=json");
            parameters.AllKeys.FirstOrDefault(k => {
                queryString.Add(parameters[k], "{" + k + "?}");
                return false;
            });

            searchUrl.Query = queryString.ToString();
            urls.Add(new OpenSearchDescriptionUrl("application/json",
                                                  searchUrl.ToString(),
                                                  "search"));

            osd.Url = urls.ToArray();

            return osd;
        }
        public void MultiLimitTwoTest()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            OpenSearchEngine ose = new OpenSearchEngine();
            ose.LoadPlugins();

            IOpenSearchable entity1 = TestOpenSearchable.GenerateNumberedItomFeed("A", 1, new TimeSpan(0));
            IOpenSearchable entity2 = TestOpenSearchable.GenerateNumberedItomFeed("B", 1, TimeSpan.FromHours(-1));

            List<IOpenSearchable> entities = new List<IOpenSearchable>();
            entities.Add(entity1);
            entities.Add(entity2);

            IOpenSearchable multiEntity = new MultiGenericOpenSearchable(entities, ose, true);

            NameValueCollection nvc = new NameValueCollection();

            var osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(2, osr.Count);
        }
 public QuerySettings GetQuerySettings(OpenSearchEngine ose)
 {
     return new QuerySettings(this.DefaultMimeType, new GenericJsonOpenSearchEngineExtension().ReadNative);
 }
        public void GenericProxiedOpenSearchableTest()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            OpenSearchEngine ose = new OpenSearchEngine();
            ose.LoadPlugins();

            IOpenSearchable entity1 = TestOpenSearchable.GenerateNumberedItomFeed("A", 100, new TimeSpan(0));

            List<IOpenSearchable> entities = new List<IOpenSearchable>();
            entities.Add(entity1);

            IOpenSearchable multiEntity = new MultiGenericOpenSearchable(entities, ose, true);

            NameValueCollection nvc = new NameValueCollection();

            var osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(100, osr.TotalResults);
            Assert.AreEqual(OpenSearchEngine.DEFAULT_COUNT, osr.Count);
            string totalResults = osr.ElementExtensions.ReadElementExtensions<string>("totalResults", "http://a9.com/-/spec/opensearch/1.1/")[0];
            Assert.AreEqual("100", totalResults);

            nvc.Set("count", "100");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(100, osr.TotalResults);
            Assert.AreEqual(100, osr.Count);
            Assert.AreEqual("A1", osr.Items.First().Identifier);
            Assert.AreEqual("A100", osr.Items.Last().Identifier);

            nvc.Set("count", "6");
            nvc.Set("startPage", "1");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(100, osr.TotalResults);
            Assert.AreEqual(6, osr.Count);
            Assert.AreEqual("A1", osr.Items.First().Identifier);
            Assert.AreEqual("A6", osr.Items.Last().Identifier);

            nvc.Set("count", "3");
            nvc.Set("startPage", "2");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(100, osr.TotalResults);
            Assert.AreEqual(3, osr.Count);
            Assert.AreEqual("A4", osr.Items.First().Identifier);
            Assert.AreEqual("A6", osr.Items.Last().Identifier);

            nvc.Set("startIndex", "16");
            nvc.Set("startPage", "1");
            nvc.Set("count", "100");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(85, osr.Count);
            Assert.AreEqual("A16", osr.Items.First().Identifier);
            Assert.AreEqual("A100", osr.Items.Last().Identifier);

            nvc.Set("count", "5");
            nvc.Set("startIndex", "5");
            nvc.Set("startPage", "1");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(5, osr.Count);
            Assert.AreEqual("A5", osr.Items.First().Identifier);
            Assert.AreEqual("A9", osr.Items.Last().Identifier);

            nvc.Set("count", "5");
            nvc.Set("startIndex", "5");
            nvc.Set("startPage", "2");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(5, osr.Count);
            Assert.AreEqual("A10", osr.Items.First().Identifier);
            Assert.AreEqual("A14", osr.Items.Last().Identifier);

            nvc.Set("count", "5");
            nvc.Set("startIndex", "5");
            nvc.Set("startPage", "4");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(5, osr.Count);
            Assert.AreEqual("A20", osr.Items.First().Identifier);
            Assert.AreEqual("A24", osr.Items.Last().Identifier);

            nvc.Set("count", "5");
            nvc.Set("startIndex", "5");
            nvc.Set("startPage", "5");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(5, osr.Count);
            Assert.AreEqual("A25", osr.Items.First().Identifier);
            Assert.AreEqual("A29", osr.Items.Last().Identifier);

            nvc.Set("count", "5");
            nvc.Set("startIndex", "1");
            nvc.Set("startPage", "1");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(5, osr.Count);
            Assert.AreEqual("A1", osr.Items.First().Identifier);
            Assert.AreEqual("A5", osr.Items.Last().Identifier);

            nvc.Set("count", "5");
            nvc.Set("startIndex", "1");
            nvc.Set("startPage", "5");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(5, osr.Count);
            Assert.AreEqual("A21", osr.Items.First().Identifier);
            Assert.AreEqual("A25", osr.Items.Last().Identifier);

            IOpenSearchable entity2 = TestOpenSearchable.GenerateNumberedItomFeed("B", 100, TimeSpan.FromHours(-1));

            entities.Add(entity2);
            multiEntity = new MultiGenericOpenSearchable(entities, ose, true);

            nvc = new NameValueCollection();
            nvc.Set("count", "10");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(200, osr.TotalResults);
            Assert.AreEqual(10, osr.Count);
            Assert.AreEqual("A1", osr.Items.First().Identifier);
            Assert.AreEqual("B5", osr.Items.Last().Identifier);

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(200, osr.TotalResults);
            Assert.AreEqual(10, osr.Count);
            Assert.AreEqual("A1", osr.Items.First().Identifier);
            Assert.AreEqual("B5", osr.Items.Last().Identifier);

            nvc.Set("count", "4");
            nvc.Set("startIndex", "2");
            nvc.Set("startPage", "1");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(4, osr.Count);
            Assert.AreEqual("B1", osr.Items.First().Identifier);
            Assert.AreEqual("A3", osr.Items.Last().Identifier);

            nvc.Set("count", "4");
            nvc.Set("startIndex", "4");
            nvc.Set("startPage", "1");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(4, osr.Count);
            Assert.AreEqual("B2", osr.Items.First().Identifier);
            Assert.AreEqual("A4", osr.Items.Last().Identifier);

            nvc.Set("count", "4");
            nvc.Set("startIndex", "4");
            nvc.Set("startPage", "2");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(4, osr.Count);
            Assert.AreEqual("B4", osr.Items.First().Identifier);
            Assert.AreEqual("A6", osr.Items.Last().Identifier);
        }
        internal void Initialize()
        {
            // Config log
            log = ConfigureLog();

            log.Debug("Initialize Addins registry.");

            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            log.Debug("Initialize SSL verification.");
            // Override automatic validation of SSL server certificates.
            System.Net.ServicePointManager.ServerCertificateValidationCallback = (s, ce, ca, p) => true;

            log.Debug("Load OpenSearch Engine.");
            ose = new OpenSearchEngine();

            LoadOpenSearchEngineExtensions(ose);

            InitCache();
        }
        public void StartIndexMultiOpenSearchableTest()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            OpenSearchEngine ose = new OpenSearchEngine();
            ose.LoadPlugins();

            IOpenSearchable entity1 = TestOpenSearchable.GenerateNumberedItomFeed("A", 4, new TimeSpan(0));

            List<IOpenSearchable> entities = new List<IOpenSearchable>();
            entities.Add(entity1);

            IOpenSearchable multiEntity = new MultiGenericOpenSearchable(entities, ose, true);

            NameValueCollection nvc = new NameValueCollection();

            nvc = new NameValueCollection();
            nvc.Set("count", "2");
            nvc.Set("startIndex", "5");

            var osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(4, osr.TotalResults);
            Assert.AreEqual(0, osr.Count);

            nvc.Set("count", "2");
            nvc.Set("startIndex", "4");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(4, osr.TotalResults);
            Assert.AreEqual(1, osr.Count);
            Assert.AreEqual("A4", osr.Items.First().Identifier);
            Assert.AreEqual("A4", osr.Items.Last().Identifier);

            nvc.Set("count", "2");
            nvc.Set("startIndex", "3");

            osr = ose.Query(multiEntity, nvc, "atom");

            Assert.AreEqual(4, osr.TotalResults);
            Assert.AreEqual(2, osr.Count);
            Assert.AreEqual("A3", osr.Items.First().Identifier);
            Assert.AreEqual("A4", osr.Items.Last().Identifier);
        }
        private IOpenSearchResultCollection QueryOpenSearch(OpenSearchEngine ose, IOpenSearchable entity, NameValueCollection parameters)
        {
            IOpenSearchResultCollection osr;

            if (string.IsNullOrEmpty(queryFormatArg))
                osr = ose.Query(entity, parameters);
            else
                osr = ose.Query(entity, parameters, queryFormatArg);

            return osr;
        }
        /// <summary>
        /// Finds the open search description.
        /// </summary>
        /// <returns>The open search description.</returns>
        /// <param name="baseUrl">Base URL.</param>
        public static IOpenSearchable FindOpenSearchable(OpenSearchEngine ose, Uri baseUrl, string mimeType = null, bool soft = false)
        {
            OpenSearchUrl url = new OpenSearchUrl(baseUrl);
            OpenSearchDescription openSearchDescription = null;
            UrlBasedOpenSearchableFactory urlBasedOpenSearchableFactory;
            IOpenSearchable result;
            try {
                openSearchDescription = OpenSearchFactory.LoadOpenSearchDescriptionDocument(url);
                OpenSearchDescriptionUrl openSearchDescriptionUrl;
                if (mimeType == null) {
                    openSearchDescriptionUrl = openSearchDescription.Url.First<OpenSearchDescriptionUrl>();
                } else {
                    openSearchDescriptionUrl = openSearchDescription.Url.FirstOrDefault((OpenSearchDescriptionUrl u) => u.Type == mimeType);
                }
                if (openSearchDescriptionUrl == null) {
                    throw new InvalidOperationException("Impossible to find an OpenSearchable link for the type " + mimeType);
                }
                openSearchDescription.DefaultUrl = openSearchDescriptionUrl;
            } catch (InvalidOperationException ex) {
                if (!(ex.InnerException is FileNotFoundException) && !(ex.InnerException is SecurityException) && !(ex.InnerException is UriFormatException)) {
                    openSearchDescription = ose.AutoDiscoverFromQueryUrl(new OpenSearchUrl(baseUrl));
                    urlBasedOpenSearchableFactory = new UrlBasedOpenSearchableFactory(ose, soft);
                    result = urlBasedOpenSearchableFactory.Create(url);
                    if (string.IsNullOrEmpty(mimeType))
                        return result;
                    var murl = openSearchDescription.Url.FirstOrDefault((OpenSearchDescriptionUrl u) => u.Type == mimeType);
                    if (murl != null)
                        result.GetOpenSearchDescription().DefaultUrl = murl;

                    return result;
                }
                try {
                    url = new OpenSearchUrl(new Uri(baseUrl, "/description"));
                    openSearchDescription = OpenSearchFactory.LoadOpenSearchDescriptionDocument(url);
                } catch {
                    try {
                        url = new OpenSearchUrl(new Uri(baseUrl, "/OSDD"));
                        openSearchDescription = OpenSearchFactory.LoadOpenSearchDescriptionDocument(url);
                    } catch {
                        throw new EntryPointNotFoundException(string.Format("No OpenSearch description found around {0}", baseUrl));
                    }
                }
            }
            if (openSearchDescription == null) {
                throw new EntryPointNotFoundException(string.Format("No OpenSearch description found around {0}", baseUrl));
            }
            urlBasedOpenSearchableFactory = new UrlBasedOpenSearchableFactory(ose, soft);
            result = urlBasedOpenSearchableFactory.Create(openSearchDescription);
            return result;
        }
Esempio n. 31
0
 public IOpenSearchable CreateOpenSearchable(IEnumerable<Uri> baseUrls, string queryFormatArg, OpenSearchEngine ose, IEnumerable<NetworkCredential> netCreds, bool lax)
 {
     return modelExtension.CreateOpenSearchable(baseUrls, queryFormatArg, ose, netCreds, lax);
 }
        public static Type ResolveTypeFromRequest(HttpRequest request, OpenSearchEngine ose)
        {
            Type type = ose.Extensions.First().Value.GetTransformType();

            if (request.Params["format"] != null) {
                var osee = ose.GetExtensionByExtensionName(request.Params["format"]);
                if (osee != null) {
                    type = osee.GetTransformType();
                }
            } else {
                if (request.AcceptTypes != null) {
                    foreach (string contentType in request.AcceptTypes) {
                        var osee = ose.GetExtensionByContentTypeAbility(contentType);
                        if (osee != null) {
                            type = osee.GetTransformType();
                            break;
                        }
                    }
                }
            }

            return type;
        }