private void OnAnswer(object sender, ICallEventArgs args) { Console.WriteLine($"{Port.TelephoneNumber}: talking with {args.FromTelephoneNumber}"); Console.WriteLine($"{Port.TelephoneNumber}: Press any key to break conversation with {args.FromTelephoneNumber}"); Console.ReadKey(true); // Port.EndCall(args.FromTelephoneNumber); }
public void OnAnswerExecute(object obj, ICallEventArgs args) { _startConversation = DateTime.Now; _numberPortStorage[args.FromTelephoneNumber].ChangePortState(PortState.Calling); _numberPortStorage[args.ToTelephoneNumber].ChangePortState(PortState.Calling); Console.WriteLine($"ATS: {args.ToTelephoneNumber} talks with {args.FromTelephoneNumber} {DateTime.Now}"); }
public void OnDeclineExecute(object obj, ICallEventArgs args) { var dateTime = DateTime.Now; Console.WriteLine($"ATS: {args.ToTelephoneNumber} rejected call from {args.FromTelephoneNumber}"); _numberPortStorage[args.FromTelephoneNumber].GetResponseFromATS($"{args.ToTelephoneNumber} rejected your call"); CallInfoEvent?.Invoke(this, new CallInformation(args.FromTelephoneNumber, args.ToTelephoneNumber, dateTime, dateTime)); }
void port_AnswerEvent(object sender, ICallEventArgs e) { if (e is AnswerEventArgs) { var answerArgs = (AnswerEventArgs)e; var callListFirst = _callInfoList.First(x => x.Number.Equals(answerArgs.PhoneNumber)); var port = _usersData[callListFirst.Number].Item1; port.AnswerCall(answerArgs.PhoneNumber, answerArgs.TargetPhoneNumber, answerArgs.CallState); } }
void port_EndCallEvent(object sender, ICallEventArgs e) { if (e is EndCallEventArgs) { var args = (EndCallEventArgs)e; CallInfo info = _callInfoList.First(x => x.Number.Equals(args.PhoneNumber)); info.EndCall = DateTime.Now; info.Cost = _usersData[info.Number].Item2.Tariff.CostCallPerMinute * (info.EndCall - info.BeginCall).Minutes; _usersData[info.Number].Item2.Debit(info.Cost); _usersData[args.PhoneNumber].Item1.EndCall(args.PhoneNumber); } }
public void OnEndCallExecute(object sender, ICallEventArgs args) { _endConversation = DateTime.Now; Console.WriteLine($"ATS: {args.ToTelephoneNumber} finished talk with {args.FromTelephoneNumber} {DateTime.Now}"); _numberPortStorage[args.FromTelephoneNumber].GetResponseFromATS($"finished talk with {args.ToTelephoneNumber}"); _numberPortStorage[args.ToTelephoneNumber].GetResponseFromATS($"finished talk with {args.FromTelephoneNumber}"); _numberPortStorage[args.FromTelephoneNumber].ChangePortState(PortState.Connected); _numberPortStorage[args.ToTelephoneNumber].ChangePortState(PortState.Connected); CallInfoEvent?.Invoke(this, new CallInformation(args.FromTelephoneNumber, args.ToTelephoneNumber, _startConversation, _endConversation)); }
private void OnIncomeCall(object sender, ICallEventArgs args) { Console.WriteLine($"{Port.TelephoneNumber}: Incoming call from {args.FromTelephoneNumber}"); Console.WriteLine("Answer?(Y -- yes, another symbol -- no)"); char choise = Console.ReadKey(true).KeyChar; if (choise.Equals('Y')) { Port.Answer(args.FromTelephoneNumber); } else { Port.Decline(args.FromTelephoneNumber); } }
void port_CallEvent(object sender, ICallEventArgs e) { if (_usersData.ContainsKey(e.TargetPhoneNumber)) { if (e is CallEventArgs) { if (_usersData[e.PhoneNumber].Item2.Ballance >= _usersData[e.PhoneNumber].Item2.Tariff.CostCallPerMinute) { _callInfoList.Add(new CallInfo(e.PhoneNumber, e.TargetPhoneNumber, DateTime.Now)); var port = _usersData[e.PhoneNumber].Item1; port.IncomingCall(e.PhoneNumber, e.TargetPhoneNumber); } else { Console.WriteLine("Terminal with number {0} is not enough money in the account!", e.PhoneNumber); } } } }
public void OnCallExecute(object obj, ICallEventArgs args) { Console.WriteLine($"ATS: {args.FromTelephoneNumber} calls to {args.ToTelephoneNumber}"); Console.WriteLine($"ATS: Connection {args.FromTelephoneNumber} with {args.ToTelephoneNumber}"); if (!_numberPortStorage.ContainsKey(args.ToTelephoneNumber)) { var date = DateTime.Now; Console.WriteLine($"ATS: Connection is not available. There is no {args.ToTelephoneNumber} in the system"); _numberPortStorage[args.FromTelephoneNumber].GetResponseFromATS("Connection is not available. There is no such number in the system"); CallInfoEvent?.Invoke(this, new CallInformation(args.FromTelephoneNumber, args.ToTelephoneNumber, date, date)); return; } if (args.FromTelephoneNumber.Equals(args.ToTelephoneNumber)) { _numberPortStorage[args.FromTelephoneNumber].GetResponseFromATS("It is impossible to call itself"); return; } if (_numberPortStorage[args.ToTelephoneNumber].IsAvailable) { _numberPortStorage[args.ToTelephoneNumber].HaveIncomingCall(args.FromTelephoneNumber); } else { var dateTime = DateTime.Now; Console.WriteLine($"ATS: {args.ToTelephoneNumber} is not available now"); _numberPortStorage[args.FromTelephoneNumber].GetResponseFromATS($"{args.ToTelephoneNumber} is not available now"); CallInfoEvent?.Invoke(this, new CallInformation(args.FromTelephoneNumber, args.ToTelephoneNumber, dateTime, dateTime)); } }
public void Calling(object sender, ICallEventArgs e) { if ((Subscribers.ContainsKey(e.TargetNumber) && e.TargetNumber != e.Number) || e is EventOfEndCallArgs) { CallInfo callInfo = null; Port targetPort; Port port; int number = 0; int targetNumber = 0; if (e is EventOfEndCallArgs) { var callListFirst = Calls.First(x => x.Id.Equals(e.Id)); if (callListFirst.Number == e.Number) { targetPort = Subscribers[callListFirst.TargetNumber].Item1; port = Subscribers[callListFirst.Number].Item1; number = callListFirst.Number; targetNumber = callListFirst.TargetNumber; } else { port = Subscribers[callListFirst.TargetNumber].Item1; targetPort = Subscribers[callListFirst.Number].Item1; targetNumber = callListFirst.Number; number = callListFirst.TargetNumber; } } else { targetPort = Subscribers[e.TargetNumber].Item1; port = Subscribers[e.Number].Item1; targetNumber = e.TargetNumber; number = e.Number; } if (targetPort.State == States.StateOfPort.Connect && port.State == StateOfPort.Connect) { var portContract = Subscribers[number]; var targetPortContract = Subscribers[targetNumber]; if (e is EventOfAnswerArgs) { var answerArgs = (EventOfAnswerArgs)e; if (!answerArgs.Id.Equals(Guid.Empty) && Calls.Any(x => x.Id.Equals(answerArgs.Id))) { callInfo = Calls.First(x => x.Id.Equals(answerArgs.Id)); } if (callInfo != null) { targetPort.AnswerCall(answerArgs.Number, answerArgs.TargetNumber, answerArgs.StateOfCall, callInfo.Id); } else { targetPort.AnswerCall(answerArgs.Number, answerArgs.TargetNumber, answerArgs.StateOfCall, callInfo.Id); } } if (e is EventOfCallArgs) { if (portContract.Item2.Subscriber.Account > portContract.Item2.Tariff.PricePerMinute) { var callArgs = (EventOfCallArgs)e; if (callArgs.Id.Equals(Guid.Empty)) { callInfo = new CallInfo( callArgs.Number, callArgs.TargetNumber, DateTime.Now); Calls.Add(callInfo); } if (!callArgs.Id.Equals(Guid.Empty) && Calls.Any(x => x.Id.Equals(callArgs.Id))) { callInfo = Calls.First(x => x.Id.Equals(callArgs.Id)); } if (callInfo != null) { targetPort.IncomingCall(callArgs.Number, callArgs.TargetNumber, callInfo.Id); } else { targetPort.IncomingCall(callArgs.Number, callArgs.TargetNumber, callInfo.Id); } } else { Console.WriteLine("There is not enough money on the terminal {0}!", e.Number); } } if (e is EventOfEndCallArgs) { var args = (EventOfEndCallArgs)e; callInfo = Calls.First(x => x.Id.Equals(args.Id)); callInfo.EndOfCall = DateTime.Now; var sumOfCall = portContract.Item2.Tariff.PricePerMinute * TimeSpan.FromTicks((callInfo.EndOfCall - callInfo.StartOfCall).Ticks).TotalMinutes; callInfo.CostOfCall = (int)sumOfCall; targetPortContract.Item2.Subscriber.WithdrawMoney(callInfo.CostOfCall); targetPort.AnswerCall(args.Number, args.TargetNumber, StateOfCall.Reject, callInfo.Id); } } } else if (!Subscribers.ContainsKey(e.TargetNumber)) { Console.WriteLine("Trying to call a non-existent number".ToUpper()); } else { Console.WriteLine("Trying to call your own number".ToUpper()); } }