187 lines
7.3 KiB
C#
187 lines
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
|
|
|
|
namespace EstrazioneAnagrafica
|
|
{
|
|
|
|
public class UtilityManager
|
|
{
|
|
public static string getAppSetting(string chiave)
|
|
{
|
|
string valore = "" + ConfigurationManager.AppSettings[chiave];
|
|
|
|
if (valore != string.Empty)
|
|
return valore;
|
|
else
|
|
throw new Exception("Nel file di configurazione non è presente la chiave: " + chiave);
|
|
|
|
}
|
|
|
|
public static string getDataBaseException(DataBaseException ecc)
|
|
{
|
|
const string aCapo = "#/n#";
|
|
string ritorno = "";
|
|
ritorno += aCapo;
|
|
ritorno += " Informazioni Comando SQL:" + aCapo;
|
|
ritorno += " sql file name: " + ecc.SqlFileName + aCapo;
|
|
ritorno += " connection string: " + ecc.ConnectionStringWithoutCredentials + aCapo;
|
|
//ritorno += " command text: " + ecc.CommandText + aCapo;
|
|
//controllo se ci sono i parametri
|
|
if (ecc.Parameters != null)
|
|
{
|
|
foreach (Parametro parametro in ecc.Parameters)
|
|
{
|
|
ritorno += aCapo;
|
|
ritorno += " parametro: " + parametro.ParameterName + aCapo;
|
|
ritorno += " dimensione: " + parametro.Size.ToString() + aCapo;
|
|
ritorno += " direzione: " + parametro.Direction.ToString() + aCapo;
|
|
ritorno += " tipo: " + parametro.DbType.ToString() + aCapo;
|
|
|
|
if (parametro.Value == null)
|
|
ritorno += " valore: null" + aCapo;
|
|
else
|
|
{
|
|
string valoreParametro = "";
|
|
if (parametro.Size > 500)
|
|
{
|
|
valoreParametro = " valore: null(sono visualizzati solo i primi 500 bytes): " + parametro.Value.ToString().Substring(0, 500);
|
|
}
|
|
else
|
|
{
|
|
valoreParametro = " valore: " + parametro.Value.ToString();
|
|
}
|
|
ritorno += valoreParametro + aCapo;
|
|
}
|
|
}
|
|
}
|
|
ritorno += aCapo;
|
|
ritorno += " tipo: DataBaseException" + aCapo;
|
|
ritorno += " descrizione: " + ecc.Eccezione.Message + aCapo;
|
|
ritorno += " sorgente: " + ecc.Eccezione.Source + aCapo;
|
|
ritorno += " traccia: " + formattaErrore(ecc.StackTrace) + aCapo;
|
|
|
|
return ritorno;
|
|
|
|
}
|
|
|
|
public static string getException(Exception ecc)
|
|
{
|
|
const string aCapo = "#/n#";
|
|
string ritorno = "";
|
|
ritorno += aCapo;
|
|
ritorno += " tipo: " + ecc.GetType().ToString() + aCapo;
|
|
ritorno += " descrizione: " + ecc.Message + aCapo;
|
|
ritorno += " sorgente: " + ecc.Source + aCapo;
|
|
if (ecc.InnerException != null)
|
|
{
|
|
ritorno += " descrizione Inner: " + ecc.InnerException.Message + aCapo;
|
|
ritorno += " sorgente Inner: " + ecc.InnerException.Source + aCapo;
|
|
}
|
|
ritorno += " traccia: " + formattaErrore(ecc.StackTrace) + aCapo;
|
|
return ritorno;
|
|
|
|
}
|
|
|
|
public static string formattaErrore(string errore)
|
|
{
|
|
const string aCapo = "#/n#";
|
|
const string spazio = " ";
|
|
string separatore1 = " at ";
|
|
string separatore2 = " in ";
|
|
string separatore3 = ":line ";
|
|
string erroreInterno = errore.Replace(separatore1, "@");
|
|
string ritorno = aCapo;
|
|
|
|
|
|
//nome metodo e tutto il resto
|
|
string[] messaggioErrore = erroreInterno.Split('@');
|
|
string messaggioSenzaSpazi;
|
|
string[] messaggioInterno;
|
|
|
|
foreach (string messaggio in messaggioErrore)
|
|
{
|
|
messaggioSenzaSpazi = messaggio.Trim();
|
|
|
|
if (messaggioSenzaSpazi != "")
|
|
{
|
|
messaggioSenzaSpazi = messaggioSenzaSpazi.Replace(separatore2, "@");
|
|
messaggioInterno = messaggioSenzaSpazi.Split('@');
|
|
if (messaggioInterno.GetUpperBound(0) == 1)
|
|
{
|
|
ritorno += spazio + "metodo: " + messaggioInterno[0] + aCapo;
|
|
string fileLineaSingolo = messaggioInterno[1].Replace(separatore3, "@");
|
|
string[] fileLinea = fileLineaSingolo.Split('@');
|
|
ritorno += spazio + "percorsoFile: " + fileLinea[0] + aCapo;
|
|
ritorno += spazio + "linea: " + fileLinea[1] + aCapo;
|
|
ritorno += aCapo;
|
|
}
|
|
else
|
|
{
|
|
ritorno += spazio + "metodo: " + messaggioInterno[0] + aCapo;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ritorno;
|
|
}
|
|
|
|
//public static void scriviErroreNelDB(int codiceErrore, string descrizioErrore, int localeId, string nomePackage, string descrizionePackage)
|
|
//{
|
|
// int scriviErroreNelDB = int.Parse(UtilityManager.getAppSetting("scriviErroreNelDB"));
|
|
// if (scriviErroreNelDB == 1)
|
|
// {
|
|
// //try
|
|
// //{
|
|
// List<Parametro> parametri = new List<Parametro>();
|
|
// Parametro parametro = new Parametro();
|
|
// parametro.DbType = DbType.Int32;
|
|
// parametro.ParameterName = "codiceErrore";
|
|
// parametro.Value = codiceErrore;
|
|
// parametri.Add(parametro);
|
|
|
|
// parametro = new Parametro();
|
|
// parametro.DbType = DbType.String;
|
|
// parametro.ParameterName = "descrizioErrore";
|
|
// parametro.Value = descrizioErrore;
|
|
// parametri.Add(parametro);
|
|
|
|
// parametro = new Parametro();
|
|
// parametro.DbType = DbType.DateTime;
|
|
// parametro.ParameterName = "dataTime";
|
|
// parametro.Value = DateTime.Now;
|
|
// parametri.Add(parametro);
|
|
|
|
// parametro = new Parametro();
|
|
// parametro.DbType = DbType.String;
|
|
// parametro.ParameterName = "localeID";
|
|
// if (localeId == 0)
|
|
// parametro.Value = System.DBNull.Value;
|
|
// else
|
|
// parametro.Value = localeId;
|
|
// parametri.Add(parametro);
|
|
|
|
// parametro = new Parametro();
|
|
// parametro.DbType = DbType.String;
|
|
// parametro.ParameterName = "descrizionePackage";
|
|
// parametro.Value = descrizionePackage;
|
|
// parametri.Add(parametro);
|
|
|
|
// parametro = new Parametro();
|
|
// parametro.DbType = DbType.String;
|
|
// parametro.ParameterName = "nomePackage";
|
|
// parametro.Value = nomePackage;
|
|
// parametri.Add(parametro);
|
|
|
|
// DataAccess.ExecuteNonQueryStoredProcedure(DBProvider.SqlServerStampeC6, "[C6Mart].[UT_INSERT_ERROR]", parametri);
|
|
|
|
// }
|
|
//}
|
|
}
|
|
|
|
}
|