/// <summary> /// This event is fired in response to an incoming call. This must be accepted if no other call is in progress /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void phone_Delivered(object sender, DeliveredEventArgs args) { DateTime currentTime = DateTime.Now; CurrentState localState = getState(); if (localState == CurrentState.READY) { setState(CurrentState.CALLPENDING); conn = args.AlertingConnection; display("Going to answer incoming call from " + conn.CallerURI); conn.AnswerCall(); } else // if (localState != CurrentState.READY) { if (calleeData != null && (currentTime.Subtract(calleeData.callConnectTime) >= new TimeSpan(0, 0, maxCallDuration + waitTimeBetweenCalls))) // if (currentTime.Subtract(calleeData.callConnectTime) >= new TimeSpan(0, 0, maxCallDuration + waitTimeBetweenCalls)) { // If a call comes in after the expected time, this implies that the hangup was not // detected for the previous call. Thus, we log the previous iteration, clean up after it // and accept this new call. // The expected time >= max call interval + inter call duration display("Accepting this call as hangup might not have been detected for the previous call"); missingHangupDetectionTimer.Enabled = false; // This method sets calleeData.callReleaseTime to uninitialized value, which gets reported as a missing hangup processHangup(new DateTime()); setState(CurrentState.CALLPENDING); conn = args.AlertingConnection; conn.AnswerCall(); } else { /** * If a call arrives when not expected, reject it. */ display("Rejecting a call from " + args.CallingDevice, MessageType.WARNING); args.AlertingConnection.ClearConnection(); } } }