private void ValidateSubjectFormatString(string subjectFormatString, InitializationModel model) { if (!String.IsNullOrEmpty(subjectFormatString)) { this.TestIfSubjectFormatStringIsFormattedCorrectly(subjectFormatString, model); this.CheckWhetherFormatStringContainsIllegalCharacters(subjectFormatString, model); } }
private void CheckWhetherFormatStringContainsIllegalCharacters(string subjectFormatString, InitializationModel model) { if (subjectFormatString.Contains("\n") || subjectFormatString.Contains("\r")) { if (model == InitializationModel.Configuration) { string exceptionMessage = SR.IllegalCharactersLineBreaksAreNotAllowed(subjectFormatString, SubjectFormatStringAttribute, this.Name); throw new ProviderException(exceptionMessage); } else { throw new ArgumentException(SR.IllegalCharactersLineBreaksAreNotAllowed(), "subjectFormatString"); } } }
private void TestIfSubjectFormatStringIsFormattedCorrectly(string subjectFormatString, InitializationModel model) { try { // Test is the formatString is formatted correctly. LogEntry testEntry = new LogEntry(LoggingEventType.Error, "Message", null, null); BuildMailMessageSubject(subjectFormatString, testEntry, DateTime.MaxValue); } catch (FormatException ex) { if (model == InitializationModel.Configuration) { this.ThrowInvalidFormattedSubjectFormatStringProviderException(ex, subjectFormatString); } else { ThrowInvalidFormattedSubjectFormatStringArgumentException(ex, subjectFormatString); } } }
public IActionResult Save([FromBody] InitializationModel model) { try { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", true, reloadOnChange: true); var config = builder.Build(); config["DataBase:ConnectionString"] = DataBaseHelper.GetDbConfiguration(model.DataServerName, model.DataAccountName, model.DataPassword, model.DatabaseName, model.CommandTimeOut); config["Initialization:IsInitialization"] = "true"; WriteJson("DataBase:ConnectionString", config["DataBase:ConnectionString"], config["Initialization:IsInitialization"]); if (model.OrganizationBases != null) { DataBaseOptions options = new DataBaseOptions() { ConnectionString = config["DataBase:ConnectionString"] }; IOrganizationBaseRepository organizationBaseRepository = new OrganizationBaseRepository(options); IOrganizationBaseService _organizationBaseService = new Organization.OrganizationBaseService(organizationBaseRepository); model.OrganizationBases.ForEach(x => { _organizationBaseService.Update(x); }); } return(new JsonResult(new JsonResultObject() { IsSuccess = true })); } catch (Exception ex) { return(new JsonResult(new JsonResultObject() { IsSuccess = false, Content = ex.Message })); } }
public BackgroundJobsConfig(InitializationEngine engine, InitializationModel initializationModel, IApiConfigurationProvider apiConfigurationProvider) { _engine = engine; _initializationModel = initializationModel; _apiConfigurationProvider = apiConfigurationProvider; }