Skip to content

Instantly share code, notes, and snippets.

View warrenbuckley's full-sized avatar

Warren Buckley warrenbuckley

View GitHub Profile
@warrenbuckley
warrenbuckley / gist:a6adc536924c8528331450b929aba877
Created March 25, 2020 14:59
DisableOtherPackageComponent.cs
public class MyComposer : IUserComposer
{
public void Compose(Composition composition)
{
// Register service into the container
composition.RegisterUnique<PaletteService>();
composition.RegisterUnique<ThemeService>();
// Add our PVC to the collection of stuff
composition.PropertyValueConverters().Append<ThemePickerPropertyConvertor>();
@warrenbuckley
warrenbuckley / RazorCompletionsWithRoslyn.cs
Created February 20, 2020 14:22
Trying to get autocompletion on a Razor .cshtml view with Roslyn's CompletionService
[HttpPost]
public string FetchCompletions(RazorCode model)
{
var host = new System.Web.Razor.RazorEngineHost(new CSharpRazorCodeLanguage());
var templateEngine = new System.Web.Razor.RazorTemplateEngine(host);
var compiledCode = templateEngine.GenerateCode(new StringReader(model.Code));
var parsed = templateEngine.ParseTemplate(new StringReader(model.Code));
// Cannot convert from 'System.Web.Razor.Parser.SyntaxTree.Block' to 'Microsoft.CodeAnalysis.Document'
@warrenbuckley
warrenbuckley / MyThingCollections.cs
Last active April 18, 2019 15:48
An example of using Umbraco CMS V8 - Collections & Type Scanning or Adding Explicit Types
using System.Collections.Generic;
using Umbraco.Core.Composing;
using Umbraco.Web.WebApi;
namespace TestCollections.Code
{
// Implement IDiscoverable (To help with typescanning speed/perf)
public interface IMyThing : IDiscoverable
{
string Name { get; }
@warrenbuckley
warrenbuckley / WebApiAttributeRoutes.cs
Created February 4, 2019 11:29
How to register & use WebAPI with Attribute Routes in Umbraco V8
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Core.Components;
namespace My.Website
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class ApiComposer : IUserComposer
{
public void Compose(Composition composition)
@warrenbuckley
warrenbuckley / DatabaseExample.cs
Created February 4, 2019 11:12
Super simple example of using Database inside Umbraco V8
using Umbraco.Core.Scoping;
namespace My.Website
public class DatabaseExample
{
private IScopeProvider _scopeProvider;
public DatabaseExample(IScopeProvider scopeProvider)
{
_scopeProvider = scopeProvider;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Components;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
namespace Umbraco.Web.UI
{
@warrenbuckley
warrenbuckley / iisexpress-vscode-install.bat
Last active January 6, 2017 15:59
A work in progress Batch file to automate downloading & installing Visual Studio Code, the IIS Express VS Code extension & IISExpress itself if its not installed already
ECHO OFF
rem Check if VS Code is installed - Checks if its in the path
rem Not 100% sure best way as think installer allows yout to NOT put it in the %PATH%
CALL where /q code
IF ERRORLEVEL 1 (
ECHO Visual Studio Code is not installed.
ECHO Downloading installer from https://vscode-update.azurewebsites.net/latest/win32/stable
rem Download the file & name it VSCodeSetup.exe relative to this running batch file
@warrenbuckley
warrenbuckley / SomeTreeController.cs
Last active October 28, 2016 09:39
This is a way to determine what version of Umbraco is being used & conditionally change Angular views or logic based on that.
public static bool UseLegacyEditors()
{
return UmbracoVersion.Current < new Version(7, 4);
}
var someRoutePath = Core.Configuration.UseLegacyEditors()
? "/myApp/treeAlias/edit-legacy/" + someObj.Id
: "/myApp/treeAlias/edit/" + someObj.Id;
@warrenbuckley
warrenbuckley / UpdateCheckerController.cs
Last active November 27, 2016 10:54
V3 Nuget API using Nuget.Core Package
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using NuGet.Configuration;
using NuGet.Protocol.Core.Types;
using NuGet.Protocol.Core.v3;
using NuGet.Versioning;
namespace Umbraco.Forms.UpdateChecker.Controller
{
/*
SQL CMD
-S Server Name
-U Username
-P MyPassword
-d Datbase file to excute SQL script against
-i SQL file to excute
-x Super magic switch that managed to get SQL to run when it bombed first time
*/