Showing posts with label Links. Show all posts
Showing posts with label Links. Show all posts

Monday, November 5, 2012

Adding reactivity to NetMonitor

It was long time ago when I last time wrote about updates in the NetMonitor project. I was just using it from time to time to diagnose my network connection and it worked pretty well. However, I wasn't happy with its internals, especially with PingService implementation as it was rather complex for such simple job - it had to deal with entities from System.Threading namespace (e.g. Timer) to get called from time to time in background thread and this only added complexity without adding any business value.

Some time ago I tried playing with Task Parallel Library, but eventually it appeared that TPL is not applicable in this scenario.

This time I've found Rx Extensions and I really liked the approach. My task with sequential background execution is solved with the help of the extensions quite gracefully (here is simplified version):

var service = new PingService("google.com");

// Every second the ping service will be called from background thread, producing a sequence of metrics
var metrics = Observable.Interval(TimeSpan.FromSeconds(1))
    .Select(i => service.Execute());

// Consuming the sequence of metrics and updating UI
subscription = metrics.Subscribe(
    metric => Console.WriteLine(metric.RoundtripTime),
    exception => Console.WriteLine(exception.Message));

Applying Rx Extensions drastically simplified the service itself and program environment as additionally I got rid of events and handlers, I am satisfied with the changes it brought. In my scenario it looks like a simple messaging bus between services and their consumers.

I'm pretty confident that Reactive Extensions can change your attitude to composing asynchronous and event-based programs (as it once happened with invention of LINQ for data querying). More on Rx can be found on MSDN, 101 Samples, IntroToRx.

Sunday, November 4, 2012

Dependency injection for smarties

Till the last week I was thinking that dependency injection is a rather simple thing and mostly is about resolving a component by its interface/base class with some nuances like providing additional information as name, constructor signature, transient/singleton instance, etc. Almost everyone among my friends wrote their own implementation of IoC container, that's not big deal. They differ one from another by name of main method (Get/Resolve/Whatever) and internal implementation, but all they were about was simple component resolving and no more.

However, last week I was diving deep in autofac IoC container and one thing in their documentation just made me rethink all that I knew about the relationships between the components (actually, I didn't think of anything except the first type from the list). Here is what they call relationships:

Relationship Constructor signature Meaning
A needs B A(B b)Dependency
A needs B at some point in the future A(Lazy<B> b)Delayed instantiation
A needs B until some point in the future A(Owned<B> b)Controlled lifetime
A needs to create instances of B A(Func<B> b)Dynamic instantiation
A provides parameters of types X and Y to B A(Func<X,Y,B> b)Parameterisation
A needs all the kinds of B A(IEnumerable<B> b)Enumeration
A needs to know X about B A(Meta<T> b) and A(Meta<B,X> b)Metadata interrogation

More on the relationships you can read in the dedicated article Relationship Zoo, highly recommended. I hope it will make you rethink what DI was meant for you.

Tuesday, June 21, 2011

Free Online OCR (Optical Character Recognition) tool

In case you need to quickly recognize a text from an image file and don’t have ABBYY FineReader installed, there is an online analogue. Moreover, it is completely free. It is called Free OCR and is located here: http://www.free-ocr.com/

One thing made me laugh: they have to use Captcha technology to protect the website from spammers who used it for captcha breaking! This argument is enough to prove the service efficiency. =)

Hope this service will be helpful to someone as it was to me.

Friday, July 9, 2010

The useful finding

Just’ve found on the web an amazing resource full of nice CSS templates, licensed under the Creative Commons Attribution 3.0 Unported License — FreeCSSTemplates.org.

Here are some examples:

Well done!

Sunday, March 14, 2010

Busy people versus effective people

The excellent essay “The cult of busy” by Scott Berkun about time, efficiency, busy people and everything. Don’t miss it.

It seems that it is rather easy nowadays to become extremely busy, but will you be efficient enough to sort out the problems? The answer is not so obvious and might surprise you.