Beispiel #1
0
        private void refreshSDEFiles()
        {
            lstSDE.Items.Clear();
            pHashtable.Clear();
            string[] Files = System.IO.Directory.GetFiles(sDir, "*.sde");
            foreach (string file in Files)
            {
                IWorkspaceFactory pWSF = new SdeWorkspaceFactoryClass();
                IPropertySet      ppro = pWSF.ReadConnectionPropertiesFromFile(file);
                if (ppro != null)
                {
                    object strnames  = null;
                    object strvalues = null;
                    int    count     = ppro.Count;
                    ppro.GetAllProperties(out strnames, out strvalues);
                    object   po   = ppro.GetProperty("PASSWORD");
                    string[] strN = strnames as string[];

                    int    ipos        = file.LastIndexOf("\\");
                    string strFileName = file.Substring(ipos + 1, file.Length - ipos - 1);
                    lstSDE.Items.Add(strFileName);
                    pHashtable.Add(strFileName, ppro);
                }
            }
        }
        /// <summary>
        /// Open a table class from an SDE Workspace
        /// </summary>
        /// <param name="conFilePath">string path to the SDE connection file</param>
        /// <param name="tabName">Table class name</param>
        /// <param name="fdsName">Optional name of feature dataset</param>
        /// <param name="versionName">Optional version name, defaults to the version specified by the connection file</param>
        /// <returns></returns>
        public static ITable openTableFromSDE(string conFilePath, string tabName, string fdsName = "", string versionName = "")
        {
            ITable table = null;
            IWorkspaceFactory factory = new SdeWorkspaceFactoryClass();
            IPropertySet props = factory.ReadConnectionPropertiesFromFile(conFilePath);

            if (versionName != "")
            {
                props.SetProperty("VERSION", versionName);
            }
            IWorkspace workspace = factory.Open(props, 0);

            IFeatureWorkspace featWorkspace = (IFeatureWorkspace)workspace;
            if (fdsName != "")
            {
                IFeatureDataset featdataset = featWorkspace.OpenFeatureDataset(fdsName);
                IFeatureWorkspace datasetWorkspace = (IFeatureWorkspace)featdataset.Workspace;
                table = datasetWorkspace.OpenTable(tabName);
            }
            else
            {
                table = featWorkspace.OpenTable(tabName);
            }
            return table;
        }
Beispiel #3
0
        /// <summary>
        /// 通过sde文件连接SDE
        /// </summary>
        /// <param name="sdeFile">sde的连接配置文件</param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static IWorkspace OpenSdeWorkspace(string sdeFile, out string sdeUser, out string message)
        {
            message = string.Empty;
            sdeUser = string.Empty;

            IWorkspace        pWorkSpace  = null;
            IWorkspaceFactory pSdeFactory = null;

            try
            {
                if (string.IsNullOrEmpty(sdeFile))
                {
                    message = "获取连接文件出错";
                    return(null);
                }
                if (!File.Exists(sdeFile))
                {
                    message = "获取连接文件出错";
                    return(null);
                }

                pSdeFactory = new SdeWorkspaceFactoryClass();

                IPropertySet pPropertySet = pSdeFactory.ReadConnectionPropertiesFromFile(sdeFile);
                if (pPropertySet == null)
                {
                    message = "读取连接文件出错";
                    return(null);
                }

                string strServer = pPropertySet.GetProperty("SERVER").ToString();
                string strPort   = pPropertySet.GetProperty("INSTANCE").ToString();
                sdeUser = pPropertySet.GetProperty("USER").ToString();

                //if (NetAssist.CheckSDEConnecTion(strServer, Convert.ToInt32(strPort), out message) == false)
                //{
                //    return null;
                //}
                if (NetAssist.PingIP(strServer) == false)
                {
                    message = "无法连接服务器";
                    return(null);
                }

                if (strPort == "5151")
                {
                    if (NetAssist.PingPort(strServer, Convert.ToInt32(strPort)) == false)
                    {
                        message = "无法连接服务器";
                        return(null);
                    }
                }

                pWorkSpace = pSdeFactory.OpenFromFile(sdeFile, 0);
            }
            catch (Exception ex)
            {
                LOG.Error("空间数据库打开错误,详情:" + ex.Message);
                // Console.WriteLine("空间数据库打开错误");
                message = ex.Message;
                return(null);
            }
            return(pWorkSpace);
        }