public ResourceTypes Execute()
 {
     //Console.WriteLine($"{Owner} : resources are available. Take resources : {needResources}");
     StateLogger.DrawState($"{Owner} : resources are available. Take resources : {needResources}");
     SemaphoreSlim.Release();
     return(needResources);
 }
Esempio n. 2
0
        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())
                {
                    StateLogger.SendAlertNotification(_states, _notificationRecipients);
                    _states.Clear();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// The Init
        /// </summary>
        /// <returns>The <see cref="Task"/></returns>
        public async Task Init()
        {
            _notificationRecipients = System.Configuration.ConfigurationManager.AppSettings["To"].ToString();

            _logger = new Logger(
                (_mode == MODE.Console)
                ? MODE.Console
                : MODE.Background
                );
            await Task.Run(() => BeginPolling());
        }
Esempio n. 4
0
 public override void Run()
 {
     while (Working)
     {
         Thread.Sleep(MinCharmTime + random.Next() % Interval);
         int facId = random.Next() % factories.Length;
         //Console.WriteLine($"{Name} : casts a charm to {factories[facId].Name}");
         factories[facId].AddCharm();
         // Console.WriteLine($"{Name} : Finished");
         StateLogger.DrawState($"{Name} : casted a charm to {factories[facId].Name}");
     }
 }
Esempio n. 5
0
 public override void Run()
 {
     while (Working)
     {
         Thread.Sleep(MinCharmTime + random.Next() % Interval);
         //Console.WriteLine($"{Name} : start taking off the charms");
         foreach (var fac in factories)
         {
             fac.RemoveCharm();
         }
         //Console.WriteLine($"{Name} : Finished");
         StateLogger.DrawState($"{Name} : removed the charms");
     }
 }
Esempio n. 6
0
        private static void SetUp()
        {
            factories = new Factory[]
            {
                new Factory("Pb Factory", LibSettings.Default.PbProductionTime, LibSettings.Default.ProductionInterval),
                new Factory("S Factory", LibSettings.Default.SProductionTime, LibSettings.Default.ProductionInterval),
                new Factory("Hg Factory", LibSettings.Default.HgProductionTime, LibSettings.Default.ProductionInterval)
            };
            StateLogger.SetFactories(factories);
            Storehouse.Hg_Factory = factories[HgFacId];
            Storehouse.S_Factory  = factories[SFacId];
            Storehouse.Pb_Factory = factories[PbFacId];

            wizards = new List <Wizard>();
            for (int i = 0; i < LibSettings.Default.EvilWizardsCount; i++)
            {
                wizards.Add(new EvilWizard(factories, LibSettings.Default.CastEvilCharmTime, LibSettings.Default.CharmInterval));
            }
            for (int i = 0; i < LibSettings.Default.GoodWizardsCount; i++)
            {
                wizards.Add(new GoodWizard(factories, LibSettings.Default.CastGoodCharmTime, LibSettings.Default.CharmInterval));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// The Main
        /// </summary>
        /// <param name="args">The <see cref="string[]"/></param>
        public static void Main(string[] args)
        {
            string runMode       = String.IsNullOrEmpty(ConfigurationManager.AppSettings["mode"]) ? "console" : "background";
            var    intervalValue = ConfigurationManager.AppSettings["PollingInterval"];

            intervalValue = String.IsNullOrEmpty(intervalValue) ? "20000" : intervalValue;
            _interval     = int.Parse(intervalValue);

            _logger = new Logger(
                GetMode(runMode)
                );
            try
            {
                Task.WaitAll(Task.Run(async() => await BeginMonitoring(_interval, GetMode(runMode))));
            }
            catch (System.AggregateException ex)
            {
                ex.Flatten().InnerExceptions.ToList().ForEach(exception =>
                {
                    Console.WriteLine(ex.Message + " - " + ex.InnerException);
                    Console.ReadLine();
                });
            }
        }
Esempio n. 8
0
 protected override void LogEndWork()
 {
     base.LogEndWork();
     StateLogger.FinishB();
 }