T GetElement <T> (int index) where T : BindingElementExtensionElement { CustomBindingElement binding = OpenConfig().Bindings [index]; T element = (T)binding [typeof(T)]; Assert.IsNotNull(element, typeof(T).Name + " is not exist in collection."); return(element); }
private void ApplyConfiguration(string configurationName) { CustomBindingElement element2 = CustomBindingCollectionElement.GetBindingCollectionElement().Bindings[configurationName]; if (element2 == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidBindingConfigurationName", new object[] { configurationName, "customBinding" }))); } element2.ApplyConfiguration(this); }
public void CustomBindingElement() { CustomBindingElement binding = OpenConfig().Bindings [0]; Assert.AreEqual("CustomBinding_1", binding.Name, "Name"); Assert.AreEqual(new TimeSpan(0, 2, 0), binding.CloseTimeout, "CloseTimeout"); Assert.AreEqual(new TimeSpan(0, 2, 0), binding.OpenTimeout, "OpenTimeout"); Assert.AreEqual(new TimeSpan(0, 20, 0), binding.ReceiveTimeout, "ReceiveTimeout"); Assert.AreEqual(new TimeSpan(0, 2, 0), binding.SendTimeout, "SendTimeout"); }
public static void RemoveDuplicateBindingExtensions(this CustomBindingElement bindingElement, CustomBinding binding) { foreach (var element in bindingElement.Select(elementExtension => binding.Elements. FirstOrDefault(e => e.GetType() == elementExtension.BindingElementType)). Where(element => element != null)) { binding.Elements.Remove(element); } }
public void ClientBindingTest() { ServiceModelConfigurationManager manager = LoadManager(); ClientSection client = manager.GetClient(); CustomBindingElement binding = manager.GetCustomBinding(client.Endpoints[0].BindingConfiguration); SecurityElement securitySection = binding[typeof(SecurityElement)] as SecurityElement; Assert.IsNotNull(securitySection); Assert.AreEqual(AuthenticationMode.UserNameForSslNegotiated, securitySection.SecureConversationBootstrap.AuthenticationMode); }
private void CheckRuleForCustomBinding(CustomBindingElement customBinding) { if (customBinding != null) { SecurityElement securityElement = (SecurityElement)customBinding[typeof(SecurityElement)]; if (securityElement == null) { AddProblem(customBinding.Name); } } }
public void AddCustomBindingTest() { CustomBindingElement element = new CustomBindingElement("newBasicBinding"); ServiceModelConfigurationManager manager = LoadManager(); manager.AddCustomBinding(element); CustomBindingElement addedElement = manager.GetCustomBinding("newBasicBinding"); Assert.AreEqual(element.Name, addedElement.Name); }
/// <summary> /// Adds the custom binding. /// </summary> /// <param name="customBinding">The custom binding.</param> public void AddCustomBinding(CustomBindingElement customBinding) { if (customBinding == null) { throw new ArgumentNullException("customBinding"); } if (serviceModelSectionGroup.Bindings.CustomBinding == null) { serviceModelSectionGroup.Bindings.BindingCollections.Add(new CustomBindingCollectionElement()); } serviceModelSectionGroup.Bindings.CustomBinding.Bindings.Remove(customBinding); serviceModelSectionGroup.Bindings.CustomBinding.Bindings.Add(customBinding); }
private void CheckRuleForCustomBinding(CustomBindingElement customBinding) { SecurityElement securityElement = (SecurityElement)customBinding[typeof(SecurityElement)]; if (securityElement != null) { if (!securityElement.LocalServiceSettings.DetectReplays || !securityElement.LocalClientSettings.DetectReplays) { Resolution resolution = base.GetResolution(customBinding.Name); Problem problem = new Problem(resolution); problem.SourceFile = base.SourceFile; base.Problems.Add(problem); } } }
public void AddCustomBindingNewSectionTest() { // Remove any previous CustomBinding section ServiceModelConfigurationManager manager = LoadManager(); manager.Configuration.Sections.Remove("customBinding"); CustomBindingElement element = new CustomBindingElement("newBasicBinding"); manager.AddCustomBinding(element); CustomBindingElement addedElement = manager.GetCustomBinding("newBasicBinding"); Assert.AreEqual(element.Name, addedElement.Name); }
public void UpdateCustomBindingTest() { ServiceModelConfigurationManager manager = LoadManager(); manager.AddCustomBinding(new CustomBindingElement(Constants.ServiceBindingName)); CustomBindingElement element = manager.GetCustomBinding(Constants.ServiceBindingName); element.Add(new SecurityElement()); element.Add(new HttpTransportElement()); manager.AddCustomBinding(element); CustomBindingElement updatedElement = manager.GetCustomBinding(Constants.ServiceBindingName); Assert.AreEqual(2, updatedElement.Count); }
void ApplyConfiguration(string configurationName) { CustomBindingCollectionElement section = CustomBindingCollectionElement.GetBindingCollectionElement(); CustomBindingElement element = section.Bindings[configurationName]; if (element == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException( SR.GetString(SR.ConfigInvalidBindingConfigurationName, configurationName, ConfigurationStrings.CustomBindingCollectionElementName))); } else { element.ApplyConfiguration(this); } }
private void CheckRuleForCustomBinding(CustomBindingElement customBinding) { SecurityElement securityElement = (SecurityElement)customBinding[typeof(SecurityElement)]; if (securityElement != null) { if (securityElement.MessageProtectionOrder == MessageProtectionOrder.EncryptBeforeSign || (securityElement.AuthenticationMode == AuthenticationMode.SecureConversation && securityElement.SecureConversationBootstrap.MessageProtectionOrder == MessageProtectionOrder.EncryptBeforeSign)) { Resolution resolution = base.GetResolution( customBinding.Name, MessageProtectionOrder.SignBeforeEncrypt.ToString(), MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature.ToString()); Problem problem = new Problem(resolution); problem.SourceFile = base.SourceFile; base.Problems.Add(problem); } } }
protected internal override bool TryAdd(string name, Binding binding, System.Configuration.Configuration config) { if (string.IsNullOrEmpty(name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name"); } if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } if (config == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config"); } ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(config); CustomBindingElementCollection bindings = sectionGroup.Bindings.CustomBinding.Bindings; CustomBindingElement element = new CustomBindingElement(name); bindings.Add(element); ExtensionElementCollection bindingElementExtensions = sectionGroup.Extensions.BindingElementExtensions; CustomBinding binding2 = (CustomBinding) binding; foreach (BindingElement element2 in binding2.Elements) { BindingElementExtensionElement element3; bool flag = this.TryCreateMatchingExtension(element2, bindingElementExtensions, false, element.CollectionElementBaseType.AssemblyQualifiedName, out element3); if (!flag) { flag = this.TryCreateMatchingExtension(element2, bindingElementExtensions, true, element.CollectionElementBaseType.AssemblyQualifiedName, out element3); } if (!flag) { break; } element3.InitializeFrom(element2); element.Add(element3); } bool flag2 = element.Count == binding2.Elements.Count; if (!flag2) { bindings.Remove(element); } return flag2; }
private void TestAmfBinding() { try { Configuration servicesConfig = WebConfigurationManager.OpenWebConfiguration("~/services"); ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(servicesConfig); BindingsSection bindings = serviceModel.Bindings; CustomBindingElement amfBinding = bindings.CustomBinding.Bindings.Cast <CustomBindingElement>().FirstOrDefault(cb => cb.Name == "amfBinding"); if (amfBinding == null) { MarkAsFail(AmfBindingLabel, "Custom binding with name=\"amfBinding\" not found.", null); return; } string config = File.ReadAllText(Server.MapPath("~/Content/swf/config/paths.properties")); bool sfwUsesHttps = config.Replace(" ", string.Empty).Contains("gateway=https:"); var http = amfBinding.FirstOrDefault(x => x is HttpTransportElement); var https = amfBinding.FirstOrDefault(x => x is HttpsTransportElement); if (sfwUsesHttps) { if (https == null) { MarkAsFail(AmfBindingLabel, "httpsTransport section not found", "Use <httpsTransport /> within <binding name=\"amfBinding\"> (services/web.config)"); } } else { if (http == null) { MarkAsFail(AmfBindingLabel, "httpTransport section not found", "Use <httpTransport /> within <binding name=\"amfBinding\">. (services/web.config)"); } } MarkAsPass(AmfBindingLabel); } catch (Exception ex) { MarkAsFail(AmfBindingLabel, "EXCEPTION DURING TEST: " + ex.Message, null); } }
protected internal override bool TryAdd(string name, Binding binding, Configuration config) { if (String.IsNullOrEmpty(name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name"); } if (null == binding) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } if (null == config) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config"); } ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config); CustomBindingElementCollection customBindings = sg.Bindings.CustomBinding.Bindings; CustomBindingElement configElement = new CustomBindingElement(name); customBindings.Add(configElement); ExtensionElementCollection collection = sg.Extensions.BindingElementExtensions; CustomBinding customBinding = (CustomBinding)binding; foreach (BindingElement bindingElement in customBinding.Elements) { BindingElementExtensionElement bindingElementExtension; bool foundMatch = TryCreateMatchingExtension(bindingElement, collection, false, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension); if (!foundMatch) { foundMatch = TryCreateMatchingExtension(bindingElement, collection, true, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension); } if (!foundMatch) { break; } bindingElementExtension.InitializeFrom(bindingElement); configElement.Add(bindingElementExtension); } bool retval = configElement.Count == customBinding.Elements.Count; if (!retval) { customBindings.Remove(configElement); } return retval; }
protected internal override bool TryAdd (string name, Binding binding, SysConfig config) { if (!binding.GetType ().Equals (typeof (CustomBinding))) return false; var element = new CustomBindingElement (); element.Name = name; element.InitializeFrom (binding); Bindings.Add (element); return true; }
public void ThrowOnGetCustomBindingThatNotExistsTest() { CustomBindingElement element = LoadManager().GetCustomBinding("NotExist"); }
/// <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; }