2015-09-30 2 views
1

comment puis-je reprendre mon transfert dans Azure à partir de la dernière déconnexion? en cas d'échec du réseau, je peux continuer, mais ce que je dois faire après une panne de courant lorsque mon système est redémarré. comment puis-je sauvegarder l'état actuel de mon logiciel (qui télécharge le fichier sur Azure). donc si je sauve mon état je peux le reprendre du dernier point. J'utilise ce code pour le téléchargement. Le code est d'Internet.Reprendre le téléversement avec Azure après une coupure de courant

private void UploadBigFile(){ 
int count = 0, bufferSize = 40 * 1024, blockCount = 0; 
string filePath = @"D:\Dua.zip"; 
List<string> blockIds = new List<string>(); 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); 
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 
CloudBlobContainer container = blobClient.GetContainerReference("mytestcontainer"); 
container.CreateIfNotExists(); 
byte[] bufferBytes = new byte[bufferSize]; 
string fileName = Path.GetFileName(filePath); 
CloudBlockBlob blob = container.GetBlockBlobReference(fileName); 
using (FileStream fileStream = File.OpenRead(filePath)){ 
blockCount = (int)(fileStream.Length/bufferSize) + 1; 
Int64 currentBlockSize = 0; 
int currentCount = blockIds.Count(); 
fileStream.Seek(bufferSize * currentCount, SeekOrigin.Begin); 
for (int i = blockIds.Count; i < blockCount; i++){ 
currentBlockSize = bufferSize; 
if (i == blockCount - 1){ 
currentBlockSize = fileStream.Length - bufferSize * i; 
bufferBytes = new byte[currentBlockSize];} 
if (currentBlockSize == 0) break; 
fileStream.Read(bufferBytes, 0, Convert.ToInt32(currentBlockSize)); 
using (MemoryStream memoryStream = new MemoryStream(bufferBytes)){ 
try{ 
string blockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())); 
blob.PutBlock(blockId, memoryStream, null); 
blockIds.Add(blockId); 
count++; 
label1.Text = Convert.ToString(count); 
label1.Refresh();} 
catch (Exception){}}}} 
blob.PutBlockList(blockIds);} 

Répondre

1

Si vous garder la trace des blocs, vous pouvez enregistrer la position, puis redémarrez-le. Voici un article de blog sur uploading large files; la fin de cela dit exactement comment faire ce que vous essayez de faire.