public static UInt64 Log(ulong sourceTypeId, ulong?currPriceItemId, string addition, string shortErrorMessage, DownPriceResultCode resultCode, string archFileName, string extrFileName, MySqlConnection connection) { if (!String.IsNullOrEmpty(addition)) { if (currPriceItemId.HasValue) { using (NDC.Push("." + currPriceItemId)) _logger.InfoFormat("Logging.Addition : {0}", addition); } else { _logger.InfoFormat("Logging.Addition : {0}", addition); } } var command = CreateLogCommand(); command.Parameters["?PriceItemId"].Value = currPriceItemId; command.Parameters["?Addition"].Value = addition; command.Parameters["?ResultCode"].Value = Convert.ToByte(resultCode); command.Parameters["?ArchFileName"].Value = archFileName; command.Parameters["?ExtrFileName"].Value = extrFileName; command.Parameters["?ShortErrorMessage"].Value = String.IsNullOrEmpty(shortErrorMessage) ? Convert.DBNull : shortErrorMessage; command.Parameters["?SourceTypeId"].Value = sourceTypeId; bool NeedLogging = true; //Если это успешная загрузка, то сбрасываем все ошибки //Если это ошибка, то если дополнение в словаре и совпадает, то запрещаем логирование, в другом случае добавляем или обновляем ulong tmpCurrPriceItemId = (currPriceItemId.HasValue) ? currPriceItemId.Value : 0; if (resultCode == DownPriceResultCode.ErrorDownload) { if (ErrorPriceLogging.ErrorMessages.ContainsKey(tmpCurrPriceItemId)) { if (ErrorPriceLogging.ErrorMessages[tmpCurrPriceItemId] == addition) { NeedLogging = false; } else { ErrorPriceLogging.ErrorMessages[tmpCurrPriceItemId] = addition; } } else { ErrorPriceLogging.ErrorMessages.Add(tmpCurrPriceItemId, addition); } } else if (ErrorPriceLogging.ErrorMessages.ContainsKey(tmpCurrPriceItemId)) { ErrorPriceLogging.ErrorMessages.Remove(tmpCurrPriceItemId); } if (NeedLogging) { var owneConnection = false; if (connection == null) { owneConnection = true; connection = new MySqlConnection(ConnectionHelper.GetConnectionString()); } try { if (connection.State == ConnectionState.Closed) { connection.Open(); } command.Connection = connection; return(Convert.ToUInt64(command.ExecuteScalar())); } finally { if (owneConnection) { connection.Close(); } } } return(0); }
public static UInt64 Log(ulong sourceTypeId, ulong?currPriceItemId, string addition, DownPriceResultCode resultCode, string archFileName, string extrFileName) { return(Log(sourceTypeId, currPriceItemId, addition, null, resultCode, archFileName, extrFileName, null)); }