Exemplo n.º 1
0
        public void Th_Ping_SitePing()
        {
            Worker wk = new Worker();

            wk.AddSite(Constantes.GoogleDNS_IP);
            wk.AddSite(Constantes.NoneExistingSite);


            wk.Parameter.TimeIntervalSec = 1;

            Thread.Sleep(10000);
            wk.Stop();

            SiteParameters siteGoogle      = wk.GetSiteByName(Constantes.GoogleDNS_IP);
            SiteParameters siteNonExisting = wk.GetSiteByName(Constantes.NoneExistingSite);


            Assert.AreEqual(siteGoogle.OffLineTime, new TimeSpan(), "Not offtime possible for 8.8.8.8");
            Assert.AreEqual(siteNonExisting.OffLineTime, siteNonExisting.SurveyTime, "Offtime must be egal to Suvey time for none existing site");
        }
Exemplo n.º 2
0
        public void Th_Ping_SitePingInterval()
        {
            Worker wk = new Worker();

            wk.AddSite(Constantes.GoogleDNS2_IP);

            Stopwatch timeElapsed = Stopwatch.StartNew();

            wk.Parameter.TimeIntervalSec = 1;

            Thread.Sleep(10050);
            wk.Stop();

            SiteParameters site = wk.GetSiteByName(Constantes.GoogleDNS2_IP);

            if ((site.SurveyTime - timeElapsed.Elapsed) > TimeSpan.FromSeconds(0.5))
            {
                Assert.Fail("Difference too importante > 0.5 sec");
            }

            wk.RemoveSite(site.SiteName);
        }
Exemplo n.º 3
0
        private static async Task Run(string pp)
        {
            var p = await SiteParameters.LoadAsync(pp);

            if (p == null)
            {
                p = SiteParameters.GenerateInitial();

                if (pp == null)
                {
                    pp = "param.json";
                }
                await SiteParameters.SaveAsync(pp, p);

                return;
            }

            var baseUri = new Uri("http://temp/");

            FindAll(p.Path, baseUri, p.IgnorePaths);

            foreach (var root in p.RootFiles)
            {
                var rootUri = new Uri(baseUri, root);
                _findPath.Add(rootUri.LocalPath.ToLower());
                _existsPathes.Remove(rootUri.LocalPath.ToLower());
                _checkQueue.Enqueue(rootUri);
            }

            var checkPatterns = p.CheckPatterns.Select(t => new Regex(t)).ToArray();

            while (true)
            {
                if (_checkQueue.Count == 0)
                {
                    break;
                }
                var targetUri = _checkQueue.Dequeue();

                IEnumerable <string> refPathes = null;
                if (targetUri.LocalPath[targetUri.LocalPath.Length - 1] != '/')
                {
                    var tp = targetUri.ToPath(p.Path);
                    if (!checkPatterns.Any(t => t.Match(Path.GetFileName(tp)).Success))
                    {
                        continue;
                    }

                    try { refPathes = await LoadRefPathes(tp); }
                    catch { continue; }
                }
                else
                {
                    foreach (var defaultName in p.DefaultNames)
                    {
                        var nextUri  = new Uri(targetUri, defaultName);
                        var nextPath = nextUri.ToPath(p.Path);
                        if (File.Exists(nextPath))
                        {
                            refPathes = await LoadRefPathes(nextPath);

                            break;
                        }
                    }
                    if (refPathes == null)
                    {
                        refPathes = Enumerable.Empty <string>();
                    }
                }

                foreach (var s in refPathes)
                {
                    if (s.StartsWith("mailto:"))
                    {
                        continue;
                    }

                    var su = new Uri(targetUri, s);
                    if (su.Host != "temp")
                    {
                        continue;
                    }

                    var lp = su.LocalPath.ToLower();
                    if (_findPath.Add(lp))
                    {
                        _existsPathes.Remove(lp);
                        _checkQueue.Enqueue(su);
                    }
                }
            }

            using (var writer = File.CreateText("out.txt"))
            {
                var ips = p.IgnorePatterns.Select(t => new Regex(t)).ToArray();

                foreach (var item in _existsPathes)
                {
                    if (ips.Any(t => t.Match(item).Success))
                    {
                        continue;
                    }
                    await writer.WriteLineAsync(item);
                }
            }
        }
Exemplo n.º 4
0
 public Seismicity(int value, string description, SiteParameters siteParameters)
     : base(value, description)
 {
     SiteParameters = siteParameters;
 }