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); }
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]); }
/// <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); }