Esempio n. 1
0
        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);

            var args = Environment.GetCommandLineArgs();

            if (args.Length == 2)
            {
                Guid key    = Guid.Parse(args[1]);
                var  buffer = ClientDataAccess.SelectBarcodeInfoData(key);

                using (MemoryStream mem = new MemoryStream(buffer))
                    using (Image img = Bitmap.FromStream(mem))
                    {
                        BarcodeReader reader = new BarcodeReader();
                        reader.BarcodesToRead = 1;
                        reader.BarcodeTypes   = BarcodeTypeEnum.BT_Inter2of5;
                        Barcode[]        barcodes = reader.ReadFromImage(img);
                        var              barArray = new BarcodeInfoArray(barcodes);
                        ObjectSerializer ser      = new ObjectSerializer(true);
                        var              buffer2  = ser.Serialize(barArray);
                        ClientDataAccess.UpdateBarcodeInfo(key, buffer2);
                    }
            }
            Close();
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var g      = Guid.NewGuid();
            var buffer = File.ReadAllBytes(@"C:\Users\Rosen.rusev\Desktop\Voucher1.png");

            ClientDataAccess.InsertBarcodeInfo(g, buffer);

            var p = Process.Start(@"C:\PROJECTS\VScan\BarReaderProc\bin\Debug\ReaderProc.exe", g.ToString());

            p.WaitForExit();
            var buffer2 = ClientDataAccess.SelectBarcodeInfoData(g);

            ClientDataAccess.DeleteBarcodeInfo(g);
            ObjectSerializer ser = new ObjectSerializer(true);
            var barArray         = ser.Deserialize <BarcodeInfoArray>(buffer2);
        }
Esempio n. 3
0
        public static BarcodeInfo ReadBarcodeReaderResults(Process p, Guid g)
        {
            if (!p.WaitForExit((int)TimeSpan.FromSeconds(10).TotalMilliseconds))
            {
                throw new TimeoutException("Reader timeout");
            }

            var buffer2 = ClientDataAccess.SelectBarcodeInfoData(g);

            ClientDataAccess.DeleteBarcodeInfo(g);
            ObjectSerializer ser = new ObjectSerializer(true);
            var barArray         = ser.Deserialize <BarcodeInfoArray>(buffer2);

            if (barArray.Count == 0)
            {
                throw new IndexOutOfRangeException("No barcode found");
            }
            return(barArray[0]);
        }
Esempio n. 4
0
        /// <summary>
        /// Used to find and exctract the barcode
        /// </summary>
        /// <returns></returns>
        public static VoucherProcessDelegate CreateExtractBarCodeDelegate2()
        {
            var method = new VoucherProcessDelegate((Voucher data, StateObj state) =>
            {
                Debug.Assert(state.Main != IntPtr.Zero);
                Debug.Assert(state.Scan != IntPtr.Zero);
                Debug.Assert(data != null);

                if (data.VoucherImage == null)
                {
                    throw new AppWarningException("No image found");
                }

                Guid g     = Guid.NewGuid();
                var buffer = data.VoucherImage.ToArray();
                ClientDataAccess.InsertBarcodeInfo(g, buffer);

                string path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ReaderProc.exe");
                var p       = Process.Start(path, g.ToString());

                if (!p.WaitForExit((int)TimeSpan.FromSeconds(10).TotalMilliseconds))
                {
                    throw new TimeoutException("Reader timeout");
                }

                var buffer2 = ClientDataAccess.SelectBarcodeInfoData(g);
                ClientDataAccess.DeleteBarcodeInfo(g);

                ObjectSerializer ser      = new ObjectSerializer(true);
                BarcodeInfoArray barArray = ser.Deserialize <BarcodeInfoArray>(buffer2);
                if (barArray.Count == 0)
                {
                    throw new IndexOutOfRangeException("No barcode found");
                }

                if (barArray == null || barArray.Count == 0)
                {
                    var ex = new ApplicationException("No bar code found");
                    ex.AddNext(new MethodInvoker(() =>
                    {
                        string id    = Strings.VScan_EditItem.Uniqueue();
                        data.Message = ex.Message;
                        DataSlot.Set(id, data);
                        WinMsg.SendText(state.Scan, state.Main, id);
                    }));
                    throw ex;
                }
                else if (barArray.Count > 1)
                {
                    var ex = new ApplicationException("More than one bar code on image.");
                    ex.AddNext(new MethodInvoker(() =>
                    {
                        string id    = Strings.VScan_EditItem.Uniqueue();
                        data.Message = ex.Message;
                        DataSlot.Set(id, data);
                        WinMsg.SendText(state.Scan, state.Main, id);
                    }));
                    throw ex;
                }

                try
                {
                    data.Parse(barArray[0].String);
                }
                catch (Exception e)
                {
                    var ex = new ApplicationException("Can't parse barcode string.", e);
                    ex.AddNext(new MethodInvoker(() =>
                    {
                        string id    = Strings.VScan_EditItem.Uniqueue();
                        data.Message = ex.Message;
                        DataSlot.Set(id, data);
                        WinMsg.SendText(state.Scan, state.Main, id);
                        VoucherMonitorForm.ShowImage(id);
                    }));
                    throw ex;
                }
            });

            return(method);
        }