public IncomingCallsPriority Answer(string consultant)
 {
     if (Calls.Count > 0)
     {
         IncomingCallsPriority call = Calls.Dequeue();
         call.Consultant = consultant;
         call.StartTime  = DateTime.Now;
         return(call);
     }
     return(null);
 }
        public void Call(int clientId, bool isPriority = false)
        {
            IncomingCallsPriority call = new IncomingCallsPriority()
            {
                Id         = ++_counter,
                ClientId   = clientId,
                CallTime   = DateTime.Now,
                IsPriority = isPriority
            };

            Calls.Enqueue(call, isPriority ? 0 : 1);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // Many Consultant
            //CallCenter centerMany = new CallCenter();
            //Parallel.Invoke(
            //    () => CallersAction(centerMany),
            //    () => ConsultantAction(centerMany, "Marcin", ConsoleColor.Red),
            //    () => ConsultantAction(centerMany, "James", ConsoleColor.Yellow),
            //    () => ConsultantAction(centerMany, "Olivia", ConsoleColor.Green));



            // One Consultant

            //Random random = new Random();

            //CallCenter center = new CallCenter();
            //center.Call(1234);
            //center.Call(5678);
            //center.Call(1468);
            //center.Call(9641);

            //while (center.AreWaitingCalls())
            //{
            //    IncomingCalls call = center.Answer("Marcin");
            //    Log($"Call #{call.Id} from {call.ClientId} is answered by {call.Consultant}.");
            //    Thread.Sleep(random.Next(1000, 10000));
            //    center.End(call);
            //    Log($"Call #{call.Id} from {call.ClientId} is ended by {call.Consultant}.");



            // Priority Queue
            Random random = new Random();

            CallCenterPriority center = new CallCenterPriority();

            center.Call(1234);
            center.Call(5678, true);
            center.Call(1468);
            center.Call(9641, true);

            while (center.AreWaitingCalls())
            {
                IncomingCallsPriority call = center.Answer("Marcin");
                Log($"Call #{call.Id} from {call.ClientId} is answered by {call.Consultant} / Mode: {(call.IsPriority ? "priority" : "normal")}.");
                Thread.Sleep(random.Next(1000, 10000));
                center.End(call);
                Log($"Call #{call.Id} from {call.ClientId} is ended by {call.Consultant}.");
            }
        }
 public void End(IncomingCallsPriority call)
 {
     call.EndTime = DateTime.Now;
 }