Exemplo n.º 1
0
        /// <summary>
        ///     Loads the package XML from the underlying workspace.
        /// </summary>
        /// <returns>
        ///     Returns a <see cref="string" /> representing the design XML; otherwise <c>null</c>
        /// </returns>
        /// <exception cref="NullReferenceException">The process framework workspace is null.</exception>
        public string GetDesignXml()
        {
            IWorkspace workspace = ((IMMPxApplicationEx2)base.PxApplication).Workspace;

            if (workspace == null)
            {
                throw new NullReferenceException("The process framework workspace is null.");
            }

            string         name        = this.ID.ToString(CultureInfo.InvariantCulture);
            IMMPackageName packageName = new MMPackageNameClass();

            packageName.Category = mmPackageCategory.mmPCDesignXML;
            packageName.Type     = mmPackageType.mmPTHidden;
            packageName.Name     = name;

            IMMPackageByWS packageByWs = new MMPackageManagerClass();
            IMMPackage     package     = packageByWs.GetPackageByWS(packageName, workspace, name);

            if (package != null)
            {
                IStream stream = new XMLStreamClass();
                package.Contents.SaveToStream(stream);
                string xml = ((IXMLStream)stream).SaveToString();
                return(xml);
            }

            return(null);
        }
Exemplo n.º 2
0
        private void btnSaveAs_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog
            {
                Filter          = "空间参考文件 (*.prj)|*.prj",
                OverwritePrompt = true
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = dialog.FileName;
                ESRI.ArcGIS.esriSystem.IPersistStream stream =
                    (ESRI.ArcGIS.esriSystem.IPersistStream) this.ispatialReference_0;
                IXMLStream stream2 = new XMLStreamClass();
                stream.Save((ESRI.ArcGIS.esriSystem.IStream)stream2, 1);
                stream2.SaveToFile(fileName);
                string str2  = stream2.SaveToString();
                int    index = str2.IndexOf("[");
                str2  = str2.Substring(index - 6);
                index = str2.LastIndexOf("]");
                str2  = str2.Substring(0, index + 1);
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                using (System.IO.FileStream stream3 = File.Create(fileName))
                {
                    this.method_2(stream3, str2);
                }
            }
        }
Exemplo n.º 3
0
        public static void SaveRendererToByte(ref byte[] _RendererValue, ref string _RendererType, IRendererUI pRendererUI)
        {
            if (pRendererUI == null)
            {
                _RendererValue = null;
                _RendererType  = enumRendererType.SimpleRenderer.ToString();
                return;
            }

            _RendererType = pRendererUI.RendererType.ToString();

            try
            {
                IPersistStream pPersistStream = pRendererUI.Renderer as IPersistStream;
                IStream        pStream        = new XMLStreamClass();
                pPersistStream.Save(pStream, 0);
                IXMLStream pXMLStream = pStream as IXMLStream;
                _RendererValue = pXMLStream.SaveToBytes();
            }
            catch (Exception ex)
            {
                _RendererValue = null;
                _RendererType  = enumRendererType.SimpleRenderer.ToString();
            }
        }
Exemplo n.º 4
0
 public static void LoadLayerFromStream(ILayer paramLayer, byte[] paramLayerContent)
 {
     if (((paramLayer != null) && (paramLayerContent != null)) && (paramLayerContent.Length != 0))
     {
         IPersistStream stream = paramLayer as IPersistStream;
         XMLStreamClass class2 = new XMLStreamClass();
         class2.LoadFromBytes(ref paramLayerContent);
         stream.Load(class2);
     }
 }
    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;
    }
Exemplo n.º 6
0
 public static byte[] SaveLayerToStream(ILayer paramLayer)
 {
     byte[] buffer = null;
     if (paramLayer is IPersistStream)
     {
         IPersistStream stream = paramLayer as IPersistStream;
         XMLStreamClass class2 = new XMLStreamClass();
         stream.Save(class2, 0);
         buffer = class2.SaveToBytes();
     }
     return(buffer);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Serializes an object using ArcObjects xml serialization into a BSON Element
        /// Used by the CatalogDataset to store metadata
        /// </summary>
        /// <param name="ipItem">The object to serialize</param>
        /// <returns>The BSON element containing the bytes</returns>
        internal static BsonValue ObjectToBson(System.Object ipItem)
        {
            IXMLStream ipXmlStream = new XMLStreamClass();
            IXMLWriter ipXmlWriter = new XMLWriterClass();

            ipXmlWriter.WriteTo((IStream)ipXmlStream);
            IXMLSerializer ipXmlSer = new XMLSerializerClass();

            ipXmlSer.WriteObject(ipXmlWriter, null, null, "Test", "Test", ipItem);
            byte[] bytes = ipXmlStream.SaveToBytes();
            return(BsonValue.Create(bytes));
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        private void method_5()
        {
            ESRI.ArcGIS.esriSystem.IPersistStream stream =
                (ESRI.ArcGIS.esriSystem.IPersistStream) this.ispatialReference_0;
            IXMLStream stream2 = new XMLStreamClass();

            stream.Save((ESRI.ArcGIS.esriSystem.IStream)stream2, 1);
            string str   = stream2.SaveToString();
            int    index = str.IndexOf("[");

            str   = str.Substring(index - 6);
            index = str.LastIndexOf("]");
            str   = str.Substring(0, index + 1);
        }
Exemplo n.º 11
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");
     }
 }
Exemplo n.º 12
0
        public static ILayer Clone(this ILayer layer)
        {
            if (layer is IPersistStream)
            {
                IObjectCopy objectCopy = new ObjectCopyClass();
                object      clone      = objectCopy.Copy(layer);
                ILayer      layerClone = clone as ILayer;
                return(layerClone);
            }
            if (layer is IPersistVariant)
            {
                // Create an XML Stream
                IXMLStream       xmlStream       = new XMLStreamClass();
                IVariantStreamIO variantStreamIO = new VariantStreamIOClass()
                {
                    Stream = (IStream)xmlStream
                };

                // Save Layer to Stream
                IVariantStream  variantStream = (IVariantStream)variantStreamIO;
                IPersistVariant save          = (IPersistVariant)layer;
                save.Save(variantStream);

                // Move Seek Pointer to beginning of Stream
                xmlStream.Reset();

                // Create New Layer
                ILayer newlayer = null;
                if (layer is IImageServerLayer)
                {
                    newlayer = new ImageServerLayerClass();
                }
                if (newlayer == null)
                {
                    return(null);
                }

                // Create new Layer
                IPersistVariant load = (IPersistVariant)newlayer;
                load.Load(variantStream);

                // Return Cloned Layer
                return(newlayer);
            }
            return(null);
        }
Exemplo n.º 13
0
        private void WriteMapToDB(IMap pMap, Dictionary <string, object> pDic, string strCondition)
        {
            //linyand add set map SpatialReference
            //pMap.SpatialReference = LoadProjectedCoordinateSystem();

            IPersistStream pPersistStream = pMap as IPersistStream;
            IStream        pStream        = new XMLStreamClass();

            pPersistStream.Save(pStream, 0);

            IXMLStream pXMLStream = pStream as IXMLStream;

            byte[]            RenderByte        = pXMLStream.SaveToBytes();
            IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();

            pMemoryBlobStream.ImportFromMemory(ref RenderByte[0], (uint)RenderByte.GetLength(0));


            pDic.Add(SysCommon.ModSysSetting._MxdListTable_MapField, pMemoryBlobStream);
            //采用更新blob字段的方法
            SysGisTable sysTable = new SysGisTable(Plugin.ModuleCommon.TmpWorkSpace);
            Exception   eError   = null;
            object      objValue = sysTable.GetFieldValue(SysCommon.ModSysSetting._MxdListTable, SysCommon.ModSysSetting._MxdListTable_MapField, strCondition, out eError);
            bool        flag     = false;

            if (objValue == null)
            {
                flag = sysTable.NewRow(SysCommon.ModSysSetting._MxdListTable, pDic, out eError);
            }
            else
            {
                flag = sysTable.UpdateRow(SysCommon.ModSysSetting._MxdListTable, strCondition, pDic, out eError);
            }
            sysTable = null;
            if (flag)
            {
                MessageBox.Show("保存显示方案成功!", "提示");
            }
            else
            {
                MessageBox.Show("保存显示方案失败", "提示");
            }
        }
        public static ILayer Clone(this ILayer layer)
        {
            if (layer is IPersistStream) {
                IObjectCopy objectCopy = new ObjectCopyClass();
                object clone = objectCopy.Copy(layer);
                ILayer layerClone = clone as ILayer;
                return layerClone;
            }
            if (layer is IPersistVariant) {
                // Create an XML Stream
                IXMLStream xmlStream = new XMLStreamClass();
                IVariantStreamIO variantStreamIO = new VariantStreamIOClass() {
                    Stream = (IStream)xmlStream
                };

                // Save Layer to Stream
                IVariantStream variantStream = (IVariantStream)variantStreamIO;
                IPersistVariant save = (IPersistVariant)layer;
                save.Save(variantStream);

                // Move Seek Pointer to beginning of Stream
                xmlStream.Reset();

                // Create New Layer
                ILayer newlayer = null;
                if (layer is IImageServerLayer) {
                    newlayer = new ImageServerLayerClass();
                }
                if (newlayer == null) { return null; }

                // Create new Layer
                IPersistVariant load = (IPersistVariant)newlayer;
                load.Load(variantStream);

                // Return Cloned Layer
                return newlayer;
            }
            return null;
        }
Exemplo n.º 15
0
 public static byte[] SaveLayerToStream(ILayer paramLayer)
 {
     byte[] buffer = null;
     if (paramLayer is IPersistStream)
     {
         IPersistStream stream = paramLayer as IPersistStream;
         XMLStreamClass class2 = new XMLStreamClass();
         stream.Save(class2, 0);
         buffer = class2.SaveToBytes();
     }
     return buffer;
 }
Exemplo n.º 16
0
 public static void LoadLayerFromStream(ILayer paramLayer, byte[] paramLayerContent)
 {
     if (((paramLayer != null) && (paramLayerContent != null)) && (paramLayerContent.Length != 0))
     {
         IPersistStream stream = paramLayer as IPersistStream;
         XMLStreamClass class2 = new XMLStreamClass();
         class2.LoadFromBytes(ref paramLayerContent);
         stream.Load(class2);
     }
 }
        unsafe public static void Save(System.Runtime.InteropServices.ComTypes.IStream stream, object data)
        {
            // Exit if Stream or DataTable is NULL
            if (stream == null)
            {
                return;
            }
            if (data == null)
            {
                return;
            }

            //COM objects needs special care...
            if (Marshal.IsComObject(data))
            {
                //*** Create XmlWriter ***
                IXMLWriter xmlWriter = new XMLWriterClass();

                //*** Create XmlStream ***
                IXMLStream xmlStream = new XMLStreamClass();

                //*** Write the object to the stream ***
                xmlWriter.WriteTo(xmlStream as IStream);

                //*** Serialize object ***
                IXMLSerializer xmlSerializer = new XMLSerializerClass();
                xmlSerializer.WriteObject(xmlWriter, null, null, "arcobject", "http://www.esri.com/schemas/ArcGIS/9.2", data);

                string str = xmlStream.SaveToString();

                data = (object)str;
                if (null == data)
                {
                    return;
                }
            }

            //make sure that the object is serializable
            if (!data.GetType().IsSerializable)
            {
                throw new Exception("Object is not serializable.");
            }

            // Convert the string into a byte array
            MemoryStream    memoryStream    = new MemoryStream();
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            binaryFormatter.Serialize(memoryStream, data);
            byte[] bytes = memoryStream.ToArray();
            memoryStream.Close();

            // Get Memory Pointer to Int32
            int  cb;
            int *pcb = &cb;

            // write the object to the structured stream
            byte[] arrLen = BitConverter.GetBytes(bytes.Length);  // Get Byte Length
            stream.Write(arrLen, arrLen.Length, new IntPtr(pcb)); // Write Byte Length
            stream.Write(bytes, bytes.Length, new IntPtr(pcb));   // Write Btye Array

            if (bytes.Length != cb)
            {
                throw new Exception("Error writing object to stream");
            }
        }
        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);
        }
    unsafe public static void Save(System.Runtime.InteropServices.ComTypes.IStream stream, object data)
    {
      // Exit if Stream or DataTable is NULL
      if (stream == null) { return; }
      if (data == null) { return; }

      //COM objects needs special care...
      if (Marshal.IsComObject(data))
      {
        //*** Create XmlWriter ***
        IXMLWriter xmlWriter = new XMLWriterClass();

        //*** Create XmlStream ***
        IXMLStream xmlStream = new XMLStreamClass();

        //*** Write the object to the stream ***
        xmlWriter.WriteTo(xmlStream as IStream);

        //*** Serialize object ***
        IXMLSerializer xmlSerializer = new XMLSerializerClass();
        xmlSerializer.WriteObject(xmlWriter, null, null, "arcobject", "http://www.esri.com/schemas/ArcGIS/9.2", data);

        string str = xmlStream.SaveToString();

        data = (object)str;
        if (null == data)
          return;
      }

      //make sure that the object is serializable
      if (!data.GetType().IsSerializable)
        throw new Exception("Object is not serializable.");
      
      // Convert the string into a byte array
      MemoryStream memoryStream = new MemoryStream();
      BinaryFormatter binaryFormatter = new BinaryFormatter();
      binaryFormatter.Serialize(memoryStream, data);
      byte[] bytes = memoryStream.ToArray();
      memoryStream.Close();

      // Get Memory Pointer to Int32
      int cb;
      int* pcb = &cb;

      // write the object to the structured stream
      byte[] arrLen = BitConverter.GetBytes(bytes.Length);  // Get Byte Length
      stream.Write(arrLen, arrLen.Length, new IntPtr(pcb));   // Write Byte Length
      stream.Write(bytes, bytes.Length, new IntPtr(pcb));     // Write Btye Array

      if (bytes.Length != cb)
        throw new Exception("Error writing object to stream");
    }