Una semana súper ocupada (como todas)

Pero ha sido una semana de muchos éxitos trabajando con C# y MVC 4 en la plataforma de trazabilidad de proteina para Zgura.

Hemos implementado localización, membresía y autorización. Por cierto esos son temas de nuevos posts para este blog.

Una recomendación, si alguién empieza a trabajar con MVC 4, en mi humilde opinion (IMHO) es mejor comenzar de una vez utilizando las herramientas de la plataforma (MVC 4): código primero (pertenece en realidad a Entity Framework, Code First), modelos de vistas en vez de viewbag, fuertemente tipado en las vistas (views), etc.

Utilizar las herramientas que nos da esta tecnología nos ahorra mucho trabajo, cuando la aplicación crece y se le tiene que dar mantenimiento, lo anterior es de gran ayuda.

Coding Dojo Managua August 17th

I attended last Coding Dojo Managua past. Congratulations to organizers Juan Bautista from Dalehom and Primitivista, Tayron Portillo from IQUELO and Steven Hansen from Rain.

Great presentations by Tayron Portillo on SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion), this is a very important object oriented programming concept. Tayron made emphasis on the importance of learning and practicing these concepts because they help to improve quality of developed code and their use can be a requirement by customers.

There was one question from the audience on one of the components of SOLID: it was what is the difference between Dependency Inversion and Dependency Injection, I’d like to add to that discussion, in few words, that Dependency Injection is one implementation, one way to do Dependency Inversion. In order to implement that Dependency Injection you use a framework like Ninject, ZendFramework, Pinject, etc.

The second presentation was by Steven Hansen from Rain, he showed and allowed the audience to try Google Glasses. Steven mentioned the programming capabilities for Google Glass, the Mirror API. As whe should expect, the model is based on Cloud. I was able to try the glasses and even ask it to take a picture “Glass, take a picture”




Yes, localization working for EPPlus generated Excel files to Azure

It works (will write soon on how to implement localization in general on MVC 4). What I’ve changed on my approach is now the central provider for the names for properties, henceforth, for the field’s display names is the resource provider, which in my case, is in the Azure SQL DB.

Key is to just use [Display(Name={“Key_Name”}] in the case of the data annotations for properties and string myString=LocalizationResourceProvider.Current.GetString(“{Key_Name}”); for getting key value programmatically.

Then, for the generated Excel file, I just assign the myString to the header row:



Upload and download file to Azure Blob storage

Windows Azure includes a storage service that allows us to store binary and text data as files. This data is stored in BLOB (binary large object). For each Azure subscription we can have up to 5 storages accounts. Each storage account can have up to 100TB of data. More information at: Azure Storage.

We can use BLOBS to store files from an application. Two operation we will need to implement will be upload and download files.

I have implemented both, upload and download methods and use in MVC 4 web applications running on Azure.

I’m showing here code for upload and download methods, the kind I use with MVC 4 web app. In this case, although we are deploying to Azure, we are doing it to a Azure website, so no need for having a cloud project in the application solution. I implemented these methods at a separated model project.

public class AzureStorage
        public void UploadToBlob(string fileName, Stream stream, string containerName)
            //Bellow, not working, use this if using cloud project, when deploying to services
            //CloudStorageAccount storageAcct = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);

            CloudStorageAccount storageAcct = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

            CloudBlobClient blobClient = storageAcct.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
            stream.Position = 0;
            using (var fileStream = stream)
public string DownloadBlob(string fileName, string containerName)
            string uri = string.Empty;

            CloudStorageAccount storageAcct = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

            CloudBlobClient blobClient = storageAcct.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);

            using (var fileStream = File.OpenWrite(fileName))
            uri = @"http://MyAccountName.blob.core.windows.net/" + containerName + "/" + fileName;
            return uri;

As I was implementing the methods in a separated project (Model, in my case) I had to install Windows Azure Storage library, from Nuget and System Configuration library. In addition, be aware that I’m using release 2 of Azure libraries (instructions to use may change on previous versions of these libraries).

One of the practical uses for upload and download is for generating files using EP Plus and saving them at blob so to allow for later download by users. I’ll write another article to show how to use EPPlus. One of the interesting aspects of its use I’m currently implementing is mixing localization and use of localized data annotations so, instead for example writing the DisplayName of a property at a class like:

[DisplayName(“Inventory Code”)]

I use something like:


Where Inventory_Code is a resource key that points to a value, so, it could be Inventory Code or Código de Inventario. Now, imagine, you only have to set the data annotation at the property level and that will be used by views helpers to show the display values. In addition, I’m using data annotations for the headers I set for the Excel file I generate using EPPlus so localization will apply too to generated files.

More in following posts.


Note: in the specific case I was working on, since what I want is have the user to download files directly from Azure Blob, I just had to use the following code for downloading:

public string DownloadBlob(string fileName, string containerName)
            return @"http://MyStorageAccountName.blob.core.windows.net/" + containerName + "/" + fileName;


eCommerce, comentario a artículo de Juan Ortega Ulloa

Quiero comentar el artículo de Juan, aparecido en su blog http://juanortega.info/entendiendo-el-consumo-la-rentabilidad-en-los-medios-digitales/#more-2350

Es interesante el punto de obtener mayor audiencia como unico fin puede no ser suficiente para logrmar obtener más ventas (rentabilidad) y que esto se logra a través de ofrecer contenido relevante al usuario (cliente potencial). Al final, y estoy de acuerdo, si estamos hablando de comercio electrónico, el objetivo es generar rentabilidad.

Interesante también la estrategia de ofrecer múltiples modelos de ingresos, seria bueno profundizar enn esta área, desde el punto de vista de desarrollar las herramientas (CMS especializados) que permitan su habilitación. Creo que ya hay versiones de algunos conocidos CMS como Drupal Commerce.

Testing sample REST service using Web API and Azure

I did the example at http://www.windowsazure.com/en-us/develop/net/tutorials/rest-service-using-web-api/

As I was discussing with Anders and Alejandro in a previous post, there is another alternative to access data models and that is using Web API and script blocks. I think this sample helps to clarify in how to do that.

The key parts concerning use of Web API, I believe, for this sample are:

public string Self
                return string.Format(CultureInfo.CurrentCulture,
                    "api/contacts/{0}", this.ContactId);
            set { }

At the Contact class definition.

Notice the use of the property Self at the script block at the Index view for Home controller. Notice how Self property is used to connect with the methods at the API type controller Contacts.

You can see the site at http://contactmgr23.azurewebsites.net/. You can also try adding /api/contacts to the URL and see what happens, it will be shown differently at Firefox and Chrome than as in IE.

Note:Julio Avellaneda has a serie of posts in Spanish on Web API. http://julitogtu.com/category/asp-net-web-api/ Julio participates too at FB group Desarrolladores Nicaragua.

Free 20MB SQL Database in Azure

If you want to get started with Windows Azure, developing your first application, you can use Azure websites, you have up to 10 websites you can use for free.

Adding to that, you can have up to 1 20MB SQL database, per subscription, per the first 12 months of use of your Azure subscription.

This is great because we can use the free options, Azure websites and SQL database for learning and for testing without spending any money. To configure a website to use the free database, just select the appropriate database type, when adding the new website, through custom create:

Create Free Azure DB

More details on pricing at http://www.windowsazure.com/en-us/pricing/details/web-sites/