private void CheckHttp(CheckingResult check)
        {
            _cancelTokenSource.Token.ThrowIfCancellationRequested();

            string address;

            if (_port != 0)
            {
                var adresswithport = string.Format("{0}:{1}", check.Ip, _port);
                address = string.Format(Settings.Default.HttpCheckAddressFormat, adresswithport);
            }
            else
            {
                address = string.Format(Settings.Default.HttpCheckAddressFormat, check.Ip);
            }

            using (var client = new HttpClient())
            {
                try
                {
                    var task = client.GetAsync(address, _cancelTokenSource.Token);
                    task.Wait(_cancelTokenSource.Token);
                    check.HttpStatusCode = task.Result.StatusCode;
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    check.Error = ex.Message;
                }
            }
        }
        private void CheckAvailability(CheckingResult check)
        {
            _cancelTokenSource.Token.ThrowIfCancellationRequested();

            var ping = new Ping();

            try
            {
                var task = ping.SendPingAsync(check.Ip);
                task.Wait(_cancelTokenSource.Token);
                check.IPStatus = task.Result.Status;

                if (check.IPStatus == IPStatus.Success)
                {
                    lock (_httpList)
                    {
                        _httpList.Add(check);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                check.Error = ex.Message;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            CheckingResult result = Controller.CheckString(textBox1.Text);

            textBox2.Text = null;
            textBox3.Text = null;
            textBox4.Text = null;
            if (result.Error == null)
            {
                textBox2.Text = "Список идентификаторов:\r\n\r\n";
                for (int i = 0; i < result.Vars.Count; ++i)
                {
                    textBox2.Text += result.Vars.ElementAt(i) + "\r\n";
                }
                textBox3.Text += "Список констант:\r\n\r\n";
                for (int i = 0; i < result.Consts.Count; ++i)
                {
                    textBox3.Text += result.Consts.ElementAt(i) + "\r\n";
                }
            }
            else
            {
                textBox4.Text = result.Error.Description;
                textBox1.Focus();
                textBox1.SelectionStart = result.Error.Pos;
            }
        }
Exemple #4
0
        private void FillQueue(long start, long end)
        {
            for (long i = start; i <= end; i++)
            {
                _cancelTokenSource.Token.ThrowIfCancellationRequested();

                var item = new CheckingResult {
                    Ip = IpConverter.LongToString(i)
                };
                _result.Add(item);
            }
        }
        private void CreateCheckingResult(long ip)
        {
            _cancelTokenSource.Token.ThrowIfCancellationRequested();

            var item = new CheckingResult {
                Ip = IpConverter.LongToString(ip)
            };

            lock (_result)
            {
                _result.Add(item);
            }
        }
        public static string CheckEntries(string apiUrl, string apiKey)
        {
            var            uri        = BuildUrl(apiUrl, apiKey, "account_view");
            var            response   = Client.DownloadString(uri);
            CheckingResult result     = new CheckingResult();
            var            serializer = new XmlSerializer(result.GetType());

            using (TextReader reader = new StringReader(response))
            {
                result = serializer.Deserialize(reader) as CheckingResult;
            }
            if (result.ResultCode == 1)
            {
                return(result.Account);
            }
            throw new Exception("Credentials for Active Campaign are not valid");
        }