Skip to content

Instantly share code, notes, and snippets.

View jraps20's full-sized avatar

John Rappel jraps20

View GitHub Profile
@jraps20
jraps20 / build.yml
Created August 12, 2019 17:57
Cache NuGet Packages with Cache Task in Azure DevOps YAML
- powershell: | # generates a hash of all packages.config and saves each on a single line on 'hash.txt'
Get-FileHash -Algorithm MD5 -Path (Get-ChildItem packages.config -Recurse) >> hash.txt
Write-Host "Hash File saved to $pwd\hash.txt"
workingDirectory: src
displayName: 'Calculate and save packages.config hash'
- task: CacheBeta@0 # speed up builds by caching packages folder
inputs:
key: nuget|1|$(Agent.OS)|$(Build.SourcesDirectory)\src\hash.txt # hash map generated in previous step
path: $(Build.SourcesDirectory)\src\packages
namespace MyClient.Foundation.Services
{
using Sitecore.Data.Items;
using Sitecore.ExperienceEdge.Connector.Abstraction.DirectPublishing;
public class EdgeService : IEdgeService
{
private const string EdgePublishingTargetId = "{3013BEED-71CA-4DE3-A1D2-17DD871597F1}";
/// <summary>
namespace Foundation.Search.Crawlers
{
using System;
using Microsoft.Extensions.DependencyInjection;
using Sitecore;
using Sitecore.Abstractions;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Events;
using Sitecore.Data.Items;
@jraps20
jraps20 / PublishUtils.cs
Last active May 2, 2022 17:40
Sitecore publishing Utils to quickly queue up a batch of items to a publish queue and publish the queue, as opposed to individual publishes which cause the publish:end event to fire multiple times (read: individual index updates, cache clearing, etc.)
public static class PublishUtils
{
public static void CreateAndPublishQueue(Database sourceDatabase, Database[] targetDatabases, Language[] targetLanguages, IEnumerable<ID> itemIds, bool skipEvents = false, bool useSecurityDisabler = true)
{
Assert.IsNotNull(sourceDatabase, "sourceDatabase");
Assert.IsNotNull(targetDatabases, "targetDatabases");
Assert.IsNotNull(targetLanguages, "targetLanguages");
var publishingCandidates = SetPublishingCandidates(sourceDatabase, targetDatabases, targetLanguages, itemIds);
@jraps20
jraps20 / RemoteDelete.config
Created July 3, 2018 20:39
Delete Sitecore items from remote databases when delete occurs in master.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:deleting">
<handler type="MyProject.MyNamespace.RemoteDeleteHandler, MyProject" method="OnItemDeleting" />
</event>
</events>
</sitecore>
</configuration>
var localCopyrightSettingsItem = Context.Items.Get(MultisiteConstants.LocalCopyrightSettingsItem);
namespace MyProject.Pipelines
{
public class ItemsLookup : HttpRequestProcessor
{
public override void Process(HttpRequestArgs args)
{
// Shared Data Folder
Context.Items.SetLazy(MultisiteConstants.SharedDataFolderItem, () =>
Context.Database.GetItem(new ID(MultisiteConstants.SharedDataFolderId))
);
namespace MyProject.Extensions
{
public static class ItemsContextExtensions
{
public static Item Get(this ItemsContext source, string identifier)
{
if (string.IsNullOrWhiteSpace(identifier))
throw new Exception("Must set identifier for getting global property");
var dictionary = source as IDictionary;
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<httpRequestBegin>
<processor type="MyProject.Pipelines.ItemsLookup, MyProject" resolve="true" patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" />
</httpRequestBegin>
</pipelines>
</sitecore>
</configuration>
@jraps20
jraps20 / PublishDeployedItemsWithPublishingQueue.cs
Last active July 19, 2018 11:09
TDS Post Deploy Action to publish items via publishing queue instead of native solution
[Description("Publishes deployed items after deployment using publishing queue.\nPublishing targets are specified in the Parameter as a comma separated list.")]
public class PublishDeployedItemsWithPublishingQueue : IPostDeployAction
{
/// <summary>
/// Borrowed directly from HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor.BuiltIn.PublishDeployedItems, HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor
/// </summary>
private static Database[] GetPublishingTargetDatabases(string parameters)
{
if (string.IsNullOrEmpty(parameters))
{