Beispiel #1
0
        public RFIDListener()
        {
            DokanNFCConfig config = DokanNFCConfig.GetSingletonInstance();

            this.readerProviderName = config.ReaderProvider;
            this.readerUnitName     = config.ReaderUnit;
        }
Beispiel #2
0
        private void RemovalChecker()
        {
            new Thread(new ThreadStart(delegate()
            {
                IReaderUnit readerUnit = DokanNFCConfig.CreateReaderUnitFromName(readerProvider, readerUnitName);
                if (readerUnit.ConnectToReader())
                {
                    if (readerUnit.WaitInsertion(1))
                    {
                        while (!readerUnit.WaitRemoval(500) && IsRunning)
                        {
                            ;
                        }

                        if (insertedChip != null)
                        {
                            ResetCard();
                        }
                    }
                    readerUnit.DisconnectFromReader();
                }

                GC.KeepAlive(readerUnit);
            }
                                       )).Start();
        }
        public static DokanNFCConfig GetSingletonInstance()
        {
            if (instance == null)
            {
                instance = GetInstanceFromFile();
            }

            return(instance);
        }
 public void SetConfiguration(DokanNFCConfig config)
 {
     rbtnModeRaw.Checked           = (config.Mode == DisplayMode.RawRFID);
     rbtnModeNFC.Checked           = (config.Mode == DisplayMode.NFC);
     cbReaderProvider.SelectedItem = config.ReaderProvider;
     cbReaderUnit.SelectedItem     = config.ReaderUnit;
     chkKeepMounted.Checked        = config.AlwaysMounted;
     cbMountPoint.SelectedItem     = config.MountPoint;
 }
 public void SetConfiguration(DokanNFCConfig config)
 {
     rbtnModeRaw.Checked = (config.Mode == DisplayMode.RawRFID);
     rbtnModeNFC.Checked = (config.Mode == DisplayMode.NFC);
     cbReaderProvider.SelectedItem = config.ReaderProvider;
     cbReaderUnit.SelectedItem = config.ReaderUnit;
     chkKeepMounted.Checked = config.AlwaysMounted;
     cbMountPoint.SelectedItem = config.MountPoint;
 }
Beispiel #6
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         DokanNFCConfig config = GetConfiguration();
         config.SaveToFile();
         MessageBox.Show(Properties.Resources.ConfigSaved, Properties.Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public static DokanNFCConfig GetInstanceFromFile(string fileName)
        {
            DokanNFCConfig config = new DokanNFCConfig();

            if (File.Exists(FileName))
            {
                XmlSerializer xs = new XmlSerializer(typeof(DokanNFCConfig));
                using (StreamReader rr = new StreamReader(FileName))
                {
                    config = xs.Deserialize(rr) as DokanNFCConfig;
                }
            }
            return(config);
        }
        public DokanNFCConfig GetConfiguration()
        {
            DokanNFCConfig config = new DokanNFCConfig();

            if (rbtnModeRaw.Checked)
                config.Mode = DisplayMode.RawRFID;
            else if (rbtnModeNFC.Checked)
                config.Mode = DisplayMode.NFC;
            config.ReaderProvider = (cbReaderProvider.SelectedIndex > -1) ? cbReaderProvider.SelectedItem.ToString() : String.Empty;
            config.ReaderUnit = (cbReaderUnit.SelectedIndex > -1) ? cbReaderUnit.SelectedItem.ToString() : String.Empty;
            config.AlwaysMounted = chkKeepMounted.Checked;
            config.MountPoint = (cbMountPoint.SelectedIndex > -1) ? cbMountPoint.SelectedItem.ToString() : String.Empty;

            return config;
        }
        public DokanNFCConfig GetConfiguration()
        {
            DokanNFCConfig config = new DokanNFCConfig();

            if (rbtnModeRaw.Checked)
            {
                config.Mode = DisplayMode.RawRFID;
            }
            else if (rbtnModeNFC.Checked)
            {
                config.Mode = DisplayMode.NFC;
            }
            config.ReaderProvider = (cbReaderProvider.SelectedIndex > -1) ? cbReaderProvider.SelectedItem.ToString() : String.Empty;
            config.ReaderUnit     = (cbReaderUnit.SelectedIndex > -1) ? cbReaderUnit.SelectedItem.ToString() : String.Empty;
            config.AlwaysMounted  = chkKeepMounted.Checked;
            config.MountPoint     = (cbMountPoint.SelectedIndex > -1) ? cbMountPoint.SelectedItem.ToString() : String.Empty;

            return(config);
        }
Beispiel #10
0
        public static DokanNFCConfig GetSingletonInstance()
        {
            if (instance == null)
            {
                instance = GetInstanceFromFile();
            }

            return instance;
        }
Beispiel #11
0
 public static DokanNFCConfig GetInstanceFromFile(string fileName)
 {
     DokanNFCConfig config = new DokanNFCConfig();
     if (File.Exists(FileName))
     {
         XmlSerializer xs = new XmlSerializer(typeof(DokanNFCConfig));
         using (StreamReader rr = new StreamReader(FileName))
         {
             config = xs.Deserialize(rr) as DokanNFCConfig;
         }
     }
     return config;
 }
Beispiel #12
0
 public void SetConfiguration(DokanNFCConfig config)
 {
     dokanNFCConfigControl.SetConfiguration(config);
 }
 public DokanRFIDDriver(RFIDListener rfidListener)
 {
     this.rfidListener = rfidListener;
     this.cacheFiles   = new Dictionary <string, FileCache>();
     this.nfcConfig    = DokanNFCConfig.GetSingletonInstance();
 }
 private void InitMountPoints()
 {
     cbMountPoint.Items.Clear();
     cbMountPoint.Items.Add(String.Empty);
     cbMountPoint.Items.AddRange(DokanNFCConfig.GetAvailableMountPoints());
 }
 private void DokanNFCConfigControl_Load(object sender, EventArgs e)
 {
     InitializeReaderProviderList();
     InitMountPoints();
     SetConfiguration(DokanNFCConfig.GetSingletonInstance());
 }
Beispiel #16
0
 public DokanRFIDDriver(RFIDListener rfidListener)
 {
     this.rfidListener = rfidListener;
     this.cacheFiles = new Dictionary<string, FileCache>();
     this.nfcConfig = DokanNFCConfig.GetSingletonInstance();
 }
Beispiel #17
0
        protected void Listen()
        {
            IsRunning         = true;
            waitRemoval       = new AutoResetEvent(false);
            insertedChip      = null;
            chipInsertionDate = null;

            log.Info(String.Format("Listening on {0} reader {1}...", readerProviderName, readerUnitName));

            readerProvider = DokanNFCConfig.CreateReaderProviderFromName(readerProviderName);
            readerUnit     = DokanNFCConfig.CreateReaderUnitFromName(readerProvider, readerUnitName);

            if (readerProvider != null && readerUnit != null)
            {
                if (readerUnit.ConnectToReader())
                {
                    DokanNFCConfig config = DokanNFCConfig.GetSingletonInstance();
                    switch (config.Mode)
                    {
                    case DisplayMode.RawRFID:
                        break;

                    case DisplayMode.NFC:
                        driver = new NFCDokanRFIDDriver(this);
                        break;
                    }

                    if (driver != null)
                    {
                        string mountPoint = config.MountPoint;
                        if (String.IsNullOrEmpty(mountPoint))
                        {
                            string[] mountPoints = DokanNFCConfig.GetAvailableMountPoints();
                            if (mountPoints.Length > 0)
                            {
                                mountPoint = mountPoints[0];
                            }
                        }

                        if (!String.IsNullOrEmpty(mountPoint))
                        {
                            DokanOptions options = DokanOptions.FixedDrive;
                            if (config.AlwaysMounted)
                            {
                                Mount(mountPoint, options);
                            }
                            else
                            {
                                options |= DokanOptions.RemovableDrive;
                            }
                            do
                            {
                                if (readerUnit.WaitInsertion(500))
                                {
                                    Thread.Sleep(400);
                                    chipInsertionDate = DateTime.Now;
                                    log.Info("Card inserted.");
                                    if (readerUnit.Connect())
                                    {
                                        insertedChip = readerUnit.GetSingleChip();
                                        if (insertedChip != null)
                                        {
                                            log.Info(String.Format("Chip type `{0}`", insertedChip.Type));
                                            if (!config.AlwaysMounted)
                                            {
                                                Mount(mountPoint, options);
                                            }

                                            RemovalChecker();
                                            while (!waitRemoval.WaitOne(500) && IsRunning)
                                            {
                                                ;
                                            }
                                            log.Info("Card removed.");

                                            if (!config.AlwaysMounted)
                                            {
                                                Unmount(mountPoint);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        log.Error("Cannot connect to the card.");
                                    }
                                    chipInsertionDate = null;
                                }
                            } while (IsRunning);

                            if (config.AlwaysMounted)
                            {
                                Unmount(mountPoint);
                            }
                        }
                        else
                        {
                            log.Error("No mount point.");
                        }
                    }
                    else
                    {
                        log.Error("No matching file system driver to mount.");
                    }
                    readerUnit.DisconnectFromReader();
                }
                else
                {
                    log.Error("Cannot connect to the reader.");
                }

                GC.KeepAlive(readerUnit);
                GC.KeepAlive(readerProvider);
            }
            else
            {
                log.Error("Error in RFID reader resource allocation.");
            }
        }
Beispiel #18
0
 public void SetConfiguration(DokanNFCConfig config)
 {
     dokanNFCConfigControl.SetConfiguration(config);
 }