/// <summary> /// Try to load the FabricTransport settings from a sectionName specified in the configuration file. /// Configuration File can be specified using the filePath or using the name of the configuration package specified in the service manifest . /// It will first try to load config using configPackageName . if configPackageName is not specified then try to load from filePath. /// </summary> /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it return false</param> /// <param name="filepath"> Full path of the file where the settings will be loaded from. /// If not specified , it will first try to load from default Config Package"Config" , if not found then load from Settings "ClientExeName.Settings.xml" present in Client Exe directory. </param> /// <param name="configPackageName"> Name of the configuration package. If its null or empty,it will check for file in filePath</param> /// <param name="settings">When this method returns it sets the <see cref="FabricTransportSettings"/> settings if load from Config succeeded. If fails ,its sets settings to null/> </param> /// <returns><see cref="bool"/> specifies whether the settings get loaded successfully from Config. /// It returns true when load from Config succeeded, else return false. </returns> /// <remarks> /// The following are the parameter names that should be provided in the configuration file,to be recognizable by service fabric to load the transport settings. /// /// 1. MaxQueueSize - <see cref="MaxQueueSize"/>value in long. /// 2. MaxMessageSize - <see cref="MaxMessageSize"/>value in bytes. /// 3. MaxConcurrentCalls - <see cref="MaxConcurrentCalls"/>value in long. /// 4. SecurityCredentials - <see cref="SecurityCredentials"/> value. /// 5. OperationTimeoutInSeconds - <see cref="OperationTimeout"/> value in seconds. /// 6. KeepAliveTimeoutInSeconds - <see cref="KeepAliveTimeout"/> value in seconds. /// 7. ConnectTimeoutInMilliseconds - <see cref="ConnectTimeout"/> value in milliseconds. /// </remarks> public static bool TryLoadFrom(string sectionName, out FabricTransportSettings settings, string filepath = null, string configPackageName = null) { try { bool isInitialized; var fabricTransportSettings = new FabricTransportSettings(); if (!string.IsNullOrEmpty(configPackageName)) { isInitialized = fabricTransportSettings.InitializeConfigFileFromConfigPackage(configPackageName); if (!isInitialized) { settings = null; return(false); } } else if (!string.IsNullOrEmpty(filepath)) { isInitialized = fabricTransportSettings.InitializeConfigFile(filepath); if (!isInitialized) { settings = null; return(false); } } isInitialized = fabricTransportSettings.InitializeSettingsFromConfig(sectionName); if (!isInitialized) { settings = null; return(false); } settings = fabricTransportSettings; AppTrace.TraceSource.WriteInfo( TraceType, "MaxMessageSize: {0} , MaxConcurrentCalls: {1} , MaxQueueSize: {2} , OperationTimeoutInSeconds: {3} KeepAliveTimeoutInSeconds : {4} , SecurityCredentials {5} , ConnectTimeoutInMilliseconds {6}", settings.MaxMessageSize, settings.MaxConcurrentCalls, settings.MaxQueueSize, settings.OperationTimeout.TotalSeconds, settings.KeepAliveTimeout.TotalSeconds, settings.SecurityCredentials.CredentialType, settings.ConnectTimeout.TotalMilliseconds); return(true); } catch (Exception ex) { // return false if load from fails AppTrace.TraceSource.WriteWarning(TraceType, "Exception thrown while loading from Config {0}", ex); settings = null; return(false); } }
/// <summary> /// Loads the FabricTransport settings from a sectionName specified in the configuration file /// Configuration File can be specified using the filePath or using the name of the configuration package specified in the service manifest . /// It will first try to load config using configPackageName . if configPackageName is not specified then try to load from filePath. /// </summary> /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it will throw ArgumentException</param> /// <param name="filepath"> Full path of the file where the settings will be loaded from. /// If not specified , it will first try to load from default Config Package"Config" , if not found then load from Settings "ClientExeName.Settings.xml" present in Client Exe directory. </param> /// <param name="configPackageName"> Name of the configuration package.If its null or empty,it will check for file in filePath</param> /// <returns>FabricTransportSettings</returns> /// <remarks> /// The following are the parameter names that should be provided in the configuration file,to be recognizable by service fabric to load the transport settings. /// /// 1. MaxQueueSize - <see cref="MaxQueueSize"/>value in long. /// 2. MaxMessageSize - <see cref="MaxMessageSize"/>value in bytes. /// 3. MaxConcurrentCalls - <see cref="MaxConcurrentCalls"/>value in long. /// 4. SecurityCredentials - <see cref="SecurityCredentials"/> value. /// 5. OperationTimeoutInSeconds - <see cref="OperationTimeout"/> value in seconds. /// 6. KeepAliveTimeoutInSeconds - <see cref="KeepAliveTimeout"/> value in seconds. /// 7. ConnectTimeoutInMilliseconds - <see cref="ConnectTimeout"/> value in milliseconds. /// </remarks> public static FabricTransportSettings LoadFrom( string sectionName, string filepath = null, string configPackageName = null) { bool isInitialized; var settings = new FabricTransportSettings(); if (!string.IsNullOrEmpty(configPackageName)) { isInitialized = settings.InitializeConfigFileFromConfigPackage(configPackageName); if (!isInitialized) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorConfigPackageNotFound, configPackageName)); } } else if (!string.IsNullOrEmpty(filepath)) { isInitialized = settings.InitializeConfigFile(filepath); if (!isInitialized) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorConfigFileNotFound, filepath)); } } isInitialized = settings.InitializeSettingsFromConfig(sectionName); if (!isInitialized) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorSectionNameNotFound, sectionName)); } AppTrace.TraceSource.WriteInfo( TraceType, "MaxMessageSize: {0} , MaxConcurrentCalls: {1} , MaxQueueSize: {2} , OperationTimeoutInSeconds: {3} KeepAliveTimeoutInSeconds : {4} , SecurityCredentials {5} , ConnectTimeoutInMilliseconds {6}", settings.MaxMessageSize, settings.MaxConcurrentCalls, settings.MaxQueueSize, settings.OperationTimeout.TotalSeconds, settings.KeepAliveTimeout.TotalSeconds, settings.SecurityCredentials.CredentialType, settings.ConnectTimeout.TotalMilliseconds); return(settings); }
/// <summary> /// FabricTransportSettings returns the default Settings .Loads the configuration file from default Config Package"Config" , if not found then try to load from default config file "ClientExeName.Settings.xml" from Client Exe directory. ///</summary> /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it will return the default Settings</param> /// <returns></returns> internal static FabricTransportSettings GetDefault(string sectionName = DefaultSectionName) { FabricTransportSettings settings = null; if (!TryLoadFrom(sectionName, out settings)) { settings = new FabricTransportSettings(); AppTrace.TraceSource.WriteInfo( TraceType, "Loading Default Settings , MaxMessageSize: {0} , MaxConcurrentCalls: {1} , MaxQueueSize: {2} , OperationTimeoutInSeconds: {3} KeepAliveTimeoutInSeconds : {4} , SecurityCredentials {5}", settings.MaxMessageSize, settings.MaxConcurrentCalls, settings.MaxQueueSize, settings.OperationTimeout.TotalSeconds, settings.KeepAliveTimeout.TotalSeconds, settings.SecurityCredentials.CredentialType); } return(settings); }