Esempio n. 1
0
        /// <summary>
        /// The BeginPolling
        /// </summary>
        private void BeginPolling()
        {
            while (ResourcePoller.IsNetworkAvailable())
            {
                System.Threading.Thread.Sleep(this._interval);
                foreach (var resource in urls)
                {
                    ResourcePoller poller = new ResourcePoller(resource, this._interval);
                    Console.WriteLine("Currently Polling:{0}---{1} ", resource.Name, resource.GetAbsoluteUri());
                    Task <State> pollingTask = poller.PollAsync();

                    pollingTask.ContinueWith(t =>
                    {
                        StringBuilder errMsgs = new StringBuilder();
                        Console.WriteLine("Currently Polling:{0}---{1} ", resource.Name, resource.GetAbsoluteUri());
                        ProcessTask(t, resource, errMsgs);
                    });
                }

                if (_states.Any())
                {
                    _states.ToList().ForEach(x =>
                    {
                        _logger.Log(x, x.Status);
                    });

                    _states.Clear();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The BeginMonitoring
        /// </summary>
        /// <param name="interval">The <see cref="int"/></param>
        /// <returns>The <see cref="Task"/></returns>
        public static async Task BeginMonitoring(int interval, MODE mode)
        {
            var _recipients = ConfigurationManager.AppSettings["To"].ToString();
            var _resources  = ConfigurationManager.AppSettings["resources"];

            _resources = String.IsNullOrEmpty(_resources) ? "https://www.google.com" : _resources;
            List <Resource> resources = new List <Resource>();

            var urls = _resources.Split(',').ToList();

            urls.ForEach(s =>
            {
                Resource r = new ResourceFactory().GetResource(s);
                if (r.Exist())
                {
                    resources.Add(r);
                }
                else
                {
                    Console.WriteLine("Unrecognizable resource: {0} . Please verify config file", string.Concat(r.Name, "@", r.GetAbsoluteUri()));
                }
            });

            try
            {
                StateMonitor sm = new StateMonitor(_interval, resources, mode);
                await sm.Init();
            }
            catch (System.AggregateException ex)
            {
                Console.WriteLine("Program Crashed because of " + ex.Data);
                IList <State> st = new List <State>();
                st.Add(new State()
                {
                    Status = ex.StackTrace
                });

                st.ToList().ForEach(x =>
                {
                    _logger.Log(x, x.Status);
                });
            }
        }