예제 #1
0
        private async Task FillCache(string url)
        {
            Chromium          chromium = Chromium.GetInstance();
            Response          response;
            string            sourceCode;
            PrerenderSpecials prerenderSpecials;

            // relaunch method on chromium fail
            try
            {
                (response, sourceCode, prerenderSpecials) = await chromium.GoToUrlAsync(url);
            }
            catch (Exception)
            {
                await FillCache(url);

                return;
            }

            // save page to db
            var db = new CachedPageContext();

            db.Database.EnsureCreated();
            db.CachedPages.Add(new CachedPage
            {
                Url            = url,
                TimeStamp      = Utils.Dt.UnixNow(),
                AnswerHttpCode = string.IsNullOrEmpty(prerenderSpecials.StatusCode) ? (int)response.Status : Convert.ToInt32(prerenderSpecials.StatusCode),
                SourceCode     = sourceCode
            });
            db.SaveChanges();
        }