Skip to content

Instantly share code, notes, and snippets.

@hishaamn
hishaamn / KeyBehaviorCacheExample.cs
Last active December 2, 2017 12:28
Check if goal has been triggered
Guid goalId = // your goal Id
KeyBehaviorCache cache = Sitecore.Analytics.Tracker.Current.Contact.GetKeyBehaviorCache();
bool goalTriggered = cache.Goals.Any(a => a.Id == goalId);
if(!goalTriggered)
{
// continue with goal execution
}
@hishaamn
hishaamn / KeyBehaviorCacheOutcome.cs
Created December 2, 2017 12:33
Check if user has already the specified outcome
Guid outcomeId= // your outcome ID
KeyBehaviorCache cache = Sitecore.Analytics.Tracker.Current.Contact.GetKeyBehaviorCache();
bool isAssociatedOutcome = cache.Outcomes.Any(a => a.Id == outcomeId);
if(!isAssociatedOutcome)
{
// continue with assignment of Outcome here
}
@hishaamn
hishaamn / RegisterSitecoreGallery.ps1
Created February 10, 2018 18:34
Register the public MyGet Sitecore Gallery
Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2
@hishaamn
hishaamn / install.ps1
Last active February 10, 2018 18:43
This is the script to install the Sitecore 9 instance with xConnect
# Define Parameters
$prefix = "local"
$PSScriptRoot = "C:\resourcefile"
$XConnectCollectionService = "$prefix.xconnect"
$sitecoreSiteName = "$prefix.sitecore"
$SolrUrl = "https://localhost:8989/solr"
$SolrRoot = "C:\solr-6.6.1"
$SolrService = "solr-6.6.1"
$SqlServer = "(local)"
$SqlAdminUser = "sa"
@hishaamn
hishaamn / OffersImport.cs
Created March 13, 2018 13:56
Agent to import offers
public class OfferImport
{
public string CouponPath { get; set; }
public string[] Databases { get; set; }
public string SiteName { get; set; }
public void Process(Item[] items, CommandItem command, ScheduleItem schedule)
{
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Data.Managers;
using Sitecore.Diagnostics;
public class OffersImportCommandItem : CustomItem
{
public static readonly ID TemplateID = ID.Parse("{CC29CCE7-D1CC-4EA2-90CF-573CBA493616}");
public static readonly ID SiteNameFieldId = ID.Parse("{D7D0D0EA-1904-473B-B003-3B4E88F9740C}");
@hishaamn
hishaamn / JobsExtension.aspx
Created April 9, 2018 18:35
Extension of the default Sitecore Job page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JobsExtension.aspx.cs" Inherits="Sitecore.Tools.Extensions.JobsExtension" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Jobs Viewer</title>
<link rel="Stylesheet" type="text/css" href="/sitecore/shell/themes/standard/default/WebFramework.css" />
<link rel="Stylesheet" type="text/css" href="./default.css" />
<style type="text/css">
private readonly DateTime now = DateTime.Now;
protected override void ShowJobs(StringBuilder stringBuilder, string name, ICollection<Job> jobs)
{
stringBuilder.AppendLine("<h1>" + name + ":</h1><br />");
if (jobs.Count > 0)
{
stringBuilder.AppendLine("<table class='jobs-table'>");
stringBuilder.AppendLine("<thead><tr><td class='counter'>No</td><td class='add-time'>Added</td><td class='title'>Title</td><td class='progress'>Progress</td><td class='priority'>Priority</td><td class='owner'>Owner</td></tr></thead>");
protected override void ShowRefreshStatus(StringBuilder stringBuilder)
{
int result;
int.TryParse(this.Request.QueryString["refresh"], out result);
stringBuilder.Append("Last updated: {0}. ".FormatWith(DateTime.Now.ToString(CultureInfo.InvariantCulture)));
int[] numArray = { 1, 2, 5, 10, 20, 30, 60 };
protected override void OnLoad(EventArgs e)
{
JobManager.GetJobs();
var stringBuilder = new StringBuilder();
var requiredService = ServiceLocator.ServiceProvider.GetRequiredService<BaseJobManager>();
DefaultJobManager defaultJobManager;