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); } }
private void SetProcessingErrors(List <BaseIntegrationObject> pack, string responseStr, bool isTimeout, bool isUsePA) { var errorMessage = String.IsNullOrEmpty(responseStr) ? String.Empty : responseStr.Replace("'", "''").Replace("{", "").Replace("}", ""); if (errorMessage.Length > 250) { errorMessage = errorMessage.Substring(0, 250); } DBConnectionProvider.ExecuteNonQuery(String.Format("Update {1} Set {4} = {3}, ErrorMessage = '{2}' Where Id in ({0})", String.Join(",", pack.Select(p => String.Format("'{0}'", p.Id))), _tableName, errorMessage, isTimeout ? "4" : "2", isUsePA ? "StatusCS" : "StatusPC")); }
public virtual void ProceedResult(PackResult result, List <BaseIntegrationObject> pack, bool isNeedSendToPersonalArea) { lock (_lockRes) { try { var columnName = isNeedSendToPersonalArea ? "StatusCS" : "StatusPC"; var query = new StringBuilder(); if (result.IsSuccess) { foreach (var obj in pack) { query.AppendLine($"Update {_tableName} Set {columnName} = 1 Where Id = '{obj.Id}';"); } } else { var errorMessage = String.IsNullOrEmpty(result.ErrorMessage) ? String.Empty : result.ErrorMessage.Replace("'", "").Replace("{", "").Replace("}", ""); if (errorMessage.Length > 250) { errorMessage = errorMessage.Substring(0, 250); } foreach (var obj in pack) { query.AppendLine($"Update {_tableName} Set {columnName} = {2}, ErrorMessage = '{errorMessage}' Where Id = '{ obj.Id}';"); } } var sql = query.ToString(); if (!string.IsNullOrEmpty(sql)) { DBConnectionProvider.ExecuteNonQuery(sql); } } catch (Exception e) { Logger.LogError(String.Format("Ошибка обновления состояний в ШТ {0} для первичного импорта", _tableName), e); } } }
protected override List <BaseIntegrationObject> ReadPack(bool isPC) { var columnName = isPC ? "StatusPC" : "StatusCS"; var pack = new List <BaseIntegrationObject>(); lock (_lock) { using (var provider = new DBConnectionProvider()) { using (var reader = provider.Execute(_selectContact, packSize, columnName)) { while (reader != null && reader.Read()) { pack.Add(new Contact() { Email = reader.GetValue("email", String.Empty), FirstName = reader.GetValue("GivenName", String.Empty), MiddleName = reader.GetValue("MiddleName", String.Empty), Phone = reader.GetValue("MobilePhone", String.Empty), RegistrationDate = reader.GetValue("RegistrationDate", String.Empty), BirthDay = reader.GetValue("BirthDate", String.Empty), Id = reader.GetValue("Id", Guid.Empty), Surname = reader.GetValue("Surname", String.Empty), Code = reader.GetValue("Code", String.Empty), ShopCode = reader.GetValue("RegistrationPlaceCode", String.Empty), IsGenderNull = String.IsNullOrEmpty(reader.GetValue("GenderCode", String.Empty)), IsMan = reader.GetValue("GenderCode", String.Empty).ToLower() == "male", }); } } } if (pack.Count > 0) { DBConnectionProvider.ExecuteNonQuery($"Update Contact Set {columnName} = 3 Where Id in ({String.Join(",", pack.Select(p => String.Format("'{0}'", p.Id)))})"); } } return(pack); }
public static void CreateColumns() { DBConnectionProvider.ExecuteNonQuery(@"IF (SELECT 1 FROM sys.columns WHERE Name = N'StatusPC' AND Object_ID = Object_ID(N'Contact')) is null BEGIN ALTER TABLE Contact ADD StatusPC int not null default 0 END IF (SELECT 1 FROM sys.columns WHERE Name = N'StatusCS' AND Object_ID = Object_ID(N'Contact')) is null BEGIN ALTER TABLE Contact ADD StatusCS int not null default 0 END IF (SELECT 1 FROM sys.columns WHERE Name = N'ErrorMessage' AND Object_ID = Object_ID(N'Contact')) is null BEGIN ALTER TABLE Contact ADD ErrorMessage nvarchar(max) null END " ); }