Skip to content

Instantly share code, notes, and snippets.

View harshbaid's full-sized avatar

Harsh Baid harshbaid

View GitHub Profile
using System;
using Microsoft.Owin;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Owin
{
using Predicate = Func<IOwinContext, bool>;
using AppFunc = Func<IDictionary<string, object>, Task>;
@harshbaid
harshbaid / RenderSvg.cs
Created January 24, 2020 16:16
Render inline SVG helper method
public static MvcHtmlString RenderSvg(this HtmlHelper helper, Image image)
{
if (image != null)
{
string result;
var imageItem = Sitecore.Context.Database.GetItem(image.MediaId.ToString());
if (imageItem == null)
{
return new MvcHtmlString("<!-- Null -->");
}
@harshbaid
harshbaid / XConnectService.cs
Created December 12, 2019 17:36 — forked from digitalParkour/XConnectService.cs
Sitecore XConnectService extension
namespace Sitecore.Foundation.SitecoreExtensions.Services
{
using Sitecore.Diagnostics;
using Sitecore.Foundation.DependencyInjection;
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using System;
using System.Linq;
/// <summary>
@harshbaid
harshbaid / XConnect.ConsoleCode.cs
Created November 18, 2019 15:39
Received in #xconnect channel in Sitecore Slack from Chris Auer
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Schema;
using System;
using System.Threading.Tasks;
using Sitecore.XConnect.Client.WebApi;
using Sitecore.Xdb.Common.Web;
using Sitecore.XConnect.Collection.Model;
using System.Collections.Generic;
using Sitecore.Xdb.Common.Web;
@harshbaid
harshbaid / Enable.FusionLog.md
Last active November 1, 2019 14:18
Enable FusionLog to understanding assembly binding conflicts

Add the following values to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
Add:
DWORD ForceLog set value to 1
DWORD LogFailures set value to 1
DWORD LogResourceBinds set value to 1
DWORD EnableLog set value to 1
String LogPath set value to folder for logs (e.g. C:\FusionLog\)
function Swap-DataSource ($item, $renderingToUpdate, $renderingDataSourceIdToAdd, $useFinalLayout) {
$renderingItem = Get-Item -Path $renderingToUpdate.ItemID
Write-Host "Swaping Rendering Datasource: $($renderingId.UniqueID) - '$($renderingItem.Name)' to: $($renderingDataSourceIdToAdd) for Item: $($item.Name)"
$renderingToUpdate.Datasource = $renderingDataSourceToAdd
Set-Rendering -Item $item -Instance $renderingToUpdate -FinalLayout:$useFinalLayout
}
function Swap-Rendering ($item, $renderingToSwapOut, $placeholder, $renderingIdToAdd, $renderingDataSourceIdToAdd, $useFinalLayout) {
$renderingItem = Get-Item -Path $renderingToSwapOut.ItemID
Write-Host "Swaping Rendering: $($renderingToSwapOut.UniqueID) - '$($renderingItem.Name)' in Placeholder: $($placeholder) to: $($renderingIdToAdd) - '$($renderingToAdd.Name)' for Item: $($item.Name)"
@harshbaid
harshbaid / Prune.Git.Branches.txt
Created September 26, 2019 18:25
Steps on How to prune local tracking branches that do not exist on remote anymore
Install NPM Package: `npm install -g git-removed-branches`
To see branches that will be removed: `git removed-branches`
To actually remove branches: `git removed-branches --prune`
More info here - https://www.npmjs.com/package/git-removed-branches
@harshbaid
harshbaid / Renew.Sitecore.and.XConnect.Certs.ps1
Created September 26, 2019 15:46
Steps to update expired Sitecore SSL cert, XConnect site SSL cert, and XConnect Client cert
<#
Steps to update expired Sitecore SSL cert, XConnect site SSL cert, XConnect client cert
- Remove existing expired certs and client certs including root certs
- Download SIF scripts from https://github.com/Sitecore/Sitecore.HabitatHome.Utilities/
- Use Add-SSLSiteBindingWithCertificate.ps1 to generate SSL cert for Sitecore and XConnect IIS site
- Comment everything else in install-xp0.ps1 except the part that generates client cert for xconnect
- Use install-xp0.ps1 to generate Client cert for XConnect cert authentication
- Ensure root cert, cert and client cert are installed correctly using certlm.msc
- Update IIS Site bindings to use new certs
New-UsingBlock (New-Object Sitecore.SecurityModel.SecurityDisabler) {
$item = Get-Item .
$item.Locking.Unlock()
Get-ChildItem . -Recurse | Where-Object { $_.Locking.IsLocked() } | % { $_.Locking.Unlock() }
}
Close-Window
@harshbaid
harshbaid / Sitecore xDB Links
Created April 16, 2019 14:27
Important module links for Sitecore xDB