Tercer Aniversario

abril 15, 2010 :: Posted by - Emilio Torrens :: Category -

Pastel_r2d2

Ayer hizo 3 años que tenemos el blog en marcha, así que como mínimo un pastel un tanto freak (que es una foto que he encontrado por la red, pero no estaría mal que un día me sorprendierais con uno) y un POST para celebrarlo.

Estaba revisando el primer POST y era sobre certificaciones de software para Windows Vista, ayer en el día del aniversario posteamos sobre Velocity, mucho mejor ….

Bueno pues nada gracias a todos los que nos visitáis y felicidades para Jordi y para … mi :)

Cliente C# para Velocity

abril 14, 2010 :: Posted by - Emilio Torrens :: Category - , , ,

Hoy he estado liado con este tema con unas pruebas básicas para probar el Cache del AppFabric

El Windows Server AppFabric Beta 2 lo he instalado en un Windows Server 2008 con el Framework 4.0 RC, ojo que tiene que ser el RC no puede ser el final, además tiene otros requisitos con el Windows Power Shell 2.0 RTM y algunas cosas mas, pero el instalador te avisa y te dice de donde bajarlos.

El cliente en C# con VS2010 y Framework 4.0, recién salido del horno :)

Creamos el proyecto cliente y le añadimos esta referencias del AppFabric (Encontraremos las dll en la carpeta C:\Windows\System32\AppFabric del servidor donde lo hayamos instalado

  • Microsoft.ApplicationServer.Caching.Client.dll
  • Microsoft.ApplicationServer.Caching.Core.dll
  • Microsoft.WindowsFabric.Common.dll
  • Microsoft.WindowsFabric.Data.Common.dll

Podemos configurar el cliente por código o en el AppConfig.

Por código:

private DataCache Client
 {
     get
     {
         if (dataCache != null) return dataCache;

         // Aqui los servidores de cache en este caso 1.
         DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
         servers[0] = new DataCacheServerEndpoint("CACHESERVER", 22233);

         DataCacheFactoryConfiguration factoryConfig =
                                       new DataCacheFactoryConfiguration();
         factoryConfig.Servers = servers;

         DataCacheFactory mycacheFactory = new DataCacheFactory(factoryConfig);

         //El Cache, en este caso el que pone por defecto al instalarlo
         DataCache myDefaultCache = mycacheFactory.GetCache("default");

         dataCache = myDefaultCache;
         return dataCache;
     }
 }

Por configuración:

App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!--configSections must be the FIRST element -->
  <configSections>
    <!-- required to read the <dataCacheClient> element -->
    <section name="dataCacheClient"
       type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
            Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0,
            Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       allowLocation="true"
       allowDefinition="Everywhere"/>
  </configSections>

  <dataCacheClient>
    <hosts>
      <host name="CACHESERVER" cachePort="22233"/>
    </hosts>
  </dataCacheClient>
</configuration>

Codigo:

private DataCache Client
      {
          get
          {
              if (dataCache != null) return dataCache;

              //Configurado en el app.config
              DataCacheFactory mycacheFactory = new DataCacheFactory();

              // Get a cache client for the cache "default".
              DataCache myDefaultCache = mycacheFactory.GetCache("default");

              dataCache = myDefaultCache;
              return dataCache;
          }
      }

Y listo para probarlo:

private void Test()
{
    DataCache cliente = Client;

    cliente.Add("key", "data");
    object data = cliente.Get("key");
    cliente.Remove("key");
}