ValidateObjectStructure() public method

Validates the object structure.
public ValidateObjectStructure ( ) : void
return void
Example #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);
            }
        }
Example #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 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 ValidateFolderStructureIsFineIfNoObjectIsStored([Values(true, false)]bool withValidation) {
     var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation);
     storage.ValidateObjectStructure();
 }
        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 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());
        }