1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.Mvc;
6
7 using System.Diagnostics;
8
9 using Microsoft.Practices.ServiceLocation;
10
11 using Happy.Commands;
12 using Happy.WCF.Demo.Commands;
13 using Happy.WCF.Commands;
14
15 namespace Happy.WCF.Demo.Mvc.Controllers
16 {
17 public class DefaultController : Controller
18 {
19 public ActionResult Index()
20 {
21 var watch = Stopwatch.StartNew();
22
23 var localBus = ServiceLocator.Current.GetInstance<ICommandBus>();
24 var localCommand = new TestCommand { X = 5, Y = 5 };
25 localBus.Send(localCommand);
26
27 watch.Stop();
28
29 var localMessage = string.Format("本地命令:{0} + {1} = {2},执行时间:{3}", localCommand.X, localCommand.Y, localCommand.Result, watch.Elapsed);
30
31
32 watch = Stopwatch.StartNew();
33
34 var remoteBus = ServiceLocator.Current.GetInstance<ICommandBus>("Proxy");
35 var remoteCommand = new TestCommand { X = 5, Y = 5 };
36 remoteBus.Send(remoteCommand);
37
38 watch.Stop();
39
40 var remoteMessage = string.Format("远程命令:{0} + {1} = {2},执行时间:{3}", remoteCommand.X, remoteCommand.Y, remoteCommand.Result, watch.Elapsed);
41
42
43 return this.Content(
44 localMessage
45 +
46 "<br/>"
47 +
48 remoteMessage
49 );
50 }
51 }
52 }