Skip to content

Instantly share code, notes, and snippets.

@ivanbuzyka
ivanbuzyka / AzureADIdentityProviderProcessor.cs
Created February 12, 2024 18:15
[TEMP] AAD Identity provider sample
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Owin.Infrastructure;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Notifications;
using Microsoft.Owin.Security.OpenIdConnect;
using Owin;
using Sitecore.Abstractions;
using Sitecore.Configuration;
using Sitecore.Data.Clones;
using Sitecore.Diagnostics;
@ivanbuzyka
ivanbuzyka / purge.html
Created September 28, 2023 10:43
HTML + JavaScript implementation for calling Sitecore xConnect purge API without authentication (HTML file should be run from within logged in CM browser session). This particular example calls POST contacts API, it can be extended to use other API and supply parameters
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sitecore Purge API</title>
</head>
<body>
<h1>POST Request Example</h1>
<button id="purge-button">Purge</button>
<div id="response-panel" style="display: none;"></div>
@ivanbuzyka
ivanbuzyka / CreateAmountOfGroups.ps1
Created December 12, 2022 15:06
Login to the Azure AD Tenant with no Azure Subscription. Create a lot of Azure AD Groups and add a user as member to them. This can be used to test Azure AD authentication for scenarios when a lot of Groups are send by Claims
$userId = "<ObjectID of AAD User>"
$countOfGroupsToCreate = 300
$groupNamePrefix = "testgroup"
for ($i = 0; $i -lt $countOfGroupsToCreate; $i++)
{
$newGroup = (az ad group create --display-name "$groupNamePrefix-group$i" --mail-nickname "$groupNamePrefix-group$i" -o json) | ConvertFrom-Json
az ad group member add --group $newGroup.Id --member-id $userId
}
@ivanbuzyka
ivanbuzyka / getEXMClickEvents.sql
Created October 12, 2022 08:59
SQL queries to investigate Sitecore EXM issues
SELECT TargetPageUrl, ContactId FROM [xdb_collection].[Interactions]
CROSS APPLY
OPENJSON([xdb_collection].[Interactions].[Events]) WITH
(
OdataType varchar(200) '$."@odata.type"',
MessageId varchar(200) '$.MessageId',
TargetPageUrl varchar(200) '$.Url'
)
WHERE
OdataType = '#Sitecore.EmailCampaign.Model.XConnect.Events.EmailClickedEvent'
@ivanbuzyka
ivanbuzyka / deploy.cmd
Created September 2, 2022 06:42
Deploy dacpac file to Microsoft Azure SQL Database
msdeploy.exe -Verb:Sync -Source:dbDacFx="C:\path\to\dacpac\Sitecore.Xdb.Collection.Shard0.dacpac" -Dest:dbDacFx="Data Source=sqlservername.database.windows.net;Database=shard0; User ID=sa; Password=hereissupersecretpassword"
@ivanbuzyka
ivanbuzyka / flushsc10.aspx
Created June 4, 2022 10:46
The file to use for ending session in Sitecore 10.1 to flush the data from session store to xDB
<%@ Page language="c#" %>
<%@ Import namespace="Microsoft.Extensions.DependencyInjection" %>
<script runat="server">
void Page_Load(object sender, System.EventArgs e) {
var identificationManager = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetRequiredService<Sitecore.Analytics.Tracking.Identification.IContactIdentificationManager>();
Sitecore.Analytics.Tracking.Identification.IdentificationResult result = identificationManager.IdentifyAs(new Sitecore.Analytics.Tracking.Identification.KnownContactIdentifier("directsource", "user_" + Guid.NewGuid()));
Sitecore.Analytics.Tracker.Current.EndTracking();
Session.Abandon();
@ivanbuzyka
ivanbuzyka / GetOpensAndClicks.csx
Created September 23, 2021 07:30
Sitecore EXM API call example for getting opens and clicks
var client = new RestClient("https://101.cm/sitecore/api/ssc/EXM/OpensClicks");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", ".AspNet.Cookies=bgpR8QztTd9NZSUxslRERNisA0vfddxT2EPo6ntOWeLNTl_-ivEd5KrzdhUmSlQubeoG0wRrRhqCnK6anpbIvrShqzTE0GFedn9POFSJr3cUUjN-ZNiUldGXecBBX3q-TN-cODWap-ReuekxmaK-_xMeev_kGT2W10PhPPc6axLf73juAPp9vvsVZaBzofPjiO6bexAm405zAZi05gqfJEZL27Ga9ykriJTvWUbR0SCO8UD_DF7DWFVbEprbpdjoDixVI1BcE3D_Z54SI1o0htmeJdfsAZp7W2gf8y17wZzNxBon1m7juM_wdvhIcsYSjjfqL-sk0f6JIMcLbspcnEFaY1frYyIoe3yjJCQU-FFIH44oIdIg5YvmhRRU-wlcweFgLt-4yBo1AGsw7ryQa1ADA8GRxBcfBPik16mPqDAaiRQoeIm0zqwV378456YwFJ1w_EPvTPJzqPwZ1KKrjASxMXIl-8qhjXUQfFHGq3ycqfGFV5OkVbEzty88K_zxzU4QRAXqVgBbwSWNuwBuY5T9zNPBO_I5tAckFmiuRsCbicvQApERfk6PQhMH0XFI6jSps3LPRGEe2qf_kaWKayB9rcui4yyr46AsTJtMd0-4JvYUlCRCiLJbSg2EaJZcqLk6fn4ihUCL9MQU0GJF6Sb4dNO_w5Ms3I0KuFaUZPBAT2PYTMTAQbFJAmQjkTO_G-qINZ3QPyYKUeqB1ESc12kRNkso-L5HVztk4cGvmtz_9lr3WZ4i2tIERX
@ivanbuzyka
ivanbuzyka / MatchFilenamesInCsv.ps1
Created August 23, 2021 15:36
Powershell script for looking through CSV using regular expression and outputting matching string. Can be used in Content Hub target job export to analyze imageMagick failures
$csvFile = Get-Item "C:\path-to-csv-file.csv"
$stateDescriptions = Import-Csv $csvFile -Delimiter ';' | Select-Object Target.StateDescription
$result1 = @()
foreach($desc in $stateDescriptions)
{
# searching for filename with extension here (example pattern match /123testfile.tif:)
$desc -match "\/(?<filename>[^\/]*\.\w+):" #"\/\d{6}_.+\.[a-z0-9]+:"
if($Matches.Count -gt 0)
{
@ivanbuzyka
ivanbuzyka / code.js
Last active October 19, 2021 14:26
Sitecore Content Hub. External Page component that renders styled taxonomy label on entity details page
var source = document.getElementById("entry-template").innerHTML;
var template = Handlebars.compile(source);
var entityLoadedSubscription = options.mediator.subscribe("entityLoaded", function (entity) {
updateUI(entity);
var entitySavedEvent = Utils.format("entitySaved:{id}", { id: entity.systemProperties.id() });
options._page.mediator.subscribe(entitySavedEvent, updateUI);
});
function updateUI(entity){
@ivanbuzyka
ivanbuzyka / Program.cs
Created July 6, 2021 09:22
Sitecore Content Hub. Changing entity definition programmatically
using Stylelabs.M.Sdk.Models.Base;
using Stylelabs.M.Sdk.Models.Base.PropertyDefinitions;
using Stylelabs.M.Sdk.WebClient;
using Stylelabs.M.Sdk.WebClient.Authentication;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace SchemaModification
{