コード例 #1
0
        private static void ConsultantAction(CallCenter center, string name, ConsoleColor color)
        {
            Random random = new Random();

            while (true)
            {
                IncomingCall call = center.AnswerCall(name);
                if (call != null)
                {
                    Console.ForegroundColor = color;
                    Log($"Call #{call.Id} from {call.ClientId} is answered by { call.Consultant}.");
                    Console.ForegroundColor = ConsoleColor.Gray;

                    Thread.Sleep(random.Next(1000, 10000));
                    center.End(call);

                    Console.ForegroundColor = color;
                    Log($"Call #{call.Id} from {call.ClientId} is ended by { call.Consultant}.");
                    Console.ForegroundColor = ConsoleColor.Gray;

                    Thread.Sleep(random.Next(500, 1000));
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }
コード例 #2
0
        static void TestCallCenter()
        {
            CallCenter center = new CallCenter();

            Parallel.Invoke(
                () => CallersAction(center),
                () => ConsultantAction(center, "Marcin", ConsoleColor.Red),
                () => ConsultantAction(center, "James", ConsoleColor.Yellow),
                () => ConsultantAction(center, "Olivia", ConsoleColor.Green)

                );
        }
コード例 #3
0
        private static void CallersAction(CallCenter center)
        {
            Random random = new Random();

            while (true)
            {
                int clientid     = random.Next(1, 10000);
                int waitingCount = center.Call(clientid);
                Log($"Incoming call from {clientid}, waiting in the queue: {waitingCount} ");
                Thread.Sleep(random.Next(1000, 5000));
            }
        }