/// <summary> /// GetTableWithCode tampers with with the request to return the specific table and a success code. /// </summary> /// <param name="session"></param> /// <param name="statusCode"></param> private static void GetTableWithCode(Session session, int statusCode) { // Find relevant facts about this table creation. Uri hostName = new Uri(string.Format("http://{0}/", session.oRequest["Host"])); string requestString = session.GetRequestBodyAsString(); string tableName = null; string tableUri = null; if (string.IsNullOrEmpty(requestString)) { tableName = tableNameRegex.Match(session.url).Groups[1].Value; } else { XElement request = XElement.Parse(requestString); tableName = request.Descendants(TableConstants.OData + "TableName").Single().Value; tableUri = new Uri(hostName, string.Format("/Tables('{0}')", tableName)).AbsoluteUri; } // mark that we're going to tamper with it session.utilCreateResponseAndBypassServer(); session.oResponse.headers = CreateResponseHeaders(tableUri); session.responseCode = statusCode; // Create the response XML XElement response = TableConstants.GetEntry(hostName.AbsoluteUri); response.Add(new XElement(TableConstants.Atom + "id", session.fullUrl)); response.Add(new XElement(TableConstants.Title)); response.Add(new XElement(TableConstants.Atom + "updated", DateTime.UtcNow.ToString("o"))); response.Add(TableConstants.Author); response.Add(TableConstants.GetLink(tableName)); string accountName = hostName.Host.Substring(0, hostName.Host.IndexOf('.')); response.Add(TableConstants.GetCategory(accountName + ".Tables")); // Add in the most important part -- the table name. response.Add(new XElement( TableConstants.Atom + "content", new XAttribute("type", "application/xml"), new XElement( TableConstants.Metadata + "properties", new XElement( TableConstants.OData + "TableName", tableName)))); var responseString = response.ToString(); session.utilSetResponseBody(responseString); }