Skip to content

Instantly share code, notes, and snippets.

internal class ServiceControllerFactory : IServiceControllerFactory
{
public IServiceController CreateController()
{
if (Process.GetCurrentProcess().GetParent().ProcessName == "services")
return new ScmServiceController();
return new AsynchronousServiceController();
}
}
public static class ProcessExtensions
{
public static Process GetParent(this Process child)
{
int parentPid = 0;
IntPtr hnd = Kernel32.CreateToolhelp32Snapshot(Kernel32.TH32CS_SNAPPROCESS, 0);
if (hnd == IntPtr.Zero)
return null;
# robocopy.rb
class Robocopy
attr_accessor :source, :target, :excludeDirs, :includeFiles, :logPath
def run()
robocopy = "robocopy.exe " \
"\"#{@source}\" " \
"\"#{@target}\" " \
require 'rubygems'
require 'rake/gempackagetask'
task :default => [:package]
spec = Gem::Specification.new do |spec|
spec.platform = Gem::Platform::RUBY
spec.summary = "NoRM - A MongoDB driver for .Net"
spec.name = "norm"
spec.version = "0.9.7"
require 'rubygems'
require 'rake/gempackagetask'
task :default => [:package]
spec = Gem::Specification.new do |spec|
spec.platform = Gem::Platform::RUBY
spec.summary = "A MongoDB driver for .Net"
spec.name = "norm"
spec.version = "0.9.8"
public static class StringExtensions
{
public static string Hash(this string value, string salt)
{
return SHA1.Create().
ComputeHash(Encoding.UTF8.GetBytes(salt + value)).
Select(x => x.ToString("x2")).
Aggregate((a, x) => a + x);
}
}
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Norm;
using System.Linq;
namespace MongoSandbox
{
class Program
using (var mongo = Mongo.Create("mongodb://user:password@localhost/Test"))
{
// Some strongly typed filter, I want a document with a number of 2
Expression<Func<User, bool>> filterExpression = u => u.Number == 2;
// A NoRM specific object, not important
var filter = new Expando();
// I need to pull the name "Number" and the value 2
// and programatically pass it to the NoRM expando object.
public class MongoDbSandbox
{
public static void Main()
{
var repo = new MongoDbObjectRepository("mongodb://user:password@localhost/Test");
var model = new Model {Number = 2};
var user = repo.Fetch<User>(u => u.Number == model.GetNumber(45));
public static class IEnumerableExtensions
{
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
{
foreach (var item in items) action(item);
}
}