Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (56 sloc) 2.03 KB
// ----------------------------------------------------------------------
// <copyright file="GenericCommand.cs" company="Expensify">
// (c) Copyright Expensify. http://www.expensify.com
// This source is subject to the Microsoft Public License (Ms-PL)
// Please see license.txt on https://github.com/Expensify/WindowsPhoneTestFramework
// All other rights reserved.
// </copyright>
//
// Author - Stuart Lodge, Cirrious. http://www.cirrious.com
// ------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace WindowsPhoneTestFramework.Client.AutomationClient.Remote
{
public partial class GenericCommand
{
private static readonly Dictionary<string, Func<GenericCommand, Action>> _handlerFactories =
new Dictionary<string, Func<GenericCommand, Action>>();
public static void AddHandlerFactory(string key, Func<GenericCommand, Action> handlerFactory)
{
lock (_handlerFactories)
{
_handlerFactories[key] = handlerFactory;
}
}
public static void RemoveHandlerFactory(string key)
{
lock (_handlerFactories)
{
if (_handlerFactories.ContainsKey(key))
_handlerFactories.Remove(key);
}
}
protected override void DoImpl()
{
Action processor = null;
lock (_handlerFactories)
{
foreach (var handler in _handlerFactories)
{
processor = handler.Value(this);
if (processor != null)
break;
}
}
if (processor != null)
{
processor();
return;
}
// if we've reached this stage, then this is an error...
// and this DoImpl() call will almost certainly result in an exception
base.DoImpl();
}
}
}