public void ProcessRequest(HttpContext context)
        {
            string accountName = string.Empty;
              string sharedKey = string.Empty;
              string queueTypeOfCall = string.Empty;
              string message = string.Empty;

              string queueName = string.Empty;
              string messageID = string.Empty;
              string popReceipt = string.Empty;
              string qParameters = 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("queuetypeofcall"))
              {
            queueTypeOfCall = context.Request.Params["queuetypeofcall"].ToString();
              }
              if (context.Request.Params.AllKeys.Contains("queuename"))
              {
            queueName = context.Request.Params["queuename"].ToString();
              }
              if (context.Request.Params.AllKeys.Contains("messageid"))
              {
            messageID = context.Request.Params["messageid"].ToString();
              }
              if (context.Request.Params.AllKeys.Contains("popreceipt"))
              {
            popReceipt = context.Request.Params["popreceipt"].ToString();
              }
              if (context.Request.Params.AllKeys.Contains("message"))
              {
            message = context.Request.Params["message"].ToString();
              }
              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.AzureQueueStorage aqs = new Finsel.AzureCommands.AzureQueueStorage(accountName,
            string.Format("http://{0}.blob.core.windows.net", accountName), sharedKey,
            "SharedKey");

              switch (queueTypeOfCall.ToLower())
              {
            case "addqueuemetadata":
              ar = aqs.MetaData(cmdType.put, queueName, ht);
              retVal = processAzureResults(ar);
              break;
            case "clearqueue":
               ar = aqs.Messages(cmdType.delete, queueName, "", "", "");
               retVal = processAzureResults(ar);
               break;
            case "createmessage":
               ar = aqs.Messages(cmdType.post, queueName, message, "", "");
               retVal = processAzureResults(ar);
               break;
            case "createqueue":
              ht.Add("x-ms-meta-CreatedBy", "Finsel.AzureCommands");
              ar = aqs.Queues(cmdType.put, queueName,qParameters , ht);
              retVal = processAzureResults(ar);
              break;
            case "deletemessage":
              qParameters = string.Format("popreceipt={0}", popReceipt);
              ar = aqs.Messages(cmdType.delete, queueName,"",qParameters , messageID);
              retVal = processAzureResults(ar);
              break;
            case "deletequeue":
              ar = aqs.Queues(cmdType.delete, queueName,qParameters, new Hashtable());
              retVal = processAzureResults(ar);
              break;
            case "deletequeuemetadata":
              ar = aqs.MetaData(cmdType.get, queueName, null);
              retVal = processAzureResults(ar);
              break;
            case "displayqueuemetadata":
              ar = aqs.MetaData(cmdType.get, queueName, null);
              retVal = processAzureResults(ar);
              break;
            case "getmessage":
              ar = aqs.Messages(cmdType.get, queueName, "", qParameters, messageID);
              retVal = processAzureResults(ar);
              break;
            case "getqueuelist":
              ar = aqs.GetQueueList(qParameters);
              retVal = processAzureResults(ar);
              break;
            case "peekmessage":
              ar = aqs.Messages(cmdType.get, queueName, "", "peekonly=true", messageID);
              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>Finsel Azure Queue Handler Form</title>
            </head>
            <body>
            <form action='aqsHandler.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='queuename' maxlength='100' /></td>
            </tr><tr>
            <td>Blob Name</td><td><input name='messageid' maxlength='1240' /></td>
            </tr><tr>
            <td>Parameters</td><td><input name='parameters' maxlength='1240' /></td>
            </tr><tr>
            <td>Type of call</td><td>
            <select name='queuetypeofcall'>
            <option>AddQueueMetadata</option>
            <option value='CreateQueue'>CreateContainer</option>
            <option value='DeleteMessage'>DeleteBlob</option>
            <option value='DeleteQueue'>DeleteContainer</option>
            <option value='DeleteQueueMetadata'>DeleteContainerMetadata</option>
            <option value='DisplayQueueMetadata'>DisplayContainerMetadata</option>
            <option value='GetBlob'>GetMessage</option>
            <option value='GetQueueList'>GetContainerList</option>
            </td>
            </tr><tr>
            <td colspan='2'><input type='submit' /></td>
            </tr>
            </table>
            </form>
            </body>
            </html>";
              retValType = "text/html";

              break;
              }

              context.Response.ContentType = retValType;
              context.Response.Write(retVal);
        }
示例#2
0
        private void btnGetQueues_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
               cbQueues.Items.Clear();
               cbQueues.Text = string.Empty;

               AzureQueueStorage aqs = new AzureQueueStorage(txtAccount.Text, string.Format("http://{0}.queue.core.windows.net", txtAccount.Text), txtSharedKey.Text, "SharedKey");

               azureResults ar = aqs.GetQueueList("");
               if (ar.Succeeded)
               {
            XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(ar.Body);
            XmlNodeList nodes = xdoc.SelectNodes("//Queue");

            foreach (XmlNode node in nodes)
            {
             cbQueues.Items.Add(node.SelectSingleNode("Name").InnerText);
            }
               }
               ProcessResults(ar);

               this.Cursor = Cursors.Default;
        }
 private void click_Queues(object sender, RoutedEventArgs e)
 {
     if (e.Source.ToString().StartsWith("System.Windows.Controls.Button"))
     {
         this.Cursor = Cursors.Wait;
         AzureQueueStorage aqs = new AzureQueueStorage(azAccount, string.Format("http://{0}.queue.core.windows.net", azAccount), azSharedKey, "SharedKey");
         azureResults ar = new azureResults();
         Hashtable ht = new Hashtable();
         if (e.Source == btnAddQueueMetaData)
         {
             string[] AllData = txtQMetaData.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);
                 }
             }
             ar = aqs.MetaData(cmdType.put, cbQueues.Text, ht);
         }
         else if (e.Source == btnClearQueue)
         {
             ar = aqs.Messages(cmdType.delete, cbQueues.Text, "", "", "");
         }
         else if (e.Source == btnCreateMessage)
         {
             ar = aqs.Messages(cmdType.post, cbQueues.Text, txtMessage.Text, "", "");
         }
         else if (e.Source == btnCreateQueue)
         {
             ht.Add("createdBy", "Finsel.AzureCommands");
             ar = aqs.Queues(cmdType.put, cbQueues.Text, "", ht);
         }
         else if (e.Source == btnDeleteMessage)
         {
             string parameters = string.Empty;
             if (txtPopReceipt.Text != string.Empty)
                 parameters = string.Format("popreceipt={0}", txtPopReceipt.Text);
             ar = aqs.Messages(cmdType.delete, cbQueues.Text, "", parameters, txtMessageID.Text);
         }
         else if (e.Source == btnDeleteQueue)
         {
             ar = aqs.Queues(cmdType.delete, cbQueues.Text, "", new Hashtable());
         }
         else if (e.Source == btnDeleteQueueMetaData)
         {
             ar = aqs.MetaData(cmdType.put, cbQueues.Text, new Hashtable());
         }
         else if (e.Source == btnDisplayQueueMetadata)
         {
             ar = aqs.MetaData(cmdType.get, cbQueues.Text, new Hashtable());
         }
         else if (e.Source == btnGetMessage)
         {
             ar = aqs.Messages(cmdType.get, cbQueues.Text, "", txtQParameters.Text, "");
             txtMessageID.Text = "";
             txtPopReceipt.Text = "";
             txtMessage.Text = "";
             if (ar.Body != null)
             {
                 System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
                 xdoc.LoadXml(ar.Body);
                 System.Xml.XmlNodeList nodes = xdoc.SelectNodes("//QueueMessage");
                 if (nodes.Count == 0)
                     txtMessage.Text = "No message to process";
                 else
                     foreach (System.Xml.XmlNode node in nodes)
                     {
                         txtMessageID.Text = node.SelectSingleNode("MessageId").InnerText;
                         if (node.SelectNodes("//PopReceipt").Count > 0)
                             txtPopReceipt.Text = node.SelectSingleNode("PopReceipt").InnerText;
                         if (node.SelectNodes("//MessageText").Count > 0)
                             txtMessage.Text = node.SelectSingleNode("MessageText").InnerText;
                     }
             }
             else txtMessage.Text = "No message to process";
         }
         else if (e.Source == btnGetQueues)
         {
             cbQueues.Items.Clear();
             cbQueues.Text = string.Empty;
             ar = aqs.GetQueueList("");
             if (ar.Succeeded)
             {
                 XmlDocument xdoc = new XmlDocument();
                 xdoc.LoadXml(ar.Body);
                 XmlNodeList nodes = xdoc.SelectNodes("//Queue");
                 foreach (XmlNode node in nodes)
                 {
                     cbQueues.Items.Add(node.SelectSingleNode("Name").InnerText);
                 }
                 if (cbQueues.Items.Count > 0)
                     cbQueues.SelectedIndex = 0;
             }
         }
         ProcessResults(ar);
         this.Cursor = Cursors.Arrow;
     }
 }