WinDoc.IndexUpdateManager.CheckIndexIsFresh C# (CSharp) Method

CheckIndexIsFresh() public method

public CheckIndexIsFresh ( ) : Task
return Task
		public Task<bool> CheckIndexIsFresh ()
		{
			return Task.Factory.StartNew (() => {
				var path = Path.Combine (baseUserDir, sumFile);
				
				// Two cases can trigger index creation/re-creation:
				//   1- there is no search_index folder or no monodoc.index file (i.e. GetIndex or GetSearchIndex returns null)
				//   2- one of the doc source we use is stale
				if (Program.Root.GetIndex () == null || Program.Root.GetSearchIndex () == null) {
					// force stale state
					md5sums = new Dictionary<string, string> ();
				} else {
					if (File.Exists (path)) {
						try {
							md5sums = DeserializeDictionary (path);
						} catch {}
					}
					if (md5sums == null)
						md5sums = new Dictionary<string, string> ();
				}
				
				bool isFresh = true;
				HashAlgorithm hasher = MD5.Create ();
				
				foreach (var source in sourceFiles) {
					var hash = StringHash (hasher, File.OpenRead (source));
					string originalHash;
					if (md5sums.TryGetValue (source, out originalHash))
						isFresh &= originalHash.Equals (hash, StringComparison.OrdinalIgnoreCase);
					else
						isFresh = false;
					md5sums[source] = hash;
				}
				
				Console.WriteLine ("We have a {0} fresh index", isFresh);
				
				return IsFresh = isFresh;
			});
		}