Exemplo n.º 1
0
        /// <summary>
        /// XML 파일로부터 컨피그 설정을 읽어와서 세팅한다.
        /// </summary>
        private bool LoadConfig(string configFile)
        {
            try
            {
                // 서비스에서 설치 폴더명을 읽어오는 코드
                string currentFolder = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Service1)).CodeBase);
                currentFolder = currentFolder.Replace("file:\\", "");

                XmlTextReader reader = new XmlTextReader(currentFolder + @"\" + configFile);
                reader.WhitespaceHandling = WhitespaceHandling.None;

                while (reader.Read())
                {
                    reader.MoveToContent();

                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (reader.Name == "SERVER")
                        {
                            this.serverPort = Convert.ToInt32(reader.GetAttribute("PORT"));
                        }
                        else if (reader.Name == "LAUNCHER")
                        {
                            ICSLauncherMap.SetLauncher(reader.GetAttribute("id"), reader.GetAttribute("path"));
                        }
                        break;
                    }
                }
            }
            catch
            {
                Console.WriteLine("[Error] Config File Load Fail. - " + configFile);

                return(false);
            }

            Console.WriteLine("Config File Read Success...");

            return(true);
        }
Exemplo n.º 2
0
        // 클라이언트로 부터 받은 패킷을 처리한다.
        private void Receive()
        {
            try
            {
                while (true)
                {
                    if (client.Connected == false)       // 클라이언트와 소켓이 끊겼을때
                    {
                        Close();
                        break;
                    }

                    string message = reader.ReadLine().Trim();
                    if (message == null)
                    {
                        continue;
                    }

                    char[]   ch    = { '#' };
                    string[] token = message.Split(ch);
                    switch (token[0])
                    {
                    case ICSPacket.C_REQ_LAUNCER_EXECUTE:
                    {
                        // 런처를 실행한다.
                        string path = ICSLauncherMap.GetLauncher(token[1]);
                        if (path != null)
                        {
                            ExecuteLauncher(path);
                        }
                    }
                    break;
                    }
                }
            }
            catch   // 클라이언트와 통신 실패 or 끊기
            {
                Close();
            }
        }