예제 #1
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            LastError = string.Empty;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            try
            {
                int count = 0;
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty)
                    {
                        continue;
                    }


                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];

                    if (command == "ERROR")
                    {
                        LastError = line;
                    }
                    else if (command == "MSG")
                    {
                    }
                    count++;
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }


            if (LastError != string.Empty)
            {
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                LastUpdate = DateTime.Now;
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }

            UpdateInProgress = false;
        }
예제 #2
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            BZID           = string.Empty;
            LastError      = string.Empty;
            OK             = false;
            NameRegistered = false;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            try
            {
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty || LastError != string.Empty)
                    {
                        continue;
                    }

                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];
                    if (command.ToUpperInvariant() == "MSG:")
                    {
                        continue;
                    }

                    if (command == "TOKGOOD")
                    {
                        LastError      = string.Empty;
                        OK             = true;
                        NameRegistered = true;

                        string[] parts = cmdParts[1].Trim().Split(":".ToCharArray());

                        string[] desiredGroups = Groups.ToArray();

                        Groups.Clear();
                        foreach (string g in parts) // scan the groups to match the names up to the requested format, if not just blast it in.
                        {
                            string n = g;
                            foreach (var dg in desiredGroups)
                            {
                                if (dg.ToUpperInvariant() == g.ToUpperInvariant())
                                {
                                    n = dg;
                                }
                            }

                            Groups.Add(n);
                        }
                    }
                    else if (command == "TOKBAD")
                    {
                        NameRegistered = true;
                        LastError      = "Bad Token";
                        OK             = false;
                    }
                    else if (command == "UNK")
                    {
                        OK             = false;
                        NameRegistered = true;
                    }
                    else if (command == "BZID")
                    {
                        if (cmdParts.Length == 1)
                        {
                            LastError = "Malformed BZID";
                        }
                        else
                        {
                            string[] parts = cmdParts[1].Trim().Split(" ".ToCharArray());
                            if (parts.Length == 0)
                            {
                                LastError = "Malformed BZID";
                            }
                            else
                            {
                                BZID = parts[0];
                            }
                        }
                    }
                    else if (command == "ERROR")
                    {
                        LastError = "ERROR " + cmdParts[1].Trim();
                    }
                    else if (command == "NOTICE")
                    {
                        LastError = "NOTICE " + cmdParts[1].Trim();
                    }
                    else
                    {
                    }
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }

            if (OK && BZID == string.Empty)
            {
                OK        = false;
                LastError = "Missing BZID";
            }

            if (LastError != string.Empty)
            {
                OK = false;

                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                OK = true;
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }
        }
예제 #3
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            LastError = string.Empty;
            LastToken = string.Empty;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            ServerList.Clear();

            try
            {
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty)
                    {
                        continue;
                    }

                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];
                    if (command == "TOKEN")
                    {
                        LastToken = cmdParts[1].Trim();
                    }
                    else if (command == "NOTOK")
                    {
                        LastError = "No Token " + cmdParts[1].Trim();
                    }
                    else if (command == "ERROR")
                    {
                        LastError = "ERROR " + cmdParts[1].Trim();
                    }
                    else if (command == "NOTICE")
                    {
                        LastError = "NOTICE " + cmdParts[1].Trim();
                    }
                    else
                    {
                        ListServerData data = new ListServerData();

                        string[] dataParts = line.Split(" ".ToCharArray(), 5);
                        data.Name    = dataParts[0];
                        data.Version = dataParts[1];
                        data.Info.ReadFromString(dataParts[2]);
                        IPAddress.TryParse(dataParts[3], out data.Address);

                        data.Host = dataParts[3];
                        data.Port = 5154;
                        if (dataParts[0].Contains(":"))
                        {
                            string[] portParts = dataParts[0].Split(":".ToCharArray(), 2);

                            data.Host = portParts[0];
                            int.TryParse(portParts[1], out data.Port);
                        }

                        if (dataParts.Length > 4)
                        {
                            data.Description = dataParts[4];
                        }

                        ServerList.Add(data);
                    }
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }


            if (LastError != string.Empty)
            {
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }
        }
예제 #4
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            LastError = string.Empty;
            LastToken = string.Empty;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            try
            {
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty)
                    {
                        continue;
                    }

                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];
                    if (command == "TOKEN")
                    {
                        LastToken = cmdParts[1].Trim();
                    }
                    else if (command == "NOTOK")
                    {
                        LastError = "No Token " + cmdParts[1].Trim();
                    }
                    else if (command == "ERROR")
                    {
                        LastError = "ERROR " + cmdParts[1].Trim();
                    }
                    else if (command == "NOTICE")
                    {
                        LastError = "NOTICE " + cmdParts[1].Trim();
                    }
                    else
                    {
                    }
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }


            if (LastError != string.Empty)
            {
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }
        }