Created
December 17, 2017 09:14
-
-
Save muso31/d33c68f260f950e94bb376f50ca5185f to your computer and use it in GitHub Desktop.
Change Unicorn console images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Reflection; | |
using Unicorn.ControlPanel.Headings; | |
namespace Helixbase.Feature.Fun.Unicorn.Pipelines | |
{ | |
public class HeadingServiceFun : HeadingService | |
{ | |
private static readonly Random Random = new Random(); | |
private static readonly string[] HtmlChoices = | |
{ | |
"Helixbase.Feature.Fun.Unicorn.Images.Helixbase.html", | |
"Helixbase.Feature.Fun.Unicorn.Images.Unicorn.html", | |
"Helixbase.Feature.Fun.Unicorn.Images.Unicorn.svg.html", | |
"Helixbase.Feature.Fun.Unicorn.Images.Unicorn2.svg.html", | |
"Helixbase.Feature.Fun.Unicorn.Images.Unicorn3.svg.html" | |
}; | |
public new string GetHeadingHtml() | |
{ | |
// heh heh :) | |
//if (DateTime.Today.Month == 4 && DateTime.Today.Day == 1) return ReadResource("Unicorn.ControlPanel.Headings.April.svg.html"); | |
var headerIndex = Random.Next(0, HtmlChoices.Length); | |
return ReadResource(HtmlChoices[headerIndex]); | |
} | |
protected override string ReadResource(string name) | |
{ | |
var assembly = Assembly.GetExecutingAssembly(); | |
using (var stream = assembly.GetManifestResourceStream(name)) | |
using (var reader = new StreamReader(stream)) | |
{ | |
return reader.ReadToEnd(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
/* | |
* CSS animated rainbow dividers of awesome | |
* by Chris Heilmann @codepo8 and Lea Verou @leaverou | |
**/ | |
@-webkit-keyframes charlieeee { | |
from { | |
background-position: top left; | |
} | |
to { | |
background-position: top right; | |
} | |
} | |
@keyframes charlieeee { | |
from { | |
background-position: top left; | |
} | |
to { | |
background-position: top right; | |
} | |
} | |
.catchadream { | |
background-image: -webkit-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet, indigo, blue, green, yellow, orange, red); | |
background-image: linear-gradient(left, red, orange, yellow, green, blue, indigo, violet, indigo, blue, green, yellow, orange, red); | |
-webkit-background-clip: text; | |
-moz-background-clip: text; | |
background-clip: text; | |
-webkit-text-fill-color: transparent; | |
text-fill-color: transparent; | |
-webkit-animation: charlieeee 2.5s forwards linear 2.5; | |
animation: charlieeee 2.5s forwards linear 2.5; | |
background-size: 50% auto; | |
} | |
</style> | |
<!-- this bad-ass ASCII art is from http://www.ascii-art.de/ascii/uvw/unicorn.txt - original credit to 'sk' --> | |
<pre class="catchadream"> | |
`/o+: .://:. | |
+yyyy-.------...````-syyyyyyo. | |
`://. `..-://+osyyyyyyyyys | |
.yyyyyyyyys | |
/syyyyyyo. | |
`-` -:///: ....` | |
.:. /. ..... | |
./- `+. ``` ```` ` | |
./: `+- `` ``..`` `.......` | |
.+: -+- `. ``............ | |
.+/` :+: `. `........... | |
.++` /+: .. ........... | |
.oo. `++/ ..` `.......` | |
.oo- .++/ ... ``` | |
.::os: -++/` ... | |
-yyyy:`` /+++//:- | |
`+ss+` `...---:::::---....``` ./++++++++: | |
``..--://++++++++/+++++++++++: | |
``..--:+++++++++++/ | |
:++++++++++. | |
./++++++:` | |
```` | |
+++ `++/ +++++++: /++ -++. -++: :++- `+::::/:` -/ .//::// ///////. | |
yhy `hhs `hhy////- shh /hh: :yh+ +hh: `y .y` .oo- .s` o. | |
yhy````.hhs `hhy```` shh /hh: .yhsohy. `y .s` `s``s. .s. o. | |
yhhhhhhhhhs `hhhhhhh. shh /hh: .yhhy` `y:::/+o- s- .s` `:///-` o+///// | |
yhy `hhs `hhy shh /hh: .yhoshs. `y o: ++::::+o .s- o. | |
yhy `hhs `hhy----. shh:----` /hh: :hh+ ohy: `y o: :+ +/ +/ o. | |
sso `ss+ `sssssss/ osssssss- :ss- /ss: /ss/ `s:::://- .o o.-//:///: ++/////. | |
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Unicorn.ControlPanel.Pipelines.UnicornControlPanelRequest; | |
using Unicorn.ControlPanel.Responses; | |
using Unicorn.Logging; | |
namespace Helixbase.Feature.Fun.Unicorn.Pipelines | |
{ | |
public class SyncVerbFun : SyncVerb | |
{ | |
protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args) | |
{ | |
return new WebConsoleResponseFun("Sync Unicorn", args.SecurityState.IsAutomatedTool, | |
new HeadingServiceFun(), | |
progress => Process(progress, new WebConsoleLogger(progress, args.Context.Request.QueryString["log"]))); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Globalization; | |
using System.Timers; | |
using Kamsar.WebConsole; | |
using Sitecore.SecurityModel; | |
using Unicorn.ControlPanel.Responses; | |
namespace Helixbase.Feature.Fun.Unicorn.Pipelines | |
{ | |
public class WebConsoleResponseFun : WebConsoleResponse | |
{ | |
private readonly string _title; | |
private readonly Action<IProgressStatus> _processAction; | |
private readonly bool _isAutomatedTool; | |
private readonly HeadingServiceFun _headingService; | |
public WebConsoleResponseFun(string title, bool isAutomatedTool, HeadingServiceFun headingService, Action<IProgressStatus> processAction) : base(title, isAutomatedTool, headingService, processAction) | |
{ | |
_title = title; | |
_isAutomatedTool = isAutomatedTool; | |
_headingService = headingService; | |
_processAction = processAction; | |
} | |
protected override void ProcessInternal(IProgressStatus progress) | |
{ | |
if (_headingService != null && !_isAutomatedTool) | |
{ | |
progress.ReportStatus(_headingService.GetHeadingHtml()); | |
} | |
// note: these logs are intentionally to progress and not loggingConsole as we don't need them in the Sitecore logs | |
progress.ReportTransientStatus("Executing."); | |
var heartbeat = new Timer(3000); | |
var timer = new Stopwatch(); | |
timer.Start(); | |
heartbeat.AutoReset = true; | |
heartbeat.Elapsed += (sender, args) => | |
{ | |
var elapsed = Math.Round(timer.ElapsedMilliseconds / 1000d); | |
try | |
{ | |
progress.ReportTransientStatus("Executing for {0} sec.", elapsed.ToString(CultureInfo.InvariantCulture)); | |
} | |
catch | |
{ | |
// e.g. HTTP connection disconnected - prevent infinite looping | |
heartbeat.Stop(); | |
} | |
}; | |
heartbeat.Start(); | |
try | |
{ | |
using (new SecurityDisabler()) | |
{ | |
_processAction(progress); | |
} | |
} | |
finally | |
{ | |
heartbeat.Stop(); | |
} | |
timer.Stop(); | |
progress.Report(100); | |
progress.ReportTransientStatus("Operation completed."); | |
progress.ReportStatus(_isAutomatedTool ? "\r\n" : "<br>"); | |
progress.ReportStatus(_isAutomatedTool ? $"Completed in {timer.ElapsedMilliseconds}ms." : $"Operation completed in {timer.ElapsedMilliseconds}ms. Want to <a href=\"?verb=\">return to the control panel?</a>"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> | |
<sitecore> | |
<pipelines> | |
<unicornControlPanelRequest> | |
<processor | |
patch:instead="processor[@type='Unicorn.ControlPanel.Pipelines.UnicornControlPanelRequest.SyncVerb, Unicorn']" | |
type="Helixbase.Feature.Fun.Unicorn.Pipelines.SyncVerbFun, Helixbase.Feature.Fun" /> | |
</unicornControlPanelRequest> | |
</pipelines> | |
</sitecore> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment