Tag: configuration

How to resolve handshake with cloud mlab mongodb when connection type is SSL?

How to resolve handshake with cloud mlab mongodb when connection type is SSL?

Override the “UpdateMongoDriverSettingsProcessor” pipeline.

 

Sample code :

 

public class UpdateMongoDriverSettings: UpdateMongoDriverSettingsProcessor

{

/// <summary>

/// This pipeline is override for conection delay or handshake with cloud mlab mongodb when connection type is SSL

/// </summary>

/// <param name=”args”></param>

public override void UpdateSettings(UpdateMongoDriverSettingsArgs args)

{

Assert.ArgumentNotNull(args, nameof(args));

Int32 defaultValue = 120;

 

Int32 socketTime = String.IsNullOrEmpty(string.Format(CultureInfo.InvariantCulture,Settings.GetSetting(“MongoDB.SocketTimeout”))) ? defaultValue : Int32.Parse(Settings.GetSetting(“MongoDB.SocketTimeout”), CultureInfo.InvariantCulture);

Int32 ConnectTimeout = String.IsNullOrEmpty(Settings.GetSetting(“MongoDB.SocketTimeout”)) ? defaultValue : Int32.Parse(Settings.GetSetting(“MongoDB.ConnectTimeout”),CultureInfo.InvariantCulture);

Int32 WaitQueueTimeout = String.IsNullOrEmpty(Settings.GetSetting(“MongoDB.SocketTimeout”)) ? defaultValue : Int32.Parse(Settings.GetSetting(“MongoDB.WaitQueueTimeout”),CultureInfo.InvariantCulture);

 

if (args != null)

{

args.MongoSettings.SocketTimeout = new TimeSpan(0, 0, 0, socketTime);

args.MongoSettings.ConnectTimeout = new TimeSpan(0, 0, 0, ConnectTimeout);

args.MongoSettings.WaitQueueTimeout = new TimeSpan(0, 0, 0, WaitQueueTimeout);

}

Log.Info(String.Format(CultureInfo.InvariantCulture,”UpdateMongoDriverSettingsArgs changed”), this);

}

 

}

 

 

 

<configuration xmlns:patch=”www.sitecore.net/xmlconfig”>

<sitecore>

<pipelines>

<updateMongoDriverSettings>

<processor type=”MogoDbExtension.UpdateMongoDriverSettings, Assembly Name” />

</updateMongoDriverSettings>

</pipelines>

 

<settings>

<setting name=”MongoDB.SocketTimeout” value=”120″ />

<setting name=”MongoDB.ConnectTimeout” value=”120″ />

<setting name=”MongoDB.WaitQueueTimeout” value=”120″ />

</settings>

</sitecore>

</configuration>

 

Advertisements

How to do Configuration patching in Sitecore

In Real development many time we find lot of scenario where we have to patch the configuration. In Sietcore there is one thumb rule that all type of patching configuration file will add under “\App_Config\include” folder.

All given below patch section will add only under <sitecore> tag in config file. Sitecore have custom module which dynamically added all configuration at runtime.

Following are some requirements and examples.

  • Merging the config files: -A

    s example in Sitecore all setting will exist in Sitecore.config file under Include folder.

As example if you want to create a switcher for any logic that you can enable and disable the execution of code from configuration.

Create one new config File name as “z.SitecoreSetting.config” and add setting in this file as follows:

<setting name=”SwitchOnOff” value=”true” /> 

Note: At run time this setting will be add in Sitecore.config file.

  • How to add or update attribute of any configuration: – We can add the new attribute or update the existing attribute value also.

As example you got the requirement from Client that language will not append in Web URL.

Following are the step to implement this:

Create one new config File name as “z.SitecoreLinkManger.config” and add setting in this file as follows:

You have to add  “patch:attribute” tag containg the name of existing attribute and new value.

“<configuration  xmlns:patch=”http://www.sitecore.net/xmlconfig/&#8221; xmlns:set=”http://www.sitecore.net/xmlconfig/set/”&gt;

<sitecore>

<linkManager defaultProvider=”sitecore”>

<providers>

<add name=”sitecore”>

<patch:attribute name=”languageEmbedding”>never</patch:attribute>

</add>

</providers>

</linkManager>

</sitecore>

</configuration>

 

  • How to insert the config element before or after specific configuration?

In this requirement we have to add out custom pipeline, events or etc. Please see the below httpbegin request pipeline example.

Patch:before  Example

<configuration xmlns:patch=”http://www.sitecore.net/xmlconfig/”&gt;

<sitecore>

<pipelines>

<httpRequestBegin>

<processor type=”Your custom class name”,   DLL Name”      patch:before=”processor[@type=’Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel’]”/>

</httpRequestBegin>

</pipelines>

</sitecore>

</configuration>

 

patch:after Sitecore Example:-

 

<!– Sitecore.config –>

<test>

<processor type=”test1″ />

<processor type=”test2″ />

<processor type=”test3″ />

</test>

<!– Patch file –>

<test>

<processor type=”testA” patch:after = “processor[@type=’test2′]”/>

</test>

The configuration used at runtime is:

<test>  <processor type=”test1″ />

<processor type=”test2″ /><processor type=”testA” />  <processor type=”test3″ />

</test>

<processor type=”test2″ />

<processor type=”testA” />

<processor type=”test3″ />

</test>