public async Task<MainViewModel> ResolveAsync(string sha1) { if (sha1 != null && sha1.Contains('.')) { throw new ArgumentOutOfRangeException(nameof(sha1)); } string branch = sha1 ?? this.options.DefaultBranch; MainViewModel model; if (memoryCache.TryGetValue(branch, out model)) { return model; } Uri path = new Uri(new Uri(this.options.DataUri), branch + ".json"); HttpClient httpClient = new HttpClient(); string json = await httpClient.GetStringAsync(path); var mainViewModel = new MainViewModel { Diagnostics = JsonConvert.DeserializeObject<IEnumerable<StyleCopDiagnostic>>(json), CommitId = sha1 }; return memoryCache.Set<MainViewModel>(branch, mainViewModel, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1) }); }
public Task<MainViewModel> ResolveAsync(string sha1) { if (sha1 != null && sha1.Contains('.')) { throw new ArgumentOutOfRangeException(nameof(sha1)); } string branch = sha1 ?? this.options.DefaultBranch; MainViewModel model; if (memoryCache.TryGetValue(branch, out model)) { return Task.FromResult(model); } string path = Path.Combine(this.options.DataDirectory, branch + ".json"); string json = System.IO.File.ReadAllText(hostingEnvironment.MapPath(path)); var mainViewModel = new MainViewModel { Diagnostics = JsonConvert.DeserializeObject<IEnumerable<StyleCopDiagnostic>>(json), CommitId = sha1 }; return Task.FromResult(memoryCache.Set<MainViewModel>(branch, mainViewModel, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1) })); }