예제 #1
0
        public ActionResult Companies(string q)
        {
            Devmasters.Cache.LocalMemory.LocalMemoryCache <Index <Autocomplete> > FullTextSearchCache =
                new Devmasters.Cache.LocalMemory.LocalMemoryCache <Index <Autocomplete> >(TimeSpan.FromDays(30), "nasipolitici_firmy_autocomplete",
                                                                                          o =>
            {
                return(BuildNPFirmySearchIndex());
            });

            var searchCache = FullTextSearchCache.Get();

            var searchResult = searchCache.Search(q, 8);

            if (!string.IsNullOrEmpty(Request.Headers["Origin"]))
            {
                if (Request.Headers["Origin"].Contains(".hlidacstatu.cz"))
                {
                    Response.AddHeader("Access-Control-Allow-Origin", Request.Headers["Origin"]);
                }
            }
            return(Json(searchResult.Select(r => r.Original), JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public static ZabHostAvailability GetHostAvailabilityLong(ZabHost host)
        {
            Devmasters.Cache.LocalMemory.LocalMemoryCache <ZabHostAvailability> webData =
                new Devmasters.Cache.LocalMemory.LocalMemoryCache <ZabHostAvailability>(
                    TimeSpan.FromMinutes(10), "statniweby_host_" + host.hostid, (obj) =>
            {
                ZabHostAvailability d = null;
                using (var zr = new ZabbixReader())
                {
                    d = zr.GetAvailability_Raw(7 * 24 + 1, new ZabHost[] { host }, true).FirstOrDefault();
                    HlidacStatu.Util.Consts.Logger.Info("Cache statniweby_host_" + host.hostid + " refreshnuta");
                    return(d);
                }
            });

            try
            {
                return(webData.Get());
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #3
0
        // Used for searching
        public JsonResult FindCompany(string id)
        {
            Devmasters.Cache.LocalMemory.LocalMemoryCache <Index <SubjectNameCache> > FullTextSearchCache =
                new Devmasters.Cache.LocalMemory.LocalMemoryCache <Index <SubjectNameCache> >(TimeSpan.Zero,
                                                                                              o =>
            {
                return(new Index <SubjectNameCache>(SubjectNameCache.GetCompanies().Values));
            });

            var searchResult = FullTextSearchCache.Get().Search(id, 10);

            return(Json(searchResult.Select(r => r.Original), JsonRequestBehavior.AllowGet));
        }