Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Tamás Tárnok trnktms

:octocat:
View GitHub Profile
View RegisterDependencies.cs
public class RegisterDependencies : IServicesConfigurator
{
public void Configure(IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<IApplicationDictionaryReader, NoCacheApplicationDictionaryReader>();
}
}
View ServicesConfigurator.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<services>
<configurator type="Discovering.Sitecore101.RegisterDependencies, Discovering.Sitecore101" />
</services>
</sitecore>
</configuration>
View NoCacheApplicationDictionaryReader.cs
public class NoCacheApplicationDictionaryReader : ApplicationDictionaryReader
{
public NoCacheApplicationDictionaryReader(
IDictionaryDomainResolver dictionaryDomainResolver,
ITranslationDictionaryReader translationDictionaryReader,
HttpContextBase httpContext)
: base(dictionaryDomainResolver, translationDictionaryReader, httpContext)
{
}
View Publishing.WebHooks.RenderingHostDictionaryCacheReload.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
<sitecore>
<layoutService>
<publishWebHooks type="Sitecore.JavaScriptServices.AppServices.WebHooks.WebHooks, Sitecore.JavaScriptServices.AppServices">
<hooks hint="list:AddWebHook">
<hook type="Sitecore.JavaScriptServices.AppServices.WebHooks.WebHookDefinition, Sitecore.JavaScriptServices.AppServices">
<name>ReloadDictionary</name>
<url>http://rendering/api/localization/reload</url>
<method>POST</method>
</hook>
View ContentBlock.cshtml
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
<div>@Localizer["label1"]</div>
View LocalizationController.cs
public class LocalizationController : Controller
{
private readonly ISitecoreLocalizer _sitecoreLocalizer;
public LocalizationController(ISitecoreLocalizer sitecoreLocalizer)
{
_sitecoreLocalizer = sitecoreLocalizer;
}
[HttpPost]
View Startup.cs
public class Startup
{
private static readonly string _defaultLanguage = "en";
private static readonly List<CultureInfo> _supportedCultures = new List<CultureInfo> { new CultureInfo(_defaultLanguage) };
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers();
View SitecoreLocalizer.cs
public interface ISitecoreLocalizer : IStringLocalizer
{
Task Reload();
}
public class SitecoreLocalizer : ISitecoreLocalizer
{
private static readonly Dictionary<string, Dictionary<string, string>> _sitecoreDictionary = new Dictionary<string, Dictionary<string, string>>();
private readonly HttpClient _httpClient;
private readonly SitecoreLocalizerOptions _sitecoreLocalizerOptions;
View dictionary-raw.json
{
"lang": "en",
"app": "Discovering.Sitecore101",
"phrases": {
"label1": "label 1",
"label2": "label 2"
}
}
View Measure-Response-Time.ps1
while ($true) {
$measuredTime = (Measure-Command -Expression { Invoke-WebRequest -Uri www.google.com }).TotalMilliseconds;
If ($measuredTime -gt 1000) {
$color = "red"
}
Else {
$color = "green"
}
Write-Host (Get-Date -Format "HH:mm:ss.ffff"): $measuredTime -ForegroundColor $color
}