Skip to content

Instantly share code, notes, and snippets.

@BillCacy
BillCacy / BlueGreenSolrSettings.psm1
Created October 10, 2018 04:19
Solr settings object for Blue/Green deployment.
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
<#
.SYNOPSIS
Classes and properties utilized by the scripts to update SolrCloud in a blue/green environment
#>
class OctopusMachineSettings
{
@BillCacy
BillCacy / BlueGreenSolrSettingsMap.psm1
Created October 10, 2018 04:20
Solr settings mapping from Octopus variables.
using module ".\BlueGreenSolrSettings.psm1"
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
<#
.SYNOPSIS
Creates a BlueGreenSolrSettings object with property values defined by Octopus variables.
.PARAMETER Settings
An string dictionary passed in from Octopus deploy containing the variables used in
the defined deployment process.
@BillCacy
BillCacy / BlueGreenSolrHelper.psm1
Last active July 27, 2021 13:57
Solr script to handle the CDCR replication switching during a Blue/Green deployment.
using module ".\BlueGreenSolrSettings.psm1"
$ErrorActionPreference = "Stop"
<#
.SYNOPSIS
Pushes the specified config and related pieces to the SolrCloud Zookeepers.
.PARAMETER solrPath
Path on the machine to the Solr installation.
EX: C:\solr\solr-6.2.1
@BillCacy
BillCacy / BlueGreenSolr.ps1
Created October 10, 2018 04:25
Script to call the Solr functionality from an Octopus step.
using module ".\BlueGreenSolrSettings.psm1"
using module ".\BlueGreenSolrSettingsMap.psm1"
<#
.SYNOPSIS
Calls the Solr functions for SolrCloud CDCR to update a Live environment (with Octopus deploy).
The .\BlueGreenSolrSettingsMap.psm1 file is used to map Octopus-defined variable values to
the .\BlueGreenSolrSettings.psm1 properties.
.PARAMETER startingReplication
@BillCacy
BillCacy / BlueGreenSolr-Local.ps1
Created October 10, 2018 04:27
Script to utilize in local testing of the Solr functionality pieces of a blue/green deployment. This utilizes the LocalSettings.psm1 file that maps user-defined values to the Solr settings.
using module ".\BlueGreenSolrSettings.psm1"
using module ".\LocalSettings.psm1"
<#
.SYNOPSIS
Calls the Solr functions for SolrCloud CDCR to test in a non-live environment (without Octopus deploy).
The .\LocalSettings.psm1 file is used to map user-defined variable values to
the .\BlueGreenSolrSettings.psm1 properties.
.PARAMETER startingReplication
@BillCacy
BillCacy / LocalSettings.psm1
Created October 10, 2018 04:28
Mapping of Solr settings using user-defined values. This is used for local testing to simulate the process Octopus will use.
using module ".\BlueGreenSolrSettings.psm1"
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
<#
.SYNOPSIS
Creates a BlueGreenSolrSettings object with property values defined by the user
#>
function Get-LocalBlueGreenSolrSettings()
@BillCacy
BillCacy / FindAllItemsByTemplateWithValueInField.ps1
Created May 22, 2020 19:33
Looks for all items with specified template name that have a value in the specified field
$root = gi master:// -id "{C557F52C-BDBA-4F3D-BAD0-E315AD39C9CB}"
$items = $root | ls -r | ?{$_.TemplateName -eq "<TEMPLATE NAME>"}
$fieldName = "<FIELD NAME>"
foreach($i in $items){
if(-not([string]::IsNullOrWhitespace($i.Fields[$fieldName]))){
$i.Name + " : " + $i.Fields[$fieldName].Value + " : " + $i.Paths.FullPath
}
}
@BillCacy
BillCacy / StringInputEncryptedViewModel.cs
Created July 31, 2020 05:39
Sitecore 9 Forms Encrypted Field View Model
using System;
using Sitecore.ExperienceForms.Mvc.Models.Fields;
namespace Sample.Feature.Forms.ViewModels
{
[Serializable]
public class StringInputEncryptedViewModel : StringInputViewModel
{
}
}
@BillCacy
BillCacy / SingleLineTextEncrypted.cshtml
Created July 31, 2020 05:52
Sitecore 9 Forms Encrypted text field view
@using Sitecore.ExperienceForms.Mvc.Html
@model Sample.Feature.Forms.ViewModels.StringInputEncryptedViewModel
<label for="@Html.IdFor(m => Model.Value)" class="@Model.LabelCssClass">@Html.DisplayTextFor(t => Model.Title)</label>
<input id="@Html.IdFor(m => Model.Value)" name="@Html.NameFor(m => Model.Value)" class="@Model.CssClass" type="text" value="@Model.Value" @if (Model.MaxLength > 0) { <text> maxlength="@Model.MaxLength" </text> } placeholder="@Model.PlaceholderText" data-sc-tracking="@Model.IsTrackingEnabled" data-sc-field-name="@Model.Name" data-sc-field-key="@Model.ConditionSettings.FieldKey" @Html.GenerateUnobtrusiveValidationAttributes(m => m.Value) />
@Html.ValidationMessageFor(m => Model.Value)
@BillCacy
BillCacy / SaveDataWithEncryption.cs
Last active July 31, 2020 06:15
Sitecore 9 Forms Encrypted Field Save Action
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Sample.Foundation.Core.Helpers;
using Sitecore.Diagnostics;
using Sitecore.ExperienceForms.Data;
using Sitecore.ExperienceForms.Data.Entities;
using Sitecore.ExperienceForms.Models;
using Sitecore.ExperienceForms.Processing;