public void Starter()
        {
            var simulation = new Simulation();

            var patientReset = new PatientReset();
            var statusReset  = new StatusReset();
            var writer       = new KrankenHausStatisticsWriter();
            var logger       = new KrankenhausStatisticsFileLogger();

            simulation.RecoveredAndDeathEvent += writer.TotalDeathAndRecoveredOutput;
            simulation.RecoveredAndDeathEvent += logger.RecoveredAndDeathsStatistics;
            simulation.MovedEvent             += logger.MovedOutput;
            simulation.MovedEvent             += writer.MovedStatisticOutput;

            //trådarna för simulationen
            var t1 = new Thread(simulation.Add30Patients);
            var t2 = new Thread(simulation.MovePatients);
            var t3 = new Thread(() => RandomizePatientsIllnessLevel(new Random()));
            var t4 = new Thread(simulation.UpdatePatientStatus);

            t1.Start();
            t1.Join(); //låter t1 köra klart innan de andra anropas


            t2.Start();
            t3.Start();
            t4.Start();
            t4.Join();
        }
        static void Main(string[] args)
        {
            var simulation    = new Simulation();
            var patientReset  = new PatientReset();
            var statusReset   = new StatusReset();
            var logger        = new KrankenhausStatisticsFileLogger();
            var statusCreator = new StatusCreator();

            logger.ClearFile();
            statusReset.ResetAll();
            patientReset.Reset();
            statusCreator.CreateAll();

            DateTime startTime = DateTime.Now;

            Console.WriteLine("simulating ... \n");

            simulation.Starter();
            var runTime = CalculateRuntime(startTime);


            Console.WriteLine($"\napplication runtime: {runTime}");
            Console.ReadLine();
        }
Esempio n. 3
0
        /// <summary>
        /// Set status of the application.
        /// </summary>
        /// <param name="type">Type of the status.</param>
        /// <param name="text">Text to be set.</param>
        /// <param name="resetTime">Reset time until status will be 'Ready'.</param>
        public static void Set(StatusType type, StatusReset resetTime, string text, params string[] parameters)
        {
            if (Changing != null)
            {
                StatusChangedEventArgs e = new StatusChangedEventArgs(mainForm.statusLabel.Text, oldType, text, type);
                Changed(null, e);

                if (e.Handled == true)
                {
                    return;
                }
            }

            if (readyTimer.Enabled == true)
            {
                readyTimer.Stop();
            }

            Color color = Color.Empty;

            switch (type)
            {
                case StatusType.Error:
                {
                    color = Color.FromArgb(170, 0, 0);
                    break;
                }
                case StatusType.Finish:
                {
                    color = Color.FromArgb(0, 94, 157);
                    break;
                }
                case StatusType.Info:
                {
                    color = Color.FromArgb(0, 122, 204);
                    break;
                }
                case StatusType.Warning:
                {
                    color = Color.FromArgb(202, 81, 0);
                    break;
                }
            }

            string oldText = mainForm.statusLabel.Text;
            oldType = type;

            mainForm.statusBar.BackColor = color;
            mainForm.statusLabel.Text = string.Format(text, parameters);

            if (Changed != null)
            {
                Changed(null, new StatusChangedEventArgs(oldText, oldType, mainForm.statusLabel.Text, type));
            }

            if (resetTime != StatusReset.None)
            {
                int interval = 0;

                switch (resetTime)
                {
                    case StatusReset.OneSecond:
                    {
                        interval = 1000;
                        break;
                    }
                    case StatusReset.ThreeSeconds:
                    {
                        interval = 3000;
                        break;
                    }
                    case StatusReset.FiveSeconds:
                    {
                        interval = 5000;
                        break;
                    }
                }

                readyTimer.Stop();
                readyTimer.Interval = interval;
                readyTimer.Start();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Set status of the application.
        /// </summary>
        /// <param name="type">Type of the status.</param>
        /// <param name="text">Text to be set.</param>
        /// <param name="resetTime">Reset time until status will be 'Ready'.</param>
        public static void Set(StatusType type, StatusReset resetTime, string text, params string[] parameters)
        {
            if (Changing != null)
            {
                StatusChangedEventArgs e = new StatusChangedEventArgs(mainForm.statusLabel.Text, oldType, text, type);
                Changed(null, e);

                if (e.Handled == true)
                {
                    return;
                }
            }

            if (readyTimer.Enabled == true)
            {
                readyTimer.Stop();
            }

            Color color = Color.Empty;

            switch (type)
            {
            case StatusType.Error:
            {
                color = Color.FromArgb(170, 0, 0);
                break;
            }

            case StatusType.Finish:
            {
                color = Color.FromArgb(0, 94, 157);
                break;
            }

            case StatusType.Info:
            {
                color = Color.FromArgb(0, 122, 204);
                break;
            }

            case StatusType.Warning:
            {
                color = Color.FromArgb(202, 81, 0);
                break;
            }
            }

            string oldText = mainForm.statusLabel.Text;

            oldType = type;

            mainForm.statusBar.BackColor = color;
            mainForm.statusLabel.Text    = string.Format(text, parameters);

            if (Changed != null)
            {
                Changed(null, new StatusChangedEventArgs(oldText, oldType, mainForm.statusLabel.Text, type));
            }

            if (resetTime != StatusReset.None)
            {
                int interval = 0;

                switch (resetTime)
                {
                case StatusReset.OneSecond:
                {
                    interval = 1000;
                    break;
                }

                case StatusReset.ThreeSeconds:
                {
                    interval = 3000;
                    break;
                }

                case StatusReset.FiveSeconds:
                {
                    interval = 5000;
                    break;
                }
                }

                readyTimer.Stop();
                readyTimer.Interval = interval;
                readyTimer.Start();
            }
        }