1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
CloudQueueMessage msg = queue.GetMessage();
if ( msg != null ) {
string path = msg.AsString;
// Récupére l'archive en local
CloudBlob blobArchive = containerTemp.GetBlobReference( path );
LocalResource sto = RoleEnvironment.GetLocalResource( "LocalStorageTemp" );
string archiveFileName = Path.Combine( sto.RootPath, "archive.zip" );
blobArchive.DownloadToFile( archiveFileName );
// Extraction de l'archive sur le LocalStorage et récupération de la liste de tout les fichiers images
ExtractArchive( archiveFileName, sto.RootPath );
string[] tabImageFile = Directory.GetFiles( sto.RootPath, "*.jpg", SearchOption.AllDirectories );
File.Delete( archiveFileName );
// Parcours de toutes les images pour ajout dans le Cloud Storage
foreach ( string imageFile in tabImageFile ) {
string fileName = Path.GetFileName( imageFile );
CloudBlob blobFullSize = containerPhotos.GetBlobReference( fileName );
// Download the image
FileStream image = File.OpenRead( imageFile );
image.Seek( 0, SeekOrigin.Begin );
// upload original image and thumbnail image
blobFullSize.UploadFromStream( image );
blobFullSize.Properties.ContentType = "image/jpeg";
blobFullSize.SetProperties();
// remove image file
File.Delete( imageFile );
}
// Delete the message on the queue, and the temp blob
queue.DeleteMessage( msg );
blobArchive.Delete();
Trace.WriteLine( path + " has been processed" );
} |
Partager