Base class to represent an OpenSearch request.
        public new void ApplyResultFilters(OpenSearchRequest request, ref IOpenSearchResultCollection osr, string finalContentType)
        {
            log.DebugFormat("Applying Fedeo source harvesting");

            base.ApplyResultFilters(request, ref osr, finalContentType);

            QueryEarthObservationResult(ref osr);
        }
Exemple #2
0
 public void ApplyResultFilters(Terradue.OpenSearch.Request.OpenSearchRequest request, ref Terradue.OpenSearch.Result.IOpenSearchResultCollection osr, string finalContentType)
 {
 }
 public void ApplyResultFilters(OpenSearchRequest request,  ref IOpenSearchResultCollection osr)
 {
     OpenSearchFactory.ReplaceSelfLinks(this, request.Parameters, osr, this.EntrySelfLinkTemplate);
 }
 public void ApplyResultFilters(OpenSearchRequest request, ref IOpenSearchResultCollection osr, string finalContentType)
 {
 }
        /*public static void ReplaceId(ref IOpenSearchResultCollection osr) {
            IOpenSearchResultCollection feed = osr;

            var matchLinks = feed.Links.Where(l => l.RelationshipType == "self").ToArray();
            if (matchLinks.Count() > 0)
                feed.Id = matchLinks[0].Uri.ToString();

            foreach (IOpenSearchResultItem item in feed.Items) {
                matchLinks = item.Links.Where(l => l.RelationshipType == "self").ToArray();
                if (matchLinks.Count() > 0)
                    item.Id = matchLinks[0].Uri.ToString();
            }
        }*/
        public static void ReplaceSelfLinks(IOpenSearchable entity, OpenSearchRequest request, IOpenSearchResultCollection osr, Func<IOpenSearchResultItem,OpenSearchDescription,string,string> entryTemplate)
        {
            ReplaceSelfLinks(entity, request.Parameters, osr, entryTemplate, osr.ContentType);
        }
        /// <summary>
        /// Applies the post search filters.
        /// </summary>
        /// <param name="request">Request.</param>
        /// <param name="response">Response.</param>
        private void ApplyPostSearchFilters(OpenSearchRequest request, ref IOpenSearchResponse response)
        {
            foreach (PostFilterAction filter in postFilters) {

                filter.Invoke(request, ref response);

            }
        }
        /// <summary>
        /// Applies the pre search filters.
        /// </summary>
        /// <param name="request">Request.</param>
        private void ApplyPreSearchFilters(ref OpenSearchRequest request)
        {
            foreach (PreFilterAction filter in preFilters) {

                filter.Invoke(ref request);

            }
        }
        void ApplyOpenSearchElements(ref IOpenSearchResultCollection newResults, OpenSearchRequest request, IOpenSearchResponse response)
        {
            foreach (SyndicationElementExtension ext in newResults.ElementExtensions.ToArray()) {
                if (ext.OuterName == "startIndex" && ext.OuterNamespace == "http://a9.com/-/spec/opensearch/1.1/")
                    newResults.ElementExtensions.Remove(ext);
                if (ext.OuterName == "itemsPerPage" && ext.OuterNamespace == "http://a9.com/-/spec/opensearch/1.1/")
                    newResults.ElementExtensions.Remove(ext);
                if (ext.OuterName == "Query" && ext.OuterNamespace == "http://a9.com/-/spec/opensearch/1.1/")
                    newResults.ElementExtensions.Remove(ext);
            }
            newResults.ElementExtensions.Add("startIndex", "http://a9.com/-/spec/opensearch/1.1/", request.OpenSearchUrl.IndexOffset);
            newResults.ElementExtensions.Add("itemsPerPage", "http://a9.com/-/spec/opensearch/1.1/", request.OpenSearchUrl.Count);

            XElement query = new XElement(XName.Get("Query", "http://a9.com/-/spec/opensearch/1.1/"));
            OpenSearchDescription osd = null;
            if (response.Entity is IProxiedOpenSearchable)
                osd = ((IProxiedOpenSearchable)response.Entity).GetProxyOpenSearchDescription();
            else
                osd = response.Entity.GetOpenSearchDescription();
            foreach (var ns in osd.ExtraNamespace.ToArray()) {
                if (string.IsNullOrEmpty(ns.Name) || ns.Namespace == "http://www.w3.org/2001/XMLSchema" || ns.Namespace == "http://www.w3.org/2001/XMLSchema-instance" || ns.Namespace == XNamespace.Xmlns.NamespaceName)
                    continue;
                query.Add(new XAttribute(XNamespace.Xmlns + ns.Name, ns.Namespace));
            }
            var osUrl = OpenSearchFactory.GetOpenSearchUrlByType(osd, request.ContentType);
            var osparams = OpenSearchFactory.GetOpenSearchParameters(osUrl);
            foreach (var key in request.Parameters.AllKeys) {
                string osparam = OpenSearchFactory.GetParamNameFromId(osparams, key);
                if (!string.IsNullOrEmpty(osparam)) {
                    try {
                        if (osparam.Contains(":"))
                            query.Add(new XAttribute(XName.Get(osparam.Split(':')[1], osd.ExtraNamespace.ToArray().First(n => n.Name == osparam.Split(':')[0]).Namespace), request.Parameters[key]));
                        else {
                            query.Add(new XAttribute(XName.Get(osparam, osd.ExtraNamespace.ToArray().First(n => n.Name == "os").Namespace), request.Parameters[key]));
                        }
                    } catch {
                    }
                }
            }
            newResults.ElementExtensions.Add(query.CreateReader());
        }
 /// <summary>
 /// Creates the policy.
 /// </summary>
 /// <returns>The policy.</returns>
 /// <param name="item">Item.</param>
 protected CacheItemPolicy CreatePolicy(OpenSearchResponseCacheItem item, OpenSearchRequest request)
 {
     CacheItemPolicy policy = new CacheItemPolicy();
     policy.AbsoluteExpiration = DateTime.UtcNow.Add(item.OpenSearchResponse.Validity);
     log.DebugFormat("OpenSearch Cache [prepare to store] AbsoluteExpiration {1} {0}", item.OpenSearchUrl, policy.AbsoluteExpiration);
     policy.RemovedCallback = new CacheEntryRemovedCallback(this.EntryRemovedCallBack);
     if (item.OpenSearchResponse.Entity is IMonitoredOpenSearchable) {
         IMonitoredOpenSearchable mos = (IMonitoredOpenSearchable)item.OpenSearchResponse.Entity;
         var monitor = new OpenSearchableChangeMonitor(mos, request);
         log.DebugFormat("OpenSearch Cache [prepare to store] Monitor {1} {0}  ", item.OpenSearchUrl, monitor.UniqueId);
         policy.ChangeMonitors.Add(monitor);
     }
     return policy;
 }
        /// <summary>
        /// Tries the replace with cache request.
        /// </summary>
        /// <param name="request">Request.</param>
        public void TryReplaceWithCacheRequest(ref OpenSearchRequest request)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            CacheItem it = cache.GetCacheItem(request.OpenSearchUrl.ToString());

            if (it == null) return;

            OpenSearchResponseCacheItem item = new OpenSearchResponseCacheItem(it);
            watch.Stop();

            log.DebugFormat("OpenSearch Cache [load] {0}", request.OpenSearchUrl);
            request = new CachedOpenSearchRequest(item.OpenSearchUrl, item.OpenSearchResponse, request.OriginalParameters, watch.Elapsed);
        }
        /// <summary>
        /// Caches the response.
        /// </summary>
        /// <param name="request">Request.</param>
        /// <param name="response">Response.</param>
        public void CacheResponse(OpenSearchRequest request, ref IOpenSearchResponse response)
        {
            CacheItem it = cache.GetCacheItem(request.OpenSearchUrl.ToString());

                if (it != null) return;

            if (response.Entity != null && !response.Entity.CanCache)
                return;

            var clonedResponse = response.CloneForCache();

            if (clonedResponse == null)
                throw new InvalidOperationException(string.Format("Response cannot be cached because it is null. Check the CloneForCache of the response [{0}] or the CanCache() method of the Opensearchable [{1}] requested", response.GetType(), response.Entity.GetType()));

            OpenSearchResponseCacheItem item = new OpenSearchResponseCacheItem(request.OpenSearchUrl, clonedResponse);
            CacheItemPolicy policy = this.CreatePolicy(item, request);
            log.DebugFormat("OpenSearch Cache [store] {0}", request.OpenSearchUrl);

            cache.Set(item, policy);

            log.DebugFormat("OpenSearch Cache [count] {0}", cache.GetCount());
        }
 public OpenSearchableChangeMonitor(IMonitoredOpenSearchable entity, OpenSearchRequest request)
 {
     this.contentType = request.ContentType;
     this.parameters = request.OriginalParameters;
     this.entity = entity;
     InitDisposableMembers();
 }