Exemple #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ComSerializable{T}" /> class.
        /// </summary>
        /// <param name="info">The information.</param>
        /// <param name="context">The context.</param>
        protected ComSerializable(SerializationInfo info, StreamingContext context)
        {
            byte[] data   = (byte[])info.GetValue("DATA", typeof(byte[]));
            string progId = info.GetString("PROGID");

            using (ComReleaser com = new ComReleaser())
            {
                IMemoryBlobStream blob = new MemoryBlobStreamClass();
                com.ManageLifetime(blob);

                IMemoryBlobStreamVariant variant = (IMemoryBlobStreamVariant)blob;
                variant.ImportFromVariant(data);

                IObjectStream stream = new ObjectStreamClass();
                stream.Stream = blob;

                com.ManageLifetime(stream);

                Type t = Type.GetTypeFromProgID(progId);

                IPersistStream persist = (IPersistStream)Activator.CreateInstance(t);
                persist.Load(stream);

                this.Value = (T)persist;
            }
        }
Exemple #2
0
        /// <summary>
        ///     Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with the data needed to serialize the
        ///     target object.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to populate with data.</param>
        /// <param name="context">
        ///     The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this
        ///     serialization.
        /// </param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            using (ComReleaser cr = new ComReleaser())
            {
                IPersistStream persist = this.Value as IPersistStream;
                if (persist == null)
                {
                    return;
                }

                IObjectStream stream = new ObjectStreamClass();
                cr.ManageLifetime(stream);

                IMemoryBlobStream blob = new MemoryBlobStreamClass();
                cr.ManageLifetime(blob);

                stream.Stream = blob;

                persist.Save(stream, 0);

                IMemoryBlobStreamVariant variant = (IMemoryBlobStreamVariant)blob;

                object value;
                variant.ExportToVariant(out value);

                var data = (byte[])value;
                info.AddValue("DATA", data);
                info.AddValue("PROGID", this.ProgId);
            }
        }
Exemple #3
0
        private IMemoryBlobStream GetStreamFromFile(string fileName)
        {
            MemoryBlobStreamClass fileBlob = new MemoryBlobStreamClass();

            fileBlob.LoadFromFile(fileName);
            return(fileBlob);
        }
Exemple #4
0
        private ISymbol method_7(string string_1)
        {
            int num2;

            byte[] buffer = Convert.FromBase64String(string_1);
            int    num    = buffer.Length - 16;

            byte[] b = new byte[16];
            for (num2 = 0; num2 < 16; num2++)
            {
                b[num2] = buffer[num2];
            }
            Guid clsid = new Guid(b);

            ESRI.ArcGIS.esriSystem.IPersistStream stream =
                Activator.CreateInstance(System.Type.GetTypeFromCLSID(clsid)) as IPersistStream;
            byte[] buffer3 = new byte[num];
            for (num2 = 0; num2 < num; num2++)
            {
                buffer3[num2] = buffer[num2 + 16];
            }
            IMemoryBlobStream pstm = new MemoryBlobStreamClass();

            ((IMemoryBlobStreamVariant)pstm).ImportFromVariant(buffer3);
            stream.Load(pstm);
            return(stream as ISymbol);
        }
Exemple #5
0
        private void LoadToolbarControlItems(string filePath)
        {
            IBlobStream blobStream = new MemoryBlobStreamClass();
            IStream     stream     = blobStream;

            blobStream.LoadFromFile(filePath);
            axToolbarControl1.LoadItems(stream);
        }
Exemple #6
0
        private void SaveToolbarControlItems(string filePath)
        {
            IBlobStream blobStream = new MemoryBlobStreamClass();
            IStream     stream     = blobStream;

            axToolbarControl1.SaveItems(stream);
            blobStream.SaveToFile(filePath);
        }
 public object Deserialize(object data)
 {
     IMemoryBlobStreamVariant str = new MemoryBlobStreamClass();
     str.ImportFromVariant(data);
     ((IVariantStreamIO)vs).Stream = (IMemoryBlobStream)str;
     object o = vs.Read();
     return o;
 }
Exemple #8
0
        //从数据库中读取图层设置
        public static object GetLayerConfigFromBlob(string sql, IWorkspace pConfigWks)
        {
            Exception err = null;

            Fan.Common.Gis.IGisTable pGISTable = new Fan.Common.Gis.SysGisTable(pConfigWks);

            //获取Layer
            byte[] LayerByte = pGISTable.GetFieldValue("Render", "LayerConfig", sql, out err) as byte[];

            //是否得到了序列化的blob,没得到,则返回NULL
            if (LayerByte == null)
            {
                return(null);
            }
            //从数据库中得到图层的类型
            string strLayerType = pGISTable.GetFieldValue("Render", "LayerType", sql, out err).ToString();

            ILayer pLayer = null;

            switch (strLayerType)
            {
            case "FDOGraphicsLayer":        //注记层
                pLayer = new FDOGraphicsLayerClass();
                break;

            case "DimensionLayer":          //标注层
                pLayer = new DimensionLayerClass();
                break;

            case "GdbRasterCatalogLayer":           //影像层(RC)
                pLayer = new GdbRasterCatalogLayerClass();
                break;

            case "RasterLayer":             //影像数据集(RD)
                pLayer = new RasterLayerClass();
                break;

            case "FeatureLayer":            //普通地物层
                pLayer = new FeatureLayerClass();
                break;

            default:
                pLayer = new FeatureLayerClass();
                break;
            }
            IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();

            pMemoryBlobStreamVariant.ImportFromVariant((object)LayerByte);
            IStream pStream = pMemoryBlobStreamVariant as IStream;

            if (pLayer != null)
            {
                IPersistStream pPersistStream = pLayer as IPersistStream;
                pPersistStream.Load(pStream);
                pLayer = pPersistStream as ILayer;
            }
            return(pLayer);
        }
Exemple #9
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Exception     exError       = null;
            ITransactions pTransactions = null;

            //保存查询配置文件(由本地向数据库保存)
            try
            {
                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();

                pBlobStream.LoadFromFile(_QueryConfigPath);
                //启动事务
                pTransactions = (ITransactions)_TmpWorkSpace;
                if (!pTransactions.InTransaction)
                {
                    pTransactions.StartTransaction();
                }
                SysGisTable sysTable = new SysGisTable(_TmpWorkSpace);
                Dictionary <string, object> dicData = new Dictionary <string, object>();
                dicData.Add("SETTINGVALUE2", pBlobStream);
                dicData.Add("SETTINGNAME", "统计配置");
                //判断是更新还是添加
                //不存在则添加,已存在则更新
                if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='统计配置'"))
                {
                    if (!sysTable.NewRow("SYSSETTING", dicData, out exError))
                    {
                        MessageBox.Show(exError.Message);
                        return;
                    }
                }
                else
                {
                    if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='统计配置'", dicData, out exError))
                    {
                        MessageBox.Show(exError.Message);
                        return;
                    }
                }
                //提交事务
                if (pTransactions.InTransaction)
                {
                    pTransactions.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                //出错则放弃提交
                if (pTransactions.InTransaction)
                {
                    pTransactions.AbortTransaction();
                }
                MessageBox.Show(exError.Message);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
        public static EsriDataObject ConvertToEsriDataObject(IDataObject dataObject)
        {
            //
            EsriDataObject esriDataObject = new EsriDataObject();

            // Exit if dropped object is invalid
            if (EsriDataObject.IsValid(dataObject))
            {
                // Get Byte Array from DataObject
                object       esriLayers   = dataObject.GetData(EsriRegistry.DATAOBJECT_ESRILAYERS);
                MemoryStream memoryStream = (MemoryStream)esriLayers;
                byte[]       bytes        = memoryStream.ToArray();

                // Load Byte Array into a Stream (ESRI Wrapper of IStream)
                IMemoryBlobStreamVariant memoryBlobStreamVariant = new MemoryBlobStreamClass();
                memoryBlobStreamVariant.ImportFromVariant(bytes);
                IMemoryBlobStream2 memoryBlobStream = (IMemoryBlobStream2)memoryBlobStreamVariant;
                IStream            stream           = (IStream)memoryBlobStream;

                // Load Stream into an ESRI ObjectStream
                IObjectStream objectStream = new ObjectStreamClass();
                objectStream.Stream = stream;

                // Get Number of Layers in Dropped Object
                byte pv;
                uint cb = sizeof(int);
                uint pcbRead;
                objectStream.RemoteRead(out pv, cb, out pcbRead);
                int count = Convert.ToInt32(pv);

                // Define Guids
                Guid guidLayer = new Guid(EsriRegistry.INTERFACE_ILAYER);
                Guid guidTable = new Guid(EsriRegistry.INTERFACE_ITABLEPROPERTY);

                // Get Dropped Layers
                for (int i = 0; i < count; i++)
                {
                    object o     = objectStream.LoadObject(ref guidLayer, null);
                    ILayer layer = (ILayer)o;
                    esriDataObject.LayerCollection.Add(layer);
                }

                // Get Dropped TableProperties
                for (int i = 0; i < count; i++)
                {
                    object o = objectStream.LoadObject(ref guidTable, null);
                    if (o == null)
                    {
                        continue;
                    }
                    ITableProperty tableProperty = (ITableProperty)o;
                    esriDataObject.TablePropertyCollection.Add(tableProperty);
                }
            }

            return(esriDataObject);
        }
 public object Serialize(object arcObject)
 {
     IMemoryBlobStream  str = new MemoryBlobStreamClass();
     ((IVariantStreamIO)vs).Stream = str;
     vs.Write(arcObject);
     object variant;
     ((IMemoryBlobStreamVariant) str).ExportToVariant(out variant);
     return variant;
 }
Exemple #12
0
        public object Deserialize(object data)
        {
            IMemoryBlobStreamVariant str = new MemoryBlobStreamClass();

            str.ImportFromVariant(data);
            ((IVariantStreamIO)vs).Stream = (IMemoryBlobStream)str;
            object o = vs.Read();

            return(o);
        }
Exemple #13
0
        private object method_2(IPropertySet pPropertySet)
        {
            IMemoryBlobStream stream = new MemoryBlobStreamClass();
            IObjectStream     pstm   = new ObjectStreamClass
            {
                Stream = stream
            };

            (pPropertySet as IPersistStream).Save(pstm, 0);
            return(stream);
        }
Exemple #14
0
        public object Serialize(object arcObject)
        {
            IMemoryBlobStream str = new MemoryBlobStreamClass();

            ((IVariantStreamIO)vs).Stream = str;
            vs.Write(arcObject);
            object variant;

            ((IMemoryBlobStreamVariant)str).ExportToVariant(out variant);
            return(variant);
        }
Exemple #15
0
        private object ConvertByte2Object(byte[] objValue)
        {
            if (objValue == null || objValue.Length == 0)
            {
                return(null);
            }
            IMemoryBlobStream pMemory = new MemoryBlobStreamClass();

            pMemory.ImportFromMemory(ref objValue[0], (uint)objValue.GetLength(0));
            return(pMemory);
        }
Exemple #16
0
 private void SaveToolbarControlItems(string filePath)
 {
     //Create a MemoryBlobStream.
     IBlobStream blobStream = new MemoryBlobStreamClass();
     //Get the IStream interface.
     IStream stream = blobStream;
     //Save the ToolbarControl into the stream.
     axToolbarControl1.SaveItems(stream);
     //Save the stream to a file.
     blobStream.SaveToFile(filePath);
 }
Exemple #17
0
 private void LoadToolbarControlItems(string filePath)
 {
     //Create a MemoryBlobStream.
     IBlobStream blobStream = new MemoryBlobStreamClass();
     //Get the IStream interface.
     IStream stream = blobStream;
     //Load the stream from the file.
     blobStream.LoadFromFile(filePath);
     //Load the stream into the ToolbarControl.
     axToolbarControl1.LoadItems(stream);
 }
        private void SaveToolbarControlItems(string filePath)
        {
            //Create a MemoryBlobStream
            IBlobStream blobStream = new MemoryBlobStreamClass();
            //Get the IStream interface
            IStream stream = blobStream;

            //Save the ToolbarControl into the stream
            axToolbarControl1.SaveItems(stream);
            //Save the stream to a file
            blobStream.SaveToFile(filePath);
        }
        private void LoadToolbarControlItems(string filePath)
        {
            //Create a MemoryBlobStream
            IBlobStream blobStream = new MemoryBlobStreamClass();
            //Get the IStream interface
            IStream stream = blobStream;

            //Load the stream from the file
            blobStream.LoadFromFile(filePath);
            //Load the stream into the ToolbarControl
            axToolbarControl1.LoadItems(stream);
        }
Exemple #20
0
 private void LoadBookmarkDatFile(string filePath, ISceneBookmarks _SceneBookmarks)
 {
     try
     {
         IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
         pMemoryBlobStream.LoadFromFile(filePath);
         IObjectStream pObjectStream = new ObjectStreamClass();
         pObjectStream.Stream = pMemoryBlobStream as IStream;
         _SceneBookmarks.LoadBookmarks(pObjectStream.Stream);
     }
     catch { }
 }
Exemple #21
0
        /// <summary>
        /// Deserializes a COM object from a byte array created using <see cref="SerializeComObject"></see>.
        /// </summary>
        /// <param name="bytes">The bytes array.</param>
        /// <returns></returns>
        public static object DeserializeComObject([NotNull] byte[] bytes)
        {
            Assert.ArgumentNotNull(bytes, nameof(bytes));
            Assert.ArgumentCondition(bytes.Length > 0, "byte array is empty");

            IMemoryBlobStream2 memoryBlobStream = new MemoryBlobStreamClass();
            IVariantStream     variantStream    = CreateVariantStream(memoryBlobStream);

            var memoryBlobStreamVariant = (IMemoryBlobStreamVariant)memoryBlobStream;

            memoryBlobStreamVariant.ImportFromVariant(bytes);

            return(variantStream.Read());
        }
Exemple #22
0
        public static ESRI.ArcGIS.Carto.IFeatureRenderer LoadRendererFromByte(byte[] _RendererValue, string _RendererType)
        {
            if (_RendererValue == null || _RendererValue.Length == 0)
            {
                return(null);
            }
            try
            {
                enumRendererType pRendererType = (enumRendererType)Enum.Parse(typeof(enumRendererType), _RendererType);
                ESRI.ArcGIS.Carto.IFeatureRenderer pRenderer = null;
                switch (pRendererType)
                {
                case enumRendererType.SimpleRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.SimpleRendererClass();
                    break;

                case enumRendererType.UniqueValueRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.UniqueValueRendererClass();
                    break;

                case enumRendererType.BreakColorRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.ClassBreaksRendererClass();
                    break;

                case enumRendererType.BreakSizeRenderer:
                    pRenderer = new ESRI.ArcGIS.Carto.ClassBreaksRendererClass();
                    break;
                }

                if (pRenderer == null)
                {
                    return(null);
                }

                IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();
                pMemoryBlobStreamVariant.ImportFromVariant((object)_RendererValue);
                IStream        pStream        = pMemoryBlobStreamVariant as IStream;
                IPersistStream pPersistStream = pRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                pRenderer = pPersistStream as ESRI.ArcGIS.Carto.IFeatureRenderer;
                return(pRenderer);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemple #23
0
        public static void SetBlobValue(this IActiveRecord wrapper, FieldAttribute attribute, object value)
        {
            if (!(value is IPersistStream))
            {
                throw new ActiveRecordException("Nâo é possível persistir um objeto que não implementa IPersistStream.");
            }

            IMemoryBlobStream memStream = new MemoryBlobStreamClass();
            IObjectStream     objStream = new ObjectStreamClass();

            objStream.Stream = memStream;
            IPersistStream persist = (IPersistStream)value;

            persist.Save(memStream, 0);

            wrapper.UnderlyingObject.set_Value(attribute.Index, memStream);
        }
Exemple #24
0
        private IFeatureRenderer ReadRender(string filename)
        {
            System.IO.FileStream input  = new System.IO.FileStream(filename, FileMode.Open);
            BinaryReader         reader = new BinaryReader(input);
            int count = reader.ReadInt32();

            byte[]            buffer  = reader.ReadBytes(count);
            IMemoryBlobStream stream2 = new MemoryBlobStreamClass();
            IObjectStream     pstm    = new ObjectStreamClass
            {
                Stream = stream2
            };

            ((IMemoryBlobStreamVariant)stream2).ImportFromVariant(buffer);
            IPropertySet set = new PropertySetClass();

            (set as IPersistStream).Load(pstm);
            return(set.GetProperty("Render") as IFeatureRenderer);
        }
Exemple #25
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("保存显示方案失败", "提示");
            }
        }
Exemple #26
0
        private string method_6(ISymbol isymbol_0)
        {
            Guid   guid;
            object obj2;

            ESRI.ArcGIS.esriSystem.IPersistStream stream = (ESRI.ArcGIS.esriSystem.IPersistStream)isymbol_0;
            IMemoryBlobStream pstm    = new MemoryBlobStreamClass();
            IObjectStream     stream3 = new ObjectStreamClass
            {
                Stream = pstm
            };

            stream.GetClassID(out guid);
            stream.Save(pstm, 1);
            ((IMemoryBlobStreamVariant)pstm).ExportToVariant(out obj2);
            System.Array array  = obj2 as Array;
            byte[]       buffer = new byte[array.Length + 16];
            guid.ToByteArray().CopyTo(buffer, 0);
            array.CopyTo(buffer, 16);
            return(Convert.ToBase64String(buffer));
        }
Exemple #27
0
        public static byte[] SerializeComObject([NotNull] object persistableComObject)
        {
            Assert.ArgumentNotNull(persistableComObject, nameof(persistableComObject));
            Assert.ArgumentCondition(Marshal.IsComObject(persistableComObject),
                                     "not a com object");
            Assert.ArgumentCondition(persistableComObject is IPersistStream,
                                     "the object is not persistable");

            IMemoryBlobStream2 memoryBlobStream = new MemoryBlobStreamClass();
            IVariantStream     variantStream    = CreateVariantStream(memoryBlobStream);

            var memoryBlobStreamVariant = (IMemoryBlobStreamVariant)memoryBlobStream;

            variantStream.Write(persistableComObject);

            object bytes;

            memoryBlobStreamVariant.ExportToVariant(out bytes);

            return((byte[])bytes);
        }
Exemple #28
0
        private object CloneElement(IElement pElement)
        {
            IClone            clone  = pElement as IClone;
            IMemoryBlobStream stream = new MemoryBlobStreamClass();
            IObjectStream     pstm   = new ObjectStreamClass
            {
                Stream = stream
            };
            IPropertySet   set     = new PropertySetClass();
            IPersistStream stream3 = set as IPersistStream;

            try
            {
                set.SetProperty("Element", clone.Clone());
                stream3.Save(pstm, 0);
            }
            catch
            {
            }
            return(stream);
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdOpenSceneDoc.OnClick implementation
            //文件名称
            string         pOpenFileName = "";
            OpenFileDialog pOpenDoc      = new OpenFileDialog();

            pOpenDoc.Title  = "打开三维空间";
            pOpenDoc.Filter = "ArcScene Document(*.sxd)|*.sxd";
            if (pOpenDoc.ShowDialog() == DialogResult.OK)
            {
                pOpenFileName = pOpenDoc.FileName;
            }
            try
            {
                if (pSceneControl.CheckSxFile(pOpenFileName))
                {
                    pSceneControl.LoadSxFile(pOpenFileName);
                }
                else
                {
                    IScene        pScene        = pSceneControl.Scene;
                    IObjectStream pObjectStream = new ObjectStreamClass();

                    IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
                    pMemoryBlobStream.LoadFromFile(pOpenFileName);

                    pObjectStream.Stream = pMemoryBlobStream;

                    IPersistStream pPersistStream = pScene as IPersistStream;

                    pPersistStream.Load(pObjectStream);
                }
            }
            catch
            {
                //MessageBox.Show("文件选择为空或者选择格式不正确!");
            }
        }
Exemple #30
0
        private void SaveRender(IFeatureRenderer pRender, string filename)
        {
            object            obj2;
            IMemoryBlobStream stream = new MemoryBlobStreamClass();
            IObjectStream     pstm   = new ObjectStreamClass
            {
                Stream = stream
            };
            IPropertySet   set     = new PropertySetClass();
            IPersistStream stream3 = set as IPersistStream;

            set.SetProperty("Render", pRender);
            stream3.Save(pstm, 0);
            ((IMemoryBlobStreamVariant)stream).ExportToVariant(out obj2);
            System.IO.FileStream output = new System.IO.FileStream(filename, FileMode.CreateNew);
            BinaryWriter         writer = new BinaryWriter(output);

            writer.Write(((byte[])obj2).Length);
            writer.Write((byte[])obj2);
            writer.Close();
            output.Close();
        }
Exemple #31
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdSaveSceneDoc.OnClick implementation

            for (int i = 0; i < pSceneControl.Scene.LayerCount; i++)
            {
                ILayer pLayer = pSceneControl.Scene.get_Layer(i);
                if (pLayer == pSceneControl.Scene.ActiveGraphicsLayer)
                {
                    pSceneControl.Scene.DeleteLayer(pLayer);
                    pSceneControl.Scene.SceneGraph.RefreshViewers();
                }
            }
            try
            {
                //文件名称
                string         pSaveFileName = "";
                SaveFileDialog pSaveDoc      = new SaveFileDialog();
                pSaveDoc.Title  = "保存工作空间";
                pSaveDoc.Filter = "ArcScene Document(*.sxd)|*.sxd";
                if (pSaveDoc.ShowDialog() == DialogResult.OK)
                {
                    pSaveFileName = pSaveDoc.FileName;
                }

                IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
                IObjectStream     pObjectStream     = new ObjectStreamClass();
                pObjectStream.Stream = pMemoryBlobStream;

                IPersistStream pPersistStream = pSceneControl.Scene as IPersistStream;

                pPersistStream.Save(pObjectStream, 1);

                pMemoryBlobStream.SaveToFile(pSaveFileName);
            }
            catch
            {
            }
        }
Exemple #32
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter      = "所有文件|*.*",
                Multiselect = true
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                ITableAttachments  attachments       = (ITableAttachments)this.Object.Class;
                IAttachmentManager attachmentManager = attachments.AttachmentManager;
                ListViewItem       item  = null;
                string[]           items = new string[2];
                foreach (string str in dialog.FileNames)
                {
                    IMemoryBlobStream stream = new MemoryBlobStreamClass();
                    stream.LoadFromFile(str);
                    string          fileName = Path.GetFileName(str);
                    AttachmentClass class2   = new AttachmentClass
                    {
                        ContentType = this.GetType(str),
                        Data        = stream,
                        Name        = fileName
                    };
                    IAttachment attachment = class2;
                    items[0] = attachment.Name;
                    items[1] = attachment.Size.ToString();
                    item     = new ListViewItem(items)
                    {
                        Tag = attachment
                    };
                    this.listView1.Items.Add(item);
                }
            }
        }
            private static MemoryBlobStreamClass ToBlob(object object_0)
            {
                MemoryBlobStreamClass class2 = new MemoryBlobStreamClass();

                if (object_0 != null)
                {
                    string path = object_0.ToString();
                    try
                    {
                        if (File.Exists(path))
                        {
                            class2.LoadFromFile(path);
                        }
                        else
                        {
                            return(class2);
                        }
                    }
                    catch
                    {
                    }
                }
                return(class2);
            }
Exemple #34
0
        /// <summary>
        /// 得到Renderer从数据库中
        /// </summary>
        /// <returns></returns>
        public static object GetRendererFromBlob(string sql, IWorkspace pConfigWks)
        {
            Exception err = null;

            SysCommon.Gis.IGisTable pGISTable = new SysCommon.Gis.SysGisTable(pConfigWks);

            //获取Renderer
            byte[] renderByte = pGISTable.GetFieldValue("Render", "Render", sql, out err) as byte[];

            //是否得到了序列化的blob,没得到,则返回NULL
            if (renderByte == null)
            {
                return(null);
            }

            IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();

            pMemoryBlobStreamVariant.ImportFromVariant((object)renderByte);
            IStream pStream = pMemoryBlobStreamVariant as IStream;

            //从数据库中得到符号的类型  shduan 20110721 增加RasterRenderer
            string strRenderType = pGISTable.GetFieldValue("Render", "RenderType", sql, out err).ToString();
            string strLyrType    = pGISTable.GetFieldValue("Render", "LayerType", sql, out err).ToString();

            if (strLyrType == "RasterLayer")
            {
                IRasterRenderer pRRenderer = null;
                switch (strRenderType)
                {
                case "RasterClassifyColorRampRenderer":
                    pRRenderer = new RasterClassifyColorRampRendererClass();
                    break;

                case "RasterUniqueValueRenderer":
                    pRRenderer = new RasterUniqueValueRendererClass();
                    break;

                case "RasterDiscreteColorRenderer":
                    pRRenderer = new RasterDiscreteColorRendererClass();
                    break;

                case "RasterRGBRenderer":
                    pRRenderer = new RasterRGBRendererClass();
                    break;

                case "RasterStretchColorRampRenderer":
                    pRRenderer = new RasterStretchColorRampRendererClass();
                    break;
                }
                IPersistStream pPersistStream = pRRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                //pRRenderer = pPersistStream as IRasterRenderer;

                return(pRRenderer);
            }
            else
            {
                IFeatureRenderer pFRenderer = null;
                switch (strRenderType)
                {
                case "AnnoColor":
                    string sAnnoColor = Encoding.Default.GetString(renderByte);
                    return((object)sAnnoColor);

                case "SimpleRenderer":
                    pFRenderer = new SimpleRendererClass();
                    break;

                case "UniqueValueRenderer":
                    pFRenderer = new UniqueValueRendererClass();
                    break;

                case "ClassBreaksRenderer":
                    pFRenderer = new ClassBreaksRendererClass();
                    break;

                case "ProportionalSymbolRenderer":
                    pFRenderer = new ProportionalSymbolRendererClass();
                    break;

                case "ChartRenderer":
                    pFRenderer = new ChartRendererClass();
                    break;
                }
                IPersistStream pPersistStream = pFRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                pFRenderer = pPersistStream as IFeatureRenderer;

                return(pFRenderer);
            }
        }
        public static void SetBlobValue(this IActiveRecord wrapper, FieldAttribute attribute, object value)
        {
            if (!(value is IPersistStream))
                throw new ActiveRecordException("Nâo é possível persistir um objeto que não implementa IPersistStream.");

            IMemoryBlobStream memStream = new MemoryBlobStreamClass();
            IObjectStream objStream = new ObjectStreamClass();
            objStream.Stream = memStream;
            IPersistStream persist = (IPersistStream)value;
            persist.Save(memStream, 0);

            wrapper.UnderlyingObject.set_Value(attribute.Index, memStream);
        }
        private void CreateAttachTable(IFeatureClass pFeatureClass,int pID,string pFilePath,string pFileType)
        {
            //要素表是否有附件表,数据库只能是10版本的
             ITableAttachments pTableAtt = pFeatureClass as ITableAttachments;

             if (pTableAtt.HasAttachments == false)
             {
                 pTableAtt.AddAttachments();
             }

             //获取附件管理器
             IAttachmentManager pAttachmentManager = pTableAtt.AttachmentManager;

             //用二进制流读取数据
             IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
             pMemoryBlobStream.LoadFromFile(pFilePath);

             //创建一个附件
             IAttachment pAttachment = new AttachmentClass();

             pAttachment.ContentType=pFileType;

             pAttachment.Name = System.IO.Path.GetFileName(pFilePath);

             pAttachment.Data = pMemoryBlobStream;

             //添加到表中
             pAttachmentManager.AddAttachment(pID, pAttachment);
        }