コード例 #1
0
        /// <summary>
        /// Create a new AzureCommands object with default settings
        /// </summary>
        /// <param name="account">The account is generally the first part of the Endpoint.</param>
        /// <param name="endPoint">The Endpoint for Azure Table Storage as defined for your account</param>
        /// <param name="sharedKey">The SharedKey for access</param>
        /// <param name="keyType">Shared</param>
        public AzureQueueStorage(string account, string endPoint, string sharedKey, string keyType)
        {
            pAuth = new Authentication(account, string.Format(EndpointFormat, account), sharedKey);

              ad = new azureDirect(pAuth);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: CarpDeus/Azure-Commands
 private void ProcessGeneric(cmdType cmd)
 {
     this.Cursor = Cursors.WaitCursor;
        azureResults ar = new azureResults();
        try
        {
     azureDirect  ad= new azureDirect(txtAccount.Text, txtEndpoint.Text, txtSharedKey.Text, "SharedKey");
     Hashtable ht = new Hashtable();
     string[] AllData = txtGenericHeaders.Text.Split("\n".ToCharArray());
     foreach (string metadataDetail in AllData)
     {
      string[] detail = metadataDetail.Split(":".ToCharArray());
      string key = "";
      string value = "";
      if (detail[0] != string.Empty)
      {
       key = detail[0];
       if (metadataDetail.Contains(":"))
        value = detail[1];
       ht.Add(key, value.Replace("\r",""));
      }
     }
     ar= ad.ProcessRequest(cmd, txtURI.Text, new System.Text.ASCIIEncoding().GetBytes(txtGenericBody.Text), ht);
     ProcessResults(ar);
        }
        catch (Exception ex)
        {
     //Literal1.Text = string.Format("<textarea id=\"txtResponse\" name=\"S1\">{0}</textarea>", ex.ToString()); //.Replace("<", "&lt").Replace(">", "&gt;");
     lblError.Text = ex.ToString();
     lblStatus.Text = "Error:";
     lblCalledURL.Text = "";
        }
        this.Cursor = Cursors.Default;
 }
コード例 #3
0
        /// <summary>
        /// PutBlob creates/updates a blob within Microsoft's Azure Blob Storage
        /// </summary>
        /// <param name="ContentLength">How many bytes are in the Content</param>
        /// <param name="ContentType">Content type of the blob. application/bin is used by default if nothing else is passed in</param>
        /// <param name="Content">A byte array representing the blob being stored.</param>
        /// <param name="containerName">The name of the container to store the blob in.</param>
        /// <param name="blobName">The name of the blob. Can inlcude paths (/path/blob.txt, for instance)</param>
        /// <param name="htMetaData">A hashtable containing the Name-Value pairs of MetaData.</param>
        /// <returns></returns>
        public azureResults PutBlobWithBlocks(string ContentType, byte[] Content, string containerName, string blobName, Hashtable htMetaData, int BlockLength, int StartBlock)
        {
            azureResults retVal = new azureResults();
              try
              {
            StringBuilder sb = new StringBuilder();
            string sendBody = string.Empty;
            string rtnBody = string.Empty;

            string requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}{1}/{2}", auth.EndPoint, containerName, blobName);
            requestDate = DateTime.UtcNow;

            string blockURI = string.Empty;
            Hashtable htHeaders = htMetaData;
            htHeaders.Add("Content-Type", ContentType);
            azureDirect ad = new azureDirect(auth.Account, auth.EndPoint, auth.SharedKey, auth.KeyType);
            int blocksCount = (int)Math.Ceiling((double)Content.Length / BlockLength);
            string[] blockIds = new string[blocksCount];
            int startPosition = StartBlock * BlockLength;
            int blockIdPosition = 0;
            for (int i = StartBlock; i < blocksCount; i++)
            {
              blockIds[blockIdPosition] = Convert.ToBase64String(BitConverter.GetBytes(i));
              blockURI = string.Format("{0}?comp=block&blockid={1}", requestUrl, blockIds[blockIdPosition]);
              blockIdPosition++;
              byte[] blockContent = new byte[BlockLength];
              Array.Copy(Content, startPosition, blockContent, 0, (startPosition + BlockLength > Content.Length ? Content.Length - startPosition : BlockLength));
              retVal = ad.ProcessRequest(cmdType.put, blockURI, blockContent, htHeaders);
              while (retVal.StatusCode != HttpStatusCode.Created)
            retVal = ad.ProcessRequest(cmdType.put, blockURI, blockContent, htHeaders);
              startPosition += BlockLength;
              Console.WriteLine(i);
            }
            blockURI = string.Format("{0}?comp=blocklist", requestUrl);
            StringBuilder sbBlockList = new StringBuilder();
            sbBlockList.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<BlockList>");
            foreach (string id in blockIds)
            {
              sbBlockList.AppendFormat("<Block>{0}</Block>\n", id);
            }
            sbBlockList.Append("</BlockList>");
            retVal = ad.ProcessRequest(cmdType.put, blockURI, new System.Text.ASCIIEncoding().GetBytes(sbBlockList.ToString()), htHeaders);

              }
              catch (HttpException hex)
              {
            retVal.StatusCode = (HttpStatusCode)hex.GetHttpCode();
            retVal.Succeeded = false;
            retVal.Body = hex.GetHtmlErrorMessage();
              }
              catch (Exception ex)
              {
            retVal.StatusCode = HttpStatusCode.SeeOther;
            retVal.Body = ex.ToString();
            retVal.Succeeded = false;
              }
              return retVal;
        }
コード例 #4
0
        /// <summary>
        /// Process Entity Group Transactions against a table by taking an XML block of Entity Data and turning it into Multipart and executing it.
        /// </summary>
        /// <param name="cmd">Method to execute</param>
        /// <param name="tableName">Table to execute the data against</param>
        /// <param name="entityData">Entity Data</param>
        /// <returns>string with results of the group transaction</returns>
        public string entityGroupTransaction(cmdType cmd,string tableName, string entityData)
        {
            int entityCounter = 1;
               StringBuilder sbResults = new StringBuilder();
               StringBuilder sbMultiPart = new StringBuilder();
               string singlePart = string.Empty;
               string PartitionKey = string.Empty;
               string oldPartitionKey = string.Empty;
               string boundaryIdentifier = Guid.NewGuid().ToString();
               string batchIdentifier = Guid.NewGuid().ToString();
               string contentType = string.Format("multipart/mixed; boundary=batch_{0}", boundaryIdentifier);
               azureResults ar = new azureResults();
            DateTime requestDate = DateTime.UtcNow.AddHours(1);

               Hashtable headers = new Hashtable();
               headers.Add("x-ms-version", "2009-04-14");
               headers.Add("Content-Type", contentType);
               azureDirect ad = new azureDirect(auth.Account, "", auth.SharedKey, auth.KeyType);
               XmlDocument msgDoc = new XmlDocument();

               //Instantiate an XmlNamespaceManager object.
               System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(msgDoc.NameTable);
               //Add the namespaces used in books.xml to the XmlNamespaceManager.
               xmlnsManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
               xmlnsManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
               msgDoc.LoadXml(entityData);
               XmlNodeList pnodes = msgDoc.SelectNodes("//m:properties", xmlnsManager);
               foreach (XmlNode pnode in pnodes)
               {
            PartitionKey = pnode.SelectSingleNode("d:PartitionKey", xmlnsManager).InnerText;
            string RowKey = pnode.SelectSingleNode("d:RowKey", xmlnsManager).InnerText;
            if (PartitionKey != oldPartitionKey || entityCounter > 98)
            {
             if (sbMultiPart.Length > 0)
             {
              sbMultiPart.AppendFormat("--changeset_{0}--\n--batch_{1}--", batchIdentifier, boundaryIdentifier);
              ar = ad.ProcessRequest(cmdType.post, string.Format("http://{0}.table.core.windows.net/$batch", auth.Account), new System.Text.ASCIIEncoding().GetBytes(sbMultiPart.ToString()), headers);
              sbResults.AppendLine(ar.Body);
             }
             sbMultiPart = new StringBuilder();

             boundaryIdentifier = Guid.NewGuid().ToString();
             batchIdentifier = Guid.NewGuid().ToString();
             contentType = string.Format("multipart/mixed; boundary=batch_{0}", boundaryIdentifier);
             headers["Content-Type"] = contentType;
             sbMultiPart.AppendFormat(batchTemplate, boundaryIdentifier,batchIdentifier );
             sbMultiPart.AppendLine();
             sbMultiPart.AppendLine();
             entityCounter = 1;
             oldPartitionKey = PartitionKey;
            }
            string postUrl =string.Format("http://{0}.table.core.windows.net/{1}", auth.Account,tableName);
            if (cmd != cmdType.post)
             postUrl = string.Format("{0}(PartitionKey='{1}',RowKey='{2}')", postUrl, PartitionKey, RowKey);

            string atomData = string.Format(createEntityXML, requestDate, pnode.OuterXml);

            singlePart = string.Format(entityTemplate, batchIdentifier, cmd.ToString().ToUpper(), postUrl , entityCounter,atomData.Length, atomData );
            sbMultiPart.AppendLine(singlePart);
            entityCounter++;
               }
               sbMultiPart.AppendFormat("--changeset_{0}--\n--batch_{1}--", batchIdentifier, boundaryIdentifier);
               ar = ad.ProcessRequest(cmdType.post, string.Format("http://{0}.table.core.windows.net/$batch", auth.Account), new System.Text.ASCIIEncoding().GetBytes(sbMultiPart.ToString()), headers);
               sbResults.AppendLine(ar.Body);
               return sbResults.ToString();
        }
コード例 #5
0
 public azureResults CopyBlob(string OriginalBlobUrl, string NewBlobUrl, Hashtable htHeaders)
 {
     if (htHeaders.ContainsKey("x-ms-copy-source"))
     htHeaders["x-ms-copy-source"] = new azureCommon().CanonicalizeUrl(OriginalBlobUrl);
       else
     htHeaders.Add("x-ms-copy-source", new azureCommon().CanonicalizeUrl(OriginalBlobUrl));
       azureResults retVal = new azureResults();
       azureDirect ad = new azureDirect(auth);
       retVal = ad.ProcessRequest(cmdType.put, NewBlobUrl, "", htHeaders);
       return retVal;
 }