コード例 #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        public bool Init()
        {
            string fileName = m_filePath + "\\AutoUpdate.xml";

            if (!File.Exists(fileName))
            {
                MessageDialog.ShowErrorMessage("系统配置文件不存在,可能文件损坏,请与管理员联系!");
                return(false);
            }

            m_xmlParams       = new XmlParams(fileName);
            m_dicUpdateSystem = m_xmlParams.GetParams();

            if (m_dicUpdateSystem.Count == 0)
            {
                MessageDialog.ShowErrorMessage("配置文件不正确,没有包含所需的文件信息,可能文件损坏,请与管理员联系!");
                return(false);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 初始化公有参数类
        /// </summary>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>成功初始化返回true,失败返回false</returns>
        public static bool Init(out string error)
        {
            error = null;

            m_xmlParams = new XmlParams(GetAppRunPath() + "\\SystemParams.xml");

            m_dicParams = m_xmlParams.GetParams();

            Dictionary <string, string> paramItem = m_dicParams["系统参数"] as Dictionary <string, string>;

            m_dataServerIP = paramItem["数据库服务器地址"];

            string serverInfo = string.Format("Data Source={0},1433;Network Library=DBMSSOCN;Initial Catalog=", m_dataServerIP);
            string pwd        = ";User ID=InfoSysUser;PWD=meimima123";

            m_dbPlatformServiceConnectionString = string.Format("{0}{1}{2}", serverInfo, "PlatformService", pwd);

            string[] ips = m_dataServerIP.Split(new char[] { '.' });

            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");

            ManagementObjectCollection moc = mc.GetInstances();

            List <string> lstAddress = new List <string>();

            Dictionary <string, string> dicIp = new Dictionary <string, string>();

            foreach (ManagementObject mo in moc)
            {
                string[] ip = (string[])mo["IPAddress"];

                if (ip != null && ip.Length > 0)
                {
                    lstAddress.Add(string.Format("{0}.{1}.{2}.{3}", ips[0], ips[1], ips[2], ips[3]));
                }
            }

            if (lstAddress.Count == 0)
            {
                error = "您没有可用的网络连接,请检查网络是否正常";
                return(false);
            }

            if (lstAddress.Count > 1)
            {
                for (int i = 0; i < lstAddress.Count; i++)
                {
                    if (!TestDBServer(lstAddress[i]))
                    {
                        lstAddress.RemoveAt(i--);
                    }

                    // 至少留一个IP地址
                    if (lstAddress.Count == 1)
                    {
                        break;
                    }
                }
            }

            if (m_dataServerIP != lstAddress[0])
            {
                m_dataServerIP = lstAddress[0];

                serverInfo = string.Format("Data Source={0},1433;Network Library=DBMSSOCN;Initial Catalog=", m_dataServerIP);

                m_dbPlatformServiceConnectionString = string.Format("{0}{1}{2}", serverInfo, "PlatformService", pwd);

                Save();
            }

            return(true);
        }