RSS

Monthly Archives: September 2008

Implementando un Plugin en C#

EDIT: Con el tiempo he aprendido otras tecnicas para crear plug ins, aqui hay un articulo con un par de ellas http://hmadrigal.wordpress.com/2010/03/28/writing-a-plug-in/ lamentablemente lo escribi en ingles, hay un ejemplo. :P

Yo siempre me pregunte como trabajan los plugins. Entonces, yo lei articulos acerca de eso, y encontre algunas interesantes ideas. Yo he encontrado una manera para implementar plugins, que no significa que sea la ultima, pero usted puede investigar mas si esta idea no es suficiente.

When debo utilizar plugins?
Solo puedo pensar en escenarios como:

Cuando las reglas de negocios cambian muy amenudo y no quiero recompilar la aplicacion entera para actualizarla.
Para poder dar oportunidad a un tercero de implementar funcionalidad en mi aplicacion.

Entonces, que necesito para un plugin?

1. Definir un Contrato: Esta parte de la aplicacion esta a cargo de exponer toda las tareas que el pluing tiene que implementar, y tambien expone los recursos de la aplicacion que el plug in es capaz de acceder.
2. Implementacion del contrato: Esta es la implementacion de las tareas.
3. El cargador de plugins: Esta es la parte de la aplicacion encargada de cargar los archivos relacionados a la aplicacion. El resultado final es tener una manera de accessar todos los plugins cargados, junto con sus miembros.

Suena facil verdad?, de hecho, es facil!, el unico detalle es como implementar cada paso en su lenguaje de preferencia.

Yo he implementado un simple ejemplo utilizando C# 3.0, LINQ y genericos. Yo me base en un ejemplo de un articulos que encontre en internet, sin embargo agrege el soporte para genericos y LINQ para sacar ventaja del .NET framework 3.5.

Paso 1: Contrato del Plugin
En C# la mas comun manera para defininr un contrato es por medio del uso de interfaces. Entonces, nosotros solamente necesitamos creat un proyecto que almacene toas las interfaces que el plugin necesita sean implementadas, y los recursos que son compartidos entre el plug in y la aplicacion.

Paso 2: Implementacion del Plugin
Ahora tenemos que creat una clase que implemente (lo cual quiere decir escribir funcionalidad) para el contrato del paso anterior.

Step 3: Plugin loaders
Esta es la parte dificil de esto, nuestra applicacion va ha cargar archivos binarios. Estos archivos van a ser incorporados a nuestra applicacion en ejecucion. Despues de esto, nosotros podremos llamar (si se requiere) una tarea en particular de nuestro plugin. Para lograr esto en C#, nosotros utilizamos el concepto de ‘late binding’, que esta dentro del .NET framwork. Esto permite a nuestra applicacion cargar los archivos binarios en tiempo de ejecucion. Tambien al utilizar reflexion nosotros podemos generar instances de las clases de los archivos binarios.

Here is a screenshot of my sample in C#:

Adjunto un codigo de ejemplo de como implementar un cargador de plugins.
http://hmadrigal.googlepages.com/Transtool.zip

Tambien puede chequear estos buenos articulos:

Creating a Flexible Dynamic Plugin Architecture under .NET

http://www.codeproject.com/KB/dotnet/PluginManagerClassBrk.aspx?fid=26061&df=90&mpp=25&noise=3&sort=Position&view=Quick

ASP.NET Technical Articles – Creating a Plug-In Framework

http://msdn.microsoft.com/en-us/library/ms972962.aspx

Dynamic Loading Made Simple

http://www.codeproject.com/KB/library/dynamicloading.aspx

Enabling Your Application to Become a Plugin Host

http://www.codeproject.com/KB/cs/Plugin_Basics.aspx

Let Users Add Functionality to Your .NET Applications with Macros and Plug-Ins

http://msdn.microsoft.com/en-us/magazine/cc164072.aspx

Plugin Architecture using C#

http://www.codeproject.com/KB/cs/c__plugin_architecture.aspx

Saludos,
Herberth

 
Leave a comment

Posted by on 2008/09/11 in .net, c#, plugin, programming

 

Tags: , , ,

Firefox: Last.fm and DownloadHelper

Hola,

Bien, estoy planeadno cambiar de computador por uno mas nuevo, entonces decidi instalar plugins en firefox para pobarlos. Tengo un lista de extensiones que me parecen utiles para ustedes, pero hay una combinacion que me parecio interesante:

1. fire.fm Esta extension permite escuchar musica desde el sitio de Last.fm .
2. DownloadHelper: Esta extension te ayuda a bajar cualquier contenido multimedia que esttes navegando. Vea mas detalles en la pagina downloadhelper

Aqui esta la cuestion, cuando trabajas junto los dos plugins te permiten descargar musica directamente from Last.fm. Como siempre, es un curioso efecto secundario.

Saludos,
Herberth

 
Leave a comment

Posted by on 2008/09/05 in download, firefox

 

Firefox: Last.fm and DownloadHelper

Hello,

Well, I’m planning to change my computer for a new one, so I decided to install plugin in firefox for testing all I haven’t had the chance. I have a list of plug ins that I might encourage you to use, but here I only want to point an interesting combination:

1. fire.fm This plug in lets you listen your station or your favorites stations from Last.fm site.
2. DownloadHelper: This plug in help you to download any media content where you are navigating. See downloadhelper’s page for more details.

Here is the deal, when you work with both plug ins at the same time, you are able to download song from Last.fm. As always, it’s a kind of funny side effect. Enjoy it.

Regards,
Herberth

 
 

Implementing a Plug-in Loader in C#

I always asked myself how the Plugins work. So I read some articles about it, and found some really interesting ideas. I’ve found the following way for implementing plugins, it does not mean that it’s the only one, but you can research more if this approach does not work for you.

When do I need to implement a plugin?
I can think in some scenarios such as:

  • When the business rules change often and you don’t want to recompile the whole application for an udpate. (You can solve this by developing with layers, and others techniques).
  • In order to give the chance to thrid party for implementing functionally in your application.

So, What do I need for a plugin?
Easy, you need 3 key parts:

  1. Contract definition: This part of you application is in charge of expose all the tasks that the plugin has to implement, and also exposes the application’s resources that the plug in allowed to access.
  2. Contract implementation: The final implementation of tasks.
  3. Plugin loader: This part of you application is going to load all the files related to the application. The final result is to have a way to access all the loaded plugins and its members.

Sounds easy right? In fact, it’s easy, the only thing is how you could implement each step in you favorite language.

I have implemented a simple loader by using C# 3.0, LINQ and Generics. I based my example on a article that I found in Internet, however I added the Generics and LINQ in order to take advantage of .NET 3.5.

Step 1: Plugin contract.
In C# the most common way for defining a contract is by using a Interface. So, we only need to create a project that is going to store all the interfaces that plug in has to implement, and the resources that are shared among the plug in and the application.

Step 2: Plugin Implementation
Now, we have to create a class that implements (which means write the functionality) for the contracts of the previous step.

Step 3: Plugin loaders
Here is the tricky part of this, our application is going to load binary files. Those files are going to be incorpored to our running application. After that, we should be able to call (if required) a particular task from a plugin. In order to do this in C#, we use ‘late binding’ concept, that .NET includes. It allows our application for loading assemblies in runtime. Also by using reflextion we can generate instances of our loaded assemblies.

Here is a screenshot of my sample in C#:


So, I’m attaching the related code as an example of how you could implement a plug in loader.
http://hmadrigal.googlepages.com/Transtool.zip

Also you can check some really nice articles:

Creating a Flexible Dynamic Plugin Architecture under .NET
http://www.codeproject.com/KB/dotnet/PluginManagerClassBrk.aspx?fid=26061&df=90&mpp=25&noise=3&sort=Position&view=Quick

ASP.NET Technical Articles – Creating a Plug-In Framework
http://msdn.microsoft.com/en-us/library/ms972962.aspx

Dynamic Loading Made Simple
http://www.codeproject.com/KB/library/dynamicloading.aspx

Enabling Your Application to Become a Plugin Host
http://www.codeproject.com/KB/cs/Plugin_Basics.aspx

Let Users Add Functionality to Your .NET Applications with Macros and Plug-Ins
http://msdn.microsoft.com/en-us/magazine/cc164072.aspx

Plugin Architecture using C#
http://www.codeproject.com/KB/cs/c__plugin_architecture.aspx

Regards,
Herberth

 
Leave a comment

Posted by on 2008/09/05 in .net, c#, plugin, programming

 

Movimiento Retro

Hola,

Bien, aqui nosotros hemos tenido la oportunidad para jugar “Mario 3″ en u LCD Bravia de 42 pulgadas. Estoy seguro de que es ona de las experiencias retro jamas vivida. Aqui esta la foto dek gran momento:

Al fin y al cabo, quien no lo ha hecho todavia?

Saludos,
Yog.

 
Leave a comment

Posted by on 2008/09/05 in LCD Bravia, Mario 3, Retro

 

Retro Movement

Hello,

Well, here we had the change to play Mario 3 in a LCD Bravia of 42″. I’m sure that it’s one of the most retro game you could ever play. So, here is the big moment:


Anyway, how hasn’t done it yet?

Regards,
Yog

 
Leave a comment

Posted by on 2008/09/05 in LCD Bravia, Mario 3, Retro

 

Guerra de consolas

Hola,

Una amiga me pregunto cual es mejor…, un xbox 360, un ps3 o un Wii. Actualmente yo tengo un Xbox 360 y un Wii, entonces my punto de vista del PS3 es algo pobre. Sin embargo he intentado resumir tolo lo que se acerca de consolas en el siguiente document:

http://docs.google.com/Doc?id=dg4d5pp2_1379t74skhh

Saludos,
Herberth

 
Leave a comment

Posted by on 2008/09/01 in consolas, ps3, wii, xbox 360

 

Console War

Hello,

Everyone, a friend asked me about which is better… the PS3, the Xbox (or the Wii). I only own a Xbox360 and a Wii, so my point of view about the PS3 is kind of poor. However I have tried to sum up all I know about the consoles in this document.

http://docs.google.com/Doc?id=dg4d5pp2_1379t74skhh

Regards,
Herberth

 
Leave a comment

Posted by on 2008/09/01 in console, ps3, wii, xbox 360

 
 
Follow

Get every new post delivered to your Inbox.

Join 126 other followers