Reputation: 1422
Currently I'm writing a program that can estimate the costs of an Azure application. For this I have the idea to intercept all the methods that will do (indirectly) a call to the (Azure) server. And for each of the methods decide to which aspect of the costs it belongs to (for example (storage-transactions, servicebus-transactions, token-requests etc.))
One of the difficulties of this is that I also want to intercept a method call when the class/method is mocked, so the program can also be used in (unit-)tests during the development of an Azure application.
So I was wondering if there is a way to 'subscribe' on a method of a class. And when this method is called an event will be fired. Or are there other (better) solutions to intercept storage-transactions, servicebus-transactions, token-request etc. also for classes that send for example a storage-transactions but are mocked?
Thanks in advance
EDIT 1: Does anyone know if there are some (helper) classes/libraries or references that contains/knows all the classes/methods that influences the Costs of an Azure application?
EDIT 2 Is this a good approach to achieve above problem? Or are there alternatives?
Upvotes: 7
Views: 1261
Reputation: 7729
You can create log file. Write time and error or reaction. This is good solution. Half I ?
Upvotes: 0
Reputation: 31146
I did some work on what I consider Modern C# design, including proxy generation and dynamic method invocation based on interfaces. The blog explains how it works and how to use it.
I'm pretty sure that this works for your scenario.
The relevant link can be found:
and the more generic dynamic method invocation can be found:
Upvotes: 0
Reputation: 12174
We use the Trace API to track method calls - I'd recommend reading Using Trace in Windows Azure Cloud Applications. Once you have the data captured in Azure Tables, it is easy to report on the data you are tracking (similar to diagnostics reporting).
Upvotes: 0
Reputation: 24870
Create an HTTP proxy and have your application go through that proxy. That way you can really intercept each request to Windows Azure Storage / Service Bus / ...
While AOP is a good solution, it won't fit your needs. Take the CloudBlob.UploadFile method for example. From an AOP perspective this is a single call, but if you look at the number of HTTP transactions this can be a lot more than 1 call (large files are chunked and sent over multiple HTTP requests).
That's why you need to use something low level like an HTTP proxy if you want to monitor all calls to Windows Azure services.
Upvotes: 3
Reputation: 44650
You're looking for an aspect-oriented solution. Something like PostSharp should work for you. I've used it with good success. Not sure if there are other free options available.
Upvotes: 0
Reputation: 15931
You may be able to use dynamic proxy to generate classes that intercept the calls to the underlying objects, record details about the call and then forward them.
I'm not exactly sure how you'd wire it all up, but hopefully this will get you going in the right direction.
Upvotes: 0
Reputation: 34820
You're referring to Aspect Oriented Programming (AOP.) AOP deals with intercepting dispatch messages between objects and their methods and properties. Logic may be executed that depends on the content of the calls.
Here's a question on AOP frameworks in .NET:
What is the best implementation for AOP in .Net?
Upvotes: 3