Skip to main content

Posts

Showing posts from October, 2013

Events, Delegates, Actions, Tasks with Mutex

Mutex. If you are a developer than you heard about mutex. Mutex are used to ensure that only one thread/process has an exclusive access to a specific sections of the code.
Let’s look over the following code and see if the code is correct or not?
public class Foo { Mutex mutex = new Mutex(); event SomeActionEvent someActionEvent; public void Do() { mutex.WaitOne(); ... someActionEvent += OnSomeAction(); } public void OnSomeAction(...) { mutex.ReleaseMutex(); } } “WaitOne” method is used to block the current thread until we received a release signal – WaitHandler. “ReleaseMutex” is used when we want to release the lock.
The above code release the mutex lock on an event handler that is executed on a different thread. The problem is that we don’t call the release mutex method from the same thread from where we call “WaitOne”. Because of this, the obtained behavior is not the one that we expect.
The same problem will appear if we use mutex in combina…

Digging through SignalR - Commands

Looking over source code of SignalR. I found some interesting class and ways to implement different behaviors. In the next series of post I will share with you what I found interesting.
Before starting, you should know that SignalR is an open source project that can be accessed using GitHub.
In today post we will talk about command pattern. This patterns over the ability to define a “macro”/command that can be executed without knowing the caller. Commands can be handle in different ways, from create a queue of them to combining or offering support for redo/undo.
In SignalR library I found an implementation of command pattern that caught my attention.
internal interface ICommand { string DisplayName { get; } string Help { get; } string[] Names { get; } void Execute(string[] args); } internal abstract class Command : ICommand { public Command(Action<string> info, Action<string> success, Action<string> warning, Action<string> error) { …

Story - Developers that don’t understand the business of the application

This days I participate to a presentation of a product. The idea of the product was great, I think that they will have a lot of success in the future.
Being a technical presentation, the presentation was held by one of the developers of the team. From this point of view this was great, because the audience was developers and other technical person. He could respond to a lot of question related to architecture, scalability, protocol that were used, base concept and so on.

Until….

Someone asked about something related to business idea and what kind of problem this application will solved….

In that moment our developer stopped……..

He could not give an answer….

And…he sad…
I’m a technical person, is not my business to know the business of the application!

In that moment I freeze. How the hell you can develop an application without understand the business? This is one of the biggest mistakes that can be done by a team member – refuse to understand the business of the application. Before thi…

Custom Content Delivery Network Mechanism using Cloud (Azure)

Requirements:
Lets’ imagine an application that need to deliver Excel report in different location of the world. Based on the client origin the application should be able to deliver specific Excel version. The application should be deployed in different location on the world.
The current CDN solution cannot be used because the master node needs to push the content to the slaves (CDN nodes) and the total report size for each slave will be over 20GB.
Non-Cloud solution:
If we would go on a non-cloud solution we should develop an application that is deployed on different location all around the world. Each application should be able to detect the source of the request and provide the specific Excel report. We should also develop a redirecting mechanism/ load balancing solution that is able to redirect the user to a specific node.
Cloud solution:
If we go on a cloud solution, based on Windows Azure we can imagine a master slave solution.
Each slave of our application will have the Excel rep…

CMS application for 3 different mobile platforms – Hybrid Mobile Apps + Mobile Services

This days I attended to a session where an idea of a great mobile application was presented. From the technical perspective, the application was very simple, the content that is deliver to the consumer has a great value.

The proposal of the application was 3 different application for each platform (iOS, Android and Windows Phone). When I asked why it is so important to have 3 different native application for an application that has the main purpose to bring content to the users I found up that they need push notification support and all the rest of the content that will be displayed will be loaded from the server (CMS).
Having 3 different native application means that you will need to develop the same application 3 times for 3 different platform…. 3X maintenance 3X more bugs and so on….
In this moment I have a rendevu. I have the feeling that I already wrote about this.
For this kind of application you develop a great HTML5 application. For push notification support it is very easily …

How to track who is accessing your blob content

In this post we’ll talk about how we can monitor our blobs from Windows Azure.
When hosting content on a storage one of the most commune request that is coming from clients is

How I can monitor each request that is coming to my storage?For them it is very important to know Who downloaded the content?When the content was downloaded?How the request ended (with success)?
I saw different solution for this problem. Usually the solutions involve services that are called by the client after the download ends. It is not nothing wrong to have a service for confirmation, but you add another service that you need to maintain. Also it will be pretty hard to identify why a specific device cannot download your content.
In this moment, Windows Azure has a build-in feature that give us the possibility to track all the requests that are made to the storage. In this way you will be able to provide all the information related to the download process.
Monitor
In Windows Azure portal you will need to go to …

Certificates and resource management

Last month I had two posts where I tacked a little about certificates in .NET (12).
In this post I want to discuss about resource management when X5099Certificate2 is used. This is applicable for X509Certificate also.
When we use a .NET object we usually check if IDisposable interface is implemented. If yes, than we will call ‘Dispose’ method. But unfortunately X509Certificate don’t implement this interface.
Behind this class there is a handle (SafeCertContextHandle) to unmanaged resources. Because of this, each new instance of the certificate will have a handle to unmanaged resources. If you need to process 2.000 certificates from the store it will be very easy for you to get a wonderful “OutOfMemoryException”.
To be able to release all the resources that are used by a reference to a certificate you will need to call the ‘Reset’ method. This method will release all the resources that are associated with the specific certificate.
X509Certificate2 cert = … … cert.Reset(); X509Store …

Feature of a Smart Devices that I miss

Nowadays, everyone has a smart device like a phone, a tablet, a watch or a camera. This devices give us the power to stay connected with the world in real time and to access or information extremely fast.
All this devices has different security mechanism, which allow us to track them, make them ring and erase all the data.
But once the device is stolen and all the data are deleted, the “new” owner can register and use the device without any kind of problem. From that point, it is pretty complicated to track our device and recover it.
A feature that I miss on this new smart devices is the ability to track and block them after someone reset it. Based on the unique ID of each devices we should be able to track them even if a factory reset is made.
I would like to see a feature for devices that were already register online to request a confirmation from the old owner when the device is register with another account.
Imagine yourself that you buy a device and someone steal it. He will not…

How to assign a private key to a certificate (from command line or code)

In the last post we saw how we can extract certificate from a PKCS7 store. In this post we will see two different ways how we can register a certificate into local store using C#.
The first method that can be used to register a certificate into the store is using X509Store class.
X509Certificate2 cert = new X509Certificate2(...) X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(cert); store.Close(); If you want to import the private key to the certificate you will need to need to specify to the certificate constructor the flag that say to the system “Please, persist the private key".
X509Certificate2 cert = new X509Certificate2 ( [path], [password], X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet); X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(cert); store.Close(); This solution will works in 99.9% cases, but I ha…

How to get a certificate from a PKCS7 file

In the last period of time I was forced to play a lot with certificates from .NET code (in my case was C#). The good part when you are using .NET is that you have an API that can be used to manage system certificates.
It is pretty simple to load a certificate from certificates store, file or an array of bytes.
X509Certificate2 cert = new X509Certificate2(bytes); In the above example I am loading a certificate from an array of bytes. The code is pretty simple and works great.
There are situations when you receive a certificate from an external system. In this cases the first step that you need to do is to save the certificate local. When you are a 3rd party and you are receiving a certificate from a server you should be aware of the format of the certificate.
In my case I received a certificate signed in PKCS7 byte array without knowing this and I assumed that it is enough to load the certificate using the constructor. The funny thing is that you will be able to load a signed PKC…

Microsoft Summit 2013, 6-7 November in Bucharest

Did you heard about Microsoft Summit 2013? This year Microsoft Romania will organize an event dedicated to IT. There will be special tracks for Developers, IT Professional and Business Managers.
The speaker list contains interesting names like David Chappell, Chris Capossela or Beat Schwegler.
At this summit I will have two session where I will talk about how you can create and run load tests using the new features from Visual Studio 2013 and Windows Azure. In the second session we will talk about choosing the right path when you are developing Windows Phone 8 and Windows 8 applications.
I invite you to visit and register to this summit: www.mssummit.ro

See you there!

MVP Award - Renewed

I am pleased to announce that my Windows Azure MVP award was renewed.
Thank you for this award and I hope to continue to bring value to online and offline community.