public static bool LoadFromFile(string fileName, out dvd obj) { System.Exception exception = null; return LoadFromFile(fileName, out obj, out exception); }
/// <summary> /// Deserializes workflow markup from file into an dvd object /// </summary> // <param name="xml">string workflow markup to deserialize</param> // <param name="obj">Output dvd object</param> // <param name="exception">output Exception value if deserialize failed</param> // <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out dvd obj, out System.Exception exception) { exception = null; obj = default(dvd); try { obj = LoadFromFile(fileName); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public static bool Deserialize(string xml, out dvd obj) { System.Exception exception = null; return Deserialize(xml, out obj, out exception); }
/// <summary> /// Deserializes workflow markup into an dvd object /// </summary> // <param name="xml">string workflow markup to deserialize</param> // <param name="obj">Output dvd object</param> // <param name="exception">output Exception value if deserialize failed</param> // <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out dvd obj, out System.Exception exception) { exception = null; obj = default(dvd); try { obj = Deserialize(xml); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public void Dvd() { lock (testLock) { // Copy resource file to the run-time directory GetInputFilePath("Actor.xsd", Resources.Actor); // Copy resource file to the run-time directory string inputFilePath = GetInputFilePath("Dvd.xsd", Resources.dvd); var generatorParams = GetGeneratorParams(inputFilePath); generatorParams.CollectionObjectType = CollectionType.List; generatorParams.TargetFramework = TargetFramework.Net35; generatorParams.EnableDataBinding = true; generatorParams.EnableSummaryComment = true; generatorParams.GenerateDataContracts = false; generatorParams.UseGenericBaseClass = false; generatorParams.GenerateXMLAttributes = true; var xsdGen = new GeneratorFacade(generatorParams); var result = xsdGen.Generate(); Assert.IsTrue(result.Success, result.Messages.ToString()); // Create new dvd collection and save it to file var dvd = new DvdCollection(); dvd.Dvds.Add(new dvd {Title = "Matrix"}); var newitem = new dvd(); newitem.Actor.Add(new Actor {firstname = "James", nationality = "Us"}); dvd.Dvds.Add(newitem); var originalXml = dvd.Serialize(); dvd.SaveToFile("dvd.xml"); // Load data fom file and serialize it again. var loadedDvdCollection = DvdCollection.LoadFromFile("dvd.xml"); var finalXml = loadedDvdCollection.Serialize(); // Then comprate two xml string if (!originalXml.Equals(finalXml)) { Assert.Fail("Xml value are not equals"); } var compileResult = CompileCSFile(generatorParams.OutputFilePath); Assert.IsTrue(compileResult.Success, compileResult.Messages.ToString()); } }
public void Dvd() { lock (testLock) { // Copy resource file to the run-time directory GetInputFilePath("Actor.xsd", Resources.Actor); // Copy resource file to the run-time directory string inputFilePath = GetInputFilePath("Dvd.xsd", Resources.dvd); var generatorParams = GetGeneratorParams(inputFilePath); generatorParams.CollectionObjectType = CollectionType.List; generatorParams.TargetFramework = TargetFramework.Net35; generatorParams.EnableDataBinding = true; generatorParams.Miscellaneous.EnableSummaryComment = true; generatorParams.GenerateDataContracts = false; generatorParams.GenericBaseClass.Enabled = false; generatorParams.Serialization.GenerateXmlAttributes = true; generatorParams.TrackingChanges.Enabled = false; generatorParams.TrackingChanges.GenerateTrackingClasses = false; generatorParams.Serialization.EnableEncoding = false; generatorParams.Serialization.DefaultEncoder = DefaultEncoder.UTF8; var xsdGen = new GeneratorFacade(generatorParams); var result = xsdGen.Generate(); Assert.IsTrue(result.Success, result.Messages.ToString()); // Create new DVD collection and save it to file var dvd = new DvdCollection(); dvd.Dvds.Add(new dvd { Title = "Matrix יא?" }); var newitem = new dvd(); newitem.Actor.Add(new Actor { firstname = "Jamיs א&", nationality = "Us" }); dvd.Dvds.Add(newitem); var originalXml = dvd.Serialize(); dvd.SaveToFile(@"c:\temp\dvd.xml"); // Load data from file and serialize it again. var loadedDvdCollection = DvdCollection.LoadFromFile(@"c:\temp\dvd.xml"); var finalXml = loadedDvdCollection.Serialize(); // Then compare two XML string if (!originalXml.Equals(finalXml)) { Assert.Fail("XML values are not equals"); } Exception exp; DvdCollection deserialiseDvd; dvd.SaveToFile(@"c:\temp\dvdASCII.xml", Encoding.ASCII); if (!DvdCollection.LoadFromFile(@"c:\temp\dvdASCII.xml", Encoding.ASCII, out deserialiseDvd, out exp)) { Assert.Fail("LoadFromFile failed on ASCII encoding "); } else { if (!deserialiseDvd.Dvds[0].Title.Equals("Matrix ???")) { Assert.Fail("LoadFromFile failed on ASCII encoding "); } } dvd.SaveToFile(@"c:\temp\dvdUTF8.xml", Encoding.UTF8); if (!DvdCollection.LoadFromFile(@"c:\temp\dvdUTF8.xml", Encoding.UTF8, out deserialiseDvd, out exp)) { Assert.Fail("LoadFromFile failed on UTF8 encoding "); } else { if (!deserialiseDvd.Dvds[0].Title.Equals("Matrix יא?")) { Assert.Fail("LoadFromFile failed on UTF8 encoding "); } } dvd.SaveToFile(@"c:\temp\dvdUnicode.xml", Encoding.Unicode); if (!DvdCollection.LoadFromFile(@"c:\temp\dvdUnicode.xml", Encoding.Unicode, out deserialiseDvd, out exp)) { Assert.Fail("LoadFromFile failed on Unicode encoding "); } else { if (!deserialiseDvd.Dvds[0].Title.Equals("Matrix יא?")) { Assert.Fail("LoadFromFile failed on Unicode encoding "); } } dvd.SaveToFile(@"c:\temp\dvdUTF32.xml", Encoding.UTF32); if (!DvdCollection.LoadFromFile(@"c:\temp\dvdUTF32.xml", Encoding.UTF32, out deserialiseDvd, out exp)) { Assert.Fail("LoadFromFile failed on UTF32 encoding "); } else { if (!deserialiseDvd.Dvds[0].Title.Equals("Matrix יא?")) { Assert.Fail("LoadFromFile failed on UTF32 encoding "); } } var compileResult = CompileCSFile(generatorParams.OutputFilePath); Assert.IsTrue(compileResult.Success, compileResult.Messages.ToString()); } }