开发者

Caliburn.Micro: logging every ActionMessage?

We're starting a new Silverlight project on Caliburn.Micro. We need to log every user interaction through Google Analytics. Is there any way开发者_如何学Python to have a bit of code executed every time any ActionMessage is sent?


Fortunately, this is quite easy. Replace ActionMessage.InvokeAction with your own method which does logging and then calls the original. You will want to do this in the Bootstrapper's Configure override. Your code would look something like this:

var originalInvoke = ActionMessage.InvokeAction
ActionMessage.InvokeAction = context => {
    //do logging here using the context
    originalInvoke(context);
}

That's all there is to it. From the context variable you can get the MethodInfo, the Taget view model, the View, the EventArgs and the Source element that triggered the invocation.


I haven't tried this myself, but ActionMessage has an InvokeAction public delegate, so you could subscribe to that invocation list, perhaps in your bootstrapper's Configure method:

ActionMessage.InvokeAction +=
  c => { throw new Exception(string.Format("Method '{0}' invoked", c.Method.Name)); };

You'll recieve an ActionExecutionContext which will give you information about the action.

Perhaps do something more useful than throwing an exception :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜