public override void AwakeFromNib() { base.AwakeFromNib(); var config = ConfigManager.CurrentConfig; this.folderSelection.RemoveAllItems(); this.output.Editable = false; this.RunButton.Activated += (object sender, EventArgs e) => { var folder = config.Folders.Find(f => f.DisplayName == this.folderSelection.SelectedItem.Title); using (var dbEngine = new DBreezeEngine(folder.GetDatabasePath())) { var storage = new MetaDataStorage(dbEngine, new PathMatcher(folder.LocalPath, folder.RemotePath), false); try { storage.ValidateObjectStructure(); this.output.StringValue = string.Format("{0}: DB structure of {1} is fine", DateTime.Now, folder.GetDatabasePath()); } catch (Exception ex) { this.output.StringValue = ex.ToString(); } } }; this.DumpTree.Activated += (object sender, EventArgs e) => { this.output.StringValue = string.Empty; var folder = config.Folders.Find(f => f.DisplayName == this.folderSelection.SelectedItem.Title); using (var dbEngine = new DBreezeEngine(folder.GetDatabasePath())) { var storage = new MetaDataStorage(dbEngine, new PathMatcher(folder.LocalPath, folder.RemotePath), false); try { var ignoreStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), storage); var session = SessionFactory.NewInstance().CreateSession(folder, "DSS-DIAGNOSE-TOOL"); var remoteFolder = session.GetObjectByPath(folder.RemotePath) as IFolder; var filterAggregator = new FilterAggregator( new IgnoredFileNamesFilter(), new IgnoredFolderNameFilter(), new InvalidFolderNameFilter(), new IgnoredFoldersFilter()); var treeBuilder = new DescendantsTreeBuilder( storage, remoteFolder, new DirectoryInfoWrapper(new DirectoryInfo(folder.LocalPath)), filterAggregator, ignoreStorage); var trees = treeBuilder.BuildTrees(); var suffix = string.Format("{0}-{1}", folder.DisplayName.Replace(Path.DirectorySeparatorChar, '_'), Guid.NewGuid().ToString()); var localTree = Path.Combine(Path.GetTempPath(), string.Format("LocalTree-{0}.dot", suffix)); var remoteTree = Path.Combine(Path.GetTempPath(), string.Format("StoredTree-{0}.dot", suffix)); var storedTree = Path.Combine(Path.GetTempPath(), string.Format("RemoteTree-{0}.dot", suffix)); trees.LocalTree.ToDotFile(localTree); trees.StoredTree.ToDotFile(remoteTree); trees.RemoteTree.ToDotFile(storedTree); this.output.StringValue = string.Format("Written to:\n{0}\n{1}\n{2}", localTree, remoteTree, storedTree); } catch (Exception ex) { this.output.StringValue = ex.ToString(); } } }; foreach (var folder in config.Folders) { this.folderSelection.AddItem(folder.DisplayName); } }
public void SaveRenamedMappedObjectOverridesExistingEntry() { string id = "id"; string oldName = "my"; string newName = "newMy"; string path = Path.GetTempPath(); string parentId = "ParentId"; string oldToken = "oldToken"; string newToken = "newToken"; var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher); var rootFolder = new MappedObject("/", parentId, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); var folder = new MappedObject(oldName, id, MappedObjectType.Folder, parentId, oldToken); storage.SaveMappedObject(folder); var savedObject = storage.GetObjectByRemoteId(id); savedObject.Name = newName; savedObject.LastChangeToken = newToken; storage.SaveMappedObject(savedObject); Assert.That(storage.GetObjectByLocalPath(Mock.Of <IDirectoryInfo>(d => d.FullName == Path.Combine(path, oldName))), Is.Null); Assert.That(storage.GetObjectByLocalPath(Mock.Of <IDirectoryInfo>(d => d.FullName == Path.Combine(path, newName))), Is.EqualTo(savedObject)); }
public void SetAndGetContentChangeToken([Values(true, false)] bool withValidation) { string token = "token"; var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); storage.ChangeLogToken = token; Assert.That(storage.ChangeLogToken, Is.EqualTo(token)); }
public void SetAndGetContentChangeToken() { string token = "token"; var storage = new MetaDataStorage(this.engine, this.matcher); storage.ChangeLogToken = token; Assert.That(storage.ChangeLogToken, Is.EqualTo(token)); }
public void GetChildrenReturnsEmptyListIfNoChildrenAreAvailable() { var storage = new MetaDataStorage(this.engine, this.matcher); var folder = new MappedObject("name", "id", MappedObjectType.Folder, null, null); storage.SaveMappedObject(folder); Assert.That(storage.GetChildren(folder).Count == 0); }
public void ToLinePrintReturnsOneLineIfOnlyRootFolderIsInDB() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); Assert.That(storage.ToFindString(), Is.EqualTo("name" + Environment.NewLine)); }
public void ValidateFolderStructureThrowsExceptionIfRootObjectIsMissingButOtherObjectsAreStored() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); storage.SaveMappedObject(child1Folder); storage.ValidateObjectStructure(); }
public void StoreDateOnStoringMappedObject([Values(true, false)] bool withValidation) { var underTest = new MetaDataStorage(this.engine, this.matcher, withValidation); IMappedObject obj = new MappedObject("obj", "remoteId", MappedObjectType.File, null, null); Assert.That(obj.LastTimeStoredInStorage, Is.Null); underTest.SaveMappedObject(obj); obj = underTest.GetObjectByRemoteId("remoteId"); Assert.That(obj.LastTimeStoredInStorage, Is.EqualTo(DateTime.UtcNow).Within(1).Seconds); }
public void ValidateFolderStructureThrowsExceptionIfParentObjectIsMissing() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "WRONGID", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); storage.ValidateObjectStructure(); }
public void RemoveObjectTest() { string remoteId = "remoteId"; var storage = new MetaDataStorage(this.engine, this.matcher); var obj = new MappedObject("name", remoteId, MappedObjectType.Folder, null, null); storage.SaveMappedObject(obj); storage.RemoveObject(obj); Assert.That(storage.GetObjectByRemoteId(remoteId), Is.Null); }
public void GetObjectTreeReturnsOneItemWithEmptyChildrenList() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); var tree = storage.GetObjectTree(); Assert.That(tree.Item, Is.EqualTo(rootFolder)); Assert.That(tree.Children, Is.Empty); }
public void GetObjectByPathThrowsExceptionIfLocalPathDoesNotMatchToSyncPath() { var matcher = new Mock <IPathMatcher>(); string localpath = Path.GetTempPath(); var folder = Mock.Of <IDirectoryInfo>(f => f.FullName == localpath); matcher.Setup(m => m.CanCreateRemotePath(It.Is <string>(f => f == localpath))).Returns(false); var storage = new MetaDataStorage(this.engine, matcher.Object); storage.GetObjectByLocalPath(folder); }
public void GetObjectByPathThrowsExceptionIfLocalPathDoesNotMatchToSyncPath([Values(true, false)] bool withValidation) { var matcher = new Mock <IPathMatcher>(); string localpath = Path.GetTempPath(); var folder = Mock.Of <IDirectoryInfo>( f => f.FullName == localpath); matcher.Setup(m => m.CanCreateRemotePath(It.Is <string>(f => f == localpath))).Returns(false); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); Assert.Throws <ArgumentException>(() => storage.GetObjectByLocalPath(folder)); }
public void ValidateFolderStructureIsFineOnCleanFolderStructure() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); var child2File = new MappedObject("sub2", "subId2", MappedObjectType.File, "subId1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); storage.SaveMappedObject(child2File); storage.ValidateObjectStructure(); }
public void GetObjectByGuidReturnsSavedObject() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var uuid = Guid.NewGuid(); var file = new MappedObject("name", "rootId", MappedObjectType.File, null, "token") { Guid = uuid }; storage.SaveMappedObject(file); Assert.That(storage.GetObjectByGuid(uuid), Is.EqualTo(file)); }
public void ValidateFolderStructureThrowsExceptionIfFileParentIdIsFileObject() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>(), false); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1File = new MappedObject("sub1", "subId1", MappedObjectType.File, "rootId", "token"); var child2File = new MappedObject("sub2", "subId2", MappedObjectType.File, "sub1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1File); storage.SaveMappedObject(child2File); Assert.Throws <InvalidDataException>(() => storage.ValidateObjectStructure()); }
public void FindRootFolder() { string id = "id"; string path = Path.GetTempPath(); var fsInfo = new DirectoryInfoWrapper(new DirectoryInfo(path)); var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher); var rootFolder = new MappedObject("/", id, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null, "Not findable by ID"); Assert.That(storage.GetObjectByLocalPath(fsInfo), Is.Not.Null, "Not findable by path"); }
public void GetObjectByPathWithNotExistingEntryMustReturnNull([Values(true, false)] bool withValidation) { var matcher = new Mock <IPathMatcher>(); string testfilename = "test"; string testpath = Path.Combine(Path.GetTempPath(), testfilename); matcher.Setup(m => m.CanCreateRemotePath(It.Is <string>(f => f == testpath))).Returns(true); matcher.Setup(m => m.GetRelativeLocalPath(It.Is <string>(f => f == testpath))).Returns(testfilename); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); var path = Mock.Of <IFileSystemInfo>(p => p.FullName == testpath); Assert.That(storage.GetObjectByLocalPath(path), Is.Null); }
public void GetLocalPathOfNonExistingEntryReturnsNull([Values(true, false)] bool withValidation) { var matcher = new Mock <IPathMatcher>(); matcher.Setup(m => m.LocalTargetRootPath).Returns(Path.GetTempPath()); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); string id = "nonExistingId"; var rootFolder = new MappedObject("name", "otherId", MappedObjectType.Folder, null, null); var otherFolder = new MappedObject("name", id, MappedObjectType.Folder, "otherId", null); storage.SaveMappedObject(rootFolder); Assert.That(storage.GetLocalPath(otherFolder), Is.Null); }
public void GetRemotePath() { var matcher = new Mock <IPathMatcher>(); matcher.Setup(m => m.RemoteTargetRootPath).Returns("/"); var storage = new MetaDataStorage(this.engine, matcher.Object); var remoteFolder = new MappedObject("remoteFolder", "remoteId", MappedObjectType.Folder, null, null); storage.SaveMappedObject(remoteFolder); string remotePath = storage.GetRemotePath(remoteFolder); Assert.That(remotePath, Is.EqualTo("/remoteFolder")); }
public void ThrowOnDublicateGuid() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1 = new MappedObject("sub1", "subId1", MappedObjectType.File, "rootId", "token"); child1.Guid = Guid.NewGuid(); var child2 = new MappedObject("sub2", "subId2", MappedObjectType.File, "rootId", "token"); child2.Guid = child1.Guid; storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1); Assert.Throws <DublicateGuidException>(() => storage.SaveMappedObject(child2)); }
public void SaveFolderObjectAndGetObjectReturnEqualObject() { var storage = new MetaDataStorage(this.engine, this.matcher); string remoteId = "remoteId"; var folder = new MappedObject("folder", remoteId, MappedObjectType.Folder, null, null) { Description = "desc", Guid = Guid.NewGuid(), }; storage.SaveMappedObject(folder); var obj = storage.GetObjectByRemoteId(remoteId); Assert.That(obj.Equals(folder)); }
public void GetLocalPath() { var matcher = new Mock <IPathMatcher>(); matcher.Setup(m => m.LocalTargetRootPath).Returns(Path.GetTempPath()); var storage = new MetaDataStorage(this.engine, matcher.Object); string id = "remoteId"; var rootFolder = new MappedObject("name", id, MappedObjectType.Folder, null, null); storage.SaveMappedObject(rootFolder); string path = storage.GetLocalPath(rootFolder); Assert.That(path, Is.EqualTo(Path.Combine(Path.GetTempPath(), "name"))); }
public void ToLinePrintReturnsOneLinePerNotFittingEntry() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "WRONGID", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); string src = storage.ToFindString(); int count = src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(Environment.NewLine)); Assert.That(count, Is.EqualTo(2), string.Format("Newlines Counting {0}:{2} {1}", count, src, Environment.NewLine)); }
public static void Main(string[] args) { var config = ConfigManager.CurrentConfig; foreach (var repoInfo in config.Folders) { using (var dbEngine = new DBreezeEngine(repoInfo.GetDatabasePath())) { var storage = new MetaDataStorage(dbEngine, new PathMatcher(repoInfo.LocalPath, repoInfo.RemotePath), false); Console.WriteLine(string.Format("Checking {0} and DB Path \"{1}\"", repoInfo.DisplayName, repoInfo.GetDatabasePath())); storage.ValidateObjectStructure(); } } foreach (var repoInfo in config.Folders) { try { using (var dbEngine = new DBreezeEngine(repoInfo.GetDatabasePath())) { var storage = new MetaDataStorage(dbEngine, new PathMatcher(repoInfo.LocalPath, repoInfo.RemotePath), false); var ignoreStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), storage); var session = SessionFactory.NewInstance().CreateSession(repoInfo, "DSS-DIAGNOSE-TOOL"); var remoteFolder = session.GetObjectByPath(repoInfo.RemotePath) as IFolder; var filterAggregator = new FilterAggregator( new IgnoredFileNamesFilter(), new IgnoredFolderNameFilter(), new InvalidFolderNameFilter(), new IgnoredFoldersFilter()); var treeBuilder = new DescendantsTreeBuilder( storage, remoteFolder, new DirectoryInfoWrapper(new DirectoryInfo(repoInfo.LocalPath)), filterAggregator, ignoreStorage); Console.WriteLine(string.Format("Creating local, stored and remote tree in \"{0}\"", Path.GetTempPath())); var trees = treeBuilder.BuildTrees(); var suffix = string.Format("{0}-{1}", repoInfo.DisplayName.Replace(Path.DirectorySeparatorChar, '_'), Guid.NewGuid().ToString()); var localTree = Path.Combine(Path.GetTempPath(), string.Format("LocalTree-{0}.dot", suffix)); var remoteTree = Path.Combine(Path.GetTempPath(), string.Format("StoredTree-{0}.dot", suffix)); var storedTree = Path.Combine(Path.GetTempPath(), string.Format("RemoteTree-{0}.dot", suffix)); trees.LocalTree.ToDotFile(localTree); trees.StoredTree.ToDotFile(remoteTree); trees.RemoteTree.ToDotFile(storedTree); Console.WriteLine(string.Format("Written to:\n{0}\n{1}\n{2}", localTree, remoteTree, storedTree)); } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } }
public void GetRemotePathWithCorrectSlashes([Values(true, false)] bool withValidation) { var matcher = new Mock <IPathMatcher>(); matcher.Setup(m => m.RemoteTargetRootPath).Returns("/"); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); var remoteRootFolder = new MappedObject("/", "rootId", MappedObjectType.Folder, null, null); var remoteFolder = new MappedObject("remoteFolder", "remoteId", MappedObjectType.Folder, "rootId", null); storage.SaveMappedObject(remoteRootFolder); storage.SaveMappedObject(remoteFolder); string remotePath = storage.GetRemotePath(remoteFolder); Assert.That(remotePath, Is.EqualTo("/remoteFolder")); }
public void SaveFileObjectAndGetObjectReturnsEqualObject() { var storage = new MetaDataStorage(this.engine, this.matcher); string remoteId = "remoteId"; var file = new MappedObject("file", remoteId, MappedObjectType.File, null, null) { Description = "desc", Guid = Guid.NewGuid(), LastChecksum = new byte[20] }; storage.SaveMappedObject(file); var obj = storage.GetObjectByRemoteId(remoteId); Assert.That(obj.LastChecksum, Is.Not.Null); Assert.That(obj.Equals(file)); }
public void GetObjectTreeReturnsTreeEqualToFolderStructure() { var storage = new MetaDataStorage(this.engine, Mock.Of <IPathMatcher>()); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); var child2File = new MappedObject("sub2", "subId2", MappedObjectType.File, "subId1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); storage.SaveMappedObject(child2File); var tree = storage.GetObjectTree(); Assert.That(tree.Item, Is.EqualTo(rootFolder)); Assert.That(tree.Children.Count, Is.EqualTo(1)); Assert.That(tree.Children[0].Item, Is.EqualTo(child1Folder)); Assert.That(tree.Children[0].Children.Count, Is.EqualTo(1)); Assert.That(tree.Children[0].Children[0].Item, Is.EqualTo(child2File)); }
public void RemoveObjectRemovesChildrenAsWell([Values(true, false)] bool withValidation) { string remoteId = "remoteId"; string childId = "childId"; string subChildId = "subchildId"; var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); var obj = new MappedObject("name", remoteId, MappedObjectType.Folder, null, null); var child = new MappedObject("child", childId, MappedObjectType.Folder, remoteId, null); var subchild = new MappedObject("subchild", subChildId, MappedObjectType.File, childId, null); storage.SaveMappedObject(obj); storage.SaveMappedObject(child); storage.SaveMappedObject(subchild); storage.RemoveObject(obj); Assert.That(storage.GetObjectByRemoteId(remoteId), Is.Null); Assert.That(storage.GetObjectByRemoteId(childId), Is.Null); Assert.That(storage.GetObjectByRemoteId(subChildId), Is.Null); }
public void RemoveObjectDoesNotTouchParents() { string remoteId = "remoteId"; string childId = "childId"; string subChildId = "subchildId"; var storage = new MetaDataStorage(this.engine, this.matcher); var obj = new MappedObject("name", remoteId, MappedObjectType.Folder, null, null); var child = new MappedObject("child", childId, MappedObjectType.Folder, remoteId, null); var subchild = new MappedObject("subchild", subChildId, MappedObjectType.File, childId, null); storage.SaveMappedObject(obj); storage.SaveMappedObject(child); storage.SaveMappedObject(subchild); storage.RemoveObject(child); Assert.That(storage.GetObjectByRemoteId(remoteId), Is.EqualTo(obj)); Assert.That(storage.GetObjectByRemoteId(childId), Is.Null); Assert.That(storage.GetObjectByRemoteId(subChildId), Is.Null); }