protected virtual void ProceedResults(PackResults results, bool isNeedSendToPersonalArea) { try { var columnName = isNeedSendToPersonalArea ? "StatusCS" : "StatusPC"; var query = new StringBuilder(); foreach (var result in results.IntegratePackResult) { if (result.IsSuccess) { query.AppendLine($"Update {_tableName} Set {columnName} = 1 Where Id = '{result.GetCorrectId()}';"); } else { var errorMessage = String.IsNullOrEmpty(result.ErrorMessage) ? String.Empty : result.ErrorMessage.Replace("'", "''").Replace("{", "").Replace("}", ""); if (errorMessage.Length > 250) { errorMessage = errorMessage.Substring(0, 250); } query.AppendLine($"Update {_tableName} Set {columnName} = 2, ErrorMessage = '{errorMessage}' Where Id = '{result.GetCorrectId()}';"); } } var sql = query.ToString(); if (!string.IsNullOrEmpty(sql)) { DBConnectionProvider.ExecuteNonQuery(sql); } } catch (Exception e) { Logger.LogError(JsonConvert.SerializeObject(results), e); } }
public virtual void Execute(bool isNeedSendToPersonalArea) { Logger.LogInfo("Начался импорт", _tableName); var tasks = new List <Task>(); for (var j = 0; j < threadCount; j++) { var task = new Task(() => { var pack = new List <BaseIntegrationObject>(); try { pack = ReadPack(!isNeedSendToPersonalArea); Logger.LogInfo(string.Format("Прочитано данных из {0}: {1}", _tableName, pack.Count), ""); } catch (Exception e) { Logger.LogError(string.Format("Ошибка чтения данных из {0}", _tableName), e); } while (pack.Count > 0) { var now = DateTime.Now; var isProcessingSuccess = false; PackResults results = null; try { isProcessingSuccess = SendToProcessing(pack, out now, out results, isNeedSendToPersonalArea); } catch (Exception e) { Logger.LogError("SendToProcessing error ", e); } ProceedResults(results, isNeedSendToPersonalArea); Logger.LogInfo(_tableName, "pack finished"); pack = new List <BaseIntegrationObject>(); try { pack = ReadPack(!isNeedSendToPersonalArea); Logger.LogInfo(string.Format("Прочитано данных из {0}: {1}", _tableName, pack.Count), ""); } catch (Exception e) { Logger.LogError(string.Format("Ошибка чтения данных из {0}", _tableName), e); } } }); task.Start(); tasks.Add(task); } Task.WaitAll(tasks.ToArray()); Logger.LogInfo("Finished", _tableName); }
private bool SendToProcessing(List <BaseIntegrationObject> pack, out DateTime now, out PackResults results, bool isUsePA) { now = DateTime.Now; var processingResults = SendToProcessing(pack, isUsePA, _processingMethodName); Logger.LogInfo(string.Format("Запрос {0} к процессингу выполнен за {1}с", _tableName, (DateTime.Now - now).TotalSeconds.ToString("F1")), ""); results = new PackResults(); if (processingResults.IsSuccess) { results.IntegratePackResult = JsonConvert.DeserializeObject <List <PackResult> >(processingResults.ResponseStr); return(true); } else { SetProcessingErrors(pack, processingResults.ResponseStr, processingResults.IsTimeout, isUsePA); return(false); } }