Esempio n. 1
0
        /// <summary>
        /// 序列化(将对象序列化成字符串)
        /// </summary>
        /// <param name="xmlByte">序列化字节</param>
        /// <param name="obj">序列化对象</param>
        /// <returns></returns>
        public static byte[] xmlSerializer(object obj)
        {
            try
            {
                byte[] xmlByte = null;//保存序列化后的字节
                //判断是否支持IPersistStream接口,只有支持该接口的对象才能进行序列化
                if (obj is ESRI.ArcGIS.esriSystem.IPersistStream)
                {
                    ESRI.ArcGIS.esriSystem.IPersistStream pStream = obj as ESRI.ArcGIS.esriSystem.IPersistStream;

                    ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

                    pStream.Save(xmlStream as ESRI.ArcGIS.esriSystem.IStream, 0);

                    xmlByte = xmlStream.SaveToBytes();
                }
                return(xmlByte);
            }
            catch (Exception ex)
            {
                ////*********************************************
                ////guozheng 2010-12-24 平安夜  added 系统异常日志
                //if (ModData.SysLog == null) ModData.SysLog = new clsWriteSystemFunctionLog();
                //ModData.SysLog.Write(ex);
                ////**********************************************
                return(null);
            }
        }
Esempio n. 2
0
 public static string  XmlSerializer(System.Object xmlObject, System.String xmlNodeName)
 {
     System.String elementURI = "http://www.esri.com/schemas/ArcGIS/9.2";
     // Create xml writer
     ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriterCls = new ESRI.ArcGIS.esriSystem.XMLWriterClass();
     // Create xml stream
     ESRI.ArcGIS.esriSystem.IXMLStream xmlStreamCls = new ESRI.ArcGIS.esriSystem.XMLStreamClass();
     // Explicit Cast for IStream and then write to stream
     xmlWriterCls.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStreamCls);
     // Serialize
     ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializerCls = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();
     xmlSerializerCls.WriteObject(xmlWriterCls, null, null, xmlNodeName, elementURI, xmlObject);
     // Save the xmlObject to an xml file. When using xmlstream the cpu keeps data in memory until it is written to file.
     //xmlStreamCls.SaveToFile(@xmlPathFile);
     return(xmlStreamCls.SaveToString());
 }
        public System.Object DeserializeAnXMLFile(System.String xmlPathFile)
        {
            // Create xmlStream and load in the .XML file
            ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();
            xmlStream.LoadFromFile(xmlPathFile);

            // Create xmlReader and read the XML stream
            ESRI.ArcGIS.esriSystem.IXMLReader xmlReader = new ESRI.ArcGIS.esriSystem.XMLReaderClass();
            xmlReader.ReadFrom((ESRI.ArcGIS.esriSystem.IStream)xmlStream); // Explicit Cast

            // Create a serializer
            ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();

            // Return the XML contents
            return(xmlSerializer.ReadObject(xmlReader, null, null));
        }
Esempio n. 4
0
        private string SpatialReferenceToXml(ISpatialReference sr)
        {
            System.String elementURI = "http://www.esri.com/schemas/ArcGIS/9.2";

            // Create xml writer
            ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

            // Create xml stream
            ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

            // Explicit Cast for IStream and then write to stream
            xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

            // Serialize
            ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();
            xmlSerializer.WriteObject(xmlWriter, null, null, "spatialreference", elementURI, sr);

            return(xmlStream.SaveToString());
        }
Esempio n. 5
0
        private string SpatialReferenceToXml(ISpatialReference sr)
        {
            System.String elementURI = "http://www.esri.com/schemas/ArcGIS/9.2";

            // Create xml writer
            ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

            // Create xml stream
            ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

            // Explicit Cast for IStream and then write to stream
            xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

            // Serialize
            ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();
            xmlSerializer.WriteObject(xmlWriter, null, null, "spatialreference", elementURI, sr);

            return xmlStream.SaveToString();
        }
Esempio n. 6
0
        private string serializeGeo(ESRI.ArcGIS.Geometry.IGeometry geo, Boolean ESRISerialize)
        {
            if (ESRISerialize)
            {
                System.String xmlNodeName = "NodeName";
                System.String elementURI  = "http://www.esri.com/schemas/ArcGIS/10";

                // Create xml writer
                ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

                // Create xml stream
                ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

                // Explicit Cast for IStream and then write to stream
                xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

                // Serialize
                ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();


                xmlSerializer.WriteObject(xmlWriter, null, null, xmlNodeName, elementURI, geo);

                return(xmlStream.SaveToString());
            }
            else
            {
                switch (geo.GeometryType)
                {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                {
                    ESRI.ArcGIS.Geometry.IPoint pPnt = (ESRI.ArcGIS.Geometry.IPoint)geo;

                    return("<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>");

                    //break;
                }

                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                {
                    string lineString = "<PathArray>";
                    ESRI.ArcGIS.Geometry.IPolyline           pPly = (ESRI.ArcGIS.Geometry.IPolyline)geo;
                    ESRI.ArcGIS.Geometry.IGeometryCollection pGC  = (ESRI.ArcGIS.Geometry.IGeometryCollection)pPly;
                    for (int i = 0; i < pGC.GeometryCount; i++)
                    {
                        lineString = lineString + "<Path><PointArray>";
                        //ESRI.ArcGIS.Geometry.IGeometry pGeo2 = pGC.get_Geometry(i);
                        // ESRI.ArcGIS.Geometry.IPath pPath = (ESRI.ArcGIS.Geometry.IPath)pGC.get_Geometry(i);
                        ESRI.ArcGIS.Geometry.IPointCollection pPointCol = (ESRI.ArcGIS.Geometry.IPointCollection)pGC.get_Geometry(i);
                        for (int j = 0; j < pPointCol.PointCount; j++)
                        {
                            ESRI.ArcGIS.Geometry.IPoint pPathPoint = pPointCol.get_Point(j);

                            lineString = lineString + "<Point><X>" + pPathPoint.X + "</X><Y>" + pPathPoint.Y + "</Y></Point>";
                        }
                        // string tr = pGeo2.GeometryType.ToString();
                        lineString = lineString + "</PointArray></Path>";
                    }
                    lineString = lineString + "</PathArray>";
                    return(lineString);

                    // return "<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>";
                    //     break;
                }

                default:
                {
                    return("");
                    //   break;
                }
                }
            }
        }