Example #1
0
        void onEventArrived(object sender, EventArrivedEventArgs e)
        {
            ManagementBaseObject _o = e.NewEvent["TargetInstance"] as ManagementBaseObject;

            if (_o != null)
            {
                using (ManagementObject mo = new ManagementObject(_o["Dependent"].ToString()))
                {
                    if (mo != null)
                    {
                        try
                        {
                            if (mo.GetPropertyValue("DeviceID").ToString() != string.Empty)
                            {
                                //connected
                                _action?.Invoke("connected");
                            }
                        }

                        catch (ManagementException ex)
                        {
                            //disconnected
                            _action?.Invoke("disconnected");
                        }
                    }
                }
            }
        }
Example #2
0
        // Exception:
        //      可能会抛出 Exception 异常
        public BaseChannel <T> GetChannel()
        {
            // TODO: 这里需要一个特殊的异常类型
            if (string.IsNullOrEmpty(this.Url))
            {
                throw new UrlEmptyException($"尚未配置 {this.Name} URL");
            }

            return(this.Channels.GetChannel(() =>
            {
#if LOG
                LibraryChannelManager.Log?.Debug($"beginof new {this.Name} channel, Url={this.Url}");
#endif
                var channel = StartChannel(
                    this.Url,
                    out string strError);
                if (channel == null)
                {
                    throw new Exception(strError);
                }
                try
                {
#if NO
                    var result = channel.Object.GetState("");
                    if (result.Value == -1)
                    {
                        throw new Exception($"RFID 中心当前处于 {result.ErrorCode} 状态({result.ErrorInfo})");
                    }
                    channel.Started = true;

                    channel.Object.EnableSendKey(false);
#endif
                    _new_action?.Invoke(channel);
                }
                catch (Exception ex)
                {
                    if (ex is RemotingException && (uint)ex.HResult == 0x8013150b)
                    {
                        throw new NotResponseException($"启动 {this.Name} 通道时出错: “{this.Name}”({this.Url})没有响应", ex);
                    }
                    else
                    {
                        throw new Exception($"启动 {this.Name} 通道时出错(2): {ex.Message}", ex);
                    }
                }
#if LOG
                LibraryChannelManager.Log?.Debug($"endof new {this.Name} channel, Url={this.Url}");
#endif
                return channel;
            }));
        }