Ejemplo n.º 1
0
        private void CheckList()
        {
            progressCount = 0;
            int   newCount = 0, lastCount = progressCount, tempCount;
            Timer timer;

            if (ProgressString != null)
            {
                timer = new Timer(_ =>
                {
                    ProgressString.Report(string.Format(progressFormat, progressCount, newCount));
                    tempCount = progressCount;
                    //CodeSite.Send("progressCount", tempCount - lastCount);
                    lastCount = tempCount;
                }, null, 1000, 1000);
            }
            else
            {
                timer = null;
            }

            try
            {
                ParallelOptions po = new ParallelOptions()
                {
                    CancellationToken = cts.Token, MaxDegreeOfParallelism = MaxDegreeOfParallelism
                };
                //CodeSite.Send("po.MaxDegreeOfParallelism", po.MaxDegreeOfParallelism);
                Parallel.ForEach(listIP, po, (uip) =>
                {
                    Interlocked.Increment(ref progressCount);
                    IPv4SSL ip = new IPv4SSL(uip);
                    WebCheck(ip);
                    if (ip.IsSSL)
                    {
                        Interlocked.Increment(ref newCount);
                        bcIPv4SSL.Add(ip);
                    }
                });
            }
            catch (OperationCanceledException ex)
            {
                ex.SendCodeSite("OperationCanceledException");
            }
            forceSave = true;
            while (forceSave)
            {
                //CodeSite.SendReminder("等待数据保存完毕");
                Thread.Sleep(1000);
            }
            CodeSite.Send("新增数据", newCount);

            if (timer != null)
            {
                timer.Dispose();
            }
        }
Ejemplo n.º 2
0
        private void CheckList()
        {
            int   newCount = 0, lastCount = progressCount, tempCount;
            Timer timer;

            if (ProgressString != null)
            {
                timer = new Timer(_ =>
                {
                    ProgressString.Report(string.Format(progressFormat, progressCount, newCount));
                    tempCount = progressCount;
                    //CodeSite.Send("progressCount", tempCount - lastCount);
                    lastCount = tempCount;
                }, null, 1000, 1000);
            }
            else
            {
                timer = null;
            }

            try
            {
                ParallelOptions po = new ParallelOptions()
                {
                    CancellationToken = cts.Token, MaxDegreeOfParallelism = MaxDegreeOfParallelism
                };
                //CodeSite.Send("po.MaxDegreeOfParallelism", po.MaxDegreeOfParallelism);
                Parallel.ForEach(listIP, po, (uip) =>
                {
                    Interlocked.Increment(ref progressCount);
                    int time;
                    if ((time = TryPing(uip, Timeout)) != -1)
                    {
                        Interlocked.Increment(ref newCount);
                        bcIPv4SSL.Add(new IPv4SSL(uip)
                        {
                            RoundtripTime = time
                        });
                    }
                });
            }
            catch (OperationCanceledException ex)
            {
                ex.SendCodeSite("OperationCanceledException");
            }
            CodeSite.Send("新增数据", newCount);

            if (timer != null)
            {
                timer.Dispose();
            }
        }
Ejemplo n.º 3
0
        public async Task TestProgressMethod()
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            var  progressReporter       = new ProgressString();
            Task firstTask = null;

            try
            {
                firstTask = Task.Factory.StartNew(() =>
                {
                    progressReporter.Report("4");
                }, cts.Token);

                await firstTask;
            }
            catch (Exception)
            {
            }

            Assert.AreEqual(progressReporter.GetProgressValue(), "4");
        }
Ejemplo n.º 4
0
 public void AssertNoErrorsReported()
 {
     Assert.IsFalse(ProgressString.ToLower().Contains("error"));
 }