public void TextMessageEncodingElement() { TextMessageEncodingElement element = GetElement <TextMessageEncodingElement> (1); Assert.AreEqual(typeof(TextMessageEncodingBindingElement), element.BindingElementType, "BindingElementType"); Assert.AreEqual("textMessageEncoding", element.ConfigurationElementName, "ConfigurationElementName"); Assert.AreEqual(128, element.MaxReadPoolSize, "MaxReadPoolSize"); Assert.AreEqual(Encoding.UTF32, element.WriteEncoding, "WriteEncoding"); Assert.AreEqual(MessageVersion.Soap11WSAddressingAugust2004, element.MessageVersion, "MessageVersion"); Assert.AreEqual(32, element.MaxWritePoolSize, "MaxWritePoolSize"); Assert.AreEqual(128, element.ReaderQuotas.MaxArrayLength, "ReaderQuotas.MaxArrayLength"); Assert.AreEqual(128, element.ReaderQuotas.MaxBytesPerRead, "ReaderQuotas.MaxBytesPerRead"); Assert.AreEqual(128, element.ReaderQuotas.MaxDepth, "ReaderQuotas.MaxDepth"); Assert.AreEqual(128, element.ReaderQuotas.MaxNameTableCharCount, "ReaderQuotas.MaxNameTableCharCount"); Assert.AreEqual(128, element.ReaderQuotas.MaxStringContentLength, "ReaderQuotas.MaxStringContentLength"); }
/// <summary> /// Initialize History Logger configuration from the web.config. /// </summary> /// <returns> if error return true else false </returns> private void Initialize() { _valid = false; _used = false; bool error = false; try { bool isLoadingFromWebApplication = AppDomain.CurrentDomain.GetData("DataDirectory") != null; if (ConfigurationManager.AppSettings[DATABASECONFIGPATH] != null) { _used = true; try { try { _dataBaseConfigPath = ConfigurationManager.AppSettings[DATABASECONFIGPATH]; _dataBaseConfigPath = _dataBaseConfigPath.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath); ReadDBConfigFile(); } catch (Exception) { LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } catch { LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } if (ConfigurationManager.AppSettings[LOGBACKUPPATH] != null) { try { try { _logBackupPath = ConfigurationManager.AppSettings[LOGBACKUPPATH]; _logBackupPath = _logBackupPath.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath); } catch (Exception) { LogManager.WriteLog(TraceType.ERROR, "LogBackUpPath in web.config not valid", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } catch { LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } if (ConfigurationManager.AppSettings[CREATETABLESCRIPTPATH] != null) { try { try { _createTableScriptPath = ConfigurationManager.AppSettings[CREATETABLESCRIPTPATH]; _createTableScriptPath = _createTableScriptPath.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath); } catch (Exception) { LogManager.WriteLog(TraceType.ERROR, "CreateTableScript in web.config not valid", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } catch { LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } if (ConfigurationManager.ConnectionStrings[SQLCONNECTIONSTRING] != null) { try { _connectionString = ConfigurationManager.ConnectionStrings[SQLCONNECTIONSTRING].ConnectionString; SqlConnectionStringBuilder stringBuiilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["SqlServerDataDirectory"].ConnectionString); if (stringBuiilder != null && stringBuiilder.AttachDBFilename != null && stringBuiilder.AttachDBFilename.Contains("|DataDirectory|")) { string configConvertedPath = stringBuiilder.AttachDBFilename.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath); //if (File.Exists(configConvertedPath)) try { FileInfo file = new FileInfo(configConvertedPath); stringBuiilder.AttachDBFilename = file.FullName; _connectionString = stringBuiilder.ConnectionString; } catch { } } } catch { LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogSqlServerDataDirectoryError, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } if (ConfigurationManager.ConnectionStrings[SQLCREATEDBCONNECTIONSTRING] != null) { try { _createDbConnectionString = ConfigurationManager.ConnectionStrings[SQLCREATEDBCONNECTIONSTRING].ConnectionString; } catch { LogManager.WriteLog(TraceType.ERROR, "Error in connection string " + SQLCREATEDBCONNECTIONSTRING, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } } try { ServiceModelSectionGroup section; if (isLoadingFromWebApplication) { Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); section = config.GetSectionGroup("system.serviceModel") as ServiceModelSectionGroup; } else { section = ConfigurationManager.GetSection("system.serviceModel") as ServiceModelSectionGroup; } if (section != null) { CustomBindingElementCollection customBindingElements = section.Bindings.CustomBinding.Bindings; for (int customElements = 0; customElements < customBindingElements.Count; customElements++) { CustomBindingElement customBindingElement = customBindingElements[customElements]; if (customBindingElement.Name == "MaintenanceBinding") { ElementInformation txtMessageEncodingElementInfo = customBindingElement.ElementInformation; TextMessageEncodingElement txtMessageEncodingElement = (TextMessageEncodingElement)txtMessageEncodingElementInfo.Properties["textMessageEncoding"].Value; ElementInformation readerQuotasElementInfo = txtMessageEncodingElement.ElementInformation; XmlDictionaryReaderQuotasElement readerQuotasElement = (XmlDictionaryReaderQuotasElement)readerQuotasElementInfo.Properties["readerQuotas"].Value; _maxStringContentLength = readerQuotasElement.MaxStringContentLength; break; } } } } catch { LogManager.WriteLog(TraceType.ERROR, "Error in retrieving max String Content Length", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); error = true; } if (!error) { string message = "Initialize success:" + " DataBaseConfigPath=" + DataBaseConfigPath + " LogDataBaseStructureVersion=" + LogDataBaseStructureVersion + " PercentageToCleanUpInLogDatabase=" + PercentageToCleanUpInLogDatabase + " MaximumLogMessageSize=" + MaximumLogMessageSize + " MaximumLogMessageCount=" + MaximumLogMessageCount + " SqlConnectionString=" + SqlConnectionString + " SqlCreateDbConnectionString=" + SqlCreateDbConnectionString + " LogBackupPath=" + LogBackupPath + " CreateTableScriptPath=" + CreateTableScriptPath; LogManager.WriteLog(TraceType.INFO, message, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); } } catch { LogManager.WriteLog(TraceType.ERROR, "Error Initializing HistoryLoggerConfiguration", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore); } _valid = !error; }