Ejemplo n.º 1
0
        /// <summary>
        ///  修改或创建LocalMachine.ini 获得本机的IP协议  写入多播的IP和端口、MachineID
        /// </summary>
        private void CreatelLocalMachineIni()
        {
            string        strProgramDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\VoiceCyber\\UMP\\config";
            DirectoryInfo dir = new DirectoryInfo(strProgramDataPath);

            if (!dir.Exists)
            {
                dir.Create();
            }
            string   strIniPath = strProgramDataPath + "\\localmachine.ini";
            FileInfo fi         = new FileInfo(strIniPath);

            if (!fi.Exists)
            {
                FileStream fs = fi.Create();
                fs.Close();
            }
            IniOperation ini = new IniOperation(strIniPath);

            string      strHostName = Dns.GetHostName(); //得到本机的主机名
            IPHostEntry ipEntry     = Dns.GetHostEntry(strHostName);

            if (ipEntry.AddressList.Count() > 0)
            {
                foreach (IPAddress adress in ipEntry.AddressList)
                {
                    if (adress.AddressFamily == AddressFamily.InterNetwork)
                    {
                        ini.IniWriteValue("LocalMachine", "SubscribeAddress", "224.0.2.26,3789");
                        break;
                    }
                    //else if (adress.AddressFamily == AddressFamily.InterNetworkV6)
                    //{
                    //    ini.IniWriteValue("LocalMachine", "SubscribeAddress", "ff01::0226,3789");
                    //    break;
                    //}
                    continue;
                }
            }
            string strMachineID = ini.IniReadValue("LocalMachine", "MachineID");

            if (string.IsNullOrEmpty(strMachineID))
            {
                ini.IniWriteValue("LocalMachine", "MachineID", Guid.NewGuid().ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 写入日志路径到LocalMachine.ini中
        /// </summary>
        public static bool WriteLogPath(string strPath)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(strPath);
            XMLOperator  xmlOperator        = new XMLOperator(xmldoc);
            XmlNode      LocalMachineNode   = xmlOperator.SelectNode("Configurations/Configuration/LocalMachine", "");
            string       strLogPath         = xmlOperator.SelectAttrib(LocalMachineNode, "LogPath");
            string       strProgramDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\VoiceCyber\\UMP\\config";
            string       strLocalMachineIni = strProgramDataPath + "\\localmachine.ini";
            IniOperation ini = new IniOperation(strLocalMachineIni);

            ini.IniWriteValue("LocalMachine", "LogPath", strLogPath);
            //  UMPService00.IEventLog.WriteEntry("LogPath = " + strLogPath, EventLogEntryType.Warning);
            return(true);
        }