public static StubItem FromDirectory(DirectoryInfo dir) { var stubItem = new StubItem(); stubItem.FullPath = dir.FullName; stubItem.IsFile = false; stubItem.Name = dir.Name; stubItem.Timestamp = DateTime.Now; return(stubItem); }
public void AddStubItem(StubItem item) { if (item == null) { return; } if (Items.Exists(i => i.FullPath == item.FullPath)) { return; } Items.Add(item); }
public static StubItem FromFile(FileInfo file) { var stubItem = new StubItem(); stubItem.FullPath = file.FullName; stubItem.IsFile = true; stubItem.Name = file.Name; stubItem.Timestamp = DateTime.Now; using (var stream = file.OpenRead()) { using (HashAlgorithm hash = HashAlgorithm.Create()) { stubItem.Hash = hash.ComputeHash(stream); } } return(stubItem); }
public Task GenerateStubDataInternal(DirectoryInfo baseDir, DirectoryInfo localDir) { return(Task.Run(() => { var basefiles = baseDir.GetFiles(); var localfiles = localDir.GetFiles(); foreach (var lf in localfiles) { var stub = StubItem.FromFile(lf); // exclude if (basefiles.All(i => i.Name != lf.Name)) { stub.IsIgnored = true; } // have StubObj.AddStubItem(stub); } var baseDirectories = baseDir.GetDirectories(); var localDirectories = localDir.GetDirectories(); var tasks = new List <Task>(); foreach (var cd in localDirectories) { var stub = StubItem.FromDirectory(cd); var rd = baseDirectories.FirstOrDefault(i => i.Name == cd.Name); if (rd == null) { stub.IsIgnored = true; continue; } StubObj.AddStubItem(stub); var task = GenerateStubDataInternal(rd, cd); tasks.Add(task); } Task.WaitAll(tasks.ToArray()); })); }