Meta data storage.
Inheritance: IMetaDataStorage
Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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 ValidateFolderStructureThrowsExceptionIfRootObjectIsMissingButOtherObjectsAreStored() {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), false);
            var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token");
            storage.SaveMappedObject(child1Folder);

            Assert.Throws<InvalidDataException>(() => storage.ValidateObjectStructure());
        }
 public void GetObjectByIdWithNotExistingIdMustReturnNull([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
     Assert.That(storage.GetObjectByRemoteId("DOESNOTEXIST"), Is.Null);
 }
        public void SaveFileObjectAndGetObjectReturnsEqualObject([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
            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([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
            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 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 ValidateFolderStructureIsFineOnCleanFolderStructure([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
            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 GetObjectTreeReturnsNullIfNoEntryExists([Values(true, false)]bool withValidation) {
     IMetaDataStorage storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
     Assert.That(storage.GetObjectTree(), Is.Null);
 }
 public void GetRemotePathThrowsExceptionOnNonExistingIdInObject([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
     Assert.Throws<ArgumentException>(() => storage.GetRemotePath(Mock.Of<IMappedObject>()));
 }
        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 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 GetRemotePathThrowsExceptionOnNullArgument([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
     Assert.Throws<ArgumentNullException>(() => storage.GetRemotePath(null));
 }
        public void GetLocalPath([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 = "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 RemoveObjectDoesNotTouchParents([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(child);

            Assert.That(storage.GetObjectByRemoteId(remoteId), Is.EqualTo(obj));
            Assert.That(storage.GetObjectByRemoteId(childId), Is.Null);
            Assert.That(storage.GetObjectByRemoteId(subChildId), Is.Null);
        }
        public void RemoveObjectTest([Values(true, false)]bool withValidation) {
            string remoteId = "remoteId";
            var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
            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 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([Values(true, false)]bool withValidation) {
            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, withValidation);
            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 ValidateFolderStructureIsFineIfNoObjectIsStored([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
     storage.ValidateObjectStructure();
 }
        public void SaveRenamedMappedObjectOverridesExistingEntry([Values(true, false)]bool withValidation) {
            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, withValidation);
            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 GetObjectByGuidReturnsSavedObject([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
            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 ToLinePrintReturnsEmptyStringOnEmptyDB([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
     Assert.That(storage.ToFindString(), Is.EqualTo(string.Empty));
 }
        public void GetObjectTreeReturnsOneItemWithEmptyChildrenList([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
            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 ToLinePrintReturnsOneLineIfOnlyRootFolderIsInDB([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
            var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token");
            storage.SaveMappedObject(rootFolder);

            Assert.That(storage.ToFindString(), Is.EqualTo("name" + Environment.NewLine));
        }
 public void ThrowOnDublicateGuid([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
     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([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
            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 GetTokenFromEmptyStorageMustBeNull([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);
     Assert.That(storage.ChangeLogToken, Is.Null);
 }
        public void ToLinePrintReturnsOneLinePerNotFittingEntry() {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), false);
            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 void ToLinePrintReturnsOneLinePerEntry([Values(true, false)]bool withValidation) {
            var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
            var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token");
            var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token");
            var child2Folder = new MappedObject("sub2", "subId2", MappedObjectType.Folder, "rootId", "token");
            var child3Folder = new MappedObject("sub3", "subId3", MappedObjectType.Folder, "rootId", "token");
            var subChildFile = new MappedObject("file", "subId4", MappedObjectType.File, "subId1", "token");
            storage.SaveMappedObject(rootFolder);
            storage.SaveMappedObject(child1Folder);
            storage.SaveMappedObject(child2Folder);
            storage.SaveMappedObject(child3Folder);
            storage.SaveMappedObject(subChildFile);

            string src = storage.ToFindString();

            int count = src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(Environment.NewLine));
            Assert.That(count, Is.EqualTo(5), string.Format("Newlines Counting {0}:{2} {1}", count, src, Environment.NewLine));
        }
 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);
 }