Exemplo n.º 1
0
        static void Main()
        {
            ServiceConfiguration serviceConfiguration = new ServiceConfiguration();
            IRepository          repository           = serviceConfiguration.ConfigureRepository();
            var serviceCheck = new ServiceCheck(repository);

            using (ServiceHost serviceHost = new ServiceHost(serviceCheck))
            {
                try
                {
                    serviceHost.Open();
                    if (serviceHost.State == CommunicationState.Opened)
                    {
                        Console.WriteLine($"Service {serviceHost.Description.Name} started on {serviceHost.Description.Endpoints[0].Address}");
                        Console.WriteLine($"Repository: {repository.Name}");
                        Console.WriteLine("To stop service press any key...");
                        Console.ReadKey(true);
                        Console.WriteLine($"{serviceHost.Description.Name} stopped");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            logger = new Logger();

            logger.LogInfo("Program started");

            NetworkChecks networkChecks = new NetworkChecks();

            serviceCheck = new ServiceCheck();

            applicationHelpers = new ApplicationHelpers();

            networkChecks.WaitForNetwork();

            CheckIfServiceAndProcessIsRunning();

            if (serviceCheck.ServiceIsRunning(ServiceCheck.MeatMasterServiceName))
            {
                logger.LogInfo("Services are running.");
            }

            CancelStartupAndCloseDown();

            Process.Start("shutdown.exe", "-r -t 0");
        }
        public Task SendAsync(string name, int status, int?timestamp = null, string hostname = null, string[] tags = null, string serviceCheckMessage = null, bool truncateIfTooLong = false)
        {
            truncateIfTooLong = truncateIfTooLong || TruncateIfTooLong;
            var task = SendAsync(ServiceCheck.GetCommand(name, status, timestamp, hostname, _constantTags, tags, serviceCheckMessage, truncateIfTooLong));

            _optionalTelemetry?.OnServiceCheckSent();
            return(task);
        }
Exemplo n.º 4
0
        public void it_contains_the_given_value(ServiceCheck checkValue, int expectedValue)
        {
            var logs        = new List <string>();
            var contextMock = new Mock <ILambdaLogger>(MockBehavior.Strict);

            contextMock.Setup(logger => logger.LogLine(It.IsAny <string>()))
            .Callback((string s) => logs.Add(s));

            var metrics = new DogMetrics(contextMock.Object);

            metrics.Check("mystat", checkValue);

            Assert.True(logs.Count == 1);
            Assert.True(logs.First().Contains($"|{expectedValue}|"),
                        $@"Expected the given stat value: ""|{expectedValue}|"" but couldn't find it in <{logs.First()}>");
        }
        public void WhenNodeServerIsStarted()
        {
            var nodeServer  = ConfigurationManager.AppSettings[InputData.UIServer];
            var command     = $"cd {DirectorySetup.GetPath(ConfigurationManager.AppSettings[InputData.UIServerFolder])} & node {nodeServer}";
            var execution   = new CommandExecution();
            var portCorrect = int.TryParse(ConfigurationManager.AppSettings[InputData.Port], out int port);
            var host        = ConfigurationManager.AppSettings[InputData.Host];

            if (!ServiceCheck.IsListening(host, port))
            {
                ScenarioContext.Current[ContextKey.Log] = execution.Execute(command, false);
            }
            else
            {
                Assert.Fail("The server is already running");
            }
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            ServiceCheck         serviceCheck       = new ServiceCheck();
            ApplicationHelpers   applicationHelpers = new ApplicationHelpers();
            MeatMaster2Functions functions          = new MeatMaster2Functions();

            Functions.logger.LogInfo("Program is starting.");

            serviceCheck.WaitForServiceToStart(ServiceCheck.ServiceManagerServiceName, 10);

            WaitHelpers.WaitFor(() => applicationHelpers.ProcessIsRunning(MeatMaster2UiItems.Mm2ProcessName),
                                TimeSpan.FromMinutes(15));

            DatabaseHelpers.DeleteLastDataMaintenanceDate();

            functions.CancelStartup();

            functions.CloseDown(false);

            applicationHelpers.RestartWindows();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Send a service check
 /// </summary>
 public void Send(string name, int status, int?timestamp = null, string hostname = null, string[] tags = null, string serviceCheckMessage = null, bool truncateIfTooLong = false)
 {
     truncateIfTooLong = truncateIfTooLong || TruncateIfTooLong;
     Send(ServiceCheck.GetCommand(name, status, timestamp, hostname, _constantTags, tags, serviceCheckMessage, truncateIfTooLong));
 }
 public void Add(string name, int status, int?timestamp = null, string hostname = null, string[] tags = null, string serviceCheckMessage = null, bool truncateIfTooLong = false)
 {
     truncateIfTooLong = truncateIfTooLong || TruncateIfTooLong;
     _commands.Add(ServiceCheck.GetCommand(name, status, timestamp, hostname, _constantTags, tags, serviceCheckMessage, truncateIfTooLong));
     _optionalTelemetry?.OnServiceCheckSent();
 }
Exemplo n.º 9
0
        public void Check(string statName, ServiceCheck value, double sampleRate = 1, params StatTag[] tags)
        {
            var enumVal = (int)value;

            LogMetric(statName, CheckStatType, enumVal.ToString(), sampleRate, tags);
        }
Exemplo n.º 10
0
        private static ServiceRegistration CreateConsulAgentRegistration(this IConveyBuilder builder,
                                                                         ConsulOptions options)
        {
            var enabled       = options.Enabled;
            var consulEnabled = Environment.GetEnvironmentVariable("CONSUL_ENABLED")?.ToLowerInvariant();

            if (!string.IsNullOrWhiteSpace(consulEnabled))
            {
                enabled = consulEnabled == "true" || consulEnabled == "1";
            }

            if (!enabled)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(options.Address))
            {
                throw new ArgumentException("Consul address can not be empty.",
                                            nameof(options.PingEndpoint));
            }

            builder.Services.AddHttpClient <IConsulService, ConsulService>(c => c.BaseAddress = new Uri(options.Url));
            builder.Services.AddHostedService <ConsulHostedService>();

            var serviceId = string.Empty;

            using (var serviceProvider = builder.Services.BuildServiceProvider())
            {
                serviceId = serviceProvider.GetRequiredService <IServiceId>().Id;
            }

            var registration = new ServiceRegistration
            {
                Name              = options.Service,
                Id                = $"{options.Service}:{serviceId}",
                Address           = options.Address,
                Port              = options.Port,
                Tags              = options.Tags,
                Meta              = options.Meta,
                EnableTagOverride = options.EnableTagOverride,
                Connect           = options.Connect?.Enabled == true ? new Connect() : null
            };

            if (!options.PingEnabled)
            {
                return(registration);
            }

            var pingEndpoint = string.IsNullOrWhiteSpace(options.PingEndpoint) ? string.Empty :
                               options.PingEndpoint.StartsWith("/") ? options.PingEndpoint : $"/{options.PingEndpoint}";

            if (pingEndpoint.EndsWith("/"))
            {
                pingEndpoint = pingEndpoint.Substring(0, pingEndpoint.Length - 1);
            }

            var scheme = options.Address.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)
                ? string.Empty
                : "http://";
            var check = new ServiceCheck
            {
                Interval = ParseTime(options.PingInterval),
                DeregisterCriticalServiceAfter = ParseTime(options.RemoveAfterInterval),
                Http = $"{scheme}{options.Address}{(options.Port > 0 ? $":{options.Port}" : string.Empty)}" +
                       $"{pingEndpoint}"
            };

            registration.Checks = new[] { check };

            return(registration);
        }
Exemplo n.º 11
0
        private static ServiceRegistration CreateConsulAgentRegistration(this IConveyBuilder builder,
                                                                         ConsulOptions options)
        {
            var enabled       = options.Enabled;
            var consulEnabled = Environment.GetEnvironmentVariable("CONSUL_ENABLED")?.ToLowerInvariant();

            if (!string.IsNullOrWhiteSpace(consulEnabled))
            {
                enabled = consulEnabled == "true" || consulEnabled == "1";
            }

            if (!enabled)
            {
                return(null);
            }

            builder.Services.AddHttpClient <IConsulService, ConsulService>(c => c.BaseAddress = new Uri(options.Url));
            builder.Services.AddHostedService <ConsulHostedService>();

            var serviceId = string.Empty;

            using (var serviceProvider = builder.Services.BuildServiceProvider())
            {
                serviceId = serviceProvider.GetRequiredService <IServiceId>().Id;
            }

            var registration = new ServiceRegistration
            {
                Name              = options.Service,
                Id                = $"{options.Service}:{serviceId}",
                Address           = options.PreferIpAddress ? options.IpAddress : options.HostName,
                Port              = options.Port,
                Tags              = options.Tags,
                Meta              = options.Meta,
                EnableTagOverride = options.EnableTagOverride,
                Connect           = options.Connect?.Enabled == true ? new Connect() : null
            };

            if (!options.HealthCheck.Enabled)
            {
                return(registration);
            }

            var pingEndpoint = string.IsNullOrWhiteSpace(options.HealthCheck.HealthCheckPath) ? string.Empty :
                               options.HealthCheck.HealthCheckPath.StartsWith("/") ? options.HealthCheck.HealthCheckPath : $"/{options.HealthCheck.HealthCheckPath}";

            if (pingEndpoint.EndsWith("/"))
            {
                pingEndpoint = pingEndpoint.Substring(0, pingEndpoint.Length - 1);
            }

            var check = new ServiceCheck
            {
                Interval = $"{options.HealthCheck.HealthCheckInterval}s",
                DeregisterCriticalServiceAfter = $"{options.HealthCheck.HealthCheckCriticalTimeout}m",
                Timeout       = $"{options.HealthCheck.HealthCheckTimeout}s",
                Http          = $"{options.GetServiceAddress()}{pingEndpoint}",
                TLSSkipVerify = options.HealthCheck.HealthCheckTlsSkipVerify,
                Method        = options.HealthCheck.HealthCheckMethod.ToUpper()
            };

            registration.Checks = new[] { check };

            return(registration);
        }
        public static void Run()
        {
            Course                         c1            = new Course();
            Assignment                     a1            = new Assignment();
            Trainer                        tr1           = new Trainer();
            Student                        s1            = new Student();
            StudentsPerCourse              sPC           = new StudentsPerCourse();
            TrainersPerCourse              tPC           = new TrainersPerCourse();
            AssignmentsPerCourse           aPC           = new AssignmentsPerCourse();
            AssignmetsPerStudent           aPS           = new AssignmetsPerStudent();
            AssignmentsPerCoursePerStudent aPCPS         = new AssignmentsPerCoursePerStudent();
            StudentsWithMoreThanOneCourse  sMTOC         = new StudentsWithMoreThanOneCourse();
            ServiceGet                     serviseGet    = new ServiceGet();
            ServiceInsert                  serviseInsert = new ServiceInsert();
            ServiceCheck                   serviceCheck  = new ServiceCheck();

            string userInput2 = "", userInput3 = "", userInput5 = "";
            int    selectCourse;


            do
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine();
                Console.WriteLine("\tWellcome to Private School! What would you like to do?");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine("\t0. Exit.");
                Console.WriteLine("\t1. Course.");
                Console.WriteLine("\t2. Assignment.");
                Console.WriteLine("\t3. Trainer.");
                Console.WriteLine("\t4. Student.");


                Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                userInput2 = Console.ReadLine();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\n\t=================================================================================\n");
                Console.ForegroundColor = ConsoleColor.White;

                //UserInput2 = 1, normal mode, Course--------------------------------------------------------------------------------------------------------------------
                if (userInput2 == "1")
                {
                    do
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine();
                        Console.WriteLine("\tYou are in the course mode! What would you like to do?");
                        Console.WriteLine();
                        Console.ForegroundColor = ConsoleColor.White;

                        Console.WriteLine("\t0. Exit.");
                        Console.WriteLine("\t1. New course.");
                        Console.WriteLine("\t2. Output list with all courses.");
                        Console.WriteLine("\t3. Add students at courses.");
                        Console.WriteLine("\t4. Output students per course.");
                        Console.WriteLine("\t5. Add trainers at courses.");
                        Console.WriteLine("\t6. Output trainers per course.");
                        Console.WriteLine("\t7. Add assignments at courses.");
                        Console.WriteLine("\t8. Output assignments per course.");
                        Console.WriteLine("\t9. Go back.");

                        Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                        userInput3 = Console.ReadLine();

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\n\t=================================================================================\n");
                        Console.ForegroundColor = ConsoleColor.White;

                        //UserInput3 = 1, normal mode, New course-------------------------------------------------------------------------------------------------------
                        if (userInput3 == "1")
                        {
                            serviseInsert.InsertCourse();
                        }
                        //UserInput3 = 2, normal mode, List of courses-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "2")
                        {
                            c1.ListOfCoursecOutput(serviseGet.GetAllCourses());
                            MyStaticClass.PressKeyToContinue();
                        }
                        //UserInput3 = 3, normal mode, Add students at courses-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "3")
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine();
                            Console.WriteLine("\tSelect the number of course that you want to add students.");
                            Console.WriteLine();
                            Console.ForegroundColor = ConsoleColor.White;


                            List <Course> allCourses = serviseGet.GetAllCourses();
                            c1.ListOfCoursecOutput(allCourses);
                            Console.WriteLine();

                            do
                            {
                                Console.Write("\tEnter the apropriate number : ");
                                selectCourse = MyStaticClass.InputTryToConvertToInt();
                            } while (selectCourse <= 0 || selectCourse > allCourses.Count);


                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n\t=================================================================================\n");
                            Console.ForegroundColor = ConsoleColor.White;
                            do
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine("\tSelect how you want to add a student.");
                                Console.ForegroundColor = ConsoleColor.White;

                                Console.WriteLine();
                                Console.WriteLine("\t1. Add a new student.");
                                Console.WriteLine("\t2. Add an excisting student.");
                                Console.WriteLine("\t9. Go back.");

                                Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                                userInput5 = Console.ReadLine();

                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("\n\t=================================================================================\n");
                                Console.ForegroundColor = ConsoleColor.White;

                                if (userInput5 == "1")
                                {
                                    serviseInsert.InsertStudent();
                                    List <Student> students = serviseGet.GetAllStudents();
                                    serviseInsert.InsertStudentAtCourse((int)students[students.Count - 1].Sid, (int)allCourses[selectCourse - 1].Cid);
                                }
                                else if (userInput5 == "2")
                                {
                                    string addAnotherStudentfromList;
                                    bool   notSuccededAdd = true;
                                    do
                                    {
                                        Console.ForegroundColor = ConsoleColor.Yellow;
                                        Console.WriteLine();
                                        Console.WriteLine("\tSelect the number of student.");
                                        Console.WriteLine();
                                        Console.ForegroundColor = ConsoleColor.White;

                                        List <Student> allStudents = serviseGet.GetAllStudents();
                                        s1.ListOfStudentsOutput(allStudents);

                                        do
                                        {
                                            int userSelectStudent = 0;
                                            try
                                            {
                                                Console.WriteLine();
                                                Console.Write("\tEnter a propriate number : ");

                                                userSelectStudent = Convert.ToInt32(Console.ReadLine());
                                                if (userSelectStudent >= 0 && userSelectStudent <= allStudents.Count)
                                                {
                                                    if (serviceCheck.ExistStudentsPerCourse((int)allStudents[userSelectStudent - 1].Sid, (int)allCourses[selectCourse - 1].Cid))
                                                    {
                                                        Console.ForegroundColor = ConsoleColor.Red;
                                                        Console.WriteLine();
                                                        Console.WriteLine("\tThe student already exist in the course.");
                                                        Console.ForegroundColor = ConsoleColor.White;
                                                        notSuccededAdd          = true;
                                                    }
                                                    else
                                                    {
                                                        serviseInsert.InsertStudentAtCourse((int)allStudents[userSelectStudent - 1].Sid, (int)allCourses[selectCourse - 1].Cid);
                                                        notSuccededAdd = false;
                                                    }
                                                }
                                                else
                                                {
                                                    Console.ForegroundColor = ConsoleColor.Red;
                                                    Console.WriteLine("\tPlease select a propriate number.");
                                                    Console.ForegroundColor = ConsoleColor.White;
                                                    notSuccededAdd          = true;
                                                }
                                            }
                                            catch (Exception)
                                            {
                                                Console.ForegroundColor = ConsoleColor.Red;
                                                Console.WriteLine("\tPlease select a propriate number.");

                                                Console.ForegroundColor = ConsoleColor.White;
                                                notSuccededAdd          = true;
                                            }
                                        } while (notSuccededAdd);

                                        //Ask to add another student from the list in course
                                        do
                                        {
                                            Console.WriteLine();
                                            Console.Write("\tWould you like to add another student from the list in course? Y/N : ");
                                            addAnotherStudentfromList = Console.ReadLine();
                                            Console.WriteLine();
                                        } while (addAnotherStudentfromList.ToUpper() != "Y" && addAnotherStudentfromList.ToUpper() != "N");
                                    } while (addAnotherStudentfromList.ToUpper() != "N");
                                }
                            } while ((userInput5 != "1" && userInput5 != "2") && userInput5 != "9");
                        }
                        //UserInput3 = 4, normal mode, Output students per course-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "4")
                        {
                            sPC.ListOfStudentsPerCourseOutput(serviseGet.GetStudentsPerCourse());
                            MyStaticClass.PressKeyToContinue();
                        }
                        //UserInput3 = 5, normal mode, Add trainers at courses-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "5")
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine();
                            Console.WriteLine("\tSelect the number of course that you want to add trainers.");
                            Console.WriteLine();
                            Console.ForegroundColor = ConsoleColor.White;

                            List <Course> allCourses = serviseGet.GetAllCourses();
                            c1.ListOfCoursecOutput(allCourses);
                            Console.WriteLine();

                            do
                            {
                                Console.Write("\tEnter the apropriate number : ");
                                selectCourse = MyStaticClass.InputTryToConvertToInt();
                            } while (selectCourse <= 0 || selectCourse > allCourses.Count);


                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n\t=================================================================================\n");
                            Console.ForegroundColor = ConsoleColor.White;
                            do
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine("\tSelect how you want to add a trainer.");
                                Console.ForegroundColor = ConsoleColor.White;

                                Console.WriteLine();
                                Console.WriteLine("\t1. Add a new trainer.");
                                Console.WriteLine("\t2. Add an excisting trainer.");
                                Console.WriteLine("\t9. Go back.");

                                Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                                userInput5 = Console.ReadLine();

                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("\n\t=================================================================================\n");
                                Console.ForegroundColor = ConsoleColor.White;
                            } while ((userInput5 != "1" && userInput5 != "2") && userInput5 != "9");

                            if (userInput5 == "1")
                            {
                                serviseInsert.InsertTrainer();
                                List <Trainer> trainers = serviseGet.GetAllTrainers();
                                serviseInsert.InsertTrainerAtCourse((int)trainers[trainers.Count - 1].Tid, (int)allCourses[selectCourse - 1].Cid);
                            }
                            else if (userInput5 == "2")
                            {
                                string addAnotherTrainerfromList;
                                bool   notSuccededAdd = true;
                                do
                                {
                                    Console.ForegroundColor = ConsoleColor.Yellow;
                                    Console.WriteLine();
                                    Console.WriteLine("\tSelect the number of trainer.");
                                    Console.WriteLine();
                                    Console.ForegroundColor = ConsoleColor.White;

                                    List <Trainer> allTrainers = serviseGet.GetAllTrainers();
                                    tr1.ListOfTrainersOutput(allTrainers);

                                    do
                                    {
                                        int selectTrainer = 0;
                                        try
                                        {
                                            Console.WriteLine();
                                            Console.Write("\tEnter a propriate number : ");

                                            selectTrainer = Convert.ToInt32(Console.ReadLine());
                                            if (selectTrainer >= 0 && selectTrainer <= allTrainers.Count)
                                            {
                                                if (serviceCheck.ExistTrainerPerCourse((int)allTrainers[selectTrainer - 1].Tid, (int)allCourses[selectCourse - 1].Cid))
                                                {
                                                    Console.ForegroundColor = ConsoleColor.Red;
                                                    Console.WriteLine();
                                                    Console.WriteLine("\tThe trainer already exist in the course.");
                                                    Console.ForegroundColor = ConsoleColor.White;
                                                    notSuccededAdd          = true;
                                                }
                                                else
                                                {
                                                    serviseInsert.InsertTrainerAtCourse((int)allTrainers[selectTrainer - 1].Tid, (int)allCourses[selectCourse - 1].Cid);
                                                    notSuccededAdd = false;
                                                }
                                            }
                                            else
                                            {
                                                Console.ForegroundColor = ConsoleColor.Red;
                                                Console.WriteLine("\tPlease select a propriate number.");
                                                Console.ForegroundColor = ConsoleColor.White;
                                                notSuccededAdd          = true;
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.WriteLine("\tPlease select a propriate number.");

                                            Console.ForegroundColor = ConsoleColor.White;
                                            notSuccededAdd          = true;
                                        }
                                    } while (notSuccededAdd);

                                    //Ask to add another student from the list in course
                                    do
                                    {
                                        Console.WriteLine();
                                        Console.Write("\tWould you like to add another student from the list in course? Y/N : ");
                                        addAnotherTrainerfromList = Console.ReadLine();
                                        Console.WriteLine();
                                    } while (addAnotherTrainerfromList.ToUpper() != "Y" && addAnotherTrainerfromList.ToUpper() != "N");
                                } while (addAnotherTrainerfromList.ToUpper() != "N");
                            }
                        }
                        //UserInput3 = 6, normal mode, Output trainers per course-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "6")
                        {
                            tPC.ListOfTrainersPerCourseOutput(serviseGet.GetTrainersPerCourse());
                            MyStaticClass.PressKeyToContinue();
                        }
                        //UserInput3 = 7, normal mode, Add assignments at courses-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "7")
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine();
                            Console.WriteLine("\tSelect the number of course that you want to add assignments.");
                            Console.WriteLine();
                            Console.ForegroundColor = ConsoleColor.White;


                            List <Course> allCourses = serviseGet.GetAllCourses();
                            c1.ListOfCoursecOutput(allCourses);
                            Console.WriteLine();

                            do
                            {
                                Console.Write("\tEnter the apropriate number : ");
                                selectCourse = MyStaticClass.InputTryToConvertToInt();
                            } while (selectCourse <= 0 || selectCourse > allCourses.Count);


                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n\t=================================================================================\n");
                            Console.ForegroundColor = ConsoleColor.White;

                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\tSelect how you want to add an assignment.");
                            Console.ForegroundColor = ConsoleColor.White;
                            do
                            {
                                Console.WriteLine();
                                Console.WriteLine("\t1. Add a new assignment.");
                                Console.WriteLine("\t2. Add an excisting assignment.");
                                Console.WriteLine("\t9. Go back.");

                                Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                                userInput5 = Console.ReadLine();

                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("\n\t=================================================================================\n");
                                Console.ForegroundColor = ConsoleColor.White;
                            } while ((userInput5 != "1" && userInput5 != "2") && userInput5 != "9");

                            if (userInput5 == "1")
                            {
                                serviseInsert.InsertNewAssignmentAtCourse((int)allCourses[selectCourse - 1].Cid);
                            }
                            else if (userInput5 == "2")
                            {
                                string addAnotherAssignmentfromList;
                                bool   notSuccededAdd = true;

                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine();
                                Console.WriteLine("\tSelect the number of the assignment.");
                                Console.WriteLine();
                                Console.ForegroundColor = ConsoleColor.White;

                                List <Assignment> allAssignments = serviseGet.GetAllAssignments();
                                a1.ListOfAssignmentsOutput(allAssignments);

                                do
                                {
                                    int selectAssignment = 0;
                                    try
                                    {
                                        Console.WriteLine();
                                        Console.Write("\tEnter a propriate number : ");

                                        selectAssignment = Convert.ToInt32(Console.ReadLine());
                                        if (selectAssignment >= 0 && selectAssignment <= allAssignments.Count)
                                        {
                                            serviseInsert.InsertAssignmentAtCourse((int)allAssignments[selectAssignment - 1].Aid, (int)allCourses[selectCourse - 1].Cid);
                                            notSuccededAdd = false;
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.WriteLine("\tPlease select a propriate number.");
                                            Console.ForegroundColor = ConsoleColor.White;
                                            notSuccededAdd          = true;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        Console.ForegroundColor = ConsoleColor.Red;
                                        Console.WriteLine("\tPlease select a propriate number.");

                                        Console.ForegroundColor = ConsoleColor.White;
                                        notSuccededAdd          = true;
                                    }
                                } while (notSuccededAdd);
                            }
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n\t=================================================================================\n");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        //UserInput3 = 8, normal mode, Output assignments per course-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "8")
                        {
                            aPC.OutputAssignmetsPerCourse(serviseGet.GetAssignmetsPerCourse());
                            MyStaticClass.PressKeyToContinue();
                        }
                    } while (userInput3 != "0" && userInput3 != "9");
                }
                //UserInput2 = 2, normal mode, Assignment--------------------------------------------------------------------------------------------------------------------
                else if (userInput2 == "2")
                {
                    do
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine();
                        Console.WriteLine("\tYou are in the assignment mode! What would you like to do?");
                        Console.WriteLine();
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("\t0. Exit.");
                        Console.WriteLine("\t1. New assignment.");
                        Console.WriteLine("\t2. Output list with all assignments.");
                        Console.WriteLine("\t3. Output list with assignments per course per student.");
                        Console.WriteLine("\t9. Go back.");

                        Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                        userInput3 = Console.ReadLine();

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\n\t=================================================================================\n");
                        Console.ForegroundColor = ConsoleColor.White;

                        //UserInput3 = 1, normal mode, New Assignment-------------------------------------------------------------------------------------------------------
                        if (userInput3 == "1")
                        {
                            serviseInsert.InsertAssignment();
                        }
                        //UserInput3 = 2, normal mode, List of assignments-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "2")
                        {
                            a1.ListOfAssignmentsWithoutMarkOutput(serviseGet.GetAllAssignments());
                            MyStaticClass.PressKeyToContinue();
                        }
                        else if (userInput3 == "3")
                        {
                            aPCPS.ListOfAssignmentsPerCoursePerStudentOutput(serviseGet.GetAssignmentsPerCoursePerStudents());
                            MyStaticClass.PressKeyToContinue();
                        }
                    } while ((userInput3 != "0" && userInput3 != "9") && (userInput3 != "1" && (userInput3 != "2" && userInput3 != "3")));
                }
                //UserInput2 = 3, normal mode, Trainer--------------------------------------------------------------------------------------------------------------------
                else if (userInput2 == "3")
                {
                    do
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine();
                        Console.WriteLine("\tYou are in the trainer mode! What would you like to do?");
                        Console.WriteLine();
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("\t0. Exit.");
                        Console.WriteLine("\t1. New trainer.");
                        Console.WriteLine("\t2. Output list with all trainers.");
                        Console.WriteLine("\t9. Go back.");

                        Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                        userInput3 = Console.ReadLine();

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\n\t=================================================================================\n");
                        Console.ForegroundColor = ConsoleColor.White;

                        //UserInput3 = 1, normal mode, New trainer-------------------------------------------------------------------------------------------------------
                        if (userInput3 == "1")
                        {
                            serviseInsert.InsertTrainer();
                        }
                        //UserInput3 = 2, normal mode, List of trainers-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "2")
                        {
                            tr1.ListOfTrainersOutput(serviseGet.GetAllTrainers());
                            MyStaticClass.PressKeyToContinue();
                        }
                    } while ((userInput3 != "0" && userInput3 != "9") && (userInput3 != "1" && userInput3 != "2"));
                }
                //UserInput2 = 4, normal mode, Student--------------------------------------------------------------------------------------------------------------------
                else if (userInput2 == "4")
                {
                    do
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine();
                        Console.WriteLine("\tYou are in the student mode! What would you like to do?");
                        Console.WriteLine();
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("\t0. Exit.");
                        Console.WriteLine("\t1. New student.");
                        Console.WriteLine("\t2. Output list with all students.");
                        Console.WriteLine("\t3. Output list witn students who belongs to more than one course.");
                        Console.WriteLine("\t9. Go back.");

                        Console.Write("\n\tPlease enter the appropriate number to select the field you are interested in : ");
                        userInput3 = Console.ReadLine();

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\n\t=================================================================================\n");
                        Console.ForegroundColor = ConsoleColor.White;

                        //UserInput3 = 1, normal mode, New Student-------------------------------------------------------------------------------------------------------
                        if (userInput3 == "1")
                        {
                            serviseInsert.InsertStudent();
                        }
                        //UserInput3 = 2, normal mode, List of students-------------------------------------------------------------------------------------------------------
                        else if (userInput3 == "2")
                        {
                            s1.ListOfStudentsOutput(serviseGet.GetAllStudents());
                            MyStaticClass.PressKeyToContinue();
                        }

                        //UserInput3 = 3, normal mode, List of students who belongs to more than one course------------------------------------------------------------------------------------------------------ -
                        else if (userInput3 == "3")
                        {
                            sMTOC.ListOfStudentsOutput(serviseGet.GetStudentsWithMoreThanOneCourses());
                            MyStaticClass.PressKeyToContinue();
                        }
                    } while ((userInput3 != "0" && userInput3 != "9") && (userInput3 != "1" && userInput3 != "2") && (userInput3 != "3"));
                }
            } while ((userInput2 != "0" && userInput2 != "9") && userInput3 != "0");


            Console.WriteLine("\n\tTHANK YOU!!!");


            Console.ReadKey();
        }
Exemplo n.º 13
0
 /// <summary>
 /// Add a Service check
 /// </summary>
 public void Add(string name, int status, int?timestamp = null, string hostname = null, string[] tags = null, string serviceCheckMessage = null)
 {
     _commands.Add(ServiceCheck.GetCommand(name, status, timestamp, hostname, tags, serviceCheckMessage));
 }
        public void GivenServerIsRunningOnHostWithPort(string host, int port)
        {
            var isServerUp = ServiceCheck.IsListening(host, port);

            Assert.IsTrue(isServerUp, $"Service on host {host} and port {port} is not running");
        }