public IssueCollection FetchAllIssues() { var collection = new IssueCollection(); int batchSize = 100; int start = 0; List <string> fields = new List <string>() { "id", "updated" }; DateTime lastUpdated = DateTime.MinValue; var cache = QueryCache.LoadFromTemp(this.Filter.ToString()); if (false && cache != null) { if (cache.Filter.ToUpperInvariant() == this.Filter.ToString().ToUpperInvariant()) { foreach (LightIssue issue in cache.Issues) { collection.Add(new Issue() { id = issue.id, updated = issue.updated }); } this.UpdatedAfter = cache.LastUpdated; cache.LastUpdated = DateTime.Now.Date; } } var received = FetchIssues(batchSize, start); collection.AddRange(received); while (received.Count == batchSize) { start += received.Count; received = FetchIssues(batchSize, start); collection.AddRange(received); } var issues_with_history = new IssueCollection(); Parallel.ForEach(collection, (issue) => { var cached_issue = Issue.LoadFromTemp(issue.id); if (false && cached_issue != null && (cached_issue.updated <= issue.updated || issue.updated == DateTime.MinValue)) { // Console.WriteLine("{0} loaded from cache", issue.id); issues_with_history.Add(cached_issue); return; } issues_with_history.Add(Issue.GetHistory(issue)); System.Diagnostics.Trace.WriteLine(string.Format("Loading history for issue {0}", issue.id)); }); cache.Issues.Clear(); cache.AddIssues(issues_with_history); cache.SaveToTemp(); return(issues_with_history); }
public static QueryCache LoadFromTemp(string Filter) { string filename = Path.Combine(GetTempDir(), TempFileName(Filter)); if (File.Exists(filename)) { return(Load(filename)); } var result = new QueryCache(); result.Filter = Filter; return(result); }
public static QueryCache Load(string path) { try { IFormatter formatter = new BinaryFormatter(); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { QueryCache obj = (QueryCache)formatter.Deserialize(stream); return(obj); } } catch { System.IO.File.Delete(path); return(null); } }