private static string FormatString <T>( T data, string DatabaseTable, cmdType commandType, string wheres = null, List <string> excludeStrings = null, bool overWriteSelectAll = false) { Type t = data.GetType(); PropertyInfo[] props = t.GetProperties(); string commandString = commandType.GetStringValue(); if (commandType == cmdType.Select) { if (overWriteSelectAll) { commandString += $" * from {DatabaseTable}"; } else { commandString += $" {FormatProperties(props, data, excludeStrings, ValueSelectType.Names)} From {DatabaseTable}"; } } if (commandType == cmdType.Update) { commandString += $" {DatabaseTable} set {FormatProperties(props, data, excludeStrings)}"; if (wheres != null && wheres.Length > 0) { commandString += $" where {wheres}"; } } if (commandType == cmdType.Delete) { if (wheres != null && wheres.Length > 0) { commandString += $" from {DatabaseTable} where {wheres}"; } else { return("Cant delete without where case!"); } } if (commandType == cmdType.Insert) { commandString += $" {DatabaseTable} ({FormatProperties(props, data, excludeStrings, ValueSelectType.Names)}) values ({FormatProperties(props, data, excludeStrings, ValueSelectType.Values)})"; } return(commandString); }
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("<", "<").Replace(">", ">"); lblError.Text = ex.ToString(); lblStatus.Text = "Error:"; lblCalledURL.Text = ""; } this.Cursor = Cursors.Default; }
private void Process(cmdType cmd) { this.Cursor = Cursors.WaitCursor; azureResults ar = new azureResults(); try { AzureTableStorage ats = new AzureTableStorage(txtAccount.Text, txtEndpoint.Text, txtSharedKey.Text, "SharedKey"); string tableName = cbTables.Text; if (!cbBulkProcess.Checked) { if (txtRowKey.Text == string.Empty && txtPartitionKey.Text == string.Empty && txtDocumentData.Text == string.Empty ) ar = ats.Tables(cmd, tableName); else ar = ats.Entities(cmd, tableName, txtPartitionKey.Text, txtRowKey.Text, txtDocumentData.Text, txtTParameters.Text ,txtIfMatch.Text ); } else { azureHelper ah = new azureHelper(txtAccount.Text, txtEndpoint.Text, txtSharedKey.Text, "SharedKey"); string results = ah.entityGroupTransaction(cmd, cbTables.Text, txtDocumentData.Text); ar.Body = results; ar.Succeeded = true; } ProcessResults(ar); } catch (Exception ex) { //Literal1.Text = string.Format("<textarea id=\"txtResponse\" name=\"S1\">{0}</textarea>", ex.ToString()); //.Replace("<", "<").Replace(">", ">"); lblError.Text = ex.ToString(); lblStatus.Text = "Error:"; lblCalledURL.Text = ""; } this.Cursor = Cursors.Default; }
/// <summary> /// Tables handles table level operations against Azure Table Storage /// </summary> /// <param name="cmd">The type of operation you want to commit: Delete, Post, Put, Get </param> /// <param name="tableName">Name of the table to perform the command agains</param> /// <param name="parameters">Uri Parameters to include</param> /// <returns>An azureResults showing the results of the request.</returns> public azureResults Tables(cmdType cmd, string tableName, string parameters) { azureResults retVal = new azureResults(); HttpStatusCode success = HttpStatusCode.NotImplemented; Hashtable headers = new Hashtable(); try { StringBuilder sb = new StringBuilder(); string sendBody = string.Empty; string rtnBody = string.Empty; string requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}{1}", auth.EndPoint, "Tables"); requestDate = DateTime.UtcNow; switch (cmd) { case cmdType.get: method = "GET"; string allData = tableName; if (tableName != string.Empty) { if (parameters == string.Empty) { requestUrl = requestUrl.Replace("Tables", string.Format(CultureInfo.CurrentCulture, "{0}()", allData)); } else { requestUrl += string.Format(CultureInfo.CurrentCulture, "('{0}')", allData); if (!parameters.StartsWith("?")) parameters = "?" + parameters; requestUrl += string.Format(CultureInfo.CurrentCulture, "{0}", parameters); } } success = HttpStatusCode.OK; break; case cmdType.post: method = "POST"; // build valid Atom document sendBody = string.Format(createTableXml, requestDate, tableName); success= HttpStatusCode.Created; break; case cmdType.delete: method = "DELETE"; requestUrl += string.Format(CultureInfo.CurrentCulture, "('{0}')", tableName); success = HttpStatusCode.NoContent; break; default: break; } headers.Add("Content-Type", contentType); retVal = ad.ProcessRequest(cmd, requestUrl, sendBody, headers); if (success == HttpStatusCode.NotImplemented) { retVal.Succeeded = false; retVal.StatusCode = success; } else retVal.Succeeded = (retVal.StatusCode == success); } 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; }
public cmdToggle(string newName, bool newToggle, cmdType newType = cmdType.Toggle) { cmdData = newType; name = newName; toggle = newToggle; }
/// <summary> /// Metadata is a quick way to get/set the metadata about a queue /// </summary> /// <param name="cmd">The type of command you want to execute. GET, PUT and DELETE are supported</param> /// <param name="queueName">Name of the queue</param> /// <param name="htMetaData">A hashtable containing the Name-Value pairs of MetaData.</param> /// <returns>An azureResults showing the results of the request.</returns> public azureResults MetaData(cmdType cmd, string queueName, Hashtable htMetaData) { azureResults retVal = new azureResults(); Hashtable headers = new Hashtable(); HttpStatusCode success = HttpStatusCode.NotImplemented; try { StringBuilder sb = new StringBuilder(); string requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}{1}", auth.EndPoint, queueName); requestUrl += string.Format(CultureInfo.CurrentCulture, "?comp=metadata"); requestDate = DateTime.UtcNow; switch (cmd) { case cmdType.get: case cmdType.head: method = cmd.ToString().ToUpper(); StringBuilder metaDataInformation = new StringBuilder(); success = HttpStatusCode.OK; break; case cmdType.put: method = "PUT"; foreach (DictionaryEntry item in htMetaData) { string metaDataName = item.Key.ToString().ToLower().Replace(" ", "-").Replace("\r", ""); if (!metaDataName.StartsWith("x-ms-meta-")) metaDataName = "x-ms-meta-" + metaDataName; try { if (item.Value.ToString().Trim() != string.Empty) //client.RequestHeaders[metaDataName] = item.Value.ToString(); headers.Add(ac.CleanMetaDataNames(metaDataName), item.Value.ToString()); } catch { } } success = HttpStatusCode.NoContent; break; default: retVal.StatusCode = HttpStatusCode.NotImplemented; break; } retVal = ad.ProcessRequest(cmd, requestUrl, "", headers); retVal.Succeeded = (retVal.StatusCode == success); } 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; }
public cmdAction(Action newAction, Vector3 newVectorData, cmdType newActionType = cmdType.Move) { actionData = newAction; actionType = newActionType; vectorData = newVectorData; }
// Use this for initialization public cmdAction(Action newAction, cmdType newActionType = cmdType.Action) { actionData = newAction; actionType = newActionType; }
/// <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(); }
/// <summary> /// Send a request to Azure, adding only the authetication /// </summary> /// <param name="cmd">Method to execute</param> /// <param name="requestUrl">URL to execute against</param> /// <param name="body">Body to send</param> /// <param name="headers">Headers to send</param> /// <returns>An Azure Result object</returns> public azureResults ProcessRequest(cmdType cmd, string requestUrl, byte[] body, Hashtable headers) { Hashing h = new Hashing(); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(requestUrl); req.Method = cmd.ToString().ToUpper(); azureResults retVal = new azureResults(); try { StringBuilder sb = new StringBuilder(); string contentMD5 = string.Empty ; DateTime requestDate = DateTime.UtcNow; retVal.CanonicalResource = ac.CanonicalizeUrl2(requestUrl); string contentType = string.Empty; if (cmd == cmdType.head) req.ContentLength = 0; else req.ContentLength = body.Length; if (headers.ContainsKey("Content-Type")) { req.ContentType = headers["Content-Type"].ToString().Replace("\r", ""); headers.Remove("Content-Type"); } foreach (DictionaryEntry de in headers) { req.Headers[de.Key.ToString()] = de.Value.ToString(); } //req.Headers["x-ms-version"] = "2009-07-17"; //req.Headers["x-ms-version"] = "2009-09-19"; req.Headers["x-ms-version"] = "2012-02-12"; req.Headers["x-ms-date"] = string.Format(CultureInfo.CurrentCulture, "{0:R}", requestDate); string authHeader = string.Empty; if (requestUrl.Contains(".table.")) { // Required with the 2009-09-19 authentiation req.Headers["DataServiceVersion"] = "1.0;NetFx"; req.Headers["MaxDataServiceVersion"] = "1.0;NetFx"; authHeader = ac.CreateSharedKeyAuthLite(req.Method, retVal.CanonicalResource, contentMD5, requestDate, req.ContentType, auth); } else authHeader = ac.CreateSharedKeyAuth(req.Method, retVal.CanonicalResource, contentMD5, requestDate, req, auth); req.Headers["authorization"] = authHeader; retVal.Url = requestUrl; if (body.Length > 0 && cmd != cmdType.head) { System.IO.Stream requestStream = req.GetRequestStream(); requestStream.Write(body, 0, body.Length); requestStream.Flush(); } HttpWebResponse response = (HttpWebResponse)req.GetResponse(); // response = (HttpWebResponse)req.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()); retVal.Body = sr.ReadToEnd(); response.Close(); retVal.StatusCode = response.StatusCode; retVal.Headers = ac.Headers2Hash(response.Headers); } catch (WebException wex) { retVal.StatusCode = ((System.Net.HttpWebResponse)(wex.Response)).StatusCode; //retVal.StatusCode = wex. (HttpStatusCode)hex.GetHttpCode(); retVal.Succeeded = false; retVal.Body = wex.Message; /* for (int i=0;i< wex.Response.Headers.Count;i++) retVal.Headers.Add(wex.Response.Headers.Keys[i].ToString(), wex.Response.Headers[i].ToString()); */ } catch (Exception ex) { retVal.StatusCode = HttpStatusCode.SeeOther; retVal.Body = ex.ToString(); retVal.Succeeded = false; } return retVal; }
/// <summary> /// Send a request to Azure, adding only the authetication /// </summary> /// <param name="cmd">Method to execute</param> /// <param name="requestUrl">URL to execute against</param> /// <param name="body">Body to send</param> /// <param name="headers">Headers to send</param> /// <returns>An Azure Result object</returns> public azureResults ProcessRequest(cmdType cmd, string requestUrl, string body, Hashtable headers) { return ProcessRequest(cmd, requestUrl, new System.Text.ASCIIEncoding().GetBytes(body), headers); }
/// <summary> /// Metadata is a quick way to get/set the metadata about a container or a blob /// </summary> /// <param name="cmd">The type of command you want to execute. GET, PUT and DELETE are supported</param> /// <param name="containerName">Name of the container. If no blobName is passed in, will apply Metadata /// command to the Container.</param> /// <param name="blobName">The name of the blob in the container, if you want to apply the Metadata command to a blob.</param> /// <param name="htMetaData">A hashtable containing the Name-Value pairs of MetaData.</param> /// <returns>An azureResults showing the results of the request.</returns> public azureResults MetaData(cmdType cmd, string containerName, string blobName, Hashtable htMetaData) { azureResults retVal = new azureResults(); Hashtable headers = new Hashtable(); if (htMetaData != null) if (htMetaData.Count > 0) foreach (DictionaryEntry item in htMetaData) { string metaDataName = item.Key.ToString().Replace(" ", "-").Replace("\r", ""); if (!metaDataName.StartsWith("x-ms-meta-")) metaDataName = "x-ms-meta-" + metaDataName; headers.Add(ac.CleanMetaDataNames(metaDataName), item.Value); } if (blobName == string.Empty) { retVal = Containers(cmd, containerName, headers, "?comp=metadata"); retVal.Succeeded = (retVal.StatusCode == HttpStatusCode.OK); } else { retVal = Blobs(cmd, containerName, blobName, headers, "?comp=metadata"); } return retVal; }
/// <summary> /// Containers handles container level operations against Azure Blob Storage /// </summary> /// <param name="cmd">The type of operation you want to commit: Delete, Post, Put, Get </param> /// <param name="containerName">Name of the container to perform the command agains</param> /// <param name="headers">A hashtable of Name-Value pairs containing header information</param> /// <param name="parameters">Parameters to add to the URI</param> /// <returns></returns> public azureResults Containers(cmdType cmd, string containerName, Hashtable headers, string parameters) { azureResults retVal = new azureResults(); HttpStatusCode success = HttpStatusCode.NotImplemented; try { StringBuilder sb = new StringBuilder(); string sendBody = string.Empty; string rtnBody = string.Empty; string requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}{1}", auth.EndPoint, containerName); requestDate = DateTime.UtcNow; // handle version 2009-0-17 if (parameters == string.Empty) { parameters = "?restype=container"; } else { if (!parameters.ToLower().Contains("comp=list")) { parameters = string.Format("{0}&{1}", parameters, "restype=container"); } } switch (cmd) { case cmdType.get: case cmdType.head: method = cmd.ToString().ToUpper(); // do GET success = HttpStatusCode.OK; break; case cmdType.delete: method = "DELETE"; // do DELETE success = HttpStatusCode.Accepted; break; case cmdType.put: method = "PUT"; success = HttpStatusCode.Created; break; default: //retVal.StatusCode = HttpStatusCode.NotImplemented; break; } if (parameters != string.Empty && parameters != null) { if (!parameters.StartsWith("?")) parameters = string.Format("?{0}", parameters); requestUrl += string.Format(CultureInfo.CurrentCulture, "{0}", parameters); retVal.Url = requestUrl; } retVal = ad.ProcessRequest(cmd, requestUrl, "", headers); retVal.Succeeded = (retVal.StatusCode == success); } 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; }
/// <summary> /// Containers handles container level operations against Azure Blob Storage /// </summary> /// <param name="cmd">The type of operation you want to commit: Delete, Post, Put, Get </param> /// <param name="containerName">Name of the container to perform the command agains</param> /// <param name="headers">A hashtable of Name-Value pairs containing header information</param> /// <returns></returns> public azureResults Containers(cmdType cmd, string containerName, Hashtable headers) { return Containers(cmd, containerName, headers, ""); }
public cmdMove(Vector3 newVelData, cmdType newType = cmdType.Move) { name = "move"; velocityData = newVelData; cmdData = newType; }
public cmdMove(Vector3 newVelData, string newName, cmdType newType = cmdType.Move) { name = newName; velocityData = newVelData; }
public cmdFloat(string newName, float newNum, cmdType newType = cmdType.Float) { name = newName; num = newNum; cmdData = newType; }
public cmdAction(Action newAction, float newFloatData, cmdType newActionType = cmdType.Float) { actionData = newAction; actionType = newActionType; floatData = newFloatData; }
/// <summary> /// Entities returns information about entities. Uses If-Match of * and forces overwrites/deletes of data. /// </summary> /// <param name="cmd">The type of command you want to execute</param> /// <param name="tableName">Table name</param> /// <param name="PartitionKey">Partition Key</param> /// <param name="rowKey">Row Key</param> /// <param name="docData">Additional Data for Updates, Adds, Merges</param> /// <param name="parameters">Any Uri parameters to be passed in. comp=list can be passed in to get a list.</param> /// <returns></returns> public azureResults Entities(cmdType cmd, string tableName, string PartitionKey, string rowKey, string docData, string parameters) { return Entities(cmd, tableName, PartitionKey, rowKey, docData, parameters, "*"); }
/// <summary> /// Execute requests on Azure Queue Messages /// </summary> /// <param name="cmd">Type of command: Get, Delete, Post are supported</param> /// <param name="queueName">Name of the queue</param> /// <param name="messageBody">Body of the message. Max is 8KB</param> /// <param name="parameters">Uri Parameters to be included</param> /// <param name="messageID">MessageID</param> /// <returns>An azureResults object with the results of the request.</returns> public azureResults Messages(cmdType cmd, string queueName, string messageBody, string parameters, string messageID) { azureResults retVal = new azureResults(); HttpStatusCode success = HttpStatusCode.NotImplemented; Hashtable headers = new Hashtable(); try { string requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}{1}/messages", auth.EndPoint, queueName); if (messageID != string.Empty) { requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}/{1}", requestUrl, messageID); } if (parameters != string.Empty && parameters != null) { if (!parameters.StartsWith("?")) parameters = string.Format("?{0}", parameters); requestUrl += string.Format(CultureInfo.CurrentCulture, "{0}", parameters); } requestDate = DateTime.UtcNow; switch (cmd) { case cmdType.get: method = "GET"; // do GET success = HttpStatusCode.OK; break; case cmdType.delete: method = "DELETE"; // do DELETE success = HttpStatusCode.NoContent; break; case cmdType.post: method = "POST"; messageBody = string.Format("<QueueMessage><MessageText><![CDATA[{0}]]></MessageText></QueueMessage>", messageBody); success = HttpStatusCode.Created; break; default: retVal.StatusCode = HttpStatusCode.NotImplemented; break; } headers.Add("Content-Type", contentType); retVal = ad.ProcessRequest(cmd, requestUrl, messageBody, headers); retVal.Succeeded = (retVal.StatusCode == success); } 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; }
/// <summary> /// Entities returns information about entities /// </summary> /// <param name="cmd">The type of command you want to execute</param> /// <param name="tableName">Table name</param> /// <param name="PartitionKey">Partition Key</param> /// <param name="rowKey">Row Key</param> /// <param name="docData">Additional Data for Updates, Adds, Merges</param> /// <param name="IfMatch">The entity tag or * to execute an update/merge/delete regardless of the entity tag</param> /// <param name="parameters">Any Uri parameters to be passed in. comp=list can be passed in to get a list.</param> /// <returns></returns> public azureResults Entities(cmdType cmd, string tableName, string PartitionKey, string rowKey, string docData, string parameters, string IfMatch) { Hashtable headers = new Hashtable(); azureResults retVal = new azureResults(); HttpStatusCode success = HttpStatusCode.NotImplemented; try { string sendBody = string.Empty; string readBody = string.Empty; string requestUrl = string.Format(CultureInfo.CurrentCulture, "{0}{1}", auth.EndPoint, tableName); requestDate = DateTime.UtcNow; switch (cmd) { case cmdType.get: method = "GET"; IfMatch = string.Empty; sendBody = string.Empty; if (PartitionKey != string.Empty && rowKey != string.Empty) { requestUrl += string.Format(CultureInfo.CurrentCulture, "(PartitionKey='{0}',RowKey='{1}')", PartitionKey, rowKey); } else if (PartitionKey != string.Empty) { requestUrl += string.Format(CultureInfo.CurrentCulture, "(PartitionKey='{0}')", PartitionKey); } else { requestUrl += string.Format(CultureInfo.CurrentCulture, "()"); } if (parameters != string.Empty) { if (!parameters.StartsWith("?")) parameters = "?" + parameters; requestUrl += string.Format(CultureInfo.CurrentCulture, parameters); } // do GET success = HttpStatusCode.OK; break; case cmdType.post: method = "POST"; // accept input doc and parse into valid Atom for Azure Tables readBody = docData; IfMatch = ""; sendBody = string.Format(createEntityXml, requestDate, readBody); sendBody = string.Format(sendBody, PartitionKey, rowKey); success = HttpStatusCode.Created; break; case cmdType.put: method = "PUT"; requestUrl += string.Format(CultureInfo.CurrentCulture, "(PartitionKey='{0}',RowKey='{1}')", PartitionKey, rowKey); // accept input doc and parse into valid Atom for Azure Tables sendBody = docData; sendBody = string.Format(updateEntityXml, tableName, PartitionKey, rowKey, requestDate, sendBody, this.ETag.Replace(@"""", """), auth.Account); success = HttpStatusCode.NoContent; break; case cmdType.merge: method = "MERGE"; requestUrl += string.Format(CultureInfo.CurrentCulture, "(PartitionKey='{0}',RowKey='{1}')", PartitionKey, rowKey); // accept input doc and parse into valid Atom for Azure Tables sendBody = docData; sendBody = string.Format(updateEntityXml, tableName, PartitionKey, rowKey, requestDate, sendBody, this.ETag.Replace(@"""", """), auth.Account); success = HttpStatusCode.NoContent; break; case cmdType.delete: method = "DELETE"; sendBody = string.Empty; requestUrl += string.Format(CultureInfo.CurrentCulture, "(PartitionKey='{0}',RowKey='{1}')", PartitionKey, rowKey); success = HttpStatusCode.NoContent; break; default: retVal.Succeeded = false; retVal.StatusCode = HttpStatusCode.NotImplemented; break; } headers.Add("Content-Type", contentType); if (IfMatch != string.Empty) headers.Add("If-Match", IfMatch); retVal = ad.ProcessRequest(cmd, requestUrl, sendBody, headers); if (success == HttpStatusCode.NotImplemented) { retVal.Succeeded = false; retVal.StatusCode = success; } else retVal.Succeeded = (retVal.StatusCode == success); } catch (HttpException hex) { retVal.Succeeded = false; retVal.StatusCode = (HttpStatusCode)hex.GetHttpCode(); retVal.Body = hex.GetHtmlErrorMessage(); } catch (Exception ex) { retVal.StatusCode = HttpStatusCode.SeeOther; retVal.Body = ex.ToString(); retVal.Succeeded = false; } // Note: Body may contain data elements with XML... will need to use // Uri.UnescapeDataString() to format correctly return retVal; }
/// <summary> /// Queues handles queue level operations against Azure Queue Storage /// </summary> /// <param name="cmd">The type of operation you want to commit: Delete, Post, Put, Get </param> /// <param name="queueName">Name of the table to perform the command agains</param> /// <param name="parameters">Uri Parameters to be included</param> /// <param name="htMetaData">Hashtable of Name-Value pairs of metadata for the queue</param> /// <returns>An azureResults showing the results of the request.</returns> public azureResults Queues(cmdType cmd, string queueName, string parameters, Hashtable htMetaData) { azureResults retVal = new azureResults(); Hashtable headers = new Hashtable(); try { if (parameters == string.Empty && !queueName.EndsWith("/") && queueName != string.Empty) queueName = queueName + "/"; StringBuilder sb = new StringBuilder(); string sendBody = string.Empty; string rtnBody = string.Empty; string requestUrl = string.Format(CultureInfo.CurrentCulture, auth.EndPoint); requestDate = DateTime.UtcNow; HttpStatusCode success = HttpStatusCode.NotImplemented; switch (cmd) { case cmdType.get: method = "GET"; if (queueName == string.Empty) { requestUrl += string.Format(CultureInfo.CurrentCulture, "?comp=list"); } if (parameters != string.Empty) { if (!parameters.StartsWith("?")) parameters = "?" + parameters; requestUrl += string.Format(CultureInfo.CurrentCulture, "{0}", parameters); } success = HttpStatusCode.OK; break; case cmdType.delete: method = "DELETE"; requestUrl += string.Format(CultureInfo.CurrentCulture, string.Format("{0}", queueName)); success = HttpStatusCode.NoContent; break; case cmdType.put: method = "PUT"; requestUrl += string.Format(CultureInfo.CurrentCulture, string.Format("{0}", queueName)); // do PUT if (htMetaData.Count > 0) foreach (DictionaryEntry item in htMetaData) { string metaDataName = item.Key.ToString().ToLower().Replace(" ", "-").Replace("\r", ""); if (!metaDataName.StartsWith("x-ms-meta-")) metaDataName = "x-ms-meta-" + metaDataName; try { if (item.Value.ToString().Trim() != string.Empty) headers.Add(ac.CleanMetaDataNames(metaDataName), item.Value.ToString()); } catch { } } success = HttpStatusCode.Created; break; default: break; } retVal = ad.ProcessRequest(cmd, requestUrl, "", headers); retVal.Succeeded = (retVal.StatusCode == success); } 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; }
/// <summary> /// Tables handles table level operations against Azure Table Storage /// </summary> /// <param name="cmd">The type of operation you want to commit: Delete, Post, Put, Get </param> /// <param name="tableName">Name of the table to perform the command agains</param> /// <returns>An azureResults showing the results of the request.</returns> public azureResults Tables(cmdType cmd, string tableName) { return Tables(cmd, tableName, ""); }