Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Harriyott harriyott

View GitHub Profile
View WatchDirectory.cs
_fileSystemWatcher = new FileSystemWatcher
{
Path = @"C:\My Project\Apps\Analysis",
NotifyFilter = NotifyFilters.LastWrite,
Filter = "*.*"
};
_fileSystemWatcher.EnableRaisingEvents = true;
_fileSystemWatcher.Changed += OnDirectoryChange;
View Timer.cs
private readonly Timer _timer = new Timer(300) { AutoReset = false, Enabled = false };
// ...
_timer.Elapsed += (s, a) =>
{
Console.Beep(1500, 200);
_timer.Enabled = false;
};
View OnDirectoryChange.cs
private void OnDirectoryChange(object s, FileSystemEventArgs a)
{
Console.Beep(1500, 200);
}
View kitten-routes.ts
export class KittenRoutes {
static readonly listKittens = 'api/kittens/list';
static feedKitten(kittenId: any): string {
return `api/kitten/${kittenId}/feed`;
}
static adoptKitten(kittenId: any): string {
return `api/kitten/${kittenId}/feed`;
}
View KittenService.ts
import { KittenRoutes } from './kitten-routes';
export class KittenService {
feedKitten(kittenId: number): void {
const url = KittenRoutes.feedKitten(kittenId);
this.http.post(url, {}).subscribe();
}
}
View BadKittenService.ts
export class KittenService {
feedKitten(kittenId: number): void {
const url = `api/kitten/${kittenId}/feed`;
this.http.post(url, {}).subscribe();
}
}
View kitten-routes.tt
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ assembly name="$(SolutionDir)Kittens.Web\bin\Kittens.Web.dll "#>
<#@ output extension=".ts" #>
export class KittensRoutes {
<#
// Get a collection of the constants in the class
var constants = typeof(Kittens.Web.KittensRoutes).GetFields();
View BadKittenController.cs
public class KittenContoller: Controller
{
[Route("api/kittens/list")]
public ActionResult Index()
{
return View();
}
[Route("api/kitten/{kittenId}/feed")]
public ActionResult Feed(int kittenId)
View KittenController.cs
public class KittenContoller: Controller
{
[Route(RouteNames.KittenList)]
public ActionResult Index()
{
return View();
}
[Route(RouteNames.FeedKitten)]
public ActionResult Feed(int kittenId)
View KittenRoutes.cs
public static class RouteNames
{
public const string ListKittens = "api/kittens/list";
public const string FeedKitten = "api/kitten/{kittenId}/feed";
public const string AdoptKitten = "api/kitten/{kittenId}/adopt";
public const string RenameKitten = "api/kitten/{kittenId}/rename/{newName}";
}