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:4948852
Last active January 2, 2019 23:54
Checking Sitecore field type via FieldTypeManager.GetField()
var field = item.Fields[_fieldId];
var type = FieldTypeManager.GetField(field);
if (type is LinkField)
{
...
}
if (type is InternalLinkField) // such as drop tree controls
{
...
@PetersonDave
PetersonDave / gist:5096452
Last active January 7, 2017 12:57
Web forms for marketers redirect assumes the success page is relative to the form item in the tree (template: /sitecore/templates/Web Forms for Marketers/Form). When this is not the case, wffm builds a redirect URL which is not valid. Since the success page is defined using a general link field, we don't have a Guid to lookup the actual success …
/*
Extends: Sitecore.Form.Core.Pipelines.FormSubmit
forms.config needs to be updated to:
<successAction>
<processor type="MyCustom.Pipelines.SuccessRedirect, MyLibrary"/>
<processor type="Sitecore.Form.Core.Pipelines.FormSubmit.FormatSuccessMessage, Sitecore.Forms.Core"/>
</successAction>
*/
@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();
}