iT Synergy Blogs

Growing Innovation - Soluciones a problemas reales

  • Facebook
  • Instagram
  • LinkedIn
  • Phone
  • Twitter
  • YouTube

Copyright © 2025 · iT Synergy·

Cómo subir una carpeta local a un contenedor de Azure blob storage ?
Cómo subir una carpeta local a un contenedor de Azure blob storage ? avatar

May 19, 2016 By Jimmy Quejada Meneses Leave a Comment

Hola amigos!

En días pasados en un proyecto que desarrollabamos con el equipo de iT Synergy del proyecto CPE Windows App Prendo Y Aprendo me encontré con el desafío de desarrollar la funcionalidad para subir un directorio (carpeta) desde el pc del usuario a un contenedor blob storage de Azure. Aunque encontré en internet algunos links base no lograban la implementación completa o tenían referencias obsoletas. Agradezco a las pesonas que con sus post me ayudaron para resolver el problema. 

En este post les comparto la clase base de la implementación desarrollada en C#. El proyecto fue implementado con ASP.NET MVC 5.

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;

namespace CPE.PrendoYAprendo.ContentManager.Models
{
/// <summary>
/// Blob storage manager class
/// </summary>
public class BlobManager
{
private readonly CloudStorageAccount _account;
private readonly CloudBlobClient _blobClient;

/// <summary>
/// Initializes a new instance of the <see cref=”BlobManager” /> class.
/// </summary>
/// <param name=”connectionStringName”>Name of the connection string in app.config or web.config file.</param>
public BlobManager(string connectionStringName)
{
_account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[“StorageConnectionString”].ToString());

_blobClient = _account.CreateCloudBlobClient();

IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(2), 10);
_blobClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy;

}

/// <summary>
/// Updates or created a blob in Azure blobl storage
/// </summary>
/// <param name=”containerName”>Name of the container.</param>
/// <param name=”blobName”>Name of the blob.</param>
/// <param name=”content”>The content of the blob.</param>
/// <returns></returns>
public bool PutBlob(string containerName, string blobName, byte[] content)
{
return ExecuteWithExceptionHandlingAndReturnValue(
() =>
{
CloudBlobContainer container = _blobClient.GetContainerReference(containerName);
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
// Primero se convierte el array a stream
//Stream stream = new MemoryStream(content);
using (Stream stream = new MemoryStream(content))
{
blob.UploadFromStream(stream);
}
});
}

/// <summary>
/// Creates the container in Azure blobl storage
/// </summary>
/// <param name=”containerName”>Name of the container.</param>
/// <returns>True if contianer was created successfully</returns>
public bool CreateContainer(string containerName)
{
return ExecuteWithExceptionHandlingAndReturnValue(
() =>
{
CloudBlobContainer container = _blobClient.GetContainerReference(containerName);
container.Create();
});
}

/// <summary>
/// Checks if a container exist.
/// </summary>
/// <param name=”containerName”>Name of the container.</param>
/// <returns>True if conainer exists</returns>
public bool DoesContainerExist(string containerName)
{
bool returnValue = false;
ExecuteWithExceptionHandling(
() =>
{
IEnumerable<CloudBlobContainer> containers = _blobClient.ListContainers();
returnValue = containers.Any(one => one.Name == containerName);
});
return returnValue;
}

/// <summary>
/// Uploads the directory to blobl storage
/// </summary>
/// <param name=”sourceDirectory”>The source directory name.</param>
/// <param name=”containerName”>Name of the container to upload to.</param>
/// <returns>True if successfully uploaded</returns>
public bool UploadDirectory(string sourceDirectory, string containerName)
{
string[] s = containerName.Split(‘/’);
string sContainerName = s[0];
string sFolderName = s[1];

return UploadDirectory(sourceDirectory, sContainerName, sFolderName);
//return UploadDirectory(sourceDirectory, containerName, string.Empty);

}

private bool UploadDirectory(string sourceDirectory, string containerName, string prefixAzureFolderName)
{
return ExecuteWithExceptionHandlingAndReturnValue(
() =>
{
if (!DoesContainerExist(containerName))
{
CreateContainer(containerName);
}
var folder = new DirectoryInfo(sourceDirectory);
var files = folder.GetFiles();
foreach (var fileInfo in files)
{
string blobName = fileInfo.Name;
if (!string.IsNullOrEmpty(prefixAzureFolderName))
{
blobName = prefixAzureFolderName + “/” + blobName;
}
PutBlob(containerName, blobName, File.ReadAllBytes(fileInfo.FullName));
}
var subFolders = folder.GetDirectories();
foreach (var directoryInfo in subFolders)
{
var prefix = directoryInfo.Name;
if (!string.IsNullOrEmpty(prefixAzureFolderName))
{
prefix = prefixAzureFolderName + “/” + prefix;
}
UploadDirectory(directoryInfo.FullName, containerName, prefix);
}
});
}

private void ExecuteWithExceptionHandling(Action action)
{
try
{
action();
}
catch (StorageException ex)
{
var requestInformation = ex.RequestInformation;
if ((int)(System.Net.HttpStatusCode)requestInformation.HttpStatusCode != 409)
{
throw;
}
}
}

private bool ExecuteWithExceptionHandlingAndReturnValue(Action action)
{
try
{
action();
return true;
}
catch (StorageException ex)
{
var requestInformation = ex.RequestInformation;
if ((int)(System.Net.HttpStatusCode)requestInformation.HttpStatusCode == 409)
{
return false;
}
throw;
}
}
}
}

Espero les sea de ayuda.

Cordial saludo,

 

 

 

Filed Under: Desarrollo de software Tagged With: ASP.NET, Azure, Blob Storage, C#, MVC 5

Acceder desde Visual a una BD que está en Azure
Acceder desde Visual a una BD que está en Azure avatar

August 15, 2013 By Diana Díaz Grijalba Leave a Comment

Después de crear el Cloud Service se ingresa a la base de datos asociada a dicho servicio, este se encuentra como Linked Resource. Dar doble Click sobre él.

1

Se muestra la pantalla de administración. Empezaremos configurando las reglas del firewall.

2

Allí le damos permisos a la IP que está asignada a nuestro equipo para que podamos conectarnos a la Base de Datos.

3

Después hay que verificar los Connection Strings

4

Hay que copiar el ADO.NET5

Ahora en Visual Studio, se va a Server Explorer y luego a Data Connections, luego se adiciona una nueva conexión

6

Hay que ingresar los datos de Server, User y Password.

Server: __________.database.windows.net

User: _______________

Password: _________

7

Verificar que quede conectada la base de datos.

8

Filed Under: Azure Tagged With: Acceso BD, Azure, Visual

BizTalk 2010 Beta y ESB Toolkit 2.1 Beta Disponibles!!
BizTalk 2010 Beta y ESB Toolkit 2.1 Beta Disponibles!! avatar

May 25, 2010 By Marco Antonio Hernández Prado Leave a Comment

El 20 de Mayo en el evento virtual Application Infrastructure Virtual Launch se realizaron varios anuncios, la disponibilidad de BizTalk 2010 Beta (lo pueden descargar aquí) y Windows Server AppFabric RC (lo pueden descargar aquí).

Afortunadamente llego esta versión ya que estoy migrando mi portátil antiguo a mi nuevo laptop, monte Windows Server 2008 R2, la idea con este SO era tener MV para todos los clientes y en mi maquina si tener mis propios laboratorios, instale VS 2010 Ultimate y SQL 2008 R2, desafortunadamente BizTalk 2009 realmente no soporta SQL 2008 R2 ver información de Ben Cline quien ya intento realizar este tipo de instalación.

Volviendo a BizTalk 2010, el grupo esta vez nos entregó la documentación de los productos, tenemos disponibilidad de las siguientes descargas:

  • BizTalk ESB Toolkit 2.1
  • BizTalk Server 2010 Operations Manager 2007 SP1
  • BizTalk Accelerators 2010
  • BizTalk Adapter Pack 2010
  • BizTalk LOB Adapters 2010
  • BizTalk WCF LOB Adapter SDK 2010
  • Host Integration Server 2010

 

Documentación

La documentación va a ser vital para poder retroalimentar a Microsoft, aquí los links:

  • BizTalk Server 2010 Documentation
  • Microsoft BizTalk Adapter Pack 2010 Installation Guides
  • WCF LOB Adapter SDK
  • BizTalk Server 2010 Management Pack
  • Microsoft BizTalk Adapters for Enterprise Applications
  • Microsoft BizTalk 2010 Accelerator for SWIFT (A4SWIFT)
  • Microsoft BizTalk Server 2010 FileAct and InterAct Adapters
  • Microsoft BizTalk 2010 Accelerator for HL7 (BTAHL7)
  • Microsoft BizTalk 2010 Accelerator for RosettaNet (BTARN)
  • Microsoft BizTalk Server 2010 ESB Toolkit
  • Host Integration Server 2010
  • BizTalk RFID Server 2010 and BizTalk RFID Mobile 2010
  • Microsoft Windows Communication Foundation (WCF) Line of Business (LOB) Adapter SDK 2010 Installation Guide – Beta

 

Bueno creo que con esto tenemos para probar ahora si con la nueva Ola que ofrece Microsoft, realmente han ido rápido con las actualizaciones de BizTalk, para 2011 no van a ver actualizaciones de BizTalk, acordémonos que el gran cambio va a ser con la versión BizTalk vNext.

Como pruebas voy a realizar la migración de un proyecto en producción que se han desarrollado bajo ESB 2.0 con una arquitectura robusta y que actualmente es estable en producción, vamos a ver cómo se comporta todo ya que en estos proyectos hemos usado BizTalk, ESB, Portal de ESB, Itinerarios, BRE, WCF LOB Adapter, BizTalk Adapters, etc una gran cantidad de herramientas a revisar!!!, ojala disfruten de este Beta

Filed Under: BizTalk Tagged With: Azure, BizTalk

Team


Marco
Antonio Hernández

Jaime
Alonso Páez

Luis
Carlos Bernal

Ana
María Orozco

Juan
Camilo Zapata

Carlos
Alberto Rueda

Sonia
Elizabeth Soriano

Diana
Díaz Grijalba

Alexandra
Bravo Restrepo

Bernardo
Enrique Cardales

Juan
Alberto Vélez

Jhon
Jairo Rodriguez

Diana
Paola Padilla

Gustavo
Adolfo Echeverry

Yully
Arias Castillo

Carlos
Andrés Vélez

Brayan
Ruiz

Jesús
Javier Hernández

Alejandro
Garcia Forero

Natalia
Zartha Suárez

Josué
Leonardo Bohórquez

Oscar
Alberto Urrea

Odahir
Rolando Salcedo

Jimmy
Quejada Meneses

Juan
Mauricio García

Mario
Andrés Cortés

Eric
Yovanny Martinez

Carolina
Torres Rodríguez

Tag Cloud

.NET (9) 940px (1) Analysis Services mdx (1) An attempt was made to load a program with an incorrect format. (1) ASP.NET MVC (1) Azure (3) Backup (1) BAM (7) BAM API (1) BAMTraceException (2) BI (3) BizTalk (24) Business Intelligence (6) C# (2) caracteristicas de publicacion (2) Content Editor (3) ESB (15) ESB Toolkit (3) General (4) habilitar caracteristicas (3) indexes (2) Integration Services (2) Master Page (3) MDX (2) MSE (11) net.tcp (2) Office 365 (2) Oracle (2) Performance Point (2) Public Website (2) Receive Location (2) SDK (2) Servicio Web (2) Sharepoint 2010 (2) SharePoint 2013 (4) SharePoint Online (2) SOA (8) Soap Fault (2) Sort Months MDX (2) SQL Server (2) Visual (2) Visual Studio 2010 (2) WCF (19) Windows (3) Windows 8 (17)

Categories

  • .NET (33)
  • Analysis Services (1)
  • ASP.NET MVC (2)
  • Azure (7)
  • BAM (9)
  • BAM PrimaryImport (3)
  • BigData (1)
  • BizTalk (77)
  • BizTalk 2010 configurations (57)
  • BizTalk Application (60)
  • BizTalk Services (13)
  • Business Intelligence (4)
  • Cloud (3)
  • CMD (1)
  • CodeSmith – NetTiers (2)
  • CommandPrompt (1)
  • CRM OptionSet mapping component (1)
  • Desarrollo de software (6)
  • develop (6)
  • developers (3)
  • DropBox (1)
  • Dynamics (1)
  • Enterprise Architect (1)
  • Entity Framework (1)
  • Errores BizTalk (2)
  • ESB (27)
  • ETL (1)
  • Event Viewer (1)
  • Excel Services (1)
  • Foreach loop container (1)
  • General (4)
  • Gerencia de Proyectos (2)
  • Google (1)
  • Grouped Slices (1)
  • Human Talent (1)
  • IIS (4)
  • Integración (6)
  • Integration Services (3)
  • KingswaySoft (1)
  • Lync (1)
  • MSE (13)
  • Office 365 (2)
  • Oracle Data Adapter (2)
  • Performance Point (4)
  • Picklist (1)
  • Pivot Table (1)
  • Procesos (1)
  • Pruebas (1)
  • Public Website (2)
  • Reports (1)
  • SCRUM (1)
  • SDK (2)
  • SEO (1)
  • Servicios (2)
  • Sharepoint (9)
  • SharePoint 2010 (10)
  • SharePoint 2013 (4)
  • SharePoint Online (2)
  • SharpBox (1)
  • Shortcuts (1)
  • Sin categoría (1)
  • SOA (50)
  • SQL (5)
  • SQL Server (3)
  • SQL Server Management Studio (1)
  • SSIS (3)
  • SSL (1)
  • SSO (1)
  • Tracking Profile Editor (2)
  • Twitter (1)
  • Uncategorized (1)
  • Virtual Network (2)
  • Visual Studio 11 (1)
  • Visual Studio 2010 (2)
  • Visual Studio Online (1)
  • VMware (2)
  • WCF (24)
  • Web (1)
  • Web Api (1)
  • Windows (5)
  • Windows 8 (11)
  • Windows Azure (2)
  • Windows Live Write (1)
  • Windows Phone (7)
  • Windows Phone 8 (1)
  • Windows Scheduler (1)
  • windows8 (2)
  • WindowsRT (3)
  • WP7 SDK (1)

Manage

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org