예제 #1
0
        /// <summary>
        /// execute task
        /// </summary>
        public static void ExecuteTask(Tasks task)
        {
            try
            {
                AssistProcessor assist        = new AssistProcessor();
                Assist          serviceAssist = new Assist();

                string planState = serviceAssist.CheckSubscriptionPlanAvailability(task.UserId);
                if (planState != "OK")
                {
                    serviceAssist.AddErrorToDocuments(task.Id, planState);
                    //update task
                    serviceAssist.UpdateTaskState(task.Id, 4);
                    //update documents
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 4);
                    return;
                }

                string url      = serviceAssist.GetSettingValueByName("ApiUrl");
                string json     = task.ProfileContent;
                string error    = "";
                string response = assist.MakeOcr(url, json, ref error);
                if (string.IsNullOrEmpty(response))
                {
                    LogHelper.AddLog(error);
                    serviceAssist.AddErrorToDocuments(task.Id, error);
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 4);
                    serviceAssist.UpdateTaskState(task.Id, 4);
                    return;
                }

                OcrResponseModel model = new OcrResponseModel();
                serviceAssist.UpdateTaskReponseContent(task.Id, response);
                model = JsonConvert.DeserializeObject <OcrResponseModel>(response);

                if (model.Status.Equals("Submitted"))
                {
                    serviceAssist.UpdateTaskState(task.Id, 2);
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 2);
                }
                else
                {
                    string errorText = "";
                    foreach (var ocrError in model.Errors)
                    {
                        errorText += ocrError.ErrorName + ": " + ocrError.ErrorMessage;
                    }
                    serviceAssist.AddErrorToDocuments(task.Id, errorText);
                    serviceAssist.UpdateTaskState(task.Id, 4);
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 4);
                }
            }
            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);
            }
        }
예제 #2
0
        /// <summary>
        /// execute task
        /// </summary>
        public static void ExecuteTask(Tasks task)
        {
            try
            {
                AssistProcessor assist        = new AssistProcessor();
                Assist          serviceAssist = new Assist();

                FileInfo fileInfo = null;

                Documents document = serviceAssist.GetToDocumentByTaskId(task.Id);
                var       settings = SettingsTasksUnionHelper.GetSettingsByTaskId(task.Id);

                string mainPath     = serviceAssist.GetSettingValueByName("MainPath");
                string resultFolder = serviceAssist.GetSettingValueByName("ResultFolder");
                string jobPattern   = serviceAssist.GetSettingValueByName("ApiUrlJobState");
                string uploadFolder = serviceAssist.GetSettingValueByName("UploadFolder");

                string downloadPath = Path.Combine(mainPath, resultFolder);
                //string uploadPath = Path.Combine(mainPath, uploadFolder);

                string planState = serviceAssist.CheckSubscriptionPlanAvailability(task.UserId);
                if (planState != "OK")
                {
                    serviceAssist.AddErrorToDocuments(task.Id, planState);
                    //update task
                    serviceAssist.UpdateTaskState(task.Id, 4);
                    //update documents
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 4);
                    return;
                }

                string url      = serviceAssist.GetSettingValueByName("ApiUrl");
                string json     = task.ProfileContent;
                string error    = "";
                string response = assist.MakeOcr(url, json, ref error);
                if (string.IsNullOrEmpty(response))
                {
                    /// Error! Put to exc. ftp
                    LogHelper.AddLog(error);
                    serviceAssist.AddErrorToDocuments(task.Id, error);
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 4);
                    serviceAssist.UpdateTaskState(task.Id, 4);

                    if (settings != null)
                    {
                        string filePath = Path.Combine(mainPath, document.Path);

                        fileInfo = new FileInfo(filePath);
                        var exceptionSettings =
                            FlexiCapture.Cloud.FTPService
                            .Helpers.TasksHelpers.FTPHelper
                            .GetFtpExceptionSettings(settings.Id);

                        var ftpConvSetting = FlexiCapture.Cloud.
                                             ServiceAssist.DBHelpers.FtpConversionSettingsHelper
                                             .GetSettingsByUserId(settings.UserId);

                        string pathToPut = ftpConvSetting.MirrorInput ? settings.Path : exceptionSettings.Path;

                        FTPHelper.PutFileOnFtpServer(fileInfo, document.OriginalFileName, exceptionSettings, pathToPut);
                    }

                    return;
                }

                OcrResponseModel model = new OcrResponseModel();
                serviceAssist.UpdateTaskReponseContent(task.Id, response);
                model = JsonConvert.DeserializeObject <OcrResponseModel>(response);

                if (model.Status.Equals("Submitted"))
                {
                    serviceAssist.UpdateTaskState(task.Id, 2);
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 2);
                }
                else
                {
                    // Error!
                    string errorText = "";
                    foreach (var ocrError in model.Errors)
                    {
                        errorText += ocrError.ErrorName + ": " + ocrError.ErrorMessage;
                    }
                    serviceAssist.AddErrorToDocuments(task.Id, errorText);
                    serviceAssist.UpdateTaskState(task.Id, 4);
                    serviceAssist.UpdateDocumentStatesByTaskId(task.Id, 4);

                    if (settings != null)
                    {
                        string filePath = Path.Combine(mainPath, document.Path);

                        fileInfo = new FileInfo(filePath);
                        var exceptionSettings =
                            FlexiCapture.Cloud.FTPService
                            .Helpers.TasksHelpers.FTPHelper
                            .GetFtpExceptionSettings(settings.Id);

                        var ftpConvSetting = FlexiCapture.Cloud.
                                             ServiceAssist.DBHelpers.FtpConversionSettingsHelper
                                             .GetSettingsByUserId(settings.UserId);

                        string pathToPut = ftpConvSetting.MirrorInput ? settings.Path : exceptionSettings.Path;

                        FTPHelper.PutFileOnFtpServer(fileInfo, document.OriginalFileName, exceptionSettings, pathToPut);
                    }
                }
            }
            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);
            }
        }