/// <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 <BootstrapAction> bootstrapActionsExpected = this.GetTestBootstrapActionsList(); //Action XmlDocument bootstrapActionsXml = new XmlDocument(); bootstrapActionsXml.Load("TestData/BootstrapActions.xml"); BootstrapActionsXmlFactory bootstrapActionsXmlFactory = new BootstrapActionsXmlFactory(); IList <BootstrapAction> stepsActual = bootstrapActionsXmlFactory.ReadXml(bootstrapActionsXml.OuterXml); //Verify Assert.IsTrue(bootstrapActionsExpected.SequenceEqual(stepsActual), "Unexpected bootstrapActions deserialization result"); }
public void TestSerialization() { //Expectation XmlDocument bootstrapActionsExpectedXml = new XmlDocument(); bootstrapActionsExpectedXml.Load("TestData/BootstrapActions.xml"); //Action BootstrapActionsXmlFactory bootstrapActionsXmlFactory = new BootstrapActionsXmlFactory(); string xml = bootstrapActionsXmlFactory.WriteXml(this.GetTestBootstrapActionsList()); XmlDocument bootstrapActionsActualXml = new XmlDocument(); bootstrapActionsActualXml.LoadXml(xml); //load to the XmlDocument to make the same formatting //Verify Assert.AreEqual(bootstrapActionsExpectedXml.OuterXml, bootstrapActionsActualXml.OuterXml, "Unexpected bootstrapActions serialization result"); }