Skip to content

Instantly share code, notes, and snippets.

View PetersonDave's full-sized avatar

David Peterson PetersonDave

View GitHub Profile
@PetersonDave
PetersonDave / Sitecore.Rocks.Server.Packages.PackageInstaller.cs
Created November 27, 2012 21:04
Pulled directly from Sitecore.Rocks.dll for installing packages -- check out "BehaviourOptions" to specify installation options.
using Sitecore;
using Sitecore.Data.Engines;
using Sitecore.Data.Proxies;
using Sitecore.Install;
using Sitecore.Install.Files;
using Sitecore.Install.Framework;
using Sitecore.Install.Items;
using Sitecore.Install.Metadata;
using Sitecore.Install.Utils;
using Sitecore.Install.Zip;
@PetersonDave
PetersonDave / gist:4616627
Created January 24, 2013 01:13
Dynamically setting the datasource of a droptree field (or any field for that matter) to the site context of the current site.
query:ancestor-or-self::*[@@templatename='Site']/home/content-node
@PetersonDave
PetersonDave / 301 Redirect
Created January 29, 2013 18:19
301 redirects.
Context.Response.Status = "301 Moved Permanently";
Context.Response.AddHeader("Location", url);
Context.Response.End();
@PetersonDave
PetersonDave / Blog Post Ideas
Last active December 11, 2015 23:08
Blog Post Ideas
* Performance analysis with dotTrace
* DMS EventQueue and MaxSize limits
* Using Unicorn for distributed sitecore development
* Leveraging the power of GitHub to produce high performing teams
* Using The Domain Model Design Pattern to Isolate Sitecore as a Dependency
@PetersonDave
PetersonDave / gist:4756980
Last active December 12, 2015 10:09
How to handle scenario where we want to use related interfaces, but have a common interface within an abstract class?
Public Interface IBrewCoffeee
{
void DoSomething;
}
Public Interface IStarbucksBrewsCoffee
{
void DoSomething;
void DoSomething1;
void DoSomething2;
@PetersonDave
PetersonDave / Labs Ideas
Last active December 13, 2015 17:29
Labs ideas
1. Sitecore ReSharper add-on.
2. Lucene profiling utility (output queries executed against indexes).
3. Sitecore Rocks add-on for universal Rendering & Layout modification.
4. Pause scheduled PublishAgent for incremental publish.
5. Andover
(a) Valid archive email to prevent errors and application crashes.
@PetersonDave
PetersonDave / gist:6441921
Last active December 22, 2015 07:59
Move a rendering
// Move renderings example usage
var rendering = device.Renderings.Cast<RenderingDefinition>().SingleOrDefault(r => r.ItemID == MyRenderingId);
device.MoveRenderingUp(rendering);
item[Sitecore.FieldIDs.LayoutField] = layoutDefinition.ToXml();
// DeviceDefinition Extensions
public static class DeviceDefinitionExtensions
{
public static void MoveRenderingDown(this DeviceDefinition deviceDefinition, RenderingDefinition renderingDefinition)
{
// maintaining format of original source.
public override bool SetValidatorProperties(BaseValidator validator)
{
base.SetValidatorProperties(validator);
object obj = null;
if (validator as ICloneable != null)
{
obj = ((ICloneable)validator).Clone();
}
@PetersonDave
PetersonDave / gist:6804928
Created October 3, 2013 04:20
Sitecore Password-Confirmation validator
using Sitecore.Form.Core.Validators;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Sitecore.Form.Core.Client.Validators
{
public class PasswordConfimationValidator : FormCustomValidator
{
protected override bool OnServerValidate(string value)
{
@PetersonDave
PetersonDave / gist:6805061
Last active December 24, 2015 13:29
Check User Password complex validation
namespace Sitecore.Form.Submit
{
public class CheckUserPassword : CheckUserAction
{
...
public override void Execute(ID formid, IEnumerable<ControlResult> fields)
{
string empty;
string failedMessage = base.FailedMessage;
string str = failedMessage;