示例#1
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);
            }
        }
示例#2
0
        //从数据库中读取MXD文档
        private byte[] ReadByteFromBlob(string TableName, string QuerStr, string fieldName)
        {
            ICursor pCursor = null;

            byte[] newbyte = null;
            try
            {
                ITable       pTable       = (m_pWorkspace as IFeatureWorkspace).OpenTable(TableName);
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = QuerStr;
                pQueryFilter.SubFields   = fieldName;
                pCursor = pTable.Search(pQueryFilter, false);
                if (pCursor == null)
                {
                    return(null);
                }
                int FieldIndex = pCursor.Fields.FindField(fieldName);
                if (FieldIndex < 0)
                {
                    return(null);
                }
                IRow pRow = pCursor.NextRow();
                if (pRow == null)
                {
                    return(null);
                }
                object resultValue = pRow.get_Value(FieldIndex);
                if (resultValue == null)
                {
                    return(null);
                }
                if (resultValue is System.DBNull)
                {
                    return(null);
                }
                IMemoryBlobStreamVariant pMemoryBlob = resultValue as IMemoryBlobStreamVariant;
                object outValue;
                pMemoryBlob.ExportToVariant(out outValue);
                newbyte = (byte[])outValue;
            }
            catch
            {
                return(null);
            }
            return(newbyte);
        }
示例#3
0
        public void SymbolFeatrueLayer(IFeatureLayer pFealyr)
        {
            if (!(pFealyr is IGeoFeatureLayer))
            {
                return;
            }

            try
            {
                string strXMLpath = System.Windows.Forms.Application.StartupPath + "\\..\\Template\\SymbolInfo.xml";

                string strLyrName = pFealyr.Name;
                if (pFealyr.FeatureClass != null)
                {
                    IDataset pDataset = pFealyr.FeatureClass as IDataset;
                    strLyrName = pDataset.Name;
                }

                strLyrName = strLyrName.Substring(strLyrName.IndexOf('.') + 1);

                if (m_vDoc == null)
                {
                    IFeatureWorkspace pFeaWks      = ModFrameData.m_pFeatureWorkspace;
                    ITable            pTable       = pFeaWks.OpenTable("SYMBOLINFO");
                    IQueryFilter      pQueryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                    pQueryFilter.WhereClause = "SYMBOLNAME='ALLSYMBOL'";

                    ICursor pCursor = pTable.Search(pQueryFilter, false);
                    IRow    pRow    = pCursor.NextRow();
                    if (pRow == null)
                    {
                        return;
                    }

                    IMemoryBlobStreamVariant var = pRow.get_Value(pRow.Fields.FindField("SYMBOL")) as IMemoryBlobStreamVariant;
                    object tempObj = null;
                    if (var == null)
                    {
                        return;
                    }

                    var.ExportToVariant(out tempObj);
                    XmlDocument doc   = new XmlDocument();
                    byte[]      btyes = (byte[])tempObj;
                    string      xml   = Encoding.Default.GetString(btyes);
                    doc.LoadXml(xml);

                    DateTime updateTime = (DateTime)pRow.get_Value(pRow.Fields.FindField("UPDATETIME"));
                    DateTime Nowtime;

                    bool blnUpdate = false;

                    //读一个日志算了
                    string strTimeLog = System.Windows.Forms.Application.StartupPath + "\\..\\Template\\UpdateTime.txt";
                    if (System.IO.File.Exists(strTimeLog))
                    {
                        StreamReader sr      = new StreamReader(strTimeLog);
                        string       strTime = sr.ReadLine();
                        sr.Close();
                        if (!DateTime.TryParse(strTime, out Nowtime))
                        {
                            blnUpdate = true;
                        }

                        if (updateTime > Nowtime)
                        {
                            if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "存在最新符号信息,是否需要下载?"))
                            {
                                blnUpdate = true;
                            }
                        }
                    }
                    else
                    {
                        blnUpdate = true;
                    }

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
                    pCursor = null;

                    //首先判断是否需要下载符号信息
                    if (System.IO.File.Exists(strXMLpath))
                    {
                        if (blnUpdate)
                        {
                            doc.Save(strXMLpath);
                            StreamWriter sw1 = new StreamWriter(strTimeLog);
                            sw1.Write(updateTime.ToString());
                            sw1.Close();
                        }
                    }
                    else
                    {
                        doc.Save(strXMLpath);
                        StreamWriter sw = new StreamWriter(strTimeLog);
                        sw.Write(updateTime.ToString());
                        sw.Close();
                    }

                    m_vDoc = new XmlDocument();
                    m_vDoc.Load(strXMLpath);
                }
                else
                {
                }

                XmlElement pElement = m_vDoc.SelectSingleNode("//" + strLyrName) as XmlElement;
                if (pElement == null)
                {
                    return;
                }

                IFeatureRenderer pFeaRender = SysCommon.XML.XMLClass.XmlDeSerializer2(pElement.FirstChild.Value) as IFeatureRenderer;
                IGeoFeatureLayer pGeoLyr    = pFealyr as IGeoFeatureLayer;
                pGeoLyr.Renderer = pFeaRender;
            }
            catch
            {
            }
        }