Beispiel #1
0
        // return:
        //      -2  remoting服务器连接失败。驱动程序尚未启动
        //      -1  出错
        //      0   成功
        public static int AddItems(
            FingerprintChannel channel,
            List <FingerprintItem> items,
            out string strError)
        {
            strError = "";

            try
            {
                int nRet = channel.Object.AddItems(items,
                                                   out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
            }
            // [System.Runtime.Remoting.RemotingException] = {"连接到 IPC 端口失败: 系统找不到指定的文件。\r\n "}
            catch (System.Runtime.Remoting.RemotingException ex)
            {
                strError = "针对 " + Program.MainForm.FingerprintReaderUrl + " 的 AddItems() 操作失败: " + ex.Message;
                return(-2);
            }
            catch (Exception ex)
            {
                strError = "针对 " + Program.MainForm.FingerprintReaderUrl + " 的 AddItems() 操作失败: " + ex.Message;
                return(-1);
            }

            return(0);
        }
Beispiel #2
0
 public static void EndFingerprintChannel(FingerprintChannel channel)
 {
     if (channel != null && channel.Channel != null)
     {
         ChannelServices.UnregisterChannel(channel.Channel);
         channel.Channel = null;
     }
 }
Beispiel #3
0
        public static FingerprintChannel StartFingerprintChannel(
            string strUrl,
            out string strError)
        {
            strError = "";

            FingerprintChannel result = new FingerprintChannel();

            var clientProv = new BinaryClientFormatterSinkProvider();
            var serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel =
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            result.Channel = new IpcClientChannel(Guid.NewGuid().ToString(), // 随机的名字,令多个 Channel 对象可以并存
                                                  clientProv);

            ChannelServices.RegisterChannel(result.Channel, true);
            bool bDone = false;

            try
            {
                result.Object = (IFingerprint)Activator.GetObject(typeof(IFingerprint),
                                                                  strUrl);
                if (result.Object == null)
                {
                    strError = "无法连接到指纹接口服务器 " + strUrl;
                    return(null);
                }
                // result.Object.Scaned += new ScanedEventHandler(result.handler.LocallyHandleScaned);
                bDone = true;
                return(result);
            }
            catch (Exception ex)
            {
                strError = "StartFingerprintChannel() 出现异常: " + ex.Message;
                return(null);
            }
            finally
            {
                if (bDone == false)
                {
                    EndFingerprintChannel(result);
                }
            }
        }
Beispiel #4
0
        private void PageBorrow_Unloaded(object sender, RoutedEventArgs e)
        {
            if (_fingerprintChannel != null)
            {
                FingerPrint.EndFingerprintChannel(_fingerprintChannel);
                _fingerprintChannel = null;
            }

            if (_rfidChannel != null)
            {
                RFID.EndRfidChannel(_rfidChannel);
                _rfidChannel = null;
            }

            if (_timer != null)
            {
                _timer.Dispose();
            }
        }
Beispiel #5
0
        // EventProxy eventProxy;

        private void PageBorrow_Loaded(object sender, RoutedEventArgs e)
        {
            // throw new Exception("test");

            _layer   = AdornerLayer.GetAdornerLayer(this.mainGrid);
            _adorner = new LayoutAdorner(this);

            // 准备指纹通道
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(App.FingerprintUrl) == false)
            {
#if NO
                eventProxy = new EventProxy();
                eventProxy.MessageArrived +=
                    new MessageArrivedEvent(eventProxy_MessageArrived);
#endif
                _fingerprintChannel = FingerPrint.StartFingerprintChannel(
                    App.FingerprintUrl,
                    out string strError);
                if (_fingerprintChannel == null)
                {
                    errors.Add($"启动指纹通道时出错: {strError}");
                }
                // https://stackoverflow.com/questions/7608826/how-to-remote-events-in-net-remoting
#if NO
                _fingerprintChannel.Object.MessageArrived +=
                    new MessageArrivedEvent(eventProxy.LocallyHandleMessageArrived);
#endif
                try
                {
                    _fingerprintChannel.Object.GetMessage("clear");
                    _fingerprintChannel.Started = true;
                }
                catch (Exception ex)
                {
                    if (ex is RemotingException && (uint)ex.HResult == 0x8013150b)
                    {
                        errors.Add($"启动指纹通道时出错: “指纹中心”({App.FingerprintUrl})没有响应");
                    }
                    else
                    {
                        errors.Add($"启动指纹通道时出错(2): {ex.Message}");
                    }
                }
            }

            // 准备 RFID 通道
            if (string.IsNullOrEmpty(App.RfidUrl) == false)
            {
                _rfidChannel = RFID.StartRfidChannel(
                    App.RfidUrl,
                    out string strError);
                if (_rfidChannel == null)
                {
                    errors.Add($"启动 RFID 通道时出错: {strError}");
                }

                try
                {
                    var result = _rfidChannel.Object.ListReaders();

                    // TODO: 某处界面可以显示当前连接的读卡器名字
                    // 看看是否有至少一个读卡器
                    if (result.Readers.Length == 0)
                    {
                        errors.Add("当前指纹中心没有任何连接的读卡器。请检查读卡器是否正确连接");
                    }
                    else
                    {
                        _rfidChannel.Started = true;
                    }
                }
                catch (Exception ex)
                {
                    if (ex is RemotingException && (uint)ex.HResult == 0x8013150b)
                    {
                        errors.Add($"启动 RFID 通道时出错: “RFID-中心”({App.RfidUrl})没有响应");
                    }
                    else
                    {
                        errors.Add($"启动 RFID 通道时出错: {ex.Message}");
                    }
                }
            }
            else
            {
                errors.Add($"尚未配置 RFID 接口 URL");
            }

            if (errors.Count > 0)
            {
                this.Error = StringUtil.MakePathList(errors, "; ");
            }

            // https://stackoverflow.com/questions/13396582/wpf-user-control-throws-design-time-exception
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                _timer = new System.Threading.Timer(
                    new System.Threading.TimerCallback(timerCallback),
                    null,
                    TimeSpan.FromSeconds(0),
                    TimeSpan.FromSeconds(1));
            }
        }