static GameObject ImportImpl(string path, ImportParams p) { if (path == null || path == "") { return(null); } string baseName = System.IO.Path.GetFileNameWithoutExtension(path); string name = baseName; int index = 1; while (GameObject.Find("/" + name) != null) { name = baseName + index; ++index; } GameObject root = new GameObject(); root.name = name; var abcStream = root.AddComponent <AlembicStream>(); abcStream.m_pathToAbc = path; abcStream.m_swapHandedness = p.swapHandedness; abcStream.m_swapFaceWinding = p.swapFaceWinding; abcStream.AbcLoad(true); return(root); }
} // = new ConcurrentDictionary<string, IConverter>(); public static ImportResults <T> Import <T>(string ImportType, string[] ImportParams = null) { IConverter IImporter; if (ImportParams == null) { ImportParams = new string[] { }; } if (File.Exists(ImportType)) { var ImportList = ImportParams.ToList(); ImportList.Insert(0, ImportType); ImportParams = ImportList.ToArray(); IImporter = Converter.FindByExtension(Path.GetExtension(ImportType).Replace(".", "")); } else { IImporter = Converter.Find(ImportType); } var Results = IImporter.Import <T>(ImportParams); // foreach (var Result in Results.Results) // { // Result.App.SourceFilePath = Result.FileName; // } return(Results); }
public static GameObject ImportAbc(string path) { var relPath = MakeRelativePath(path); ImportParams p = new ImportParams(); return(ImportImpl(relPath, p)); }
//------------------------------------------------------------- // // //------------------------------------------------------------- // If the never call flag is being forced then add it to the query private void forceNeverCallFlag() { ImportParams importParams = (ImportParams)Session["importparams"]; bool forceNeverCall = false; int neverCallType = 0; if (importParams.exceptionType == 3) { forceNeverCall = true; neverCallType = 1; } if (importParams.exceptionType == 2) { forceNeverCall = true; neverCallType = importParams.neverCallType; } if (forceNeverCall) { if (sqlCols == string.Empty) { sqlCols = "NeverCallFlag"; sqlValues = ("" + importParams.neverCallType); strUpdate = String.Format("{0}={1}", "NeverCallFlag", ("" + neverCallType)); } else { sqlCols += "," + "NeverCallFlag"; sqlValues += "," + ("" + importParams.neverCallType); strUpdate += ", " + String.Format("{0}={1}", "NeverCallFlag", ("" + neverCallType)); } } }
private async Task <ScannedImage> ExportRawPdfPage(PdfPage page, ImportParams importParams) { string pdfPath = Path.Combine(Paths.Temp, Path.GetRandomFileName()); var document = new PdfDocument(); document.Pages.Add(page); document.Save(pdfPath); var image = ScannedImage.FromSinglePagePdf(pdfPath, false); if (!importParams.NoThumbnails || importParams.DetectPatchCodes) { using (var bitmap = await scannedImageRenderer.Render(image)) { if (!importParams.NoThumbnails) { image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); } if (importParams.DetectPatchCodes) { image.PatchCode = PatchCodeDetector.Detect(bitmap); } } } return(image); }
//------------------------------------------------------------- // // //------------------------------------------------------------- // This is where the file import actually happens protected void lbtnUpload_Click(object sender, EventArgs e) { if (ValidateDataMapping()) { ImportParams importParams = (ImportParams)Session["importparams"]; char delimiterchar = Convert.ToChar(importParams.delimter == "t" ? "\t" : importParams.delimter); List <ImportFieldRow> list = ReadCSVData(importParams.filePath, importParams.isFirstRowHeader, delimiterchar); if (list.Count > 0) { createDuplicateFile(); SetupDataImport(list); Session["DupFilePath"] = sDupFilePath; Session["ImportStats"] = importStats; Response.Redirect("ImportStatsDNC.aspx"); } else { PageMessage = "No Valid data found in this file, Please check file and mappings"; } } else { PageMessage = "Columns not assigned correctly."; } }
static void Import() { var path = MakeRelativePath(EditorUtility.OpenFilePanel("Select alembic (.abc) file in StreamingAssets directory", Application.streamingAssetsPath, "abc")); ImportParams p = new ImportParams(); ImportImpl(path, p); }
public IEnumerable <ScannedImage> Import(string filePath, ImportParams importParams, Func <int, int, bool> progressCallback) { if (!progressCallback(0, 0)) { return(Enumerable.Empty <ScannedImage>()); } int passwordAttempts = 0; bool aborted = false; int i = 0; try { PdfDocument document = PdfReader.Open(filePath, PdfDocumentOpenMode.Import, args => { if (!pdfPasswordProvider.ProvidePassword(Path.GetFileName(filePath), passwordAttempts++, out args.Password)) { args.Abort = true; aborted = true; } }); if (passwordAttempts > 0 && !document.SecuritySettings.HasOwnerPermissions && !document.SecuritySettings.PermitExtractContent) { errorOutput.DisplayError(string.Format(MiscResources.PdfNoPermissionToExtractContent, Path.GetFileName(filePath))); return(Enumerable.Empty <ScannedImage>()); } if (document.Info.Creator != MiscResources.NAPS2 && document.Info.Author != MiscResources.NAPS2) { pdfRenderer.ThrowIfCantRender(); return(importParams.Slice.Indices(document.PageCount) .Select(index => document.Pages[index]) .TakeWhile(page => progressCallback(i++, document.PageCount)) .Select(page => ExportRawPdfPage(page, importParams))); } return(importParams.Slice.Indices(document.PageCount) .Select(index => document.Pages[index]) .TakeWhile(page => progressCallback(i++, document.PageCount)) .SelectMany(page => GetImagesFromPage(page, importParams))); } catch (ImageRenderException e) { errorOutput.DisplayError(string.Format(MiscResources.ImportErrorNAPS2Pdf, Path.GetFileName(filePath))); Log.ErrorException("Error importing PDF file.", e); return(Enumerable.Empty <ScannedImage>()); } catch (Exception e) { if (!aborted) { errorOutput.DisplayError(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(filePath))); Log.ErrorException("Error importing PDF file.", e); } return(Enumerable.Empty <ScannedImage>()); } }
private ScannedImage ExportG4(PdfPage page, PdfDictionary imageObject, ImportParams importParams) { int width = imageObject.Elements.GetInteger(PdfImage.Keys.Width); int height = imageObject.Elements.GetInteger(PdfImage.Keys.Height); int bitsPerComponent = imageObject.Elements.GetInteger(PdfImage.Keys.BitsPerComponent); byte[] imageBytes = imageObject.Stream.Value; // We don't have easy access to a standalone CCITT G4 decoder, so we'll make use of the .NET TIFF decoder // by constructing a valid TIFF file "manually" and directly injecting the bytestream var stream = new MemoryStream(); Write(stream, TiffBeforeDataLen); // The bytestream is 2-padded, so we may need to append an extra zero byte if (imageBytes.Length % 2 == 1) { Write(stream, imageBytes.Length + 0x11); } else { Write(stream, imageBytes.Length + 0x10); } Write(stream, TiffBeforeData); Write(stream, imageBytes); if (imageBytes.Length % 2 == 1) { Write(stream, new byte[] { 0x00 }); } Write(stream, TiffBeforeWidth); Write(stream, width); Write(stream, TiffBeforeHeight); Write(stream, height); Write(stream, TiffBeforeBits); Write(stream, bitsPerComponent); Write(stream, TiffBeforeRealLen); Write(stream, imageBytes.Length); Write(stream, TiffTrailer); stream.Seek(0, SeekOrigin.Begin); using (Bitmap bitmap = (Bitmap)Image.FromStream(stream)) { bitmap.SetResolution(bitmap.Width / (float)page.Width.Inch, bitmap.Height / (float)page.Height.Inch); var image = new ScannedImage(bitmap, ScanBitDepth.BlackWhite, true, -1); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); if (importParams.DetectPatchCodes) { image.PatchCode = PatchCodeDetector.Detect(bitmap); } return(image); } }
//------------------------------------------------------------- // // //------------------------------------------------------------- private void createDuplicateFile() { ImportParams importParams = (ImportParams)Session["importparams"]; Campaign campaign = ReadCampaignInfo(); if (importParams.importRule == 1) { sDupFilePath = importParams.uploadDirectory; sDupFilePath += Path.GetFileNameWithoutExtension(importParams.filePath); sDupFilePath += "_DUP_" + DateTime.Today.ToString("MMddyyyy"); sDupFilePath += Path.GetExtension(importParams.filePath); } }
//----------------------------------------------------------------- // // //----------------------------------------------------------------- private bool ruleUpdatesResetAllFields() { ImportParams importParams = (ImportParams)Session["importparams"]; switch (importParams.importRule) { case 2: return(true); default: return(false); } }
//----------------------------------------------------------------- // // //----------------------------------------------------------------- private bool ruleSavesDuplicates() { ImportParams importParams = (ImportParams)Session["importparams"]; switch (importParams.importRule) { case 1: return(true); default: return(false); } }
//----------------------------------------------------------------- // // //----------------------------------------------------------------- private bool ruleAllowsUpdates() { ImportParams importParams = (ImportParams)Session["importparams"]; switch (importParams.importRule) { case 2: case 3: return(true); default: return(false); } }
private IEnumerable <ScannedImage> GetImagesFromPage(PdfPage page, ImportParams importParams) { if (page.CustomValues.Elements.ContainsKey("/NAPS2ImportedPage")) { yield return(ExportRawPdfPage(page, importParams)); yield break; } // Get resources dictionary PdfDictionary resources = page.Elements.GetDictionary("/Resources"); // Get external objects dictionary PdfDictionary xObjects = resources?.Elements.GetDictionary("/XObject"); if (xObjects == null) { yield break; } // Iterate references to external objects foreach (PdfItem item in xObjects.Elements.Values) { var reference = item as PdfReference; var xObject = reference?.Value as PdfDictionary; // Is external object an image? if (xObject != null && xObject.Elements.GetString("/Subtype") == "/Image") { // Support multiple filter schemes var element = xObject.Elements.Single(x => x.Key == "/Filter"); var elementAsArray = element.Value as PdfArray; var elementAsName = element.Value as PdfName; if (elementAsArray != null) { string[] arrayElements = elementAsArray.Elements.Select(x => x.ToString()).ToArray(); if (arrayElements.Length == 2) { yield return(DecodeImage(arrayElements[1], page, xObject, Filtering.Decode(xObject.Stream.Value, arrayElements[0]), importParams)); } } else if (elementAsName != null) { yield return(DecodeImage(elementAsName.Value, page, xObject, xObject.Stream.Value, importParams)); } else { throw new NotImplementedException("Unsupported filter"); } } } }
private async Task <Mock <RequestContext <DacFxResult> > > SendAndValidateImportRequest() { // first export a bacpac var result = GetLiveAutoCompleteTestObjects(); var exportRequestContext = new Mock <RequestContext <DacFxResult> >(); exportRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxImportTest"); string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); var exportParams = new ExportParams { DatabaseName = sourceDb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", sourceDb.DatabaseName)) }; SqlConnection sqlConn = ConnectionService.OpenSqlConnection(result.ConnectionInfo, "Import"); DacFxService service = new DacFxService(); ExportOperation exportOperation = new ExportOperation(exportParams, sqlConn); service.PerformOperation(exportOperation); // import the created bacpac var importRequestContext = new Mock <RequestContext <DacFxResult> >(); importRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); var importParams = new ImportParams { PackageFilePath = exportParams.PackageFilePath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-imported") }; ImportOperation importOperation = new ImportOperation(importParams, sqlConn); service.PerformOperation(importOperation); SqlTestDb targetDb = SqlTestDb.CreateFromExisting(importParams.DatabaseName); // cleanup VerifyAndCleanup(exportParams.PackageFilePath); sourceDb.Cleanup(); targetDb.Cleanup(); return(importRequestContext); }
private async Task GetImagesFromPage(PdfPage page, ImportParams importParams, ScannedImageSource.Concrete source) { if (page.CustomValues.Elements.ContainsKey("/NAPS2ImportedPage")) { source.Put(await ExportRawPdfPage(page, importParams)); return; } // Get resources dictionary var resources = page.Elements.GetDictionary("/Resources"); // Get external objects dictionary var xObjects = resources?.Elements.GetDictionary("/XObject"); if (xObjects == null) { return; } // Iterate references to external objects foreach (var item in xObjects.Elements.Values) { // Is external object an image? if (!((item as PdfReference)?.Value is PdfDictionary xObject) || xObject.Elements.GetString("/Subtype") != "/Image") { continue; } // Support multiple filter schemes var element = xObject.Elements.Single(x => x.Key == "/Filter"); var elementAsArray = element.Value as PdfArray; var elementAsName = element.Value as PdfName; if (elementAsArray != null) { var arrayElements = elementAsArray.Elements.Select(x => x.ToString()).ToArray(); if (arrayElements.Length == 2) { source.Put(DecodeImage(arrayElements[1], page, xObject, Filtering.Decode(xObject.Stream.Value, arrayElements[0]), importParams)); } } else if (elementAsName != null) { source.Put(DecodeImage(elementAsName.Value, page, xObject, xObject.Stream.Value, importParams)); } else { throw new NotImplementedException("Unsupported filter"); } } }
//------------------------------------------------------------- // // //------------------------------------------------------------- private void BindMappingsGrid() { ImportParams importParams = (ImportParams)Session["importparams"]; string filePath = importParams.filePath; bool hasHeader = importParams.isFirstRowHeader; string delimeter = importParams.delimter; // 2012-06-13 Dave Pollastrini // See notes in ReadCampaignInfo(). These values are being set there. //allowSevenDigitNums = importParams.allowSevenDigitNums; //allowTenDigitNums = importParams.allowTenDigitNums; char delimiterchar = Convert.ToChar(delimeter == "t" ? "\t" : delimeter); grdMappingList.DataSource = GetHeader(filePath, hasHeader, delimiterchar); grdMappingList.DataBind(); }
public async void ImportBacpac() { // first export a bacpac var result = GetLiveAutoCompleteTestObjects(); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxImportTest"); SqlTestDb targetDb = null; string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); try { var exportParams = new ExportParams { DatabaseName = sourceDb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", sourceDb.DatabaseName)) }; DacFxService service = new DacFxService(); ExportOperation exportOperation = new ExportOperation(exportParams, result.ConnectionInfo); service.PerformOperation(exportOperation, TaskExecutionMode.Execute); // import the created bacpac var importParams = new ImportParams { PackageFilePath = exportParams.PackageFilePath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-imported") }; ImportOperation importOperation = new ImportOperation(importParams, result.ConnectionInfo); service.PerformOperation(importOperation, TaskExecutionMode.Execute); targetDb = SqlTestDb.CreateFromExisting(importParams.DatabaseName); VerifyAndCleanup(exportParams.PackageFilePath); } finally { sourceDb.Cleanup(); if (targetDb != null) { targetDb.Cleanup(); } } }
private ScannedImage ExportJpegImage(PdfPage page, byte[] imageBytes, ImportParams importParams) { // Fortunately JPEG has native support in PDF and exporting an image is just writing the stream to a file. using (var memoryStream = new MemoryStream(imageBytes)) { using (var bitmap = new Bitmap(memoryStream)) { bitmap.SetResolution(bitmap.Width / (float)page.Width.Inch, bitmap.Height / (float)page.Height.Inch); var image = new ScannedImage(bitmap, ScanBitDepth.C24Bit, false, -1); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); if (importParams.DetectPatchCodes) { image.PatchCode = PatchCodeDetector.Detect(bitmap); } return(image); } } }
/// <summary> /// Handles request to import a bacpac /// </summary> /// <returns></returns> public async Task HandleImportRequest(ImportParams parameters, RequestContext <DacFxResult> requestContext) { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); if (connInfo != null) { ImportOperation operation = new ImportOperation(parameters, connInfo); ExecuteOperation(operation, parameters, SR.ImportBacpacTaskName, requestContext); } } catch (Exception e) { await requestContext.SendError(e); } }
/// <summary> /// Handles request to import a bacpac /// </summary> /// <returns></returns> public async Task HandleImportRequest(ImportParams parameters, RequestContext <DacFxResult> requestContext) { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); if (connInfo != null) { SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, "Import"); ImportOperation operation = new ImportOperation(parameters, sqlConn); await ExecuteOperation(operation, parameters, "Import bacpac", requestContext); } } catch (Exception e) { await requestContext.SendError(e); } }
public IEnumerable <ScannedImage> Import(string filePath, ImportParams importParams, Func <int, int, bool> progressCallback) { if (!progressCallback(0, 1)) { yield break; } Bitmap toImport; try { toImport = new Bitmap(filePath); } catch (Exception e) { Log.ErrorException("Error importing image: " + filePath, e); // Handle and notify the user outside the method so that errors importing multiple files can be aggregated throw; } using (toImport) { int frameCount = toImport.GetFrameCount(FrameDimension.Page); int i = 0; foreach (var frameIndex in importParams.Slice.Indices(frameCount)) { if (!progressCallback(i++, frameCount)) { yield break; } toImport.SelectActiveFrame(FrameDimension.Page, frameIndex); var image = new ScannedImage(toImport, ScanBitDepth.C24Bit, IsLossless(toImport.RawFormat), -1); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(toImport)); if (importParams.DetectPatchCodes) { image.PatchCode = PatchCodeDetector.Detect(toImport); } yield return(image); } progressCallback(frameCount, frameCount); } }
private static void InsertProgramsSqlServer(ImportParams aImportParam) { SqlTransaction transact = null; try { using (SqlConnection connection = new SqlConnection(aImportParam.ConnectString)) { DeleteProgramsDelegate deletePrograms = null; switch (aImportParam.ProgamsToDelete) { case DeleteBeforeImportOption.OverlappingPrograms: IEnumerable<ProgramListPartition> partitions = aImportParam.ProgramList.GetPartitions(); deletePrograms = () => ExecuteDeleteProgramsSqlServerCommand(partitions, connection, transact, aImportParam.SleepTime); break; case DeleteBeforeImportOption.ProgramsOnSameChannel: IEnumerable<int> channelIds = aImportParam.ProgramList.GetChannelIds(); deletePrograms = () => ExecuteDeleteProgramsSqlServerCommand(channelIds, connection, transact, aImportParam.SleepTime); break; } connection.Open(); transact = connection.BeginTransaction(); if (deletePrograms != null) { deletePrograms(); } ExecuteInsertProgramsSqlServerCommand(aImportParam.ProgramList, connection, transact, aImportParam.SleepTime); transact.Commit(); } } catch (Exception ex) { try { if (transact != null) { transact.Rollback(); } } catch (Exception ex2) { Log.Info("BusinessLayer: InsertSqlServer unsuccessful - ROLLBACK - {0}, {1}", ex2.Message, ex2.StackTrace); } Log.Info("BusinessLayer: InsertSqlServer caused an Exception - {0}, {1}", ex.Message, ex.StackTrace); } }
public ImportOperation(ImportParams parameters, ConnectionInfo connInfo) : base(connInfo) { Validate.IsNotNull("parameters", parameters); this.Parameters = parameters; }
/// <summary> /// Batch inserts programs - intended for faster EPG import. You must make sure before that there are no duplicates /// (e.g. delete all program data of the current channel). /// Also you MUST provide a true copy of "aProgramList". If you update it's reference in your own code the values will get overwritten /// (possibly before they are written to disk)! /// </summary> /// <param name="aProgramList">A list of persistable gentle.NET Program objects mapping to the Programs table</param> /// <param name="progamsToDelete">Flag specifying which existing programs to delete before the insert</param> /// <param name="aThreadPriority">Use "Lowest" for Background imports allowing LiveTV, AboveNormal for full speed</param> /// <returns>The record count of programs if successful, 0 on errors</returns> /// <remarks><para>Inserts are queued to be performed in the background. Each batch of inserts is executed in a single transaction. /// You may also optionally specify to delete either all existing programs in the same channel(s) as the programs to be inserted /// (<see cref="DeleteBeforeImportOption.ProgramsOnSameChannel"/>), or existing programs that would otherwise overlap new programs /// (<see cref="DeleteBeforeImportOption.OverlappingPrograms"/>), or none (<see cref="DeleteBeforeImportOption.None"/>). /// The deletion is also performed in the same transaction as the inserts so that EPG will not be at any time empty.</para> /// <para>After all insert have completed and the background thread is idle for 60 seconds, the program states are /// automatically updated to reflect the changes.</para></remarks> public int InsertPrograms(List<Program> aProgramList, DeleteBeforeImportOption progamsToDelete, ThreadPriority aThreadPriority) { try { int sleepTime = 10; switch (aThreadPriority) { case ThreadPriority.Highest: case ThreadPriority.AboveNormal: aThreadPriority = ThreadPriority.Normal; sleepTime = 0; break; case ThreadPriority.Normal: // this is almost enough on dualcore systems for one cpu to gather epg and the other to insert it sleepTime = 10; break; case ThreadPriority.BelowNormal: // on faster systems this might be enough for background importing sleepTime = 20; break; case ThreadPriority.Lowest: // even a single core system is enough to use MP while importing. sleepTime = 40; break; } ImportParams param = new ImportParams(); param.ProgramList = new ProgramList(aProgramList); param.ProgamsToDelete = progamsToDelete; param.SleepTime = sleepTime; param.Priority = aThreadPriority; lock (_programInsertsQueue) { _programInsertsQueue.Enqueue(param); _pendingProgramInserts.Set(); if (_insertProgramsThread == null) { _insertProgramsThread = new Thread(InsertProgramsThreadStart) { Priority = ThreadPriority.Lowest, Name = "SQL EPG importer", IsBackground = true }; _insertProgramsThread.Start(); } } return aProgramList.Count; } catch (Exception ex) { Log.Error("BusinessLayer: InsertPrograms error - {0}, {1}", ex.Message, ex.StackTrace); return 0; } }
private ScannedImage DecodeImage(string encoding, PdfPage page, PdfDictionary xObject, byte[] stream, ImportParams importParams) { switch (encoding) { case "/DCTDecode": return(ExportJpegImage(page, stream, importParams)); case "/FlateDecode": return(ExportAsPngImage(page, xObject, importParams)); case "/CCITTFaxDecode": return(ExportG4(page, xObject, stream, importParams)); default: throw new NotImplementedException("Unsupported image encoding"); } }
//------------------------------------------------------------- // // //------------------------------------------------------------- private void createImportFieldList(ImportFieldRow importRow) { ImportParams importParams = (ImportParams)Session["importparams"]; List <ImportField> fieldList = importRow.ImportFieldsList; for (int j = 0; j < fieldList.Count; j++) { ImportField field = (ImportField)fieldList[j]; string value = ""; field.FieldValue = field.FieldValue.Replace("'", "''"); switch (field.FieldType.ToLower()) { case "decimal": case "money": value = field.FieldValue.Trim() == "" ? "null" : field.FieldValue; Double dValue = 0; if (value != null && value != "null") { try { //------------------------------------- // We check to see if it is a proper // value being passed, if not we reset it. //------------------------------------- dValue = Convert.ToDouble(value); } catch { field.FieldValue = "null"; value = "null"; } } break; case "integer": value = field.FieldValue.Trim() == "" ? "null" : field.FieldValue; Int16 iValue = 0; if (value != null && value != "null") { try { //------------------------------------- // We check to see if it is a proper // value being passed, if not we reset it. //------------------------------------- iValue = Convert.ToInt16(value); } catch { field.FieldValue = "null"; value = "null"; } } break; case "date": value = field.FieldValue.Trim() == "" ? "null" : "'" + field.FieldValue + "'"; break; case "boolean": value = field.FieldValue.Trim() == "" ? "null" : field.FieldValue; if (value != null && value != "null" && (value.ToUpper() == "TRUE" || value != "0")) { value = "1"; } else { value = "0"; } break; default: value = field.FieldValue.Trim() == "" ? "null" : "'" + field.FieldValue + "'"; break; } if (field.FieldName != "NeverCallFlag" || importParams.exceptionType == 1) { if (sqlCols == string.Empty) { sqlCols = field.FieldName; sqlValues = value; strUpdate = String.Format("{0}={1}", field.FieldName, value); } else { sqlCols += "," + field.FieldName; sqlValues += "," + value; strUpdate += ", " + String.Format("{0}={1}", field.FieldName, value); } } if (field.FieldName == "PhoneNum") { strPhoneNumber = field.FieldValue; } }// end for loop forceNeverCallFlag(); }
private ScannedImage ExportAsPngImage(PdfPage page, PdfDictionary imageObject, ImportParams importParams) { int width = imageObject.Elements.GetInteger(PdfImage.Keys.Width); int height = imageObject.Elements.GetInteger(PdfImage.Keys.Height); int bitsPerComponent = imageObject.Elements.GetInteger(PdfImage.Keys.BitsPerComponent); var buffer = imageObject.Stream.UnfilteredValue; Bitmap bitmap; ScanBitDepth bitDepth; switch (bitsPerComponent) { case 8: bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); bitDepth = ScanBitDepth.C24Bit; RgbToBitmapUnmanaged(height, width, bitmap, buffer); break; case 1: bitmap = new Bitmap(width, height, PixelFormat.Format1bppIndexed); bitDepth = ScanBitDepth.BlackWhite; BlackAndWhiteToBitmapUnmanaged(height, width, bitmap, buffer); break; default: throw new NotImplementedException("Unsupported image encoding (expected 24 bpp or 1bpp)"); } using (bitmap) { bitmap.SafeSetResolution(bitmap.Width / (float)page.Width.Inch, bitmap.Height / (float)page.Height.Inch); var image = new ScannedImage(bitmap, bitDepth, true, -1); if (!importParams.NoThumbnails) { image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); } if (importParams.DetectPatchCodes) { image.PatchCode = PatchCodeDetector.Detect(bitmap); } return(image); } }
public ImportOperation(ImportParams parameters, SqlConnection sqlConnection) : base(sqlConnection) { Validate.IsNotNull("parameters", parameters); this.Parameters = parameters; }
public ScannedImageSource Import(string filePath, ImportParams importParams, ProgressHandler progressCallback, CancellationToken cancelToken) { var source = new ScannedImageSource.Concrete(); Task.Factory.StartNew(async() => { if (cancelToken.IsCancellationRequested) { source.Done(); } int passwordAttempts = 0; bool aborted = false; int i = 0; try { PdfDocument document = PdfReader.Open(filePath, PdfDocumentOpenMode.Import, args => { if (!pdfPasswordProvider.ProvidePassword(Path.GetFileName(filePath), passwordAttempts++, out args.Password)) { args.Abort = true; aborted = true; } }); if (passwordAttempts > 0 && !document.SecuritySettings.HasOwnerPermissions && !document.SecuritySettings.PermitExtractContent) { errorOutput.DisplayError(string.Format(MiscResources.PdfNoPermissionToExtractContent, Path.GetFileName(filePath))); source.Done(); } var pages = importParams.Slice.Indices(document.PageCount) .Select(index => document.Pages[index]) .TakeWhile(page => { progressCallback(i++, document.PageCount); return(!cancelToken.IsCancellationRequested); }); if (document.Info.Creator != MiscResources.NAPS2 && document.Info.Author != MiscResources.NAPS2) { pdfRenderer.ThrowIfCantRender(); foreach (var page in pages) { source.Put(await ExportRawPdfPage(page, importParams)); } } else { foreach (var page in pages) { await GetImagesFromPage(page, importParams, source); } } } catch (ImageRenderException e) { errorOutput.DisplayError(string.Format(MiscResources.ImportErrorNAPS2Pdf, Path.GetFileName(filePath))); Log.ErrorException("Error importing PDF file.", e); } catch (Exception e) { if (!aborted) { errorOutput.DisplayError(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(filePath))); Log.ErrorException("Error importing PDF file.", e); } } finally { source.Done(); } }, TaskCreationOptions.LongRunning); return(source); }
public RedirectToRouteResult Import(ImportParams importParams) { TempData["result"] = _nopDataImportAdminService.Import(importParams); return(RedirectToAction("Index")); }
public ScannedImageSource Import(string filePath, ImportParams importParams, ProgressHandler progressCallback, CancellationToken cancelToken) { var source = new ScannedImageSource.Concrete(); Task.Factory.StartNew(() => { try { if (cancelToken.IsCancellationRequested) { source.Done(); return; } Bitmap toImport; try { toImport = new Bitmap(filePath); } catch (Exception e) { Log.ErrorException("Error importing image: " + filePath, e); // Handle and notify the user outside the method so that errors importing multiple files can be aggregated throw; } using (toImport) { int frameCount = toImport.GetFrameCount(FrameDimension.Page); int i = 0; foreach (var frameIndex in importParams.Slice.Indices(frameCount)) { progressCallback(i++, frameCount); if (cancelToken.IsCancellationRequested) { source.Done(); return; } toImport.SelectActiveFrame(FrameDimension.Page, frameIndex); var image = new ScannedImage(toImport, ScanBitDepth.C24Bit, IsLossless(toImport.RawFormat), -1); if (!importParams.NoThumbnails) { image.SetThumbnail(thumbnailRenderer.RenderThumbnail(toImport)); } if (importParams.DetectPatchCodes) { image.PatchCode = PatchCodeDetector.Detect(toImport); } source.Put(image); } progressCallback(frameCount, frameCount); } source.Done(); } catch (Exception e) { source.Error(e); } }, TaskCreationOptions.LongRunning); return(source); }