Skip to content

Instantly share code, notes, and snippets.

@mskutta
mskutta / PostDeploy.ps1
Created September 21, 2015 20:05
Sitecore Update and Zip Package Installer Web Service
Write-Host "PostDeploy"
##################################################################################
# VARIABLES
##################################################################################
$excludeItemUpdates = [System.Convert]::ToBoolean($OctopusParameters["ExcludeItemUpdates"])
$internalPort = $OctopusParameters["InternalPort"]
$rootPath = $OctopusParameters["Octopus.Action.Package.CustomInstallationDirectory"]
$updatePackagesPath = [io.path]::combine($rootPath, 'Website', 'sitecore', 'admin', 'Packages')
@mskutta
mskutta / PackageInstaller.asmx
Last active March 21, 2019 13:08
Sitecore Update and Zip Package Installer Web Service
<%@ WebService Language="C#" Class="PackageInstaller" %>
using System;
using System.Configuration;
using System.IO;
using System.Web.Services;
using System.Xml;
using Sitecore.Data.Proxies;
using Sitecore.Data.Engines;
using Sitecore.Install.Files;
using Sitecore.Install.Framework;
@mskutta
mskutta / CompositeRelationshipSavingTask.cs
Created September 8, 2015 17:26
Sitecore: Automatically Save Related Items using Glass Mapper
public class CompositeRelationshipSavingTask : IObjectSavingTask
{
private static readonly ConcurrentDictionary<Type, SitecoreFieldConfiguration[]> _compositeRelationships = new ConcurrentDictionary<Type, SitecoreFieldConfiguration[]>();
private SitecoreFieldConfiguration[] GetCompositeRelationshipFields(ObjectSavingArgs args)
{
var type = args.SavingContext.Config.Type;
return _compositeRelationships.GetOrAdd(type, x => CompositeRelationshipsValueFactory(args));
}
@mskutta
mskutta / CompositeRelationshipSavingTask.cs
Created September 8, 2015 17:09
Sitecore: Automatically Save Related Items using Glass Mapper
public class CompositeRelationshipSavingTask : IObjectSavingTask
{
public void Execute(ObjectSavingArgs args)
{
// Only perform processing if composite relationship fields exist
var compositeRelationshipFields = GetCompositeRelationshipFields(args);
if (!compositeRelationshipFields.Any())
return;
// Get access to the SitecoreService
@mskutta
mskutta / GlassMapperScCustom.cs
Last active September 8, 2015 21:26
Sitecore: Automatically Save Related Items using Glass Mapper
public static IDependencyResolver CreateResolver(){
var config = new Glass.Mapper.Sc.Config();
var resolver = new DependencyResolver(config);
// Add the ability to save composite relationships. This needs to occur before the parent is saved so all IDs are known.
resolver.ObjectSavingFactory.Insert(0, () => new CompositeRelationshipSavingTask());
return resolver;
}
@mskutta
mskutta / SitecoreCompositeRelationshipAttribute.cs
Created September 8, 2015 16:45
Sitecore: Automatically Save Related Items using Glass Mapper
[AttributeUsage(AttributeTargets.Property)]
public class SitecoreCompositeRelationshipAttribute : Attribute
{
}
@mskutta
mskutta / PersonEducationSaveWhole.cs
Last active September 8, 2015 16:43
Sitecore: Automatically Save Related Items using Glass Mapper
var service = new SitecoreService("master");
var person = new Person();
person.Name = "Mike Skutta";
person.FirstName = "Mike";
person.LastName = "Skutta";
person.Education = new List<Education> { new Education
{
Name = "University of Illinois",
School = "University of Illinois",
@mskutta
mskutta / PersonEducationSaveIndividual.cs
Last active September 8, 2015 16:44
Sitecore: Automatically Save Related Items using Glass Mapper
[SitecoreType(TemplateId = "004c9474-1df4-47ab-9414-c372b25cdde6", AutoMap = true)]
public partial class Education
{
public virtual Guid Id { get; set; }
public virtual System.String Name { get; set; }
public virtual string Degree { get; set; }
public virtual string School { get; set; }
public virtual System.Int32 YearOfDegree { get; set; }
}
@mskutta
mskutta / ValidateItemTask.cs
Last active September 2, 2015 13:34
Glass Mapper Validate Required Field
public class ValidateItemTask : IObjectConstructionTask
{
private bool IsValid(ObjectConstructionArgs args)
{
var context = (SitecoreTypeCreationContext) args.AbstractTypeCreationContext;
var service = (SitecoreService)args.Service;
var requiredFields = GetRequiredFields(args);
foreach (var requiredField in requiredFields)
{
@mskutta
mskutta / ValidateItemTask.cs
Created August 24, 2015 12:29
Glass Mapper Validate Required Field
public class ValidateItemTask : IObjectConstructionTask
{
private static readonly ConcurrentDictionary<Type, SitecoreFieldConfiguration[]> _requiredFields = new ConcurrentDictionary<Type, SitecoreFieldConfiguration[]>();
private SitecoreFieldConfiguration[] GetRequiredFields(ObjectConstructionArgs args)
{
var type = args.Configuration.Type;
return _requiredFields.GetOrAdd(type, x => RequiredFieldsValueFactory(args));
}