Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
hmemcpy / PublishingContextExtensions.cs
Created April 23, 2011 14:38
Updating the blog contents from within PublishNotificationHook
// based on an old blog post in Japanese: http://blog.sharplab.net/computer/cprograming/windowslivewriter/433/
// The field was moved to a base type in the latest version of Live Writer
using System.Reflection;
using WindowsLive.Writer.Api;
using WindowsLive.Writer.Extensibility.BlogClient;
using WindowsLive.Writer.PostEditor;
namespace WindowsLiveWriterPlugin.Extensions
{
Buildfile: file:///D:/code/Tao/Tao.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: test
compile-interfaces:
[csc] Compiling 4 files to 'D:\code\Tao\build\net-2.0\Tao.Interfaces.dll'.
[csc] d:\code\Tao\src\Tao.Interfaces\IFunction.cs(8,32): error CS1031: Type expected
[csc] d:\code\Tao\src\Tao.Interfaces\IFunction.cs(8,32): error CS1519: Invalid token 'in' in class, struct, or int
public class AnonymousCheckoutController : StoreController
{
public AnonymousCheckoutController(
Services.ISalesService salesService
, Services.ICartService cartService
, Services.IAccountService accountService
, Services.IEmailerService emailerService
, Services.IDocumentService documentService
, Services.ICacheService cacheService
, Services.IAddressService addressService
@hmemcpy
hmemcpy / gist:1435212
Created December 5, 2011 20:27
Find uri.ToString() with ReSharper SSR
Here's how you can find all instances of System.Uri's ToString() method with ReSharper SSR (Structural Search and Replace):
1. Go to ReSharper menu -> Find -> Search with Pattern
2. Type in the following in the search pattern window:
$uri$.ToString()
3. Click 'Add Placeholder', select Expression. In the new dialog, put uri in the Name and 'System.Uri' in Expression type .
4. Click Find!
5. Voilla!
@hmemcpy
hmemcpy / gist:2585890
Created May 3, 2012 14:08
Which do you like better?
// #1
public IModule GetTargetModule(ICSharpExpression expression)
{
var referenceExpression = expression as IReferenceExpression;
if (referenceExpression != null)
{
var typeofExpression = referenceExpression.QualifierExpression as ITypeofExpression;
if (typeofExpression != null)
{
@hmemcpy
hmemcpy / gist:2868064
Created June 4, 2012 12:28
Non-generic pattern match
public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
{
IStructuralMatchResult match = Match(registrationRootElement);
if (match.Matched)
{
// ReSharper SSR will match a generic method with this pattern too. If has generic arguments, return
var invocationExpression = match.MatchedElement as IInvocationExpression;
if (invocationExpression == null || invocationExpression.TypeArguments.Count > 0)
{
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
var db = container.Resolve<ISisoDatabase>();
container.Register<ISession>((c, overloads) => new SessionWrapper(db.BeginSession()));
}
public class SessionWrapper : ISession
{
readonly ISession session;
@hmemcpy
hmemcpy / gist:3434473
Created August 23, 2012 09:06
Better way to indian?
// converts 0x00010203 to a byte array, containing: 0x03, 0x02, 0x01, 0x00
public static byte[] ToBigEndian(int data)
{
var result = new byte[4];
result[0] = (byte)data;
result[1] = (byte)(((uint)data >> 8) & 0xFF);
result[2] = (byte)(((uint)data >> 16) & 0xFF);
result[3] = (byte)(((uint)data >> 24) & 0xFF);
@hmemcpy
hmemcpy / readme.md
Created February 5, 2013 21:08
Your feedback on the System.Diagnostics.Abstractions API is requested...

I'm working on a small project, inspired by the awesome System.IO.Abstractions, aiming to provide a wrapper over System.Diagnostics.Process, to assist testability of anything process-related.

Where System.IO.Abstractions provides a wrapper over the Path, File, Directory types, as well as a wrapper objects over FileInfo and DirectoryInfo, all conveniently accessible from an IFileSystem, mirroring the way those types exist today in the .NET framework, the System.Diagnostics.Process type presents its own challenges when trying to create a convenient wrapper.

Your feedback on the API is, therefore, very much appreciated.

The Process class has several static methods for launching a new process, as well as other stuff:

void EnterDebugMode();

Process GetCurrentProcess();

I'm tryng to refactor a monstrous WCF service into something more manageable.
At the time of writing, the service takes about 9 dependencies via constructor, which makes unit testing it very difficult.
The service is handling local state via state machine, does validation on the parameters, throws fault exceptions, performs the actual operation and fires publication events via a pub/sub channel. This code is very similar accross all other service calls.
I realize that I can do several of those things (argument validation, pub/sub notifications) differently, perhaps via WCF behaviors, but my gut tells me that the general approach is wrong -- this feels too "procedural".
I wonder if acronyms like DDD or CQRS or other techniques can help out here?
Thanks!