public BorrowController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                    IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            if(display == null) throw new ArgumentException("Display object was not provided to begin the application");
            if (reader == null) throw new ArgumentException("Reader object was not provided to begin the application");
            if (scanner == null) throw new ArgumentException("Scanner object was not provided to begin the application");
            if (printer == null) throw new ArgumentException("Printer object was not provided to begin the application");
            if (bookDAO == null) throw new ArgumentException("BookDAO object was not provided to begin the application");
            if (loanDAO == null) throw new ArgumentException("LoanDAO object was not provided to begin the application");
            if (memberDAO == null) throw new ArgumentException("MemberDAO object was not provided to begin the application");

            _display = display;
            _reader = reader;
            _scanner = scanner;
            _printer = printer;

            _bookDAO = bookDAO;
            _loanDAO = loanDAO;
            _memberDAO = memberDAO;

            _ui = new BorrowControl(this);

            _reader.Listener = this;
            _scanner.Listener = this;

            _bookList = new List<IBook>();
            _loanList = new List<ILoan>();

            _state = EBorrowState.CREATED;
        }
Esempio n. 2
0
        public MiFARECard(ICardReader reader)
        {
            _Reader      = reader;
            _ValueReader = null;

            Initialize();
        }
Esempio n. 3
0
        public MiFARECard(ICardReader reader, ICardValueReader valueReader)
        {
            _Reader      = reader;
            _ValueReader = valueReader;

            Initialize();
        }
Esempio n. 4
0
        public static ResultArgs ReadSector(int sector, M1KeyMode keyMode, byte[] key)
        {
            ICardReader cardReader = ContextManager.GetCardReader();

            ResultArgs ret = cardReader.Select();

            if (!ret.Succ)
            {
                return(new ResultArgs(false, null, "Select Card Error!"));
            }

            CardSelectResult info = (CardSelectResult)ret.Result;

            logger.Debug(String.Format("Select card_id={0}, ATQA=0x{1}, SAK={2}",
                                       BitConverter.ToString(info.SN),
                                       info.ATQA.ToString("X4"),
                                       info.SAK.ToString("X2")));

            if (!cardReader.Authen(keyMode, sector * 4, key))
            {
                logger.Debug(String.Format("Auth sector {0} failed !", sector));
                return(new ResultArgs(false, null, "Auth sector failed !"));
            }

            byte[] buffer;
            int    len = 0;

            if (!cardReader.ReadSector(sector, out buffer, out len))
            {
                return(new ResultArgs(false, null, "Read sector failed !"));
            }

            return(new ResultArgs(true, BitConverter.ToString(buffer), "OK"));
        }
Esempio n. 5
0
        private void HandleSmartCard(String readerName)
        {
            using (ISCardContext ctx = contextFactory.Establish(SCardScope.System))
                using (ICardReader reader = ctx.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any))
                {
                    StatusMessage?.Invoke("Connected to tag");

                    IccDetection cardIdent = new IccDetection(reader);
                    cardIdent.DetectCardType();

                    StatusMessage?.Invoke("Device class: " + cardIdent.PcscDeviceClass.ToString());
                    StatusMessage?.Invoke("Card name: " + cardIdent.PcscCardName.ToString());
                    StatusMessage?.Invoke("ATR: " + BitConverter.ToString(cardIdent.Atr));

                    if (cardIdent.PcscDeviceClass == DeviceClass.StorageClass &&
                        (cardIdent.PcscCardName == CardName.MifareUltralight ||
                         cardIdent.PcscCardName == CardName.MifareUltralightC ||
                         cardIdent.PcscCardName == CardName.MifareUltralightEV1))
                    {
                        HandleMifareUL(reader);
                    }
                    else if (cardIdent.PcscDeviceClass == DeviceClass.StorageClass &&
                             (cardIdent.PcscCardName == CardName.MifareStandard1K ||
                              cardIdent.PcscCardName == CardName.MifareStandard4K))
                    {
                        HandleMifareStandard(reader);
                    }
                    else
                    {
                        HandleHCEClient(reader);
                    }
                }
        }
Esempio n. 6
0
        public Iso7816.ApduResponse SignalACR(string readerName, ACRReaderControl ctrl)
        {
            byte ledStateCtrl = 0;

            if (ctrl.finalRed)
            {
                ledStateCtrl |= 1 << 0;
            }
            if (ctrl.finalGreen)
            {
                ledStateCtrl |= 1 << 1;
            }
            if (ctrl.redMask)
            {
                ledStateCtrl |= 1 << 2;
            }
            if (ctrl.greenMask)
            {
                ledStateCtrl |= 1 << 3;
            }
            if (ctrl.initRedBlink)
            {
                ledStateCtrl |= 1 << 4;
            }
            if (ctrl.initGreenBlink)
            {
                ledStateCtrl |= 1 << 5;
            }
            if (ctrl.redBlinkMask)
            {
                ledStateCtrl |= 1 << 6;
            }
            if (ctrl.greenBlinkMask)
            {
                ledStateCtrl |= 1 << 7;
            }
            byte[] ctrlData = new byte[] { ctrl.t1Duration, ctrl.t2Duration, ctrl.reps, ctrl.buzzer };

            blockCardEvents += 1;

            try
            {
                using (ISCardContext ctx = contextFactory.Establish(SCardScope.System))
                    using (ICardReader reader = ctx.ConnectReader(readerName, SCardShareMode.Direct, SCardProtocol.Unset))
                    {
                        var apdu = new Iso7816.ApduCommand(0xFF, 0x00, 0x40, ledStateCtrl, ctrlData, null);
                        return(reader.Control(apdu));
                    }
            }
            finally
            {
                new Thread(() =>
                {
                    Thread.Sleep(((ctrl.t1Duration * 100) + (ctrl.t2Duration * 100)) * ctrl.reps);
                    blockCardEvents -= 1;
                }).Start();
            }

            // For all I'm aware, this always returns a failure APDU, but the reader does perform the specified action.
        }
Esempio n. 7
0
 private void InvokeCardReaderAdded(ICardReader cardReader)
 {
     if (this.CardReaderAdded != null)
     {
         this.CardReaderAdded(cardReader, new CardReaderEventArgs(cardReader));
     }
 }
Esempio n. 8
0
        private bool _Reading;//表示读卡器是否正在进行读卡中
        #endregion

        #region 私有方法
        private void InitReaders()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            Type[] types = asm.GetTypes();
            foreach (Type t in types)
            {
                if (t.IsClass && t.GetInterface("ICardReader") != null)
                {
                    try
                    {
                        ICardReader reader = Activator.CreateInstance(t) as ICardReader;
                        if (reader != null)
                        {
                            reader.Init();
                            if (reader.State == ReaderState.InWork)
                            {
                                _Readers.Add(reader);
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        ExceptionPolicy.HandleException(err);
                    }
                }
            }
        }
Esempio n. 9
0
        private void HandleMifareUL(ICardReader reader)
        {
            var mifare = new PcscSdk.MifareUltralight.AccessHandler(reader);

            StatusMessage?.Invoke("Handling as Mifare Ultralight");

            byte[] uid = mifare.GetUid();
            StatusMessage?.Invoke("UID: " + BitConverter.ToString(uid));
            Array.Resize(ref uid, uid.Length + 1);
            uid[uid.Length - 1] = 0xAA;
            NewTagUid?.Invoke(uid);

            byte[] infoData = mifare.Read(0);
            StatusMessage?.Invoke("CC: " + BitConverter.ToString(infoData.Skip(12).ToArray()));

            try
            {
                byte[] versionData = mifare.GetVersion();
                StatusMessage?.Invoke("Mifare Version: " + BitConverter.ToString(versionData));

                int capacity    = versionData[6] >> 1;
                int capacityMax = capacity;
                if ((versionData[6] & 1) == 1)
                {
                    capacityMax += 1;
                }
                capacity    = (int)Math.Pow(2, capacity);
                capacityMax = (int)Math.Pow(2, capacityMax);
                StatusMessage?.Invoke("Capacity is between " + capacity + " and " + capacityMax + " bytes");
            }
            catch (ApduFailedException e)
            {
                StatusMessage?.Invoke("Failed getting Mifare Version: " + e.Message);
            }

            byte identMagic    = infoData[12];
            byte identVersion  = infoData[13];
            int  identCapacity = infoData[14] * 8;
            int  major         = identVersion >> 4;
            int  minor         = identVersion & 0x0F;

            if (identMagic != 0xE1 || identVersion < 0x10)
            {
                throw new NfcHandlerException("Tag format is unsupported");
            }

            StatusMessage?.Invoke("Found Type 2 Tag version " + major + "." + minor + " with " + identCapacity + " bytes capacity.");

            if (ndefDataToWrite != null)
            {
                WriteNdefToMifareUL(mifare, ndefDataToWrite);
                ndefDataToWrite = null;
            }
            else
            {
                byte[] data = DumpMifareUL(mifare);
                ParseTLVData(data);
            }
        }
Esempio n. 10
0
 public MifareCard(ILog logger, IKeyService keyService, ICardReader reader, M1KeyMode keyMode, byte[] defaultKey)
 {
     this.logger     = logger;
     this.reader     = reader;
     this.keyService = keyService;
     this.keyMode    = keyMode;
     this.defaultKey = defaultKey;
 }
Esempio n. 11
0
 public static ICardReader GetCardReader()
 {
     if (ContextManager.reader == null)
     {
         ContextManager.reader = applicationContext.GetObject <ICardReader>(configSelected[ContextConst.CardReaderSelectedKey]);
     }
     return(ContextManager.reader);
 }
Esempio n. 12
0
        public CardReadService(ICardReader cardReader, IEventAggregator eventAggregator, ILog log)
        {
            CardReader      = cardReader;
            EventAggregator = eventAggregator;
            Log             = log;

            EventAggregator.Subscribe(this);
        }
Esempio n. 13
0
 public Atm(IPrinter printer, IAtmClock clock, ICardReader cardReader,
            IHistory history, IStringFormatter stringFormatter)
 {
     this.stringFormatter = stringFormatter;
     this.printer         = printer;
     this.history         = history;
     this.clock           = clock;
     this.cardReader      = cardReader;
 }
Esempio n. 14
0
 public ATMachine(ICardReader cardReader, ICardService cardService, IPaperNoteDispenseAlgorithm paperNoteDispenseAlgorithm,
                  IFeeService feeService, IATMMaintenance atmMaintenance)
 {
     _cardReader  = cardReader;
     _cardService = cardService;
     _paperNoteDispenseAlgorithm = paperNoteDispenseAlgorithm;
     _feeService     = feeService;
     _atmMaintenance = atmMaintenance;
 }
Esempio n. 15
0
 public ISmartCard SelectSmartCard(ISmartCardService smartCardService, string details)
 {
     using (ComponentContainer ComponentContainer = new ComponentContainer(this.componentRepository))
     {
         ISmartCardSelection Selection = ComponentContainer.ResolveInstance <ISmartCardSelection>();
         ICardReader         Reader    = Selection.ShowModal(smartCardService, false, details);
         return(Reader.SmartCard);
     }
 }
Esempio n. 16
0
        private void RemoveSmartCard(ICardReader cardReader)
        {
            Trace.Assert(cardReader != null);

            ISmartCard SmartCard = this.SmartCards[cardReader];

            this.SmartCards.Remove(SmartCard);
            this.InvokeSmartCardRemoved(SmartCard);
        }
        public IHttpActionResult Select()
        {
            ICardReader cardReader = ContextManager.GetCardReader();

            IHttpActionResult result = Json <ResultArgs>(cardReader.Select());

            logger.Debug(result.ToString());
            return(result);
        }
        public IHttpActionResult Info()
        {
            ICardReader cardReader = ContextManager.GetCardReader();

            return(Json <ResultArgs>(new ResultArgs(true)
            {
                Result = cardReader.GetVersion(),
                Msg = "OK"
            }));
        }
 public BorrowControlTests()
 {
     _display = Substitute.For<IDisplay>();
     _reader = Substitute.For<ICardReader>();
     _scanner = Substitute.For<IScanner>();
     _printer = Substitute.For<IPrinter>();
     _bookDao = Substitute.For<IBookDAO>();
     _loanDao = Substitute.For<ILoanDAO>();
     _memberDao = Substitute.For<IMemberDAO>();
 }
 public void Dispose()
 {
     _display = null;
     _reader = null;
     _scanner = null;
     _printer = null;
     _bookDao = null;
     _loanDao = null;
     _memberDao = null;
 }
Esempio n. 21
0
        private void AddSmartCard(ICardReader cardReader)
        {
            Debug.Assert(cardReader != null);
            Debug.Assert(cardReader.SmartCard != null);

            ISmartCard SmartCard = cardReader.SmartCard;

            this.SmartCards.Add(SmartCard);
            this.InvokeSmartCardAdded(SmartCard);
        }
Esempio n. 22
0
 public void Dispose()
 {
     _display   = null;
     _reader    = null;
     _scanner   = null;
     _printer   = null;
     _bookDao   = null;
     _loanDao   = null;
     _memberDao = null;
 }
        public Scenario04CompleteScans()
        {
            _bookDao = new BookDao(new BookHelper());
            _loanDao = new LoanDao(new LoanHelper());
            _memberDao = new MemberDao(new MemberHelper());

            _display = new MainWindow();
            _reader = new CardReader();
            _scanner = new Scanner();
            _printer = new Printer();
        }
Esempio n. 24
0
 public PadWinViewModel(ICardReader cardReader, ILogger logger, IFileConfiguration fileConfiguration,
                        IParameterPass parameterPass)
 {
     _cardReader        = cardReader;
     _logger            = logger;
     _fileConfiguration = fileConfiguration;
     _parameterPass     = parameterPass;
     LoadCommand        = new RelayCommand <ChromiumWebBrowser>(ExcuteLoadCommand);
     UnLoadCommand      = new RelayCommand(ExcuteUnLoadCommand);
     CloseCommand       = new RelayCommand(ExcuteCloseCommand);
 }
        public BorrowControlIntegration()
        {
            _bookDao = new BookDao(new BookHelper());
            _loanDao = new LoanDao(new LoanHelper());
            _memberDao = new MemberDao(new MemberHelper());

            _display = new MainWindow();
            _reader = new CardReader();
            _scanner = new Scanner();
            _printer = new Printer();
        }
        public Scenario02SwipeBorrowerCard()
        {
            _bookDao = new BookDao(new BookHelper());
            _loanDao = new LoanDao(new LoanHelper());
            _memberDao = new MemberDao(new MemberHelper());

            _display = new MainWindow();
            _reader = new CardReader();
            _scanner = new Scanner();
            _printer = new Printer();
        }
Esempio n. 27
0
        private void RemoveCardReader(ICardReader cardReader)
        {
            cardReader.SmartCardInserted -= this.SubsystemSmartCardInserted;
            cardReader.SmartCardRemoved  -= this.SubsystemSmartCardRemoved;
            if (cardReader.SmartCard != null)
            {
                this.RemoveSmartCard(cardReader);
            }

            this.CardReaders.Remove(cardReader);
            this.InvokeCardReaderRemoved(cardReader);
        }
Esempio n. 28
0
        public Form1()
        {
            InitializeComponent();

            //Nastaveni do Fullscreen modu
            FillWholeScreen();

            //Aktivace ctecky
            cardReader = new CardReaderFactory().CreateReader("COM3", CardFormat.Desfire);
            cardReader.OnCardRead += new AbstractCardReader.ICardRead(cardReader_OnCardRead);
            cardReader.Start();
        }
        public MainMenuController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                    IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            _display = display;
            _reader = reader;
            _scanner = scanner;
            _printer = printer;

            _bookDAO = bookDAO;
            _loanDAO = loanDAO;
            _memberDAO = memberDAO;
        }
Esempio n. 30
0
        public Form1()
        {
            InitializeComponent();

            //Nastaveni do Fullscreen modu
            FillWholeScreen();

            //Aktivace ctecky
            cardReader             = new CardReaderFactory().CreateReader("COM3", CardFormat.Desfire);
            cardReader.OnCardRead += new AbstractCardReader.ICardRead(cardReader_OnCardRead);
            cardReader.Start();
        }
        public BorrowController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                    IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            _display = display;
            _reader = reader;
            _scanner = scanner;
            _printer = printer;

            _ui = new BorrowControl(this);

            _state = EBorrowState.CREATED;
        }
        public MainMenuController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                  IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            _display = display;
            _reader  = reader;
            _scanner = scanner;
            _printer = printer;

            _bookDAO   = bookDAO;
            _loanDAO   = loanDAO;
            _memberDAO = memberDAO;
        }
Esempio n. 33
0
        /// <summary>
        /// Extension method to SmartCardConnection class similar to Transmit asyc method, however it accepts PCSC SDK commands.
        /// </summary>
        /// <param name="apduCommand">
        /// APDU command object to send to the ICC
        /// </param>
        /// <param name="reader">
        /// SmartCardConnection object
        /// </param>
        /// <returns>APDU response object of type defined by the APDU command object</returns>
        public static Iso7816.ApduResponse Transceive(this ICardReader reader, Iso7816.ApduCommand apduCommand)
        {
            Iso7816.ApduResponse apduRes = Activator.CreateInstance(apduCommand.ApduResponseType) as Iso7816.ApduResponse;

            byte[] resp          = new byte[256];
            int    bytesReceived = reader.Transmit(apduCommand.ToByteArray(), resp);

            Array.Resize(ref resp, bytesReceived);

            apduRes.ExtractResponse(resp);

            return(apduRes);
        }
Esempio n. 34
0
        private void AddCardReader(ICardReader cardReader)
        {
            //cardReader.SetCardReaderUICallback( CardReaders.cardReaderUICallback );
            this.CardReaders.Add(cardReader);
            this.InvokeCardReaderAdded(cardReader);

            cardReader.SmartCardInserted += this.SubsystemSmartCardInserted;
            cardReader.SmartCardRemoved  += this.SubsystemSmartCardRemoved;
            if (cardReader.SmartCard != null)
            {
                this.AddSmartCard(cardReader);
            }
        }
Esempio n. 35
0
 /// <summary>
 /// Receive and print ATR string attribute
 /// </summary>
 /// <param name="reader">Connected smart-card reader instance</param>
 private string DisplayAtr(ICardReader reader)
 {
     try
     {
         var atr = reader.GetAttrib(SCardAttribute.AtrString);
         return(BitConverter.ToString(atr ?? new byte[] { }));
     }
     catch (Exception exception)
     {
         outputError.Text = exception.Message;
         return(null);
     }
 }
Esempio n. 36
0
        public MainMenuController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                    IBookDAO bookDao, ILoanDAO loanDao, IMemberDAO memberDao, ICardReaderEvents cardReaderEvents)
        {
            CardReaderEvents = cardReaderEvents;
            _display = display;
            _reader = reader;
            _scanner = scanner;
            _printer = printer;

            _bookDao = bookDao;
            _loanDao = loanDao;
            _memberDao = memberDao;
        }
        public BorrowController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            if (display == null)
            {
                throw new ArgumentException("Display object was not provided to begin the application");
            }
            if (reader == null)
            {
                throw new ArgumentException("Reader object was not provided to begin the application");
            }
            if (scanner == null)
            {
                throw new ArgumentException("Scanner object was not provided to begin the application");
            }
            if (printer == null)
            {
                throw new ArgumentException("Printer object was not provided to begin the application");
            }
            if (bookDAO == null)
            {
                throw new ArgumentException("BookDAO object was not provided to begin the application");
            }
            if (loanDAO == null)
            {
                throw new ArgumentException("LoanDAO object was not provided to begin the application");
            }
            if (memberDAO == null)
            {
                throw new ArgumentException("MemberDAO object was not provided to begin the application");
            }

            _display = display;
            _reader  = reader;
            _scanner = scanner;
            _printer = printer;

            _bookDAO   = bookDAO;
            _loanDAO   = loanDAO;
            _memberDAO = memberDAO;

            _ui = new BorrowControl(this);

            _reader.Listener  = this;
            _scanner.Listener = this;

            _bookList = new List <IBook>();
            _loanList = new List <ILoan>();

            _state = EBorrowState.CREATED;
        }
Esempio n. 38
0
 /// <summary>
 /// Receive and print ATR string attribute
 /// </summary>
 /// <param name="reader">Connected smart-card reader instance</param>
 private static void DisplayAtr(ICardReader reader)
 {
     try {
         var atr = reader.GetAttrib(SCardAttribute.AtrString);
         Console.WriteLine("Reader: {0}, ATR: {1}",
                           reader.Name,
                           BitConverter.ToString(atr ?? new byte[] { }));
     } catch (Exception exception) {
         Console.WriteLine("Reader: {0}, Error by trying to receive the ATR. {1} ({2})\n",
                           reader.Name,
                           exception.Message,
                           exception.GetType());
     }
 }
Esempio n. 39
0
 /// <summary>
 /// Gets the smart card inserted in the given card reader
 /// </summary>
 /// <exception cref="IndexOutOfRangeException">Thown if no smart card is inserted in the given reader</exception>
 public ISmartCard this[ICardReader cardReader]
 {
     get
     {
         foreach (ISmartCard SmartCard in this.InnerList)
         {
             if (SmartCard.CardReader == cardReader)
             {
                 return(SmartCard);
             }
         }
         throw new IndexOutOfRangeException(cardReader.FriendlyName);
     }
 }
Esempio n. 40
0
 /// <summary>
 /// Prints the reader's status
 /// </summary>
 /// <param name="reader">Connected reader</param>
 private static void PrintReaderStatus(ICardReader reader)
 {
     try {
         var status = reader.GetStatus();
         Console.WriteLine("Reader {0} connected with protocol {1} in state {2}",
                           status.GetReaderNames().FirstOrDefault(),
                           status.Protocol,
                           status.State);
         PrintCardAtr(status.GetAtr());
     } catch (Exception exception) {
         Console.WriteLine("Unable to retrieve card status.\nError message: {0} ({1}", exception,
                           exception.GetType());
     }
 }
Esempio n. 41
0
        private void InitializeReader()
        {
            if (reader == null)
            {
                reader = new MBMEDevices.Readers.Artema();

                #if DEBUG
                    reader.InitAsync(Boolean.Parse(ConfigurationManager.AppSettings["SimulateReader"]));
                #else
                    reader.InitAsync(false);
                #endif
            }
        }
Esempio n. 42
0
 public void SendReaderParameter( ICardReader reader)
 {
              reader.SetOpenDoorAutoCloseTime(OpenDoorAutoCloseTime);
             reader.SetOpenDoorTimeoutDetectionTime(DoorOpenAlarmTime);
             reader.SetOpenDoorDetectionAlarmTime(0);
 }
Esempio n. 43
0
        void cardreader_OnStatusChanged(ICardReader reader, CardReaderEventReport rpt)
        {

            try
            {
                if (rpt.Status == (int)CardReaderStatusEnum.卡號連續錯誤 && this.EventInvalidCardAlarm || rpt.Status == (int)CardReaderStatusEnum.外力破壞 && this.EventExternalForceAlarm ||
                     rpt.Status == (int)CardReaderStatusEnum.異常入侵 && this.EventIntrusionAlarm || rpt.Status == (int)CardReaderStatusEnum.開門超時 && this.EventDoorOpenOverTimeAlarm ||
                     rpt.Status == (int)CardReaderStatusEnum.開鎖 && this.EventDoorOpenAlarm || rpt.Status == (int)CardReaderStatusEnum.號碼錯誤 && this.R23InvalidCardAlarm
                   )
                {
                    if (this.OnAlarmEvent != null)
                    {
                        ICCTV cctv = (ICCTV)SecureService.cctv_mgr[reader.TriggerCCTVID];
                        AlarmData data = new AlarmData()
                        {
                            TimeStamp = DateTime.Now,
                            AlarmType = AlarmType.Secure,
                            ColorString = "Red",
                            Description = reader.ControllerID + "," + rpt.StatusString,
                            PlaneID = reader.PlaneID,
                            IsForkCCTVEvent = true,
                            PlaneName = Global.GetPlaneNameByPlaneID(reader.PlaneID),
                            CCTVBindingData = cctv!=null?cctv.ToBindingData():null






                        };


                        this.OnAlarmEvent(reader, data);

                    }
                }



                if (rpt.Status == (int)CardReaderStatusEnum.開鎖 ||
                    rpt.Status == (int)CardReaderStatusEnum.按鈕開門 ||
                    rpt.Status == (int)CardReaderStatusEnum.密碼開門 || rpt.Status == (int)CardReaderStatusEnum.系統開門 ||
                    rpt.Status == (int)CardReaderStatusEnum.異常入侵 || rpt.Status == (int)CardReaderStatusEnum.開門超時)
                {
                    SecureDBEntities1 db = new SecureDBEntities1();
                    tblEngineRoomLog log = new tblEngineRoomLog()
                          {
                              ControlID = reader.ControllerID,
                              ABA = rpt.CardNo.ToString(),
                              StartTime = DateTime.Now,
                              TypeID = 8,
                              Memo = rpt.StatusString,
                              TypeCode = (short)rpt.Status,
                              ERNo = reader.PlaneID.ToString()
                          };
                    db.tblEngineRoomLog.Add(

                        log
                        );






                    db.SaveChanges();
                    //開門錄影
                    if (rpt.Status == (int)CardReaderStatusEnum.開鎖 ||
                   rpt.Status == (int)CardReaderStatusEnum.按鈕開門 ||
                   rpt.Status == (int)CardReaderStatusEnum.密碼開門 || rpt.Status == (int)CardReaderStatusEnum.系統開門)
                    {


                        if (reader.NVRID == -1)
                            return;
                        #region 擷取錄影
#if R23
#else
                        Task task = Task.Factory.StartNew(() =>
                            {

                                DateTime dt = DateTime.Now;
                                System.Threading.Thread.Sleep(1000 * 20);

                                long flowid = log.FlowID;
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("nvrid:" + reader.NVRID);
                                try
                                {
                                    NVR.INVR nvr = SecureService.nvr_mgr[reader.NVRID];
                                    if (nvr == null)
                                    {
                                        Console.WriteLine(reader.NVRID + " is null");
                                        return;
                                    }


                                    bool success = nvr.SaveRecord(

                                //           reader.NVRChNo, dt.AddSeconds(-10), dt.AddSeconds(10), @"C:\web\Secure\ClientBin\VideoRecord\" + flowid + ".avi");

                                     reader.NVRChNo, dt.AddSeconds(-10), dt.AddSeconds(10), @"E:\web\Secure\ClientBin\VideoRecord\" + flowid + ".avi");

                                    //bool success = nvr.SaveRecord(
                                    //reader.NVRChNo, dt.AddSeconds(-10), dt.AddSeconds(10), @"D:\" + flowid + ".avi");

                                    log.NVRFile = flowid + ".wmv";
                                    db.SaveChanges();
                                    Console.WriteLine(success);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message + "," + ex.StackTrace);
                                }
                                finally
                                {
                                    Console.ResetColor();
                                }
                            });
#endif

                        #endregion



                    }

                    if (this.serivce != null && reader.TriggerCCTVID != 0)
                    {


                        if (InOperationCCTV.Where(n => n == reader.TriggerCCTVID).Count() > 0)
                        {
                            Task.Factory.StartNew(() =>
                                {
                                    try
                                    {


                                        Console.WriteLine("Trigger " + reader.TriggerCCTVID);
                                        SecureService.cctv_mgr[reader.TriggerCCTVID].Preset(2);
                                        System.Threading.Thread.Sleep(1000 * 10);
                                        SecureService.cctv_mgr[reader.TriggerCCTVID].Preset(1);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("May be trigger cctv not found" + ex.Message + "," + ex.StackTrace);
                                    }
                                    InOperationCCTV.Remove(reader.TriggerCCTVID);
                                });

                        }
                    }

                }


                if (rpt.Status == (int)CardReaderStatusEnum.號碼錯誤 ||
                  rpt.Status == (int)CardReaderStatusEnum.卡號連續錯誤 ||
                  rpt.Status == (int)CardReaderStatusEnum.外力破壞
                  )
                {
                    SecureDBEntities1 db = new SecureDBEntities1();

                    db.tblEngineRoomLog.Add(

                          new tblEngineRoomLog()
                          {
                              ControlID = reader.ControllerID,
                              ABA = rpt.CardNo.ToString(),
                              StartTime = DateTime.Now,
                              TypeID = 8,
                              Memo = rpt.StatusString,
                              TypeCode = (short)rpt.Status,
                              ERNo = reader.PlaneID.ToString()
                          }
                        );
                    db.SaveChanges();

                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("CardManager OnStatus Change:" + ex.Message + "," + ex.StackTrace);
            }
               
           
           
        }
Esempio n. 44
0
        //void cardreader_OnAlarmEvent(CardReader reder, AlarmData alarmdata)
        //{
        //    if (this.OnAlarmEvent != null)
        //        this.OnAlarmEvent(reder, alarmdata);
        //}

        void cardreader_OnDoorEvent(ICardReader reader, DoorEventType enumEventType)
        {
            if (this.OnDoorEvent != null)
            {
                try
                {
                    this.OnDoorEvent(reader, enumEventType);
                }
                catch { ;}
            }

            if (enumEventType == DoorEventType.Connected)
            {

                SecureDBEntities1 db = new SecureDBEntities1();
                tblControllerConfig config = db.tblControllerConfig.Where(n => n.ControlID == reader.ControllerID).FirstOrDefault();
                if (config != null)
                    config.Comm_state = 1;
                tblEngineRoomLog log = new tblEngineRoomLog() { ControlID = reader.ControllerID, ABA = "0", StartTime = DateTime.Now, TypeID = 8, TypeCode = 31, Result = 1 };
                db.tblEngineRoomLog.Add(log);
                db.SaveChanges();
                db.Dispose();

                 AlarmData data = new AlarmData()
                {
                    TimeStamp = DateTime.Now,
                    AlarmType = AlarmType.Secure,
                    ColorString = "Green",
                    Description = reader.ControllerID + "復線",
                    PlaneID = reader.PlaneID,
                    IsForkCCTVEvent = false,
                    PlaneName = Global.GetPlaneNameByPlaneID(reader.PlaneID)
                    //  CCTVBindingData =cctv.ToBindingData(

                };
                
                    Program.MyServiceObject.DispatchAlarmEvent(data);

            
                this.DownloadSuperPassword(reader.ControllerID);
            }
            if (enumEventType == DoorEventType.DisConnected)
            {
               
                SecureDBEntities1 db = new SecureDBEntities1();

                tblControllerConfig config = db.tblControllerConfig.Where(n => n.ControlID == reader.ControllerID).FirstOrDefault();
                if (config != null)
                    config.Comm_state = 0;
                 tblEngineRoomLog log=new tblEngineRoomLog(){ ControlID=reader.ControllerID, ABA="0", StartTime=DateTime.Now,  TypeID=8, TypeCode=30,  Result=0};
                 db.tblEngineRoomLog.Add(log);
                 db.SaveChanges();
                db.Dispose();


                AlarmData data = new AlarmData()
                {
                    TimeStamp = DateTime.Now,
                    AlarmType = AlarmType.Secure,
                    ColorString = "Red",
                    Description = reader.ControllerID + "斷線警報",
                    PlaneID = reader.PlaneID,
                    IsForkCCTVEvent = false,
                    PlaneName = Global.GetPlaneNameByPlaneID(reader.PlaneID)
                    //  CCTVBindingData =cctv.ToBindingData(

                };
                
                    Program.MyServiceObject.DispatchAlarmEvent(data);

            }



        }
Esempio n. 45
0
        internal MiFareCard(ICardReader reader)
        {
            Reader = reader;

            Initialize();
        }