Skip to content

Instantly share code, notes, and snippets.

View steliodibello's full-sized avatar

stelio di bello steliodibello

  • www.csexpertise.com
  • london
View GitHub Profile
namespace XXXCUSTOM.Middleware
{
using Microsoft.AspNetCore.Http;
using Sitecore.AspNet.RenderingEngine;
using Sitecore.LayoutService.Client.Response.Model;
using Sitecore.LayoutService.Client.Response.Model.Fields;
using System.Threading.Tasks;
public class RedirMiddleware
{
using SharedSource.RedirectModule.Classes;
using SharedSource.RedirectModule.Helpers;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Links;
using Sitecore.Rules;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
if (HttpContext.Current?.Request?.Headers.AllKeys == null)
{
return null;
}
var customCookie = HttpContext.Current?.Request?.Headers["XXX"];
var result = ContactIdentificationManager.IdentifyAs(new KnownContactIdentifier("Salesforce.ContactId", customCookie));
SitecoreLayoutRequest sitecoreLayoutRequest = _requestMapper.Map(httpContext.Request);
string cookieValueFromContext = _httpContextAccessor.HttpContext.Request.Cookies["_XXXX_trk"];
if (!string.IsNullOrEmpty(cookieValueFromContext))
{
sitecoreLayoutRequest.AddHeader("XXXX", new string[] { cookieValueFromContext });
}
namespace XXXX.Controllers
{
using Microsoft.AspNetCore.Mvc;
using Sitecore.AspNet.RenderingEngine;
using Sitecore.LayoutService.Client.Exceptions;
public class SitecoreController : Controller
{
public IActionResult Index()
{
var request = HttpContext.GetSitecoreRenderingContext();
using Sitecore.Analytics;
using Sitecore.Analytics.XConnect.Facets;
using Sitecore.Diagnostics;
using Sitecore.Rules;
using Sitecore.Rules.Conditions;
using Sitecore.XConnect;
using Sitecore.Xdb.Configuration;
using System.Collections.Generic;
using System.Linq;
@steliodibello
steliodibello / trigger.cs
Created November 17, 2023 19:47
Trigger to enrich Assets
using System.Linq;
using System.Globalization;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Stylelabs.M.Base.Querying;
using Stylelabs.M.Base.Querying.Filters;
using Stylelabs.M.Sdk.Contracts.Querying;
$rendering = Get-Item -Path "master:\sitecore\layout\Renderings/Feature\XXXX"
$items = Get-ChildItem -Path "master:\sitecore\content\home" -Recurse
foreach($item in $items) {
$renderingInstance = Get-Rendering -Item $_ -Rendering $rendering
if ($renderingInstance) {
Set-Rendering -Item $_ -Instance $renderingInstance -Parameter @{
"Reset Caching Options" = "1"
}
Write-Host "Updated Item $($_.Paths.FullPath)"
$renderingPath = "/sitecore/layout/Renderings/Feature/MYRENDERINGPath"
$renderingItem = Get-Item -Database "master" -Path $renderingPath | New-Rendering -Placeholder "main"
# Find the item where to add the new rendering
$item = Get-Item -Path "master:\content\Home"
# Bingo! Add the rendering to the item
Add-Rendering -Item $item -PlaceHolder "main" -Instance $renderingItem -Parameter @{ "Reset Caching Options" = "1" } -FinalLayout
@steliodibello
steliodibello / SPEexportExcel
Created June 5, 2023 17:43
Export sitecore SPE to excel
Import-Function -Name ConvertTo-Xlsx
[byte[]]$myPages = Get-ChildItem -Path "/sitecore/content/Home" -Recurse |  Where-Object { $_.TemplateID -match "{xxxxxxxx-xxxx-xxxx}" }|Select-Object -Property Name,Id,TemplateName,ProviderPath, "Meta Robots"|ConvertTo-Xlsx
Out-Download -Name "report-$datetime.xlsx" -InputObject $myPages