Skip to content

Instantly share code, notes, and snippets.

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://code.jquery.com/jquery-1.5.1.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
@sclarson
sclarson / UnstoppableJob.cs
Created March 31, 2011 15:56
Unstoppable EPiServer Schedule Job Example
using System.Linq;
using System.Text;
using EPiServer;
using EPiServer.Core;
using EPiServer.PlugIn;
namespace BlendInteractive.AppCode.Plugins
{
[ScheduledPlugIn(DisplayName = "Delete Unpublished Faculty and Staff")]
public class DeleteUnpublishedPeople
@sclarson
sclarson / StoppableJob.cs
Created March 31, 2011 15:59
Stoppable EPiServer Schedule Job Example
using System.Linq;
using EPiServer;
using EPiServer.BaseLibrary.Scheduling;
using EPiServer.Core;
using EPiServer.PlugIn;
namespace BlendInteractive.AppCode.Plugins
{
[ScheduledPlugIn(DisplayName = "Delete Unpublished Faculty and Staff")]
public class DeleteUnpublishedPeople : JobBase
@sclarson
sclarson / ImpersonationJob.cs
Created May 9, 2011 14:40
EPiServer Scheduled Job with Impersonation base class
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using EPiServer.BaseLibrary.Scheduling;
namespace BlendInteractive.CustomUserJob
{
public class ImpersonationJob : JobBase
{
@sclarson
sclarson / gist:968964
Created May 12, 2011 17:09
Generic Serializer
public static void SerializeObjectToFile<T>(string filename, T objectToSerialze)
{
using (Stream stream = File.Open(filename, FileMode.Create))
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, objectToSerialze);
}
}
@sclarson
sclarson / gist:1113836
Created July 29, 2011 13:49
Fill list controls from episerver custom property settings
protected void SetSelectedMultipleItemPropertyValues(string propertyName, ListControl control)
{
var listValues = EditModel[propertyName] == null ? new List<string>() : EditModel[propertyName].ToString().Split(',').ToList();
foreach (var option in GetMultipleOptionsListItemsForProperty(propertyName).ListOptions)
{
var newItem = new ListItem(option.Key, option.Value);
if (!control.Items.Contains(newItem))
control.Items.Add(newItem);
}
@sclarson
sclarson / gist:1118877
Created August 1, 2011 20:08
Get multiple list options from pagedata property
private MultipleOptionsListSettings GetMultipleOptionsListItemsForProperty(string propertyName)
{
IPropertySettingsRepository settingsRepository = new PropertySettingsRepository();
PropertySettingsContainer container;
PageData dummyModel = DataFactory.Instance.GetDefaultPageData(SiteSettings.ModelRoot, "Model Page");
if (settingsRepository.TryGetContainer(dummyModel.Property[propertyName].SettingsID, out container))
{
var wrapper = new PropertySettingsWrapper();
@sclarson
sclarson / ExtMethod.cs
Created August 2, 2011 18:41 — forked from cammerman/ExtMethod.cs
IEnumerable Null Check
public static class IEnumerableExtensions
{
public static IEnumerable<T> OrEmptyListIfNull<T>(this IEnumerable<T> source)
{
return source ?? Enumerable.Empty<T>();
}
}
@sclarson
sclarson / gist:1628848
Created January 17, 2012 21:03
Getting around webforms all ecnompassing form for some off site posts
function createAndSubmitSalesForceLogin(selector,action,method) {
var newForm = $(document.createElement('form')).hide()
.attr('method',method).attr('action',action)
.append($(selector).html())
.appendTo('body');
$(newForm).submit();
}
@sclarson
sclarson / gist:1642884
Created January 19, 2012 21:34
Retaining headings getting stripped by the XForm cleaner
private void CleanupXFormHtmlMarkup(XFormControl formControl)
{
if (formControl.EditMode)
{
// We need to render the default table when in edit mode, otherwise the form wizard won't work
return;
}
bool firstLiteralControl = false;