Ejemplo n.º 1
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);
                });
            }
        }
Ejemplo n.º 2
0
        public static async Task BeginMonitoring(int interval)
        {
            List <Resource> resources = new List <Resource>();
            var             urls      = System.Configuration.ConfigurationManager.AppSettings["resources"].Split(',').ToList();


            urls.ForEach(s => resources.Add(new ResourceFactory().GetResource(s)));


            try {
                StateMonitor sm = new StateMonitor(_interval, resources);
                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
                });
                // StateLogger.SendAlertNotification(st, "*****@*****.**");
            }
        }