Perl en Español

  1. Home
  2. Tutoriales
  3. Foro
  4. Artículos
  5. Donativos
  6. Publicidad
 
Índice general » En Comunidad » Proyectos » Azure - Descargando Perl desde Windows Azure Responder al tema
Nuevo tema


Página 1 de 1  [ 1 mensaje ] 
 
Nota 2011-09-09 06:39 @318

Perlero Nuevo
Registrado: 2010-11-24 18:08 @797
Mensajes: 13
Azure - Descargando Perl desde Windows Azure
Hola, como primer aporte os adjunto el código necesario para que desde un WorkerRole podamos descargar Strawberry Perl 64 Bits desde la página oficial y seguidamente descomprimirlo en el WorkingDirectory. Esto lo hace automáticamente este código. (¡Ojo!, tendréis que añadir la referencia a Ionic.Zip en el proyecto.)

Syntax: [ Download ] [ Hide ]
Using csharp Syntax Highlighting
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Net;
  6. using System.IO;
  7. using Ionic.Zip;
  8. using System.Threading;
  9. using Microsoft.WindowsAzure;
  10. using Microsoft.WindowsAzure.Diagnostics;
  11. using Microsoft.WindowsAzure.ServiceRuntime;
  12. using Microsoft.WindowsAzure.StorageClient;
  13.  
  14. namespace WorkerRole1
  15. {
  16.     public class WorkerRole : RoleEntryPoint
  17.     {
  18.         const string Perlfolder = @"strawberry";
  19.         const string PerlDownloadAddresses = @"http://strawberryperl.com/download/5.12.2.0/strawberry-perl-5.12.2.0-portable.zip";
  20.            
  21.         public override void Run()
  22.         {
  23.             while (true)
  24.             {
  25.                 Thread.Sleep(10000);
  26.                 Trace.WriteLine("Working", "Information");
  27.             }
  28.         }
  29.  
  30.         public override bool OnStart()
  31.  
  32.         {
  33.             ServicePointManager.DefaultConnectionLimit = 12;
  34.  
  35.             DownloadPortablePerl();
  36.            
  37.             return base.OnStart();
  38.         }
  39.         private void DownloadPortablePerl()
  40.         {
  41.            
  42.             var perlDownloadAddress = PerlDownloadAddresses;
  43.             var locations = perlDownloadAddress.Split(' ').Select(a => a.Trim()).Where(l => l.Trim().Length > 0);
  44.  
  45.             if (locations.Count() == 0)
  46.                 throw new Exception("No download locations for Perl configured (setting 'PerlDownloadAddresses').");
  47.  
  48.             locations.ToList().ForEach(a => Trace.TraceInformation("Download location " + a));
  49.  
  50.             var perlarchive = locations.First();
  51.             perlarchive = perlarchive.Substring(perlarchive.LastIndexOf('/') + 1);
  52.             Trace.TraceInformation("File is " + perlarchive);
  53.  
  54.             if (File.Exists(perlarchive))
  55.                 Trace.TraceInformation(string.Format("Found local perl archive copy at {0}", (new FileInfo(perlarchive)).FullName));
  56.             else
  57.             {
  58.                 Trace.TraceInformation("Downloading...");
  59.  
  60.                 var client = new WebClient();
  61.                 bool success = false;
  62.                 foreach (var loc in locations)
  63.                 {
  64.                     try
  65.                     {
  66.                         Trace.TraceInformation(string.Format("Trying location {0}", loc));
  67.                         client.DownloadFile(loc, perlarchive);
  68.                         Trace.TraceInformation(string.Format("Successfully downloaded from {0}", loc));
  69.                         success = true;
  70.                         break;
  71.                     }
  72.                     catch (Exception ex)
  73.                     {
  74.                         Trace.TraceError(string.Format("Failure downloading from {0}", loc));
  75.                         Trace.TraceError(ex.Message);
  76.                     }
  77.                 }
  78.  
  79.                 if (!success)
  80.                     throw new Exception("Could not download Perl distibution");
  81.             }
  82.  
  83.             if (!Directory.Exists(Perlfolder))
  84.                 Trace.TraceInformation("Perl distribution needs to be unpacked. Starting...");
  85.  
  86.             using (var zip = new ZipFile(perlarchive))
  87.             {
  88.                 zip.ExtractAll(Perlfolder,
  89.                     ExtractExistingFileAction.DoNotOverwrite);
  90.  
  91.                 Trace.TraceInformation("Perl distribution is unpacked. Done...");
  92.             }
  93.         }
  94.            
  95.     }
  96. }



Espero que os sea de utilidad.


Responder al tema  [ 1 mensaje ] 

Reglas del Foro
No puedes abrir nuevos temas en este Foro
No puedes responder a temas en este Foro
No puedes editar tus mensajes en este Foro
No puedes borrar tus mensajes en este Foro
No puedes enviar adjuntos en este Foro

Publicidad

Socializa

Síguenos por Twitter

Suscríbete GRATUITAMENTE al Boletín de Perl en Español

Saltar a:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Traducción al español por Huan Manwë para phpbb-es.com
phpBB SEO