Exemple #1
0
 private void btnDeleteContainer_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
        AzureBlobStorage abs = new AzureBlobStorage(txtAccount.Text, string.Format("http://{0}.blob.core.windows.net", txtAccount.Text), txtSharedKey.Text, "SharedKey");
        azureResults ar = abs.Containers(cmdType.delete, cbBlobContainers.Text, new Hashtable());
        ProcessResults(ar);
        this.Cursor = Cursors.Default;
 }
Exemple #2
0
 public void RetrieveBlobs()
 {
     System.Collections.Hashtable metadata = new System.Collections.Hashtable();
        AzureBlobStorage abs = new AzureBlobStorage(Account, EndPoint, SharedKey, "SharedKey");
        if (Container == "*")
        {
     azureResults ar = abs.GetContainerList("");
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(ar.Body);
     XmlNodeList xnl = xdoc.SelectNodes("//Name");
     foreach (XmlNode xn in xnl)
     {
      ProcessContainer(abs, metadata, StartingDirectory,  xn.InnerText);
     }
        }
        else
        {
     azureResults ar = abs.Containers(cmdType.get, Container, new System.Collections.Hashtable());
     if (!ar.Succeeded)
      ar = abs.Containers(cmdType.post, Container, metadata);
     ProcessContainer(abs, metadata, StartingDirectory, Container);
        }
 }
Exemple #3
0
 private void btnCreateContainer_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
        AzureBlobStorage abs = new AzureBlobStorage(txtAccount.Text, string.Format("http://{0}.blob.core.windows.net", txtAccount.Text), txtSharedKey.Text, "SharedKey");
        Hashtable htMetaData = new Hashtable();
        htMetaData.Add("x-ms-meta-createdBy", "Finsel.AzureCommands");
        azureResults ar = abs.Containers(cmdType.put, cbBlobContainers.Text, htMetaData);
        ProcessResults(ar);
        this.Cursor = Cursors.Default;
 }
Exemple #4
0
 public void LoadBlobs()
 {
     if (FileFilter == string.Empty || FileFilter == null)
       FileFilter = "*";
        System.Collections.Hashtable metadata = new System.Collections.Hashtable();
        metadata.Add("loadingSource", "finsel.AzureBlobLoader");
        metadata.Add("dateLoaded",DateTime.Now.ToShortDateString());
        azureResults ar = new azureResults();
        AzureBlobStorage abs = new AzureBlobStorage(Account, EndPoint, SharedKey, "SharedKey");
        if (Container == "*")
        {
     foreach (string newContainer in Directory.GetDirectories(StartingDirectory))
     {
      Container = newContainer.Replace(StartingDirectory,"");
      if (Container.StartsWith(@"\")) Container = Container.Substring(1);
      ar = abs.Containers(cmdType.get, Container, new System.Collections.Hashtable());
      if (!ar.Succeeded)
       ar = abs.Containers(cmdType.put, Container, metadata);
      if(ar.Succeeded)
       ProcessDirectory(abs, metadata, newContainer, newContainer );
     }
     // Process $root
     ar = abs.Containers(cmdType.get, "$root%", new System.Collections.Hashtable());
     if (ar.Succeeded)
     ProcessDirectory(abs, metadata, StartingDirectory, "$root");
        }
        else
        {
     ar = abs.Containers(cmdType.get, Container, new System.Collections.Hashtable());
     if (!ar.Succeeded)
      ar = abs.Containers(cmdType.put, Container, metadata);
     ProcessDirectory(abs, metadata, StartingDirectory, StartingDirectory);
        }
 }
        public void ProcessRequest(HttpContext context)
        {
            string accountName = string.Empty;
              string sharedKey = string.Empty;
              string blobTypeOfCall = string.Empty;

              string containerName = string.Empty;
              string blobName = string.Empty;
              string leaseAction = string.Empty;
              string leaseID = string.Empty;
              string eTag = string.Empty;
              string mimicDirectories = string.Empty;
              string includeSnapshots = string.Empty;
              string includeUncommitted = string.Empty;

              if (context.Request.Params.AllKeys.Contains("accountname"))
            accountName = context.Request.Params["accountname"].ToString();
              if (context.Request.Params.AllKeys.Contains("sharedkey"))
            sharedKey = context.Request.Params["sharedkey"].ToString().Replace(" ", "+");
              if (context.Request.Params.AllKeys.Contains("blobtypeofcall"))
            blobTypeOfCall = context.Request.Params["blobtypeofcall"].ToString();
              if (context.Request.Params.AllKeys.Contains("containername"))
            containerName = context.Request.Params["containername"].ToString();
              if (context.Request.Params.AllKeys.Contains("blobname"))
            blobName = context.Request.Params["blobname"].ToString();
              if (context.Request.Params.AllKeys.Contains("leaseaction"))
            leaseAction = context.Request.Params["leaseaction"].ToString().ToLower();
              if (context.Request.Params.AllKeys.Contains("leaseid"))
            leaseID = context.Request.Params["leaseid"].ToString();
              if (context.Request.Params.AllKeys.Contains("etag"))
            eTag = context.Request.Params["etag"].ToString();
              if (context.Request.Params.AllKeys.Contains("mimicdirectories"))
            mimicDirectories = "1";
              if (context.Request.Params.AllKeys.Contains("includesnapshots"))
            includeSnapshots = "1";
              if (context.Request.Params.AllKeys.Contains("includeuncommitted"))
            includeUncommitted = "1";

              string retVal = string.Empty;
              string retValType = string.Empty;
              retValType = "text/xml";

              Hashtable ht = new Hashtable();

              foreach (string key in context.Request.Params.AllKeys)
              {
            if (key.StartsWith("x-ms-meta-"))
              if (ht.ContainsKey(key))
            ht[key] = string.Format("{0},{1}", ht[key].ToString(), context.Request.Params[key].ToString());
              else
            ht.Add(key, context.Request.Params[key].ToString());
              }

              azureResults ar = new azureResults();
              Finsel.AzureCommands.AzureBlobStorage abs = new Finsel.AzureCommands.AzureBlobStorage(accountName,
            string.Format("http://{0}.blob.core.windows.net", accountName), sharedKey,
            "SharedKey");

              switch (blobTypeOfCall.ToLower())
              {
            case "addblobmetadata":
              ar = abs.MetaData(cmdType.put, containerName, blobName, ht);
              retVal = processAzureResults(ar);
              break;
            case "addcontainermetadata":
              ar = abs.MetaData(cmdType.put, containerName, "", ht);
              retVal = processAzureResults(ar);
              break;
            case "copyblob":
            //ar=abs.CopyBlob(
            case "createcontainer":
              ht.Add("x-ms-meta-CreatedBy", "Finsel.AzureCommands");
              ar = abs.Containers(cmdType.put, containerName, ht);
              retVal = processAzureResults(ar);
              break;
            case "deleteblob":
              ar = abs.DeleteBlob(containerName, blobName);
              retVal = processAzureResults(ar);
              break;
            case "deletecontainer":
              ar = abs.Containers(cmdType.delete, containerName, new Hashtable());
              retVal = processAzureResults(ar);
              break;
            case "deleteblobmetadata":
              ar = abs.MetaData(cmdType.put, containerName, blobName, null);
              retVal = processAzureResults(ar);
              break;
            case "deletecontainermetadata":
              ar = abs.MetaData(cmdType.put, containerName, "", null);
              retVal = processAzureResults(ar);
              break;
            case "displayblobmetadata":
              ar = abs.MetaData(cmdType.get, containerName, blobName, null);
              retVal = processAzureResults(ar);
              break;
            case "displaycontainermetadata":
              ar = abs.MetaData(cmdType.get, containerName, "", null);
              retVal = processAzureResults(ar);
              break;
            case "getblob":
              break;
            case "getbloblist":
              string parameterList = string.Empty;
              if (mimicDirectories == "1")
            if (blobName == string.Empty)
              parameterList = "delimiter=/";
            else
              parameterList = string.Format("prefix={0}&delimiter={1}", (blobName == string.Empty ? "/" : blobName), "/");
              if (includeSnapshots == "1")
              {
            if (parameterList != string.Empty)
              parameterList = string.Format("{0}&include=snapshots", parameterList);
            else parameterList = "include=snapshots";
              }
              if (includeUncommitted == "1")
              {
            if (parameterList != string.Empty)
              parameterList = string.Format("{0}&include=uncommittedblobs", parameterList);
            else parameterList = "include=uncommittedblobs";
              }
              ar = abs.GetBlobList(containerName, parameterList);
              retVal = processAzureResults(ar);
              break;
            case "getcontainerlist":
              ar = abs.GetContainerList(containerName);
              retVal = processAzureResults(ar);
              break;
            case "leaseblob":
              AzureBlobStorage.BlobLease bl;
              switch (leaseAction)
              {
            case "acquirelease": bl = AzureBlobStorage.BlobLease.acquireLease; break;
            case "breaklease": bl = AzureBlobStorage.BlobLease.breakLease; break;
            case "releaselease": bl = AzureBlobStorage.BlobLease.releaseLease; break;
            case "renewlease": bl = AzureBlobStorage.BlobLease.renewLease; break;
            default: bl = AzureBlobStorage.BlobLease.acquireLease; break;
              }

              ar = abs.LeaseBlob(containerName, blobName, bl, leaseID);
              retVal = processAzureResults(ar);
              break;
            case "makecontainerprivate":
              ar = abs.SetContainerAccess(containerName, false);
              retVal = processAzureResults(ar);
              break;
            case "makecontainerpublic":
              ar = abs.SetContainerAccess(containerName, true);
              retVal = processAzureResults(ar);
              break;

            case "snapshotblob":
              ar = abs.SnapshotBlob(containerName, blobName);
              retVal = processAzureResults(ar);
              break;
            case "verifyblob":
              ar = abs.CheckBlobCache(containerName, blobName, eTag);
              retVal = processAzureResults(ar);
              break;
            default:
              retVal = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
            <html xmlns='http://www.w3.org/1999/xhtml' >
            <head>
            <title>Azure Architect Azure Blob Storage Handler Form</title>
            </head>
            <body>
            <form action='absHandler.ashx' method='post'>
            <table border='1'>
            <tr>
            <td>Account</td><td><input name='accountname' maxlength='100' /></td>
            </tr><tr>
            <td>Shared Key</td><td><input name='sharedkey' maxlength='100' /></td>
            </tr><tr>
            <td>Container Name</td><td><input name='containername' maxlength='100' /></td>
            </tr><tr>
            <td>Blob Name</td><td><input name='blobname' maxlength='1240' /></td>
            </tr><tr>
            <td>Type of call</td><td>
            <select name='blobtypeofcall'>
            <option>AddContainerMetadata</option>
            <option value='CreateContainer'>CreateContainer</option>
            <option value='DeleteBlob'>DeleteBlob</option>
            <option value='DeleteContainer'>DeleteContainer</option>
            <option value='DeleteContainerMetadata'>DeleteContainerMetadata</option>
            <option value='DisplayContainerMetadata'>DisplayContainerMetadata</option>
            <option value='GetBlob'>GetBlob</option>
            <option value='GetBlobList'>GetBlobList</option>
            <option value='GetContainerList'>GetContainerList</option>
            <option value='MakeContainerPrivate'>MakeContainerPrivate</option>
            <option value='MakeContainerPublic'>MakeContainerPublic</option></select>
            </td>
            </tr><tr>
            <td colspan='2'><input type='submit' /></td>
            </tr>
            </table>
            </form>
            </body>
            </html>";
              retValType = "text/html";
              //          retVal = @"<?xml version='1.0' encoding='utf-8' ?>
              //<ValidFormat>
              //  <!-- Post format -->
              //  <AccountName />
              //  <SharedKey />
              //  <ContainerName />
              //  <Blobname />
              //  <BlobTypeOfCall>
              //    <AddContainerMetadata />
              //    <CreateContainer />
              //    <DeleteBlob />
              //    <DeleteContainer />
              //    <DeleteContainerMetadata />
              //    <DisplayContainerMetadata />
              //    <GetBlob />
              //    <GetBlobList />
              //    <GetContainerList />
              //    <MakeContainerPrivate />
              //    <MakeContainerPublic />
              //  </BlobTypeOfCall>
              //</ValidFormat>";
              break;
              }

              context.Response.ContentType = retValType;
              context.Response.Write(retVal);
        }
 private void mnuNewBlobContainer_Click(object sender, RoutedEventArgs e)
 {
     newContainer nc = new newContainer();
     nc.ShowDialog();
     if (!nc.cancelled)
     {
         this.Cursor = Cursors.Wait;
         AzureBlobStorage abs = new AzureBlobStorage(azAccount, string.Format("http://{0}.blob.core.windows.net", azAccount), azSharedKey, "SharedKey");
         Hashtable htMetaData = new Hashtable();
         htMetaData.Add("x-ms-meta-createdBy", "Finsel.AzureCommands");
         azureResults ar = abs.Containers(cmdType.put, nc.newContainerName, htMetaData);
         ProcessResults(ar);
         if (ar.Succeeded)
         {
             TreeViewItem tvI = new TreeViewItem();
             blobContainer bc = new blobContainer();
             bc.ContainerName = nc.newContainerName;
             tvI.Header = bc.ContainerName;
             tvI.Tag = bc;
             tvI.Items.Add("*");
             tvBlobs.Items.Add(tvI);
         }
         this.Cursor = Cursors.Arrow;
     }
 }
 private void mnuDeleteContainer_Click(object sender, RoutedEventArgs e)
 {
     if (tvBlobs.SelectedItem != null)
     {
         TreeViewItem item = (TreeViewItem)tvBlobs.SelectedItem;
         if (item.Tag is blobContainer)
         {
             DeleteContainer dc = new DeleteContainer();
             dc.txtNewContainerName.Text = ((blobContainer)item.Tag).ContainerName;
             dc.ShowDialog();
             if (!dc.cancelled)
             {
                 this.Cursor = Cursors.Wait;
                 AzureBlobStorage abs = new AzureBlobStorage(azAccount, string.Format("http://{0}.blob.core.windows.net",
                     azAccount), azSharedKey, "SharedKey");
                 azureResults ar = abs.Containers(cmdType.delete, dc.txtNewContainerName.Text, new Hashtable());
                 ProcessResults(ar);
                 if (ar.Succeeded)
                 {
                     tvBlobs.Items.Remove(item);
                 }
                 this.Cursor = Cursors.Arrow;
             }
         }
         else if (item.Tag is blobPrefix)
         { }
         else if (item.Tag is blobData)
         { }
     }
 }