private void Channel_UnsolicitedEvent(object sender, UnsolicitedEventArgs e) { if (e.Line1 == "RING") { IncomingCall?.Invoke(this, new IncomingCallEventArgs()); } else if (e.Line1.StartsWith("VOICE CALL: BEGIN")) { CallStarted?.Invoke(this, new CallStartedEventArgs()); } else if (e.Line1.StartsWith("VOICE CALL: END")) { CallEnded?.Invoke(this, CallEndedEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("MISSED_CALL: ")) { MissedCall?.Invoke(this, MissedCallEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("+CMTI: ")) { SmsReceived?.Invoke(this, SmsReceivedEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("+CUSD: ")) { UssdResponseReceived?.Invoke(this, UssdResponseEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("+CME ERROR:")) { ErrorReceived?.Invoke(this, ErrorEventArgs.CreateFromCmeResponse(e.Line1)); } else if (e.Line1.StartsWith("+CMS ERROR:")) { ErrorReceived?.Invoke(this, ErrorEventArgs.CreateFromCmsResponse(e.Line1)); } }
private void AgentManager_AgentCreated(object sender, AddedAgentEventArgs args) { if (!_agentsWithTaskCancellationTokenSources.ContainsKey(args.NewAgent.Name)) { var agent = args.NewAgent; var cts = new CancellationTokenSource(); var ctoken = cts.Token; Task.Factory.StartNew(() => { ctoken.ThrowIfCancellationRequested(); while (!ctoken.IsCancellationRequested) { if (_queueOfCalls.TryDequeue(out var call)) { CallStarted?.Invoke(this, new CallProcessingStartedEventArgs { CallAnswerer = agent, PrecessedCall = call }); Thread.Sleep(call.DurationInSec * 1000); CallEnded?.Invoke(this, new CallProcessingEndedEventArgs { CallAnswerer = agent, PrecessedCall = call }); } } }, ctoken, TaskCreationOptions.LongRunning, TaskScheduler.Default); _agentsWithTaskCancellationTokenSources.TryAdd(args.NewAgent.Name, cts); } }
public void CallMe(string mess) { CallStarted?.Invoke(mess); }