Ejemplo n.º 1
0
        /// <summary>
        /// Connects to the server and gets the logs
        /// Adds the command according to the message enum
        /// </summary>
        public void ConnectToServer()
        {
            Console.WriteLine("got to log");
            string info = c.WriteConnection("2");

            Console.WriteLine("read " + info);
            IList <string> eachPath = info.Split('*').Reverse().ToList <string>();

            for (int i = 0; i < eachPath.Count; i++)
            {
                IList <string> each = eachPath[i].Split(',').Reverse().ToList <string>();
                if (each.Count == 2)
                {
                    lock (lockObj)
                    {
                        Int32.TryParse(each[1], out int x);
                        if (x == (int)MessageTypeEnum.INFO)
                        {
                            ListCommands.Add(new CommandInfo(MessageTypeEnum.INFO.ToString(), each[0]));
                        }
                        if (x == (int)MessageTypeEnum.FAIL)
                        {
                            ListCommands.Add(new CommandInfo(MessageTypeEnum.FAIL.ToString(), each[0]));
                        }
                        if (x == (int)MessageTypeEnum.WARNING)
                        {
                            ListCommands.Add(new CommandInfo(MessageTypeEnum.WARNING.ToString(), each[0]));
                        }
                    }
                }
            }
            //creates a new thread to always be listening for connection
            Thread t = new Thread(() => c.ReadConnection());

            t.Start();
        }