static void Main(string[] args) { Console.WriteLine("This is Test Appliacation to test faults.xml"); try { FaultXMLNavigator FaultXMLNav = new FaultXMLNavigator(); //string FaultXMLFilePath = @"E:\Fall2003\Holodeck xml files\faults.xml"; string FaultXMLFilePath = @"E:\Fall2003\Holodeck xml files\holo 2.5\faultsnew.xml"; FaultXMLNav.ValidateXmlDocument(FaultXMLFilePath); FaultXMLNav.parseXmlDocument(FaultXMLFilePath); //modify fault Fault modifyThisFault = FaultXMLNav.GetFaultByName("PagingFileTooSmall"); if(modifyThisFault != null) { modifyThisFault.ReturnValue = "test_0"; modifyThisFault.ErrorCode = "Test_1454"; FaultFunction function = new FaultFunction(); function.Name = "GlobalReAlloc"; function.Allocation = "test_GT"; function.PassThrough = "TEST_not_there"; FaultFunctionMatchParams matchparams = new FaultFunctionMatchParams(); FaultFunctionMatchParams matchparam = new FaultFunctionMatchParams(); matchparam.Name= "Flags"; matchparam.TestOperator = "test_not contains"; matchparam.TestValue = "Test_128"; matchparam.CompareAsType = "test_4"; matchparam.ID = "test_2"; matchparams.MatchParam.Insert(0,matchparam); function.MatchParams.Insert(0,matchparams); modifyThisFault.Function[0] = function; FaultXMLNav.UpdateFault("PagingFileTooSmall",modifyThisFault); } FaultXMLNav.saveFaultXmlDocument(FaultXMLNav,"fault-save.xml","",true); } catch(FileNotFoundException f) { Console.WriteLine(" File Not Found Exception caught.... : " + f.Message); Console.WriteLine("Details: " + f.StackTrace); } catch(SystemException e) { Console.WriteLine("Caught System Exception .... : " + e.Message); Console.WriteLine("Details: " + e.StackTrace); } }
static void Main(string[] args) { Console.WriteLine("This is Test Appliacation to test faults.xml"); try { FaultXMLNavigator FaultXMLNav = new FaultXMLNavigator(); //string FaultXMLFilePath = @"E:\Fall2003\Holodeck xml files\faults.xml"; string FaultXMLFilePath = @"E:\Fall2003\Holodeck xml files\holo 2.5\faultsnew.xml"; FaultXMLNav.ValidateXmlDocument(FaultXMLFilePath); FaultXMLNav.parseXmlDocument(FaultXMLFilePath); //modify fault Fault modifyThisFault = FaultXMLNav.GetFaultByName("PagingFileTooSmall"); if (modifyThisFault != null) { modifyThisFault.ReturnValue = "test_0"; modifyThisFault.ErrorCode = "Test_1454"; FaultFunction function = new FaultFunction(); function.Name = "GlobalReAlloc"; function.Allocation = "test_GT"; function.PassThrough = "TEST_not_there"; FaultFunctionMatchParams matchparams = new FaultFunctionMatchParams(); FaultFunctionMatchParams matchparam = new FaultFunctionMatchParams(); matchparam.Name = "Flags"; matchparam.TestOperator = "test_not contains"; matchparam.TestValue = "Test_128"; matchparam.CompareAsType = "test_4"; matchparam.ID = "test_2"; matchparams.MatchParam.Insert(0, matchparam); function.MatchParams.Insert(0, matchparams); modifyThisFault.Function[0] = function; FaultXMLNav.UpdateFault("PagingFileTooSmall", modifyThisFault); } FaultXMLNav.saveFaultXmlDocument(FaultXMLNav, "fault-save.xml", "", true); } catch (FileNotFoundException f) { Console.WriteLine(" File Not Found Exception caught.... : " + f.Message); Console.WriteLine("Details: " + f.StackTrace); } catch (SystemException e) { Console.WriteLine("Caught System Exception .... : " + e.Message); Console.WriteLine("Details: " + e.StackTrace); } }
//************************************************************************* // Method: saveFaultXmlDocument // Description: recreating fault.xml document // // Parameters: // faultXMLNavigator // // Return Value: None // // Output: "Faults.xml" file will be created in this application directory //************************************************************************* public void saveFaultXmlDocument(FaultXMLNavigator faultXMLNavigator, string fileNameToSaveAs, string fileEncoding, bool isValidationRequired) { XmlTextWriter saveFaultXml = null; Console.WriteLine(fileNameToSaveAs); switch (fileEncoding.ToUpper()) { case "UTF-8": case "": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs, System.Text.UTF8Encoding.UTF8); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw("<?xml version= \"1.0\"?>"); break; } case "UTF-7": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs, System.Text.UTF7Encoding.UTF7); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw("<?xml version= \"1.0\" encoding=\"UTF-7\"?>"); break; } case "ASCII": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs, System.Text.ASCIIEncoding.ASCII); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw("<?xml version= \"1.0\" encoding=\"ASCII\"?>"); break; } case "Unicode": { saveFaultXml = new XmlTextWriter(fileNameToSaveAs, System.Text.UnicodeEncoding.Unicode); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw("<?xml version= \"1.0\" encoding=\"Unicode\"?>"); break; } default: { saveFaultXml = new XmlTextWriter(fileNameToSaveAs, null); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw("<?xml version= \"1.0\"?>"); break; } } if (isValidationRequired) { saveFaultXml.WriteDocType("Faults", null, "faultsNew.dtd", ""); } saveFaultXml.WriteStartElement("Faults"); foreach (string FaultNameAsKey in FaultTableByName.Keys) { Fault FaultToSave = faultXMLNavigator.GetFaultByName(FaultNameAsKey); ///Element = Fault saveFaultXml.WriteStartElement("Fault"); ///Attribute = Name if (FaultToSave.Name != null) { saveFaultXml.WriteAttributeString("Name", FaultToSave.Name); } ///Attribute = ReturnValue if (FaultToSave.ReturnValue != null) { saveFaultXml.WriteAttributeString("ReturnValue", FaultToSave.ReturnValue); } ///Attribute = ErrorCode if (FaultToSave.ErrorCode != null) { saveFaultXml.WriteAttributeString("ErrorCode", FaultToSave.ErrorCode); } if (FaultToSave.Function != null) { foreach (FaultFunction function in FaultToSave.Function) { ///Element = Function saveFaultXml.WriteStartElement("Function"); /// Attribute = Name if (function.Name != null) { saveFaultXml.WriteAttributeString("Name", function.Name.ToString()); } /// Attribute = OverrideErrorCode if (function.OverrideErrorCode != null) { saveFaultXml.WriteAttributeString("OverrideErrorCode", function.OverrideErrorCode.ToString()); } /// Attribute = OverrideReturnValue if (function.OverrideReturnValue != null) { saveFaultXml.WriteAttributeString("OverrideReturnValue", function.OverrideReturnValue.ToString()); } /// Attribute = PassThrough if (function.PassThrough != null) { saveFaultXml.WriteAttributeString("PassThrough", function.PassThrough.ToString()); } /// Attribute = Exception if (function.Exception != null) { saveFaultXml.WriteAttributeString("Exception", function.Exception.ToString()); } /// Attribute = Allocation if (function.Allocation != null) { saveFaultXml.WriteAttributeString("Allocation", function.Allocation.ToString()); } // checkresource Tag if (function.CheckResource != null) { foreach (FaultFunctionCheckResource checkresource in function.CheckResource) { /// Element = CheckResource saveFaultXml.WriteStartElement("CheckResource"); /// Attribute = ParamIndex if (checkresource.ParamIndex != null) { saveFaultXml.WriteAttributeString("ParamIndex", checkresource.ParamIndex.ToString()); } /// Attribute = Exists if (checkresource.Exists != null) { saveFaultXml.WriteAttributeString("Exists", checkresource.Exists.ToString()); } /// end of checkresource Element saveFaultXml.WriteEndElement(); } } //matchparams tag if (function.MatchParams != null) { foreach (FaultFunctionMatchParams matchParams in function.MatchParams) { /// Element = MatchParams saveFaultXml.WriteStartElement("MatchParams"); if (matchParams.MatchParam != null) { foreach (FaultFunctionMatchParams matchParam in matchParams.MatchParam) { /// Element = MatchParam saveFaultXml.WriteStartElement("MatchParam"); /// Attribute = Name if (matchParam.Name != null) { saveFaultXml.WriteAttributeString("Name", matchParam.Name.ToString()); } /// Attribute = TestOperator if (matchParam.TestOperator != null) { saveFaultXml.WriteAttributeString("TestOperator", matchParam.TestOperator.ToString()); } /// Attribute = TestValue if (matchParam.TestValue != null) { saveFaultXml.WriteAttributeString("TestValue", matchParam.TestValue.ToString()); } /// Attribute = CompareAsType if (matchParam.CompareAsType != null) { saveFaultXml.WriteAttributeString("CompareAsType", matchParam.CompareAsType.ToString()); } /// Attribute = ID if (matchParam.ID != null) { saveFaultXml.WriteAttributeString("ID", matchParam.ID.ToString()); } /// end of MatchParam Element saveFaultXml.WriteEndElement(); } } /// end of MatchParams Element saveFaultXml.WriteEndElement(); } } /// end of Fault Functions Element saveFaultXml.WriteEndElement(); } /// end of Fault Element saveFaultXml.WriteEndElement(); } } //closeing Faluts Tag saveFaultXml.WriteFullEndElement(); //closing xmlwriter. saveFaultXml.Close( ); }
//************************************************************************* // Method: saveFaultXmlDocument // Description: recreating fault.xml document // // Parameters: // faultXMLNavigator // // Return Value: None // // Output: "Faults.xml" file will be created in this application directory //************************************************************************* public void saveFaultXmlDocument(FaultXMLNavigator faultXMLNavigator, string fileNameToSaveAs,string fileEncoding,bool isValidationRequired ) { XmlTextWriter saveFaultXml = null ; Console.WriteLine(fileNameToSaveAs); switch(fileEncoding.ToUpper()) { case "UTF-8": case "": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UTF8Encoding.UTF8); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\"?>" ); break; } case "UTF-7": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UTF7Encoding.UTF7); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"UTF-7\"?>" ); break; } case "ASCII": { Console.WriteLine(fileNameToSaveAs); saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.ASCIIEncoding.ASCII); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"ASCII\"?>" ); break; } case "Unicode": { saveFaultXml = new XmlTextWriter(fileNameToSaveAs,System.Text.UnicodeEncoding.Unicode); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\" encoding=\"Unicode\"?>" ); break; } default: { saveFaultXml = new XmlTextWriter(fileNameToSaveAs,null); saveFaultXml.Formatting = Formatting.Indented; saveFaultXml.WriteRaw( "<?xml version= \"1.0\"?>" ); break; } } if(isValidationRequired) { saveFaultXml.WriteDocType("Faults",null,"faultsNew.dtd",""); } saveFaultXml.WriteStartElement("Faults"); foreach(string FaultNameAsKey in FaultTableByName.Keys) { Fault FaultToSave = faultXMLNavigator.GetFaultByName(FaultNameAsKey); ///Element = Fault saveFaultXml.WriteStartElement("Fault"); ///Attribute = Name if(FaultToSave.Name != null) saveFaultXml.WriteAttributeString("Name",FaultToSave.Name); ///Attribute = ReturnValue if(FaultToSave.ReturnValue != null) saveFaultXml.WriteAttributeString("ReturnValue",FaultToSave.ReturnValue); ///Attribute = ErrorCode if(FaultToSave.ErrorCode != null) saveFaultXml.WriteAttributeString("ErrorCode",FaultToSave.ErrorCode); if(FaultToSave.Function != null) { foreach(FaultFunction function in FaultToSave.Function) { ///Element = Function saveFaultXml.WriteStartElement("Function"); /// Attribute = Name if(function.Name != null) { saveFaultXml.WriteAttributeString("Name",function.Name.ToString()); } /// Attribute = OverrideErrorCode if(function.OverrideErrorCode != null) { saveFaultXml.WriteAttributeString("OverrideErrorCode",function.OverrideErrorCode.ToString()); } /// Attribute = OverrideReturnValue if(function.OverrideReturnValue!= null) { saveFaultXml.WriteAttributeString("OverrideReturnValue",function.OverrideReturnValue.ToString()); } /// Attribute = PassThrough if(function.PassThrough != null) { saveFaultXml.WriteAttributeString("PassThrough",function.PassThrough.ToString()); } /// Attribute = Exception if(function.Exception != null) { saveFaultXml.WriteAttributeString("Exception",function.Exception.ToString()); } /// Attribute = Allocation if(function.Allocation != null) { saveFaultXml.WriteAttributeString("Allocation",function.Allocation.ToString()); } // checkresource Tag if(function.CheckResource != null) { foreach(FaultFunctionCheckResource checkresource in function.CheckResource) { /// Element = CheckResource saveFaultXml.WriteStartElement("CheckResource"); /// Attribute = ParamIndex if(checkresource.ParamIndex != null) { saveFaultXml.WriteAttributeString("ParamIndex",checkresource.ParamIndex.ToString()); } /// Attribute = Exists if(checkresource.Exists != null) { saveFaultXml.WriteAttributeString("Exists",checkresource.Exists.ToString()); } /// end of checkresource Element saveFaultXml.WriteEndElement(); } } //matchparams tag if(function.MatchParams!= null) { foreach(FaultFunctionMatchParams matchParams in function.MatchParams) { /// Element = MatchParams saveFaultXml.WriteStartElement("MatchParams"); if(matchParams.MatchParam!= null) { foreach(FaultFunctionMatchParams matchParam in matchParams.MatchParam) { /// Element = MatchParam saveFaultXml.WriteStartElement("MatchParam"); /// Attribute = Name if(matchParam.Name != null) { saveFaultXml.WriteAttributeString("Name",matchParam.Name.ToString()); } /// Attribute = TestOperator if(matchParam.TestOperator != null) { saveFaultXml.WriteAttributeString("TestOperator",matchParam.TestOperator.ToString()); } /// Attribute = TestValue if(matchParam.TestValue != null) { saveFaultXml.WriteAttributeString("TestValue",matchParam.TestValue.ToString()); } /// Attribute = CompareAsType if(matchParam.CompareAsType != null) { saveFaultXml.WriteAttributeString("CompareAsType",matchParam.CompareAsType.ToString()); } /// Attribute = ID if(matchParam.ID != null) { saveFaultXml.WriteAttributeString("ID",matchParam.ID.ToString()); } /// end of MatchParam Element saveFaultXml.WriteEndElement(); } } /// end of MatchParams Element saveFaultXml.WriteEndElement(); } } /// end of Fault Functions Element saveFaultXml.WriteEndElement(); } /// end of Fault Element saveFaultXml.WriteEndElement(); } } //closeing Faluts Tag saveFaultXml.WriteFullEndElement(); //closing xmlwriter. saveFaultXml.Close( ); }