Esempio n. 1
0
        private void btnPutBlobs_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
               string filename = txtBlobLocation.Text;
               if (!File.Exists(filename))
            MessageBox.Show(string.Format("{0} is not a valid file", filename), "Error with file", MessageBoxButtons.OK, MessageBoxIcon.Error);
               else
               {
             if (cbBlobs.Text == string.Empty)
               //     MessageBox.Show("You must specify a blob name!", "Blob name missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
               cbBlobs.Text = new FileInfo(filename).Name;
             //else
             {
               byte[] blobArray = FileToByteArray(filename);

               AzureBlobStorage abs = new AzureBlobStorage(txtAccount.Text, string.Format("http://{0}.blob.core.windows.net", txtAccount.Text), txtSharedKey.Text, "SharedKey");
               azureResults ar = abs.PutBlob(blobArray.Length, getMimeType(filename), blobArray, cbBlobContainers.Text, cbBlobs.Text, new Hashtable(), (chkPageBlob.Checked ? AzureBlobStorage.BlobType.PageBlob : AzureBlobStorage.BlobType.BlockBlob));
               ProcessResults(ar);
             }
               }
               this.Cursor = Cursors.Default;
        }
Esempio n. 2
0
 void ProcessDirectory(AzureBlobStorage abs, System.Collections.Hashtable metadata, string DirectoryPath, string startDirectory)
 {
     foreach(string fileName in Directory.GetFiles(DirectoryPath, FileFilter))
        {
     FileInfo fi = new FileInfo(fileName);
     // check whether a file has archive attribute
     bool isArchive = ((File.GetAttributes(fileName) & FileAttributes.Archive) == FileAttributes.Archive);
     if ((ArchiveAttributes && isArchive) || !ArchiveAttributes) // || (FilterOut != string.Empty && file))
     {
       string blobname = fi.Name;
       if (Directories)
     blobname = fileName.Replace(startDirectory, "").Replace(@"\", "/");
       if (blobname.StartsWith("/"))
     blobname = blobname.Substring(1);
       azureResults ar = abs.PutBlob(fi.Length, GetMimeType(fi.Extension),
        File.ReadAllBytes(fileName), Container, blobname, metadata);
       if (ar.Succeeded)
       {
     Console.WriteLine("Loaded: {0}", ar.Url);
     if (ArchiveAttributes)
       File.SetAttributes(fileName, File.GetAttributes(fileName) & ~(FileAttributes.Archive));
       }
       else
     Console.WriteLine("Error loading {0}\r\n\tStatus:{1}\r\n\r\n", blobname, ar.StatusCode);
     }
     if (ArchiveAttributes && !isArchive && verbose)
       Console.WriteLine("ArchiveAttribute Not Set on {0}", fileName);
        }
        foreach(string subdirectory in Directory.GetDirectories(DirectoryPath))
        {
     ProcessDirectory(abs,metadata, subdirectory, startDirectory );
        }
 }