/// <summary> /// make processing /// </summary> public static void MakeProcessing() { try { int serviceId = 2; ServiceAssist.Assist assist = new Assist(); //check tasks List <Tasks> notExecutedTasks = assist.GetToNotExecutedTasks(serviceId); //upload files foreach (var notExecutedTask in notExecutedTasks) { OcrRequestModel requestModel = JsonConvert.DeserializeObject <OcrRequestModel>(notExecutedTask.ProfileContent); if (requestModel.InputFiles != null && requestModel.InputFiles.Count > 0) { string extension = Path.GetExtension(requestModel.InputFiles[0].Name); if (extension != null && extension != ".zip" && extension != ".rar" && extension != ".7z") { TaskHelper.ExecuteTask(notExecutedTask); } } } //check statuses List <Tasks> processedTasks = assist.GetToProcessedTasks(serviceId); //download files foreach (var processedTask in processedTasks) { TaskHelper.CheckStateTask(processedTask); } //update states } catch (Exception exception) { string innerException = exception.InnerException == null ? "" : exception.InnerException.Message; string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogHelper.AddLog("Error in method: " + methodName + "; Exception: " + exception.Message + " Innner Exception: " + innerException); } }
/// <summary> /// make processing /// </summary> public static void MakeProcessing() { try { int serviceId = 4;// email attachment service id //getting available file extentions Assist assist = new Assist(); Assist serviceAssist = new Assist(); string serverPath = serviceAssist.GetSettingValueByName("MainPath"); string uploadFolder = serviceAssist.GetSettingValueByName("UploadFolder"); string uploadUrl = Path.Combine(serverPath, uploadFolder); List <string> extentions = assist.GetToAvailableFileExtensions(); // getting IMAP setttings string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "data/settings.xml"); if (File.Exists(path)) { ServiceSettingsModel settingsModel; XmlSerializer formatter = new XmlSerializer(typeof(ServiceSettingsModel)); ServiceSettingsModel model = new ServiceSettingsModel(); using (FileStream fs = new FileStream(path, FileMode.Open)) { settingsModel = formatter.Deserialize(fs) as ServiceSettingsModel; } //check tasks List <Tasks> notExecutedTasks = assist.GetToNotExecutedTasks(serviceId); //upload files foreach (var notExecutedTask in notExecutedTasks) { OcrRequestModel requestModel = JsonConvert.DeserializeObject <OcrRequestModel>(notExecutedTask.ProfileContent); if (requestModel.InputFiles != null && requestModel.InputFiles.Count > 0) { string extension = Path.GetExtension(requestModel.InputFiles[0].Name); if (extension != null && extension != ".zip" && extension != ".rar" && extension != ".7z") { TaskHelper.ExecuteTask(notExecutedTask); } } } //check statuses List <Tasks> processedTasks = assist.GetToProcessedTasks(serviceId); //download files foreach (var processedTask in processedTasks) { TaskHelper.CheckStateTask(processedTask); } EmailHelper.CreateTasksFromEmails(settingsModel, assist, extentions, uploadUrl, uploadFolder, serviceId); } else { throw new FileNotFoundException("File not found in " + path); } //update states } catch (Exception exception) { string innerException = exception.InnerException == null ? "" : exception.InnerException.Message; string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogHelper.AddLog("Error in method: " + methodName + "; Exception: " + exception.Message + " Innner Exception: " + innerException); } }
/// <summary> /// input in program /// </summary> /// <param name="args"></param> private static void Main(string[] args) { try { SettingsModel settings = new SettingsModel(); OcrRequestModel requestModel = new OcrRequestModel(); string lang = "English"; //init model requestModel.ApiKey = settings.ApiKey; requestModel.CleanupSettings = new CleanupSettingsModel() { Deskew = true, RemoveGarbage = true, RemoveTexture = true, SplitDualPage = true, RotationType = "NoRotation", JpegQuality = "", OutputFormat = "", Resolution = "" }; requestModel.OcrSettings = new OcrSettingsModel() { SpeedOcr = false, LookForBarcodes = false, AnalysisMode = "MixedDocument", PrintType = "Print", OcrLanguage = lang }; requestModel.OutputSettings = new OutputSettingsModel() { ExportFormat = "Text;PDF" }; requestModel.InputFiles.Add(new InputFileModel() { Name = Path.GetFileName(settings.TestEnglishFile), Password = "", InputUrl = "", InputBlob = FileConverter.ConvertFileToBase64(settings.TestEnglishFile), InputType = "JPG", PostFix = "" }); //end init String url = "http://api.ocr-it.com:40000/api/jobs"; var json = JsonConvert.SerializeObject(requestModel); AssistProcessor processor = new AssistProcessor(); //processor.MakeOcr(url,json); string baseUrl = "http://api.ocr-it.com:40000/api/Jobs?JobId="; string jobId = "12dea613-f6f3-4982-baa0-60e4f452ae4b"; string gUrl = baseUrl + jobId; string jobStatus = processor.GetJobStatus(gUrl); OcrResponseModel desModel = JsonConvert.DeserializeObject <OcrResponseModel>(jobStatus); string downloadDir = "d://OCRDownload//"; foreach (var file in desModel.Download) { string sName = DateTime.Now.ToString(); sName = sName.Replace(":", string.Empty); sName = sName.Replace("-", string.Empty); sName = sName.Replace(".", string.Empty); sName = sName.Replace(",", string.Empty); sName = sName.Replace(";", string.Empty); sName = sName.Replace(" ", string.Empty); string ext = ""; switch (file.OutputFormat) { case "PDF": ext = "pdf"; break; case "Text": ext = "txt"; break; } sName = sName + "." + ext; string downloadPath = Path.Combine(downloadDir, sName); // processor.DownloadFile(file.Uri,downloadPath); } //string outReq = JsonConvert.SerializeObject(model); Console.ReadKey(); } catch (Exception exception) { Console.WriteLine("Exception: " + exception.Message); Console.ReadKey(); } }
public async Task <ActionResult <string> > Ocr([FromBody] OcrRequestModel model) { return(await GetTextImage(new MemoryStream(Convert.FromBase64String(model.Image)))); }
/// <summary> /// make processing /// </summary> public static void MakeProcessing() { try { int serviceId = 3; ServiceAssist.Assist assist = new Assist(); List <string> extensions = assist.GetToAvailableFileExtensions(); List <FtpWebResponse> responses = new List <FtpWebResponse>(); string pathToDownload = assist.GetSettingValueByName("MainPath"); string resultFolder = assist.GetSettingValueByName("ResultFolder"); FlexiCapture.Cloud.FTPService.Helpers.TasksHelpers.FTPHelper.GetFtpInputSettings().ForEach(x => { if (x.Enabled) { var response = FlexiCapture.Cloud.FTPService. Helpers.TasksHelpers.FTPHelper.TryLoginToFtp(x.Host, x.UserName, PasswordHelper.Crypt.DecryptString(x.Password), x.Path, x.UserId, x.ServiceType); var ftpConversionSettings = FlexiCapture.Cloud.FTPService.Helpers.TasksHelpers. FTPHelper.GetFtpConersionSettings(x.UserId); List <Tuple <string, string> > addedFilesInResponse; if (response != null) { assist.UserProfile = assist.GetUserProfile(x.UserId, 3); addedFilesInResponse = FlexiCapture.Cloud.FTPService.Helpers. TasksHelpers.FTPHelper.ExtractFiles(response, x); addedFilesInResponse.ForEach(af => { if (CheckExtensions(extensions, af.Item2)) { var newNameGuid = Guid.NewGuid(); var uploadName = newNameGuid + af.Item2; var localName = Path.Combine(Path.Combine("data", "uploads"), uploadName); string originalFileName = af.Item1; var filePathOld = Path.Combine(assist.GetSettingValueByName("MainPath"), "data", "uploads", af.Item1); var filePathNew = Path.Combine(assist.GetSettingValueByName("MainPath"), "data", "uploads", newNameGuid.ToString() + af.Item2); //add task to db var taskId = assist.AddTask(assist.UserProfile.UserId, serviceId); if (FlexiCapture.Cloud.ServiceAssist.DBHelpers.FTPSettingsHelper.CheckOutputExceptionSettings(x.Id)) { SettingsTasksUnionHelper.AddNewItem(taskId, x.Id); } var md5 = assist.GetMD5HashFromFile(filePathOld); //add document var fileInfo = new FileInfo(filePathOld); var documentId = assist.AddDocument(taskId, fileInfo, originalFileName, newNameGuid, uploadName, localName, md5, 1, ftpConversionSettings.AddProcessed); //if (x.ServiceType == 2) // assist.ConnectTaskAndFtpSetting(taskId, x.Id); // var fileUploadStatus = System.IO.File.Move(filePathOld, filePathNew); if (File.Exists(filePathOld)) { File.Delete(filePathOld); } assist.Documents = assist.GetDocumentsByTaskId(taskId); string content = assist.ConvertProfileToRequestModel(assist.Documents, assist.UserProfile); assist.UpdateTaskProfile(taskId, content); if (x.DeleteFile) { if (File.Exists(filePathNew)) { File.Delete(filePathNew); } } } }); } } }); //responses.ForEach(x => //{ // //assist.AddTask() //}); //check tasks List <Tasks> notExecutedTasks = assist.GetToNotExecutedTasks(serviceId); //upload files foreach (var notExecutedTask in notExecutedTasks) { OcrRequestModel requestModel = JsonConvert.DeserializeObject <OcrRequestModel>(notExecutedTask.ProfileContent); if (requestModel.InputFiles != null && requestModel.InputFiles.Count > 0) { string extension = Path.GetExtension(requestModel.InputFiles[0].Name); if (extension != null && extension != ".zip" && extension != ".rar" && extension != ".7z") { //////////// TaskHelper.ExecuteTask(notExecutedTask); } } } //check statuses List <Tasks> processedTasks = assist.GetToProcessedTasks(serviceId); //download files foreach (var processedTask in processedTasks) { //////////// TaskHelper.CheckStateTask(processedTask); //FTPHelper.PutFileOnFtpServer(fInfo, processedTask); } //update states } catch (Exception exception) { string innerException = exception.InnerException == null ? "" : exception.InnerException.Message; string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogHelper.AddLog("Error in method: " + methodName + "; Exception: " + exception.Message + " Innner Exception: " + innerException); } }