Example #1
0
        public void TermReader()
        {
            //Stop reading and disable/close the reader
            if (this.mReader != null)
            {
                try {
                    //Stop all the notifications and detach all the notification handler if the user has not done it already
                    StopRead();
                    DetachReadNotify();
                    DetachStatusNotify();

                    //Disable the reader, and free it up
                    this.mReader.Actions.Disable();
                    this.mReader.Dispose();
                    this.mReader = null;
                }
                catch (Symbol.Exceptions.OperationFailureException ex) { MessageBox.Show("TermReader" + "\n" + "OperationFailure" + "\n" + ex.Message + "\n" + "Result" + " = " + (Symbol.Results)((uint)ex.Result)); }
                catch (Symbol.Exceptions.InvalidRequestException ex) { MessageBox.Show("TermReader" + "\n" + "InvalidRequest" + "\n" + ex.Message); }
                catch (Symbol.Exceptions.InvalidIndexerException ex) { MessageBox.Show("TermReader" + "\n" + "InvalidIndexer" + "\n" + ex.Message); }
            }

            // After disposing the reader, dispose the reader data.
            if (this.mReaderData != null)
            {
                try {
                    //Free it up.
                    this.mReaderData.Dispose();
                    this.mReaderData = null;
                }
                catch (Symbol.Exceptions.OperationFailureException ex) { MessageBox.Show("TermReader" + "\n" + "OperationFailure" + "\n" + ex.Message + "\n" + "Result" + " = " + (Symbol.Results)((uint)ex.Result)); }
                catch (Symbol.Exceptions.InvalidRequestException ex) { MessageBox.Show("TermReader" + "\n" + "InvalidRequest" + "\n" + ex.Message); }
                catch (Symbol.Exceptions.InvalidIndexerException ex) { MessageBox.Show("TermReader" + "\n" + "InvalidIndexer" + "\n" + ex.Message); }
            }
        }
Example #2
0
        /// <summary>
        ///     Open the scanner device
        /// </summary>
        public void Open()
        {
            if (scannerStatus == ScannerStatus.Opened)
            {
                return;
            }

            try
            {
                reader     = new Reader();
                readerData = new ReaderData(ReaderDataTypes.Text, ReaderDataLengths.MaximumLabel);
                reader.Actions.Enable();

                // SuperGros ProductNumber
                reader.Decoders.I2OF5.MinimumLength = 6;
                reader.Decoders.I2OF5.MaximumLength = 14;

                StartRead();

                scannerStatus = ScannerStatus.Opened;
            }
            catch
            {
                Close();
                throw;
            }
        }
    public override bool Initialize()
    {
        // If the scanner is already present, fail to initialize
        if (symbolReader != null)
        {
            return(false);
        }

        // Create a new scanner; use the first available scanner
        symbolReader = new Reader();

        // Create the scanner data
        symbolReaderData = new ReaderData(ReaderDataTypes.Text,
                                          ReaderDataLengths.MaximumLabel);

        // Create the event handler delegate
        symbolReader.ReadNotify += new EventHandler(symbolReader_ReadNotify);

        // Enable the scanner with a wait cursor
        symbolReader.Actions.Enable();

        // Set up the scanner
        //symbolReader.Parameters.Feedback.Success.BeepTime = 0;
        //symbolReader.Parameters.Feedback.Success.WaveFile =Application2.StartupPath + "\\beep.wav";

        return(true);
    }
        /// <summary>
        /// Funckja pozawlająca na modyfiikowanie danych czytelnika.
        /// </summary>
        /// <param name="readerID">Identyfikator czytelnika</param>
        /// <param name="newData">Nowe dane</param>
        /// <param name="dataType">Modyfikowany parametr</param>
        public void ModifyReaderData(int readerID, string newData, ReaderData dataType)
        {
            if (IsReaderIDExists(readerID))
            {
                if (newData.Trim() != "")
                {
                    switch (dataType)
                    {
                    case ReaderData.Name:
                        readers.Find(r => r.ID.Equals(readerID)).Name = newData;
                        break;

                    case ReaderData.PhoneNumber:
                        readers.Find(r => r.ID.Equals(readerID)).PhoneNumber = newData;
                        break;

                    case ReaderData.EmailAddress:
                        readers.Find(r => r.ID.Equals(readerID)).EmailAddress = newData;
                        break;
                    }
                }
                else
                {
                    throw new ArgumentException("Nowe dane nie mogą być puste");
                }
            }
            else
            {
                throw new ArgumentException("Czytelnik o podanym identyfikatorze nie istnieje");
            }
        }
        /// <summary>
        /// Initiates the Symbol scanner.
        /// </summary>
        /// <returns>Whether initialization was successful</returns>
        public override bool Initialize()
        {
            // If scanner is already present then fail initialize
            if (symbolReader != null)
            {
                return(false);
            }

            // Create new scanner, first available scanner will be used.
            symbolReader = new Reader();

            // Create scanner data
            symbolReaderData = new ReaderData(ReaderDataTypes.Text,ReaderDataLengths.DefaultText);

            // Create event handler delegate

            symbolReader.ReadNotify += new EventHandler(symbolReader_ReadNotify);

            // Enable scanner, with wait cursor
            symbolReader.Actions.Enable();

            symbolReader.Actions.GetParameters();

            // Setup scanner
            symbolReader.Parameters.Feedback.Success.BeepTime = 0;
            symbolReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";

            // Для чтения кодов плохого качества
            symbolReader.Decoders.CODE128.Enabled       = true;
            symbolReader.Decoders.CODE128.EAN128        = true;
            symbolReader.Decoders.CODE128.SecurityLevel = CODE128.SECURITYLEVEL.LEVEL_3;
            symbolReader.Decoders.CODE128.Redundancy    = false;
            symbolReader.Decoders.CODE128.Other128      = true;
            symbolReader.Decoders.CODE128.MaximumLength = 55;

            symbolReader.Decoders.I2OF5.Enabled       = true;
            symbolReader.Decoders.I2OF5.MaximumLength = 30;

            symbolReader.Decoders.RSS14.Enabled          =
                symbolReader.Decoders.RSSEXP.Enabled     =
                    symbolReader.Decoders.RSSLIM.Enabled = true;

            symbolReader.Decoders.RSSEXP.MaximumLength = 76;

            symbolReader.Actions.SetParameters();

            // Настройка WiFi отображения
            try
            {
                xWLan     = new WLAN(FusionAccessType.STATISTICS_MODE);
                base.WiFi = new SymWiFi(xWLan);
            }
            catch (Exception e)
            {
                //xRadio = new Radio();
                //base.WiFi = new SymWiFi(xRadio);
            }

            return(true);
        }
Example #6
0
 public Form1()
 {
     InitializeComponent();
     Reader = new ReaderData();
     bikes  = Reader.Bikesarr;
     FillGrid();
 }
        internal bool isBackground = false; //The flag used to track whether the application is in background or not (in foreground).

        /// <summary>
        /// Initialize the reader.
        /// </summary>
        public bool InitReader()
        {
            // If the reader is already initialized then fail the initialization.
            if (myReader != null)
            {
                return(false);
            }
            else // Else initialize the reader.
            {
                try
                {
                    // Get the device selected by the user.
                    for (int i = 0; i < Symbol.Barcode.Device.AvailableDevices.Count(); i++)
                    {
                        if (Device.AvailableDevices[i].DeviceName == "SCN1:")
                        {
                            MyDevice = Device.AvailableDevices[i];
                        }
                    }

                    if (MyDevice == null)
                    {
                        return(false);
                    }

                    // Create the reader, based on selected device.
                    myReader = new Reader(MyDevice);

                    // Create the reader data.
                    myReaderData = new ReaderData(
                        ReaderDataTypes.Text,
                        ReaderDataLengths.MaximumLabel);

                    // Enable the Reader.
                    myReader.Actions.Enable();

                    // In this sample, we are setting the aim type to trigger.
                    switch (myReader.ReaderParameters.ReaderType)
                    {
                    case Symbol.Barcode.READER_TYPE.READER_TYPE_IMAGER:
                        myReader.ReaderParameters.ReaderSpecific.ImagerSpecific.AimType = Symbol.Barcode.AIM_TYPE.AIM_TYPE_TRIGGER;
                        break;

                    case Symbol.Barcode.READER_TYPE.READER_TYPE_LASER:
                        myReader.ReaderParameters.ReaderSpecific.LaserSpecific.AimType = Symbol.Barcode.AIM_TYPE.AIM_TYPE_TRIGGER;
                        break;

                    case Symbol.Barcode.READER_TYPE.READER_TYPE_CONTACT:
                        // AimType is not supported by the contact readers.
                        break;
                    }
                    myReader.Actions.SetParameters();
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
        }
Example #8
0
        /// <summary>
        /// Stop reading and disable/close reader.
        /// </summary>
        private void TermReader()
        {
            // If we have a reader
            if (this.MyReader != null)
            {
                // Disable the reader
                this.MyReader.Actions.Disable();

                // Free it up
                this.MyReader.Dispose();

                // Indicate we no longer have one
                this.MyReader = null;
            }

            // If we have a reader data
            if (this.MyReaderData != null)
            {
                // Free it up
                this.MyReaderData.Dispose();

                // Indicate we no longer have one
                this.MyReaderData = null;
            }
        }
Example #9
0
        public void Disable()
        {
            _suspendedFlag = true;
            _reader.Actions.Flush();
            _reader.Actions.Disable();

            _readerData.Dispose();
            _reader.Dispose();

            _readerData = null;
            _reader = null;
        }
Example #10
0
        public bool InitReader()
        {
            //Initialize the reader
            if (this.mReader != null)
            {
                return(false);
            }
            else
            {
                try {
                    //Get the device selected by the user
                    Symbol.Generic.Device device = Symbol.StandardForms.SelectDevice.Select(Symbol.Barcode.Device.Title, Symbol.Barcode.Device.AvailableDevices);
                    if (device == null)
                    {
                        MessageBox.Show("No Device Selected", "SelectDevice");
                        return(false);
                    }

                    //Create the reader based on selected device, and the reader data
                    this.mReader     = new Symbol.Barcode.Reader(device);
                    this.mReaderData = new Symbol.Barcode.ReaderData(Symbol.Barcode.ReaderDataTypes.Text, Symbol.Barcode.ReaderDataLengths.MaximumLabel);

                    //Enable the Reader, and set the aim type to trigger.
                    this.mReader.Actions.Enable();
                    switch (this.mReader.ReaderParameters.ReaderType)
                    {
                    case Symbol.Barcode.READER_TYPE.READER_TYPE_IMAGER:
                        this.mReader.ReaderParameters.ReaderSpecific.ImagerSpecific.AimType = Symbol.Barcode.AIM_TYPE.AIM_TYPE_TRIGGER;
                        break;

                    case Symbol.Barcode.READER_TYPE.READER_TYPE_LASER:
                        this.mReader.ReaderParameters.ReaderSpecific.LaserSpecific.AimType = Symbol.Barcode.AIM_TYPE.AIM_TYPE_TRIGGER;
                        break;

                    case Symbol.Barcode.READER_TYPE.READER_TYPE_CONTACT:
                        // AimType is not supported by the contact readers.
                        break;
                    }
                    this.mReader.Actions.SetParameters();
                }
                catch (Symbol.Exceptions.OperationFailureException ex) {
                    MessageBox.Show("InitReader" + "\n" + "OperationFailure" + "\n" + ex.Message + "\n" + "Result" + " = " + (Symbol.Results)((uint)ex.Result));
                    return(false);
                }
                catch (Symbol.Exceptions.InvalidRequestException ex) { MessageBox.Show("InitReader" + "\n" + "InvalidRequest" + "\n" + ex.Message);
                                                                       return(false); }
                catch (Symbol.Exceptions.InvalidIndexerException ex) {
                    MessageBox.Show("InitReader" + "\n" + "InvalidIndexer" + "\n" + ex.Message);
                    return(false);
                }
                return(true);
            }
        }
Example #11
0
        private void ScannedDataEvent(object sender, EventArgs e)
        {
            ReaderData data = reader.GetNextReaderData();

            if (data != null)
            {
                if (data.Result == Results.SUCCESS)
                {
                    HandleData(data);
                    StartRead();
                }
            }
        }
Example #12
0
        private void HandleData(ReaderData reader)
        {
            List <string> list = new List <string>();

            list.Add(reader.Text);

            if (Scanned != null)
            {
                Scanned.Invoke(this, new ScannedDataEventArgs(list.ToArray()));
            }

            scannerStatus = ScannerStatus.Opened;
        }
Example #13
0
        //# __________ PROTOCOL :: PRIVATE __________ #//
        public void IntializeReader()
        {
            _reader = new Reader();
            _readerData = new ReaderData(
                ReaderDataTypes.Text,
                ReaderDataLengths.MaximumLabel);
            _reader.ReadNotify += new EventHandler(r_ReadNotify);
            _reader.Actions.Enable();

            if( _shouldAllowCode93 ) _reader.Decoders.SetEnabled(DecoderTypes.CODE93, true);
            //            this.MyReader.Parameters.Feedback.Success.BeepTime = 0;
            //            this.MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";
        }
Example #14
0
        private void HandleData(ReaderData data)
        {
            if (Scanned != null)
            {
                var barcodeData = new BarcodeData
                {
                    Text        = data.Text,
                    BarcodeType = (BarcodeTypes)data.Type
                };
                Scanned.Invoke(this, new ScannedDataEventArgs(new[] { barcodeData }));
            }

            scannerStatus = ScannerStatus.Opened;
        }
    private void symbolReader_ReadNotify(object sender, EventArgs e)
    {
        if (symbolReader != null)
        {
            ReaderData readerData = symbolReader.GetNextReaderData();

            // If successful, scan
            if (readerData.Result == Results.SUCCESS)
            {
                // Raise the scan event to the caller (with data)
                OnBarcodeScan(new BarcodeScannerEventArgs(readerData.Text));

                // Start the next scan
                Start();
            }
        }
    }
Example #16
0
        /// <summary>
        /// Initialize the reader.
        /// </summary>
        private void InitReader()
        {
            //  If reader is already present, fail.
            if (MyReader != null)
            {
                return;
            }

            MyReader = new Symbol.Barcode.Reader();
            if (MyReader == null)
            {
                throw new SymbolRFGunException("Unable to initialize reader");
            }

            //  Create reader data.
            // MyReaderData = new Symbol.Barcode.ReaderData(
            //     Symbol.Barcode.ReaderDataTypes.Text,
            //     Symbol.Barcode.ReaderDataLengths.DefaultText);

            //8-18-2010 Changed to allow greater length for 2D barcodes 254 characters
            MyReaderData = new Symbol.Barcode.ReaderData(
                Symbol.Barcode.ReaderDataTypes.Text,
                254);
            if (MyReaderData == null)
            {
                throw new SymbolRFGunException("Unable to initialize reader data");
            }

            //  Create event handler delegate.
            MyEventHandler = new EventHandler(MyReader_ReadNotify);
            if (MyEventHandler == null)
            {
                throw new SymbolRFGunException("Unable to initialize event handler for reader");
            }

            //  Enable reader.
            MyReader.Actions.Enable();
            MyReader.Decoders.CODE39.FullAscii = true;

            //  Handle success and failure sounds manually.
            MyReader.Parameters.Feedback.Success.BeepTime = 0;

            //  Start reader.
            StartRead();
        }
 public static void SetDrawerActive(int drawerId)
 {
     if (CurrentActiveRfidDrawer == drawerId)
     {
         return;
     }
     if ((Device != null) && (Device.IsConnected))
     {
         _CurrentActiveRfidDrawer = drawerId;
         if (DrawerInventoryData[_CurrentActiveRfidDrawer] == null)
         {
             DrawerInventoryData[_CurrentActiveRfidDrawer] = new ReaderData();
         }
         Device.ReaderData = DrawerInventoryData[_CurrentActiveRfidDrawer];
         Device.StopField();
         Device.SendSwitchCommand(true, (byte)_CurrentActiveRfidDrawer, false);
     }
 }
Example #18
0
        /// <summary>
        /// Close the scanner device
        /// </summary>
        public void Close()
        {
            if (reader == null)
            {
                scannerStatus = ScannerStatus.Closed;
                return;
            }

            StopRead();

            reader.Actions.Disable();
            reader.Dispose();
            reader = null;
            readerData.Dispose();
            readerData = null;

            scannerStatus = ScannerStatus.Closed;
        }
Example #19
0
 public bool AddReader(ReaderData readerData)
 {
     try
     {
         using (IRepositoryTransactionContext ctx = ObjectContainer.Instance.GetService <IRepositoryTransactionContext>())
         {
             IRepository <Reader> readerRepository = ctx.GetRepository <Reader>();
             Reader reader = readerData.ToEntity();
             readerRepository.Add(reader);
             ctx.Commit();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #20
0
        //
        //public List<T> ReaderFile<T>()
        public List <T> ReaderFile <T>(ReaderData <T> readerData)
        {
            FileStream   file   = null;
            StreamReader reader = null;
            List <T>     list   = new List <T>();

            try
            {
                var path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["path"].ToString());

                file   = new FileStream(path, FileMode.Open);
                reader = new StreamReader(file);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var item = readerData(line);
                    if (null != item)
                    {
                        list.Add(readerData(line));
                    }

                    Console.WriteLine(line); // Write to console.
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                    reader.Dispose();
                }

                if (null != file)
                {
                    file.Close();
                    file.Dispose();
                }
            }
            return(list);
        }
        /// <summary>
        /// Stop reading and disable/close the reader.
        /// </summary>
        public void TermReader()
        {
            // If we have a reader
            if (myReader != null)
            {
                try
                {
                    // stop all the notifications.
                    StopRead();

                    //Detach all the notification handler if the user has not done it already.
                    DetachReadNotify();
                    DetachStatusNotify();

                    // Disable the reader.
                    myReader.Actions.Disable();

                    // Free it up.
                    myReader.Dispose();

                    // Make the reference null.
                    myReader = null;
                }

                catch {}
            }

            // After disposing the reader, dispose the reader data.
            if (myReaderData != null)
            {
                try
                {
                    // Free it up.
                    myReaderData.Dispose();

                    // Make the reference null.
                    myReaderData = null;
                }

                catch {}
            }
        }
Example #22
0
        /// <summary>
        /// Initialize the reader.
        /// </summary>
        private void InitReader()
        {
            //  If reader is already present, fail.
            if (MyReader != null)
            {
                return;
            }

            MyReader = new Symbol.Barcode.Reader();
            if (MyReader == null)
            {
                throw new SymbolRFGunException("Unable to initialize reader");
            }

            //  Create reader data.
            MyReaderData = new Symbol.Barcode.ReaderData(
                Symbol.Barcode.ReaderDataTypes.Text,
                Symbol.Barcode.ReaderDataLengths.DefaultText);
            if (MyReaderData == null)
            {
                throw new SymbolRFGunException("Unable to initialize reader data");
            }

            //  Create event handler delegate.
            MyEventHandler = new EventHandler(MyReader_ReadNotify);
            if (MyEventHandler == null)
            {
                throw new SymbolRFGunException("Unable to initialize event handler for reader");
            }

            //  Enable reader.
            MyReader.Actions.Enable();

            //  Handle success and failure sounds manually.
            MyReader.Parameters.Feedback.Success.BeepTime = 0;

            //  Start reader.
            StartRead();
        }
Example #23
0
        private void barcode1_OnRead(object sender, ReaderData readerData)
        {
            string s;

            if (readerData.Text.Length == 12)
            {
                s = "0" + readerData.Text;
            }
            else if (readerData.Text.Length == 14)
            {
                s = readerData.Text.Substring(1);
            }
            else if (readerData.Text.Length == 13)
            {
                s = readerData.Text;
            }
            else
            {
                s = "";
            }
            OnReadBarCode(s, readerData.Text);
        }
Example #24
0
        /// <summary>
        /// Open the scanner device
        /// </summary>
        public void Open()
        {
            if (scannerStatus == ScannerStatus.Opened)
            {
                return;
            }

            try
            {
                reader     = new Reader();
                readerData = new ReaderData(ReaderDataTypes.Text, ReaderDataLengths.MaximumLabel);
                reader.Actions.Enable();

                StartRead();

                scannerStatus = ScannerStatus.Opened;
            }
            catch
            {
                Close();
                throw;
            }
        }
        /// <summary>
        /// Terminates the Symbol scanner.
        /// </summary>
        public override void Terminate()
        {
            // If we have a scanner
            if (symbolReader != null)
            {
                // Disable the scanner
                symbolReader.Actions.Disable();

                // Free it up
                symbolReader.Dispose();

                // Indicate we no longer have one
                symbolReader = null;
            }

            // If we have a scanner data object
            if (symbolReaderData != null)
            {
                // Free it up
                symbolReaderData.Dispose();

                // Indicate we no longer have one
                symbolReaderData = null;
            }
            if (xSymKeyPad != null)
            {
                xSymKeyPad.AlphaNotify    -= ALPNotify;
                xSymKeyPad.KeyStateNotify -= Sym48_KeyStateNotify;
                xSymKeyPad.Dispose();
            }
            if (xWLan != null)
            {
                xWLan.Dispose();
            }
            //if (xRadio != null)
            //    xRadio.Dispose();
        }
        private IndexReader ReplaceActiveReader(IndexReader outOfDateReader, object directoryProviderLock,
            IDirectoryProvider directoryProvider, IndexReader[] readers)
        {
            bool trace = log.IsInfoEnabled;
            IndexReader oldReader;
            bool closeOldReader = false;
            bool closeOutOfDateReader = false;
            IndexReader reader;
            /**
             * Since out of lock protection, can have multiple readers created in //
             * not worse than NotShared and limit the locking time, hence scalability
             */
            try
            {
                reader = IndexReader.Open(directoryProvider.Directory);
            }
            catch (IOException e)
            {
                throw new SearchException("Unable to open Lucene IndexReader", e);
            }
            lock (directoryProviderLock)
            {
                // Since not protected by a lock, other ones can have been added
                oldReader = activeSearchIndexReaders[directoryProvider] = reader;
                lock (semaphoreIndexReaderLock)
                {
                    searchIndexReaderSemaphores[reader] = new ReaderData(1, directoryProvider);
                    if (trace) log.Info("Semaphore: 1 for " + reader);
                    if (outOfDateReader != null)
                    {
                        ReaderData readerData;
                        searchIndexReaderSemaphores.TryGetValue(outOfDateReader, out readerData);
                        if (readerData == null)
                        {
                            closeOutOfDateReader = false; //already removed by another prevous thread
                        }
                        else if (readerData.Semaphore == 0)
                        {
                            searchIndexReaderSemaphores.Remove(outOfDateReader);
                            closeOutOfDateReader = true;
                        }
                        else
                        {
                            closeOutOfDateReader = false;
                        }
                    }

                    if (oldReader != null && oldReader != outOfDateReader)
                    {
                        ReaderData readerData = searchIndexReaderSemaphores[oldReader];
                        if (readerData == null)
                        {
                            log.Warn("Semaphore should not be null");
                            closeOldReader = true; //TODO should be true or false?
                        }
                        else if (readerData.Semaphore == 0)
                        {
                            searchIndexReaderSemaphores.Remove(oldReader);
                            closeOldReader = true;
                        }
                        else
                        {
                            closeOldReader = false;
                        }
                    }
                }
            }

            if (closeOutOfDateReader)
            {
                if (trace) log.Info("Closing out of date IndexReader " + outOfDateReader);
                try
                {
                    outOfDateReader.Close();
                }
                catch (IOException e)
                {
                    ReaderProviderHelper.Clean(readers);
                    throw new SearchException("Unable to close Lucene IndexReader", e);
                }
            }
            if (closeOldReader)
            {
                if (trace) log.Info("Closing old IndexReader " + oldReader);
                try
                {
                    oldReader.Close();
                }
                catch (IOException e)
                {
                    ReaderProviderHelper.Clean(readers);
                    throw new SearchException("Unable to close Lucene IndexReader", e);
                }
            }
            return reader;
        }
 public override void Terminate()
 {
     symbolReader     = null;
     symbolReaderData = null;
 }
        public static ReaderData CloneObject(ReaderData rd)
        {
            var jss = new JavaScriptSerializer();

            return(jss.Deserialize <ReaderData>(jss.Serialize(rd)));
        }
        /// <summary>
        /// Event that fires when a Symbol scanner has performed a scan.
        /// </summary>
        private void symbolReader_ReadNotify(object sender,EventArgs e)
        {
            ReaderData readerData = symbolReader.GetNextReaderData();

            // If it is a successful scan (as opposed to a failed one)
            if (readerData.Result == Results.SUCCESS)
            {
                BCId nType = BCId.NoData;

                // Преобразовать Symbol-тип штрихкода к моему
                switch (readerData.Type)
                {
                case DecoderTypes.EAN128:
                case DecoderTypes.CODE128:
                    nType = BCId.Code128;
                    break;

                case DecoderTypes.EAN13:
                    nType = BCId.EAN13;
                    break;

                case DecoderTypes.EAN8:
                    nType = BCId.EAN8;
                    break;

                case DecoderTypes.I2OF5:
                case DecoderTypes.D2OF5:
                case DecoderTypes.IATA2OF5:
                case DecoderTypes.CHINESE_2OF5:
                    nType = BCId.Interleaved25;
                    break;

                case DecoderTypes.IMAGE:
                    nType = BCId.Image;
                    break;

                case DecoderTypes.CODE11:
                    nType = BCId.Code11;
                    break;

                case DecoderTypes.CODE39:
                    nType = BCId.Code39;
                    break;

                case DecoderTypes.RSS14:
                case DecoderTypes.RSSEXP:
                case DecoderTypes.RSSLIM:
                    nType = BCId.GS1DataBar;
                    break;

                default:
                    nType = BCId.Unknown;
                    break;
                }

                // Raise scan event to caller (with data)
                BarcodeScannerEventArgs xBCA = new BarcodeScannerEventArgs(nType,readerData.Text);
                OnBarcodeScan(xBCA);

                // Start the next scan
                Start();
            }
        }
        public IndexReader OpenReader(IDirectoryProvider[] directoryProviders)
        {
            bool trace  = log.IsInfoEnabled;
            int  length = directoryProviders.Length;

            IndexReader[] readers = new IndexReader[length];

            if (trace)
            {
                log.Info("Opening IndexReader for directoryProviders: " + length);
            }

            for (int index = 0; index < length; index++)
            {
                IDirectoryProvider directoryProvider = directoryProviders[index];
                IndexReader        reader;
                object             directoryProviderLock = perDirectoryProviderManipulationLocks[directoryProvider];
                if (trace)
                {
                    log.Info("Opening IndexReader from " + directoryProvider.Directory);
                }
                lock (directoryProviderLock)
                {
                    activeSearchIndexReaders.TryGetValue(directoryProvider, out reader);
                }
                if (reader == null)
                {
                    if (trace)
                    {
                        log.Info("No shared IndexReader, opening a new one: " + directoryProvider.Directory);
                    }
                    reader = ReplaceActiveReader(null, directoryProviderLock, directoryProvider, readers);
                }
                else
                {
                    bool isCurrent;
                    try
                    {
                        isCurrent = reader.IsCurrent();
                    }
                    catch (IOException e)
                    {
                        throw new SearchException("Unable to read current status of Lucene IndexReader", e);
                    }

                    if (!isCurrent)
                    {
                        if (trace)
                        {
                            log.Info("Out of date shared IndexReader found, opening a new one: " +
                                     directoryProvider.Directory);
                        }
                        IndexReader outOfDateReader = reader;
                        reader = ReplaceActiveReader(outOfDateReader, directoryProviderLock, directoryProvider, readers);
                    }
                    else
                    {
                        if (trace)
                        {
                            log.Info("Valid shared IndexReader: " + directoryProvider.Directory);
                        }

                        lock (directoryProviderLock)
                        {
                            //read the latest active one, the current one could be out of date and closed already
                            //the latest active is guaranteed to be active because it's protected by the dp lock
                            reader = activeSearchIndexReaders[directoryProvider];
                            lock (semaphoreIndexReaderLock)
                            {
                                ReaderData readerData = searchIndexReaderSemaphores[reader];
                                //TODO if readerData is null????
                                readerData.Semaphore++;
                                searchIndexReaderSemaphores[reader] = readerData; //not necessary
                                if (trace)
                                {
                                    log.Info("Semaphore increased: " + readerData.Semaphore + " for " + reader);
                                }
                            }
                        }
                    }
                }
                readers[index] = reader;
            }

            return(ReaderProviderHelper.BuildMultiReader(length, readers));
        }
        private IndexReader ReplaceActiveReader(IndexReader outOfDateReader, object directoryProviderLock,
                                                IDirectoryProvider directoryProvider, IndexReader[] readers)
        {
            bool        trace = log.IsInfoEnabled;
            IndexReader oldReader;
            bool        closeOldReader       = false;
            bool        closeOutOfDateReader = false;
            IndexReader reader;

            /**
             * Since out of lock protection, can have multiple readers created in //
             * not worse than NotShared and limit the locking time, hence scalability
             */
            try
            {
                reader = IndexReader.Open(directoryProvider.Directory);
            }
            catch (IOException e)
            {
                throw new SearchException("Unable to open Lucene IndexReader", e);
            }
            lock (directoryProviderLock)
            {
                // Since not protected by a lock, other ones can have been added
                oldReader = activeSearchIndexReaders[directoryProvider] = reader;
                lock (semaphoreIndexReaderLock)
                {
                    searchIndexReaderSemaphores[reader] = new ReaderData(1, directoryProvider);
                    if (trace)
                    {
                        log.Info("Semaphore: 1 for " + reader);
                    }
                    if (outOfDateReader != null)
                    {
                        ReaderData readerData;
                        searchIndexReaderSemaphores.TryGetValue(outOfDateReader, out readerData);
                        if (readerData == null)
                        {
                            closeOutOfDateReader = false; //already removed by another prevous thread
                        }
                        else if (readerData.Semaphore == 0)
                        {
                            searchIndexReaderSemaphores.Remove(outOfDateReader);
                            closeOutOfDateReader = true;
                        }
                        else
                        {
                            closeOutOfDateReader = false;
                        }
                    }

                    if (oldReader != null && oldReader != outOfDateReader)
                    {
                        ReaderData readerData = searchIndexReaderSemaphores[oldReader];
                        if (readerData == null)
                        {
                            log.Warn("Semaphore should not be null");
                            closeOldReader = true; //TODO should be true or false?
                        }
                        else if (readerData.Semaphore == 0)
                        {
                            searchIndexReaderSemaphores.Remove(oldReader);
                            closeOldReader = true;
                        }
                        else
                        {
                            closeOldReader = false;
                        }
                    }
                }
            }

            if (closeOutOfDateReader)
            {
                if (trace)
                {
                    log.Info("Closing out of date IndexReader " + outOfDateReader);
                }
                try
                {
                    outOfDateReader.Close();
                }
                catch (IOException e)
                {
                    ReaderProviderHelper.Clean(readers);
                    throw new SearchException("Unable to close Lucene IndexReader", e);
                }
            }
            if (closeOldReader)
            {
                if (trace)
                {
                    log.Info("Closing old IndexReader " + oldReader);
                }
                try
                {
                    oldReader.Close();
                }
                catch (IOException e)
                {
                    ReaderProviderHelper.Clean(readers);
                    throw new SearchException("Unable to close Lucene IndexReader", e);
                }
            }
            return(reader);
        }