Esempio n. 1
0
        public IActionResult RegisterVisit([FromBody] Visit visit)
        {
            return(es.Execute(
                       () =>
            {
                if (visit == null || us.Empty(visit.Route))
                {
                    es.ThrowException("Wrong visit data");
                }
                visit.RequestIp = httpContext.HttpContext.Connection.RemoteIpAddress.ToString();
                visit.RequestTime = DateTimeOffset.UtcNow;
                ds.RegisterVisit(visit);

                return new JsonResult(new GenericResult());
            },
                       false
                       ));
        }
Esempio n. 2
0
        public List <Link> GetArticles(long?newsProviderId, string newsSourceId)
        {
            if (us.Empty(newsSourceId) || !newsProviderId.HasValue)
            {
                return(null);
            }

            NewsProviderDef providerDef = ProviderDefs.FirstOrDefault(x => x.Id == newsProviderId.Value);

            if (providerDef == null)
            {
                return(null);
            }

            INewsProvider provider = factory.GetProvider(providerDef);

            if (provider == null)
            {
                return(null);
            }

            string key = op.Value.Cache.NewsSourceKey + newsProviderId.Value + newsSourceId;

            List <Link> result;

            if (cache.TryGetValue(key, out result))
            {
                return(result);
            }


            result = provider.GetLinks(newsSourceId).ToList();

            cache.Set(key, result,
                      new MemoryCacheEntryOptions()
                      .SetAbsoluteExpiration(TimeSpan.FromMinutes(op.Value.Cache.NewsArticlesRefreshInterval)));

            return(result);
        }