Skip to content

Instantly share code, notes, and snippets.

View janhebnes's full-sized avatar

Jan Hebnes janhebnes

View GitHub Profile
@janhebnes
janhebnes / AutoGenerated Sitecore Entity Classes (sample).cs
Last active December 16, 2015 12:45
Sitecore Code Generation based on T4 and extending the sitecore base template fields with class information for mapping the c# code to correct types.
namespace Client.Logic.Entities.Client.Pages.Blog
{
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Text;
using FemtenNulOtte.Core.Entities;
using FemtenNulOtte.Core.Entities.Context;
@janhebnes
janhebnes / RecursiveFileSearchProgram.cs
Last active December 16, 2015 12:42
RecursiveFileSearch - compile and dump in the root of a NAS disk and run once in a while to get a full directory tree in a text file in the root allowing for quicker searches by just opening the text file - used for very large NAS shares.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecursiveFileSearch
{
class Program
@janhebnes
janhebnes / DatabaseStorageUsageQuery.sql
Created December 9, 2015 15:10
Purpose is to monitor health on mssql database installations and send one report to an email with detailed attached (Uses the opensource utilities bmail.exe, mpack.exe and munpack.exe )
SET NOCOUNT ON
SELECT '$(ServerName)' AS ServerName
,CAST( DB_NAME(mf.database_id) AS varchar) AS databaseName
,CAST(size_on_disk_bytes AS varchar(15)) as size_on_disk
,CAST(dbs.state_desc AS varchar(10)) as [state]
,CAST(dbs.recovery_model_desc AS varchar(10)) as rec_model
,CAST(dbusers.name AS varchar(10)) as [Owner]
,CAST(num_of_reads AS varchar(15)) as num_of_reads
,CAST(num_of_bytes_read AS varchar(15)) as num_of_bytes_read
,CAST(io_stall_read_ms AS varchar(15)) as io_stall_read_ms
@janhebnes
janhebnes / gist:4001318
Created November 2, 2012 13:16
Sitecore CMS - GetContentEditorWarnings AvailableLanguageVersions Quick switch between versions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Data.Items;
using Sitecore.Data.Managers;
using Sitecore.Globalization;
using Sitecore.Pipelines.GetContentEditorWarnings;
namespace SitecoreExtensions.Pipelines.GetContentEditorWarnings
@janhebnes
janhebnes / gist:3946630
Created October 24, 2012 15:06
Sitecore CMS - SQL for Removing Non Image Blobs from a Sitecore Database Blob table
-- Large blob data in test/uat environments is just wastefull use of disk space
SP_SPACEUSED [Blobs]
-- FINDING ItemIds FOR RELEVANT FIELDS
-- File > Information > Extension Field
select * from Items where ID like 'C06867FE-9A43-4C7D-B739-48780492D06F'
-- File > Media > Blob Field
select * from Items where ID like '40E50ED9-BA07-4702-992E-A912738D32DC'
-- Examining the data location of the fields
@janhebnes
janhebnes / BuildTasks.TDSExcludeRulesValidator.cs
Created October 20, 2012 06:38
BuildTasks.TDSExcludeRulesValidator / MSBuild Task for monitoring the Exclude Rules in a Sitecore TDS Project file.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@janhebnes
janhebnes / gist:3550889
Created August 31, 2012 09:39
Sitecore does not implement hard validation on the language write access at field level, so to make sure a local editor would never be able to mingle with a language he did not have access to, we added the restriction code to the Item:Saving event queue p
public class EnsureLanguageWriteAccess
{
protected void OnItemSaving(object sender, EventArgs args)
{
Item item = Event.ExtractParameter(args, 0) as Item;
Error.AssertNotNull(item, "No item in parameters");
var itemlang = item.Database.GetItem(string.Format("/sitecore/system/Languages/{0}", item.Language));
if (itemlang != null && Sitecore.Security.AccessControl.AuthorizationManager.IsDenied(itemlang
, Sitecore.Security.AccessControl.AccessRight.LanguageWrite
@janhebnes
janhebnes / gist:3550920
Created August 31, 2012 09:43
Sitecore CMS - Handling Item copying where DataSources are referenced inside the copied structure, to inserted in the Item:Copied event queue.
/// <summary>
/// Class used to update Spot Context Data, when copying trees in Sitecore.
/// </summary>
public class LayoutDataSourceReferenceUpdater
{
#region Properties
/// <summary>
/// Gets or sets the new root Item (source item).
/// </summary>
@janhebnes
janhebnes / gist:3550905
Created August 31, 2012 09:41
Sitecore CMS - Event for handling changing the DataSources from path information to GUIDs to be inserted in the item:saving event prior to the save event
/// <summary>
/// The layout data sources are saved with a text path and not a guid.
/// </summary>
public class EnsureDataSourceIsGUID
{
public void OnItemSaving(object sender, EventArgs args)
{
Sitecore.Diagnostics.Log.Info("Running EnsureDataSourceIsGUID", this);
Item item = Event.ExtractParameter(args, 0) as Item;
@janhebnes
janhebnes / gist:3550850
Created August 31, 2012 09:36
Sitecore CMS - Field level security validation for the SaveUI Pipeline so we could make sure no editor suddenly made changes to restricted languages versions of the same items.
public class EnsureLanguageWriteAccess
{
public int Limit
{
get;
set;
}
public void Process(Sitecore.Pipelines.Save.SaveArgs args)
{