Beispiel #1
0
        public async Task LoadRemoteDataAsync(string url, string schema)
        {
            string content = await RemoteJsonFetch.GetRemoteJsonContentAsync(url, schema);

            if (content != null)
            {
                RazorLocationViews razorLocationViews;
                razorLocationViews = FromJson(content);
                var now = DateTime.UtcNow;

                var query = from item in razorLocationViews.Views
                            let c = new RazorLocation(item)
                {
                    LastModified = now, LastRequested = now
                }
                select c;

                var results = query.ToList();

                var lastRequetedTime = now.Subtract(new TimeSpan(0, 1, 0));
                foreach (var result in results)
                {
                    // make sure that there is no confusion that this is new
                    result.LastModified  = now;
                    result.LastRequested = lastRequetedTime;
                }
                Insert(results);
            }
        }
        public async Task <SpaRecords> GetRemoteDataAsync(string url)
        {
            string content = await RemoteJsonFetch.GetRemoteJsonContentAsync(url);

            var spaRecords = FromJson(content);

            return(spaRecords);
        }
Beispiel #3
0
        public async Task <object> LoadAsync(string pathFragment)
        {
            var        domain           = _configuration["remoteContent:domain"];
            var        rootPathFragment = _configuration["remoteContent:rootPathFragment"];
            UriBuilder builder          = new UriBuilder(domain)
            {
                Path = $"{rootPathFragment}/{pathFragment}"
            };
            var uri          = builder.Uri;
            var fileContents = await RemoteJsonFetch.GetRemoteJsonContentAsync(uri.AbsoluteUri);

            var result = JsonConvert.DeserializeObject(fileContents);

            return(result);
        }
Beispiel #4
0
        public async Task Invoke(CancellationToken cancellationToken)
        {
            var appConfig = new ExternalUrlsOptions();

            _config.GetSection("externalViews").Bind(appConfig);

            var urlViewSchema = await RemoteJsonFetch.GetRemoteJsonContentAsync(appConfig.UrlViewSchema);

            var remoteViewUrls = await GetRemoteUrlsAsync(appConfig.Urls, true);

            foreach (var url in remoteViewUrls.Urls)
            {
                await RemoteRazorLocationStore.LoadRemoteDataAsync(url, urlViewSchema);
            }
        }
        public async Task Invoke(CancellationToken cancellationToken)
        {
            var key           = "remote-static-esternal-spa";
            var currentHealth = await HealthCheckStore.GetHealthAsync(key);

            if (currentHealth == null)
            {
                currentHealth = new HealthRecord()
                {
                    Healty = false,
                    State  = null
                };
                await HealthCheckStore.SetHealthAsync(key, currentHealth);
            }

            var appConfig = new ExternalUrlsOptions();

            _config.GetSection("externalSPAConfigs").Bind(appConfig);

            var urlViewSchema = await RemoteJsonFetch.GetRemoteJsonContentAsync(appConfig.UrlViewSchema);

            var remoteViewUrls = await GetRemoteUrlsAsync(appConfig.Urls, true);

            var loaded = false;

            foreach (var url in remoteViewUrls.Urls)
            {
                loaded = await RemoteExternalSPAStore.LoadRemoteDataAsync(url);

                if (!loaded)
                {
                    logger.Fatal("Failed to load:{0}", url);
                    break;
                }
            }
            if (loaded && !currentHealth.Healty)
            {
                // once loaded we are good
                currentHealth = new HealthRecord()
                {
                    Healty = true,
                    State  = null
                };
                await HealthCheckStore.SetHealthAsync(key, currentHealth);
            }
        }
        public string Schedule => "*/1 * * * *";  // every 1 minute
        private async Task <RemoteUrls> GetRemoteUrlsAsync(string url, bool validateSchema = false)
        {
            try
            {
                var schemaUrl = url.Replace(".json", ".schema.json");
                var schema    = await RemoteJsonFetch.GetRemoteJsonContentAsync(schemaUrl);

                string content = await RemoteJsonFetch.GetRemoteJsonContentAsync(url, schema);

                RemoteUrls remoteUrls;
                remoteUrls = ExternUrlsOptionConvert.FromJson(content);

                return(remoteUrls);
            }
            catch (Exception e)
            {
                logger.Fatal("Exception Caught:{0}", e.Message);
            }
            return(null);
        }