/// <summary> /// Used for XML serialization. /// Write an XML content of the object without a root element /// </summary> /// <param name="writer">Xml writer</param> public override void WriteXml(XmlWriter writer) { TagsXmlFactory tagsXmlFactory = new TagsXmlFactory(); ConfigsXmlFactory configsXmlFactory = new ConfigsXmlFactory(); BootstrapActionsXmlFactory bootstrapActionsXmlFactory = new BootstrapActionsXmlFactory(); StepsXmlFactory stepsXmlFactory = new StepsXmlFactory(); writer.WriteElementString("name", this.Name); writer.WriteElementString("logUri", this.LogUri); writer.WriteElementString("ec2KeyName", this.Ec2KeyName); writer.WriteElementString("jobFlowRole", this.JobFlowRole); writer.WriteElementString("amiVersion", this.AmiVersion); writer.WriteElementString("hadoopVersion", this.HadoopVersion); writer.WriteElementString("masterInstanceType", this.MasterInstanceType); writer.WriteElementString("slaveInstanceType", this.SlaveInstanceType); writer.WriteElementString("instanceCount", this.InstanceCount.ToString()); writer.WriteElementString("keepJobflowAliveWhenNoSteps", this.KeepJobFlowAliveWhenNoSteps.ToString().ToLower()); writer.WriteElementString("terminationProtected", this.TerminationProtected.ToString().ToLower()); writer.WriteElementString("additionalInfo", this.AdditionalInfo); tagsXmlFactory.WriteItems(writer, this.Tags); configsXmlFactory.WriteItems(writer, this.Configs); bootstrapActionsXmlFactory.WriteItems(writer, this.BootstrapActions); stepsXmlFactory.WriteItems(writer, this.Steps); }
/// <summary> /// Used for XML deserialization. /// Populate object nested items from the nested xml-branch /// </summary> /// <param name="reader">Xml reader</param> protected override bool ReadXmlBranch(XmlReader reader) { switch (reader.Name) { case TagsXmlFactory.RootXmlElement: TagsXmlFactory tagsXmlFactory = new TagsXmlFactory(); this.Tags = tagsXmlFactory.ReadItems(reader); return(true); case ConfigsXmlFactory.RootXmlElement: ConfigsXmlFactory configsXmlFactory = new ConfigsXmlFactory(); this.Configs = configsXmlFactory.ReadItems(reader); return(true); case BootstrapActionsXmlFactory.RootXmlElement: BootstrapActionsXmlFactory bootstrapActionsXmlFactory = new BootstrapActionsXmlFactory(); this.BootstrapActions = bootstrapActionsXmlFactory.ReadItems(reader); return(true); case StepsXmlFactory.RootXmlElement: StepsXmlFactory stepsXmlFactory = new StepsXmlFactory(); this.Steps = stepsXmlFactory.ReadItems(reader); return(true); } return(false); }
public void TestDeserialization() { //Expectation IList <ConfigBase> configsExpected = this.GetTestConfigsList(); //Action XmlDocument configsXml = new XmlDocument(); configsXml.Load("TestData/Configs.xml"); ConfigsXmlFactory configsXmlFactory = new ConfigsXmlFactory(); IList <ConfigBase> configsActual = configsXmlFactory.ReadXml(configsXml.OuterXml); //Verify Assert.IsTrue(configsExpected.SequenceEqual(configsActual), "Unexpected configs deserialization result"); }
public void TestSerialization() { //Expectation XmlDocument configsExpectedXml = new XmlDocument(); configsExpectedXml.Load("TestData/Configs.xml"); //Action ConfigsXmlFactory configsXmlFactory = new ConfigsXmlFactory(); string xml = configsXmlFactory.WriteXml(this.GetTestConfigsList()); XmlDocument configsActualXml = new XmlDocument(); configsActualXml.LoadXml(xml); //load to the XmlDocument to make the same formatting //Verify Assert.AreEqual(configsExpectedXml.OuterXml, configsActualXml.OuterXml, "Unexpected configs serialization result"); }