public void Validate(HmdBlockID root, HmdProperties hmdProperties) { debugOutput = HmdDebug.DebugOutput; if (root == null) { throw new ArgumentNullException("root"); } if (hmdProperties == null) { throw new ArgumentNullException("hmdProperties"); } hmdProperties.ResolveChildParentReferences(); debugOutput.WriteLine("[Validating HMD file...]"); hmdProperties.PrintEnums(debugOutput); currentBlock = null; blockStack = new Stack <HmdBlockValidator>(); ValidateBlockID(root, hmdProperties.root, hmdProperties); debugOutput.WriteLine("[Done validating HMD file]"); }
private void ValidateBlockID(HmdBlockID blockID, HmdBlockIDProperties blockIDProperties, HmdProperties hmdProperties) { // // Check that the current parent is valid // if (currentBlock == null) { debugOutput.Write(blockStack.Count, "Checking that \"{0}\" is the root...", blockID.idOriginalCase); if (!blockIDProperties.IsRoot) { throw new FormatException(String.Format("Block ID \"{0}\" was expected to be the root, but it wasn't?", blockIDProperties.idOriginalCase)); } debugOutput.WriteLine("Pass."); } else { debugOutput.Write(blockStack.Count, "Checking that \"{0}\" has \"{1}\" as a valid parent...", blockID.idOriginalCase, currentBlock.blockIDProperties.idOriginalCase); if (!blockIDProperties.IsValidParent(currentBlock.blockIDProperties)) { throw new FormatException(String.Format("Block ID \"{0}\" appeared in Block \"{1}\", but this is not allowed with the current properties", blockIDProperties.idOriginalCase, currentBlock.blockIDProperties.idOriginalCase)); } debugOutput.WriteLine("Pass."); // Add ID to current block validator currentBlock.NewChild(blockIDProperties); } // // Verify the Children of the Block ID // debugOutput.WriteLine(blockStack.Count, "{"); blockStack.Push(currentBlock); currentBlock = new HmdBlockValidator(blockIDProperties); blockID.Iterate(hmdProperties, ValidateValueID, ValidateBlockID); // Validate Children debugOutput.Write(blockStack.Count, "Checking counts of all children for \"{0}\"...", blockID.idOriginalCase); currentBlock.ValidateChildren(hmdProperties); debugOutput.WriteLine("Pass."); currentBlock = blockStack.Pop(); debugOutput.WriteLine(blockStack.Count, "}} (end of \"{0}\")", blockID.idOriginalCase); }