Skip to content

Instantly share code, notes, and snippets.

View hermanussen's full-sized avatar

Robin Hermanussen hermanussen

View GitHub Profile
@hermanussen
hermanussen / PowerShell_profile.ps1
Last active November 21, 2023 09:41
Get GitHub Copilot for CLI in Powershell by adding the contents here to your $Profile. Ensure that you have installed and authenticated in the GitHub CLI to make it work properly.
Function GhCopilotSuggestShell {
gh copilot suggest -t shell "$args"
}
Function GhCopilotSuggestPowerShell {
gh copilot suggest -t shell "$args using Windows Powershell"
}
Function GhCopilotSuggestPowerShellCore {
gh copilot suggest -t shell "$args using Powershell Core (pswh)"
*|node_modules\ .git\ .svn\ .idea\ .vs\ viewstate\ node_modules\ packages\ Debug\ Obj\
# Tail Sitecore log files, even when using rolling log files
# ==========================================================
# 1) Copy this file into your App_Data folder or set the logFolder parameter to point to the Sitecore logs folder.
# 2) Run it in Powershell
# 3) View the log messages as they appear (even if the worker process recycles)
param (
[string]$logFolder = ".\\logs\\",
[string]$filter = "log.*",
[int]$tailAmount = 20
)
if (Tags.Contains("fail", StringComparer.InvariantCultureIgnoreCase))
{
ChecksRun.Checks.Add(new AlwaysFailCheck());
}
// Add your checks here
ChecksRun.Checks.Add(new ItemExistsCheck("Folder template", "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}", new[] { "master", "web" }, null, false));
ChecksRun.Checks.Add(new ItemExistsCheck("Launchpad has layout", "{6B846FBD-8549-4C91-AE6B-18286EFE82D2}", new[] { "core" }, new string[] { "en" }, true));
ChecksRun.Checks.Add(new SearchIndexSizeCheck("Master index", "sitecore_master_index", 1000, null));
ChecksRun.Checks.Add(new UrlCheck("Google is reachable", "http://www.google.com/"));
ChecksRun.Checks.Add(new ConfigCheck("Check if master database is available", "/sitecore/databases/database[@id='master']", 1));
// Optional: uncomment whichever ways you feel are appropriate for security
// Ensure that your monitoring tool matches these
if (!(true
//&& Request.IsSecureConnection // Checks if using HTTPS
//&& Request.QueryString["authkey"] == @"secret"
&& Request.UserHostAddress == "127.0.0.1"
//&& Sitecore.Context.IsLoggedIn
//&& Sitecore.Context.IsAdministrator
//&& Sitecore.Context.User.IsInRole(@"sitecore\Developer")
))
[Test(Description = "Checks if all Glass mapper template and field IDs can be found in serialized data")]
public void ShouldAllTemplatesAndFieldsBeFoundInSerializedData(
[Values(
typeof(SomeType), // From assembly MyProject
)]
Type typeFromAssembyUnderTest)
{
Assembly assemblyUnderTest = Assembly.GetAssembly(typeFromAssembyUnderTest);
// Find all templates and fields that need to be checked in the serialized data
[SitecoreType(TemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}")]
public interface ISampleItem
{
[SitecoreField(FieldId = "{75577384-3C97-45DA-A847-81B00500E250}")]
string Title { get; set; }
}
[Test(Description = "Checks if Sitecore IDs in a class with constants can be found in the serialized data")]
public void ShouldIdsBeFoundInSerializedData(
[Values(typeof(Constants))]
Type typeWithIdConstants)
{
foreach (FieldInfo field in typeWithIdConstants
.GetFields(BindingFlags.Public | BindingFlags.Static)
.Where(f => f.FieldType == typeof (ID)))
{
ID constantValue = field.GetValue(null) as ID;
public static class Constants
{
public static readonly ID SampleTemplateId
= new ID("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");
}