/// <summary> /// 侦听板卡上所有外线的呼入事件,在一个循环中进行侦听并且不断的检查是否发出了停止信号(abort) /// </summary> protected override void Listen() { while (!abort) { int n; bool chnlRing = false; string callNumber; for (int i = 0; i < driver.ChannelCount; i++) { lock (D160X.SyncObj) { n = -1; callNumber = string.Empty; switch (driver.Channels[i].ChannelType) { case ChannelType.TRUNK: // 监听外线通道的呼入事件 if (D160X.RingDetect(i)) { n = i; //callNumber = GetCallerNumber(i); if (driver.Channels[i] != null) { driver.Channels[i].Logger.Info(String.Format("Call 事件分配器探测到通道 {0} 有呼入事件发生,呼入电话号码为: ", i, callNumber)); } } break; case ChannelType.USER: // 监听内线通道的呼出事件 if (D160X.OffHookDetect(i)) { n = i; callNumber = driver.Channels[i].ChannelAlias; if (driver.Channels[i] != null) { driver.Channels[i].Logger.Info(String.Format("Call 事件分配器探测到通道 {0} 有提机事件发生,呼出通道别名为: {1}", i, driver.Channels[i].ChannelAlias)); } } break; } // 分发事件到订阅者组件,此处不检查callNumber是否为空是因为没有来电显示D160X模拟卡 // 便无法取得主叫号码。 if (n != -1 && Subject.Invocations > 0) { ICallHandler handler = Subject as ICallHandler; handler.Call(n, callNumber); } } } System.Threading.Thread.Sleep(Interval); // 使事件侦听暂停一段时间 } }
public override IMessage Invoke(IMessage msg) { IMethodCallMessage call = (IMethodCallMessage)msg; IMethodReturnMessage result = null; if (call != null) { try { object ret = callHandler.Call(call.MethodName, call.Args); if (ret == null) { MethodInfo info = call.MethodBase as MethodInfo; Type returnType = info.ReturnType; if (returnType == typeof(System.Boolean)) { ret = false; } if (returnType == typeof(System.Byte)) { ret = (System.Byte) 0; } if (returnType == typeof(System.SByte)) { ret = (System.SByte) 0; } if (returnType == typeof(System.Decimal)) { ret = (System.Decimal) 0; } if (returnType == typeof(System.Double)) { ret = (System.Double) 0; } if (returnType == typeof(System.Single)) { ret = (System.Single) 0; } if (returnType == typeof(System.Int32)) { ret = (System.Int32) 0; } if (returnType == typeof(System.UInt32)) { ret = (System.UInt32) 0; } if (returnType == typeof(System.Int64)) { ret = (System.Int64) 0; } if (returnType == typeof(System.UInt64)) { ret = (System.UInt64) 0; } if (returnType == typeof(System.Int16)) { ret = (System.Int16) 0; } if (returnType == typeof(System.UInt16)) { ret = (System.UInt16) 0; } if (returnType == typeof(System.Char)) { ret = '?'; } } result = new ReturnMessage(ret, null, 0, null, call); } catch (Exception e) { result = new ReturnMessage(e, call); } } return(result); }