/// <summary> /// Recursively check sanity of the FileIndex and its children. Return true if a schema is valid. /// </summary> /// <returns>Return true if a schema is valid.</returns> public ResultReport Validate() { Queue <FileIndex> q = new Queue <FileIndex>(); q.Enqueue(this); do { FileIndex fi = q.Dequeue(); // Check if properties are not null if (fi.Name == null) { return(new ResultReport(false, "File index is corrupted")); } // Check filename / foldername if (!FileHelper.CheckWin32Path(Name, false, false)) { return(new ResultReport(false, "File index is corrupted")); } // Check per kind switch (fi.Kind) { case IndexEntryKind.Folder: { if (Children == null) { return(new ResultReport(false, $"Children of folder [{Name}] is corrupted")); } foreach (FileIndex sub in Children) { q.Enqueue(sub); } } break; case IndexEntryKind.Script: { // Check null if (FileMetadata == null) { return(new ResultReport(false, $"Metadata of script [{Name}] is corrupted")); } if (ScriptInfo == null) { return(new ResultReport(false, $"Information of script [{Name}] is corrupted")); } // Check file metadata ResultReport report = FileMetadata.Validate(); if (!report.Success) { return(report); } // Check script information report = ScriptInfo.Validate(); if (!report.Success) { return(report); } } break; case IndexEntryKind.NonScriptFile: { if (FileMetadata == null) { return(new ResultReport(false, $"Metadata of script {Name} is corrupted")); } // Check file metadata ResultReport report = FileMetadata.Validate(); if (!report.Success) { return(report); } } break; } }while (0 < q.Count); return(new ResultReport(true)); }