/// <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 <ClusterTag> tagsExpected = this.GetTestTagsList(); //Action XmlDocument tagsXml = new XmlDocument(); tagsXml.Load("TestData/Tags.xml"); TagsXmlFactory tagsXmlFactory = new TagsXmlFactory(); IList <ClusterTag> tagsActual = tagsXmlFactory.ReadXml(tagsXml.OuterXml); //Verify Assert.IsTrue(tagsExpected.SequenceEqual(tagsActual), "Unexpected tags deserialization result"); }
public void TestSerialization() { //Expectation XmlDocument tagsExpectedXml = new XmlDocument(); tagsExpectedXml.Load("TestData/Tags.xml"); //Action TagsXmlFactory tagsXmlFactory = new TagsXmlFactory(); string xml = tagsXmlFactory.WriteXml(this.GetTestTagsList()); XmlDocument tagsActualXml = new XmlDocument(); tagsActualXml.LoadXml(xml); //load to the XmlDocument to make the same formatting //Verify Assert.AreEqual(tagsExpectedXml.OuterXml, tagsActualXml.OuterXml, "Unexpected tags serialization result"); }