public static void PostItemScannedCallback(StateManager.Item item) { MainForm.Default.m_MainContext.Post(MainForm.Default.ShowItemScannedCallback, item); ms_Done.Set(); }
/// <summary> /// EXAMPLE! NOT IN USE NOW /// </summary> /// <returns></returns> private static Action <TaskProcessOrganizer <string> .TaskItem> CreateScanActionORIGINAL() { const int TRIES = 10; return(new Action <TaskProcessOrganizer <string> .TaskItem>((o) => { var fullFilePath = o.Item; Bitmap bmp = null; Bitmap bmpBarcode = null; BarcodeData data = null; string barcode = null; string siteCode = null; StateManager.Item item = null; try { var info = new FileInfo(fullFilePath); if (info.Exists && !info.IsReadOnly(TRIES)) { // ".tif" var ext = Path.GetExtension(info.FullName); #if PROC_TIFF_AS_JPEG if (ext == ".tif") { int c = 0; foreach (var im in info.FullName.TiffGetAllImages()) { var name = info.FullName.ChangeFilePath((n) => n.Replace(ext, c++ + ext)); im.Save(name); im.DisposeSf(); } return; } #endif bmp = ((Bitmap)Bitmap.FromFile(info.FullName)).Crop2(); item = StateManager.Default.ProcessItem_Begin(!MainForm.ms_ImportCoversheet); item.FullFileName = fullFilePath; item.FileInfoList.Add(new FileInfo(fullFilePath)); // Scanned Image if (!MainForm.ms_ImportCoversheet) { StateManager.VoucherItem vitem = (StateManager.VoucherItem)item; FileInfo barcFilePath = null; Rectangle rect = Rectangle.Empty; CommonTools.ParseVoucherImage(ref bmp, ref bmpBarcode, out rect, ref barcode, BarcodeTypeEnum.BT_All); vitem.Barcode = barcode; if (vitem.HasBarcode) { string user = string.Concat("Country: ", Program.currentUser.CountryID, " User: "******"{0:dd-MM-yyyy hh:mm}", DateTime.Now); gr.DrawString(str, font, Brushes.Black, new PointF(10, 10)); gr.DrawString(u.Cast <string>(), font, Brushes.Black, new PointF(10, 25)); } }, user); var coverArea = StateSaver.Default.Get <Rectangle>(Strings.VOUCHERCOVERREGION); if (!coverArea.IsEmpty) { var size = StateSaver.Default.Get <int>(Strings.PIXELSIZE, 5); bmp.Pixellate(coverArea); } List <BarcodeConfig> barcodeLayouts = StateSaver.Default.Get <List <BarcodeConfig> >(Strings.LIST_OF_BARCODECONFIGS); foreach (var cfg in barcodeLayouts) { if (cfg.ParseBarcode(barcode, ref data)) { break; } } if (data == null) { throw new ApplicationException("Can not find barcode"); } item.CountryID = data.CountryID; vitem.RetailerID = data.RetailerID; vitem.VoucherID = data.VoucherID; vitem.Barcode = barcode; var barcodePath = fullFilePath.ChangeFilePath((name) => name.Replace(".", "_barcode.")); Global.IgnoreList.Add(barcodePath); bmpBarcode.DrawOnImage((gr, s) => { using (var font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular)) { var str = Convert.ToString(s); gr.DrawString(str, font, Brushes.Red, new PointF(10, 10)); } }, barcode); bmpBarcode.Save(barcodePath, bmp.RawFormat); barcFilePath = new FileInfo(barcodePath); // Scanned Barcode vitem.FileInfoList.Add(barcFilePath); // Scanned Barcode Image } } else { MainForm.ms_ImportCoversheet = false; MainForm.Default.InvokeSf(() => MainForm.Default.cbCoversheet.Checked = false); } if (item.CountryID == 0) { item.CountryID = MainForm.ms_DefaultCountryId; } if (!ext.EqualNoCase(".tif")) { bmp.Save(fullFilePath, ImageFormat.Jpeg); } if (item.Thumbnail == null) { item.Thumbnail = bmp.GetThumbnailImage(45, 45, () => false, IntPtr.Zero); } var sec = new CertificateSecurity(X509FindType.FindBySerialNumber, Strings.CERTNUMBER, StoreLocation.LocalMachine); if (sec.Loaded) { var signFilePath = new FileInfo(Path.ChangeExtension(fullFilePath, ".sgn")); item.Signature = sec.SignData(bmp.ToArray()); File.WriteAllBytes(signFilePath.FullName, item.Signature); item.FileInfoList.Add(signFilePath); } item.State = StateManager.eState.OK; item.Message = ""; } } catch (Exception ex) { if (item != null) { item.State = StateManager.eState.Err; item.Message = ex.Message; } var scex = new ScanException(ex, data) { SiteCode = siteCode, FilePath = fullFilePath }; if (Error != null) { Error(null, new ThreadExceptionEventArgs(ex)); } } finally { bmp.DisposeSf(); bmpBarcode.DisposeSf(); MainForm.Default.m_MainContext.Post(MainForm.Default.ShowItemScannedCallback, item); try { StateManager.Default.ProcessItem_End(item); } catch (Exception ex0) { if (item != null) { item.State = StateManager.eState.Err; item.Message = ex0.Message; } var scex = new ScanException(ex0, data) { SiteCode = siteCode, FilePath = fullFilePath }; if (Error != null) { Error(null, new ThreadExceptionEventArgs(scex)); } } } })); }
public Action <TaskProcessOrganizer <string> .TaskItem> GetAction() { const int TRIES = 10; return(new Action <TaskProcessOrganizer <string> .TaskItem>((o) => { var fullFilePath = o.Item; Bitmap bmp = null; Bitmap bmpBarcode = null; BarcodeData data = null; string siteCode = null; StateManager.Item item = StateManager.Default.ProcessItem_Begin(false); try { var info = new FileInfo(fullFilePath); if (info.Exists && !info.IsReadOnly(TRIES)) { // ".tif" var ext = Path.GetExtension(info.FullName); bmp = ((Bitmap)Bitmap.FromFile(info.FullName)).Crop2(); item.FullFileName = fullFilePath; item.FileInfoList.Add(new FileInfo(fullFilePath)); // Scanned Image MainForm.ms_ImportCoversheet = false; MainForm.Default.InvokeSf(() => MainForm.Default.cbCoversheet.Checked = false); if (item.CountryID == 0) { item.CountryID = MainForm.ms_DefaultCountryId; } if (!ext.EqualNoCase(".tif")) { bmp.Save(fullFilePath, ImageFormat.Jpeg); } if (item.Thumbnail == null) { item.Thumbnail = bmp.GetThumbnailImage(45, 45, () => false, IntPtr.Zero); } item.State = StateManager.eState.OK; item.Message = ""; StateManager.Default.CompleteItem(item); } } catch (Exception ex) { if (item != null) { item.State = StateManager.eState.Err; item.Message = ex.Message; } var scex = new ScanException(ex, data) { SiteCode = "na", FilePath = fullFilePath }; DelegateHelper.FireError(this, ex); } finally { bmp.DisposeSf(); bmpBarcode.DisposeSf(); DelegateHelper.PostItemScannedCallback(item); try { StateManager.Default.AddNewItem(item); } catch (Exception ex0) { if (item != null) { item.State = StateManager.eState.Err; item.Message = ex0.Message; } var scex = new ScanException(ex0, data) { SiteCode = siteCode, FilePath = fullFilePath }; DelegateHelper.FireError(this, scex); } } })); }