public Company GetDICompany(clsGeneralSetting.Logger pLogger = null) { string[] str; //SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company(); Company companyClass = new SAPbobsCOM.Company() { UseTrusted = this.P_SERVEUR_AuthWin }; if (!this.P_SERVEUR_AuthWin) { companyClass.DbUserName = this.P_SERVEUR_Login; companyClass.DbPassword = this.P_SERVEUR_Pass; } companyClass.DbServerType = SBOTools.Str2ServerType(this.P_SERVEUR_Type); if (Operators.CompareString(this.P_LicServ, "", false) != 0) { companyClass.LicenseServer = this.P_LicServ; } companyClass.language = BoSuppLangs.ln_French; companyClass.CompanyDB = this.P_SERVEUR_DB; companyClass.UserName = this.P_SERVEUR_SAPUser; companyClass.Password = this.P_SERVEUR_SAPPass; companyClass.Server = this.P_SERVEUR_Name; int num = 0; while (true) { num = checked (num + 1); if (companyClass.Connect() == 0) { break; } if (num > 20) { if (pLogger != null) { pLogger.AddLog(string.Concat("Echec des tentatives de connexion à ", this.P_SERVEUR_DB, " : ", companyClass.GetLastErrorDescription()), clsGeneralSetting.Logger.En_LogDetail.A_Erreurs_Critiques); } throw new Exception(companyClass.GetLastErrorDescription()); } if (pLogger != null) { str = new string[] { "Tentative n° ", num.ToString(), " : Echec de la connexion à ", this.P_SERVEUR_DB, " : ", companyClass.GetLastErrorDescription(), " (LoginSQL=", this.P_SERVEUR_Login, ", ServerType=", companyClass.DbServerType.ToString(), ")" }; pLogger.AddLog(string.Concat(str), clsGeneralSetting.Logger.En_LogDetail.C_Avertissements); } Thread.Sleep(30000); } if (pLogger != null) { str = new string[] { "Tentative n° ", num.ToString(), " : Connexion à ", this.P_SERVEUR_DB, " Effectuée " }; pLogger.AddLog(string.Concat(str), clsGeneralSetting.Logger.En_LogDetail.E_Infos); } return(companyClass); }
public void SendErrorMail(ref clsGeneralSetting.Logger pLogger, string pTo = null) { string errMailBody = pLogger.getErrMailBody(); pLogger.ClearLog(); if (Operators.CompareString(errMailBody, "", false) != 0) { if (DateTime.Compare(this.LastMailLogSend.AddMinutes((double)this.ErrToMail_LimitedMinutes), DateAndTime.Now) < 0) { this.LastMailLogSend = DateAndTime.Now; } else if (this.ErrToMail_Limited) { pLogger.AddLog("Envoi du message par e-mail annulé, temps entre 2 envois trop rapproché", clsGeneralSetting.Logger.En_LogDetail.D_Infos_Importante); return; } if (!this.SendMail(this.ErrToMail_Subject, errMailBody, Conversions.ToString(Operators.AddObject(this.ErrToMail_To, Interaction.IIf(pTo != null, string.Concat(",", pTo), ""))), null, this.ErrToMail_Sender, null, false, null)) { pLogger.AddLog(this.LastSettingsError, clsGeneralSetting.Logger.En_LogDetail.A_Erreurs_Critiques); } } }