unsafe public static object Load(System.Runtime.InteropServices.ComTypes.IStream stream) { // Exit if Stream is NULL if (stream == null) { return null; } // Get Pointer to Int32 int cb; int* pcb = &cb; // Get Size of the object's Byte Array byte[] arrLen = new Byte[4]; stream.Read(arrLen, arrLen.Length, new IntPtr(pcb)); cb = BitConverter.ToInt32(arrLen, 0); // Read the object's Byte Array byte[] bytes = new byte[cb]; stream.Read(bytes, cb, new IntPtr(pcb)); if (bytes.Length != cb) throw new Exception("Error reading object from stream"); // Deserialize byte array AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(PeristStreamHelper.ResolveEventHandler); object data = null; MemoryStream memoryStream = new MemoryStream(bytes); BinaryFormatter binaryFormatter = new BinaryFormatter(); object objectDeserialize = binaryFormatter.Deserialize(memoryStream); if (objectDeserialize != null) { data = objectDeserialize; } memoryStream.Close(); AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(PeristStreamHelper.ResolveEventHandler); //deserialize ArcObjects if (data is string) { string str = (string)data; if (str.IndexOf("http://www.esri.com/schemas/ArcGIS/9.2") != -1) { IXMLStream readerStream = new XMLStreamClass(); readerStream.LoadFromString(str); IXMLReader xmlReader = new XMLReaderClass(); xmlReader.ReadFrom((IStream)readerStream); IXMLSerializer xmlReadSerializer = new XMLSerializerClass(); object retObj = xmlReadSerializer.ReadObject(xmlReader, null, null); if (null != retObj) data = retObj; } } return data; }
public void Test_Read_ReadsElement_WhenToldWhichOneToRead() { //Arrange XMLReaderClass XObject = new XMLReaderClass(); List <string> strlist = new List <string> { }; //Act strlist = XObject.Read("C:\\Users\\Joe\\Source\\Repos\\XmlReflectionExercise\\employee.xml", "hire-date"); //Assert Assert.AreEqual("1900-01-01", strlist[0]); }
public static IGeometry ReadGeometryFromXml(string filePath) { IXMLSerializer serializer = new XMLSerializerClass(); IXMLReader reader = new XMLReaderClass(); IXMLStream stream = new XMLStreamClass(); stream.LoadFromFile(filePath); reader.ReadFrom((IStream)stream); return((IGeometry)serializer.ReadObject(reader, null, null)); }
private static object ReadGeometryFromXML(string filePath) { IXMLSerializer serializer = new XMLSerializerClass(); IXMLReader reader = new XMLReaderClass(); IXMLStream stream = new XMLStreamClass(); stream.LoadFromFile(filePath); reader.ReadFrom((IStream)stream); return(serializer.ReadObject(reader, null, null)); }
public void Test_Read_ReadsFromXmlFile_WhenGivenAFileName() { //Arrange XMLReaderClass XObject = new XMLReaderClass(); List <string> strlist = null; //Act //VB: //C:\Users\Joe\Source\Repos\XmlReflectionExercise\employee.xml //FDM: //C:\\Users\\joseph.bannert\\Desktop\\XmlReflectionExercise\\employee.xml strlist = XObject.Read("C:\\Users\\Joe\\Source\\Repos\\XmlReflectionExercise\\employee.xml", null); //Assert Assert.IsNotNull(strlist[0]); }
/// <summary> /// Gets an object serialized using ArcObjects xml serialization from a BSON Element /// Used by the CatalogDataset to extract metadata /// </summary> /// <param name="byteStuff">The BSON element containing the bytes</param> /// <returns>The object deserialized</returns> internal static System.Object BsonToObject(BsonElement byteStuff) { try { byte[] bytes = byteStuff.Value.AsByteArray; IXMLStream ipXmlStream = new XMLStreamClass(); ipXmlStream.LoadFromBytes(ref bytes); IXMLReader ipXmlReader = new XMLReaderClass(); ipXmlReader.ReadFrom((IStream)ipXmlStream); IXMLSerializer ipXmlSer = new XMLSerializerClass(); return(ipXmlSer.ReadObject(ipXmlReader, null, null)); } catch (Exception) { throw new COMException("Value expected as byte array isn't"); } }
public static object ReadFromXml(string xmlFilePath) { try { IFile inputXmlFile = new FileStreamClass(); inputXmlFile.Open(xmlFilePath, esriFilePermission.esriReadWrite); IXMLReader myXmlReader = new XMLReaderClass(); myXmlReader.ReadFrom((IStream)inputXmlFile); IXMLSerializer myInputXmlSerializer = new XMLSerializerClass(); object myFunctionObject = myInputXmlSerializer.ReadObject(myXmlReader, null, null); return(myFunctionObject); } catch (Exception exc) { Console.WriteLine("Exception caught in ReadFromXml: " + exc.Message); return(null); } }
unsafe public static object Load(System.Runtime.InteropServices.ComTypes.IStream stream) { // Exit if Stream is NULL if (stream == null) { return(null); } // Get Pointer to Int32 int cb; int *pcb = &cb; // Get Size of the object's Byte Array byte[] arrLen = new Byte[4]; stream.Read(arrLen, arrLen.Length, new IntPtr(pcb)); cb = BitConverter.ToInt32(arrLen, 0); // Read the object's Byte Array byte[] bytes = new byte[cb]; stream.Read(bytes, cb, new IntPtr(pcb)); if (bytes.Length != cb) { throw new Exception("Error reading object from stream"); } // Deserialize byte array AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(PeristStreamHelper.ResolveEventHandler); object data = null; MemoryStream memoryStream = new MemoryStream(bytes); BinaryFormatter binaryFormatter = new BinaryFormatter(); object objectDeserialize = binaryFormatter.Deserialize(memoryStream); if (objectDeserialize != null) { data = objectDeserialize; } memoryStream.Close(); AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(PeristStreamHelper.ResolveEventHandler); //deserialize ArcObjects if (data is string) { string str = (string)data; if (str.IndexOf("http://www.esri.com/schemas/ArcGIS/9.2") != -1) { IXMLStream readerStream = new XMLStreamClass(); readerStream.LoadFromString(str); IXMLReader xmlReader = new XMLReaderClass(); xmlReader.ReadFrom((IStream)readerStream); IXMLSerializer xmlReadSerializer = new XMLSerializerClass(); object retObj = xmlReadSerializer.ReadObject(xmlReader, null, null); if (null != retObj) { data = retObj; } } } return(data); }
public static object ReadFromXml(string xmlFilePath) { try { IFile inputXmlFile = new FileStreamClass(); inputXmlFile.Open(xmlFilePath, esriFilePermission.esriReadWrite); IXMLReader myXmlReader = new XMLReaderClass(); myXmlReader.ReadFrom((IStream)inputXmlFile); IXMLSerializer myInputXmlSerializer = new XMLSerializerClass(); object myFunctionObject = myInputXmlSerializer.ReadObject(myXmlReader, null, null); return myFunctionObject; } catch (Exception exc) { Console.WriteLine("Exception caught in ReadFromXml: " + exc.Message); return null; } }