Exemplo n.º 1
0
        public RFIDListener()
        {
            DokanNFCConfig config = DokanNFCConfig.GetSingletonInstance();

            this.readerProviderName = config.ReaderProvider;
            this.readerUnitName     = config.ReaderUnit;
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        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;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 10
0
        public static DokanNFCConfig GetSingletonInstance()
        {
            if (instance == null)
            {
                instance = GetInstanceFromFile();
            }

            return instance;
        }
Exemplo n.º 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;
 }
Exemplo n.º 12
0
 public void SetConfiguration(DokanNFCConfig config)
 {
     dokanNFCConfigControl.SetConfiguration(config);
 }
Exemplo n.º 13
0
 public DokanRFIDDriver(RFIDListener rfidListener)
 {
     this.rfidListener = rfidListener;
     this.cacheFiles   = new Dictionary <string, FileCache>();
     this.nfcConfig    = DokanNFCConfig.GetSingletonInstance();
 }
Exemplo n.º 14
0
 private void InitMountPoints()
 {
     cbMountPoint.Items.Clear();
     cbMountPoint.Items.Add(String.Empty);
     cbMountPoint.Items.AddRange(DokanNFCConfig.GetAvailableMountPoints());
 }
Exemplo n.º 15
0
 private void DokanNFCConfigControl_Load(object sender, EventArgs e)
 {
     InitializeReaderProviderList();
     InitMountPoints();
     SetConfiguration(DokanNFCConfig.GetSingletonInstance());
 }
Exemplo n.º 16
0
 public DokanRFIDDriver(RFIDListener rfidListener)
 {
     this.rfidListener = rfidListener;
     this.cacheFiles = new Dictionary<string, FileCache>();
     this.nfcConfig = DokanNFCConfig.GetSingletonInstance();
 }
Exemplo n.º 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.");
            }
        }
Exemplo n.º 18
0
 public void SetConfiguration(DokanNFCConfig config)
 {
     dokanNFCConfigControl.SetConfiguration(config);
 }