PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/V2.2/trunk/CAL/Desktop/Composite.Tests/Mocks/MockAsyncModuleTypeLoader.cs

#
C# | 53 lines | 30 code | 7 blank | 16 comment | 0 complexity | 4964cecd998d2d5cd17863dd36f7c118 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Threading;
19using Microsoft.Practices.Composite.Modularity;
20
21namespace Microsoft.Practices.Composite.Tests.Mocks
22{
23    public class MockAsyncModuleTypeLoader : IModuleTypeLoader
24    {
25        private ManualResetEvent callbackEvent;
26
27        public MockAsyncModuleTypeLoader(ManualResetEvent callbackEvent)
28        {
29            this.callbackEvent = callbackEvent;
30        }
31
32        public int SleepTimeOut { get; set; }
33
34        public Exception CallbackArgumentError { get; set; }
35
36        public void BeginLoadModuleType(ModuleInfo moduleInfo, ModuleTypeLoadedCallback callback)
37        {
38            Thread retrieverThread = new Thread(() =>
39            {
40                Thread.Sleep(SleepTimeOut);
41                callback(moduleInfo, CallbackArgumentError);
42
43                callbackEvent.Set();
44            });
45            retrieverThread.Start();
46        }
47
48        public bool CanLoadModuleType(ModuleInfo moduleInfo)
49        {
50            throw new NotImplementedException();
51        }
52    }
53}