public static XmlDocument XmlDocumentFromHttpResponse(HttpResponse response) { var sr = new MemoryStream(response.bytes); XmlDocument doc = new XmlDocument(); try { doc.Load(sr); } catch (Exception e) { GenUtils.PriorityLogMsg("exception", "XmlDocumentFromHttpResponse", e.Message + e.StackTrace); } return doc; }
public BlobStorageResponse(HttpResponse http_response) { this.HttpResponse = http_response; this.response = null; }
public BlobStorageResponse(HttpResponse http_response, List<Dictionary<string, string>> response) { this.HttpResponse = http_response; this.response = response; }
// read atom response, select desired elements, return enum of dict<str,str> public List<Dictionary<string, string>> DictsFromBlobStorageResponse(HttpResponse response, string xpath, string[] elements, ref string next_marker) { var dicts = new List<Dictionary<string, string>>(); var doc = XmlUtils.XmlDocumentFromHttpResponse(response); XmlNodeList nodes = doc.SelectNodes(xpath); foreach (XmlNode node in nodes) { var dict = new Dictionary<string, string>(); foreach (string element in elements) { dict[element] = node.SelectSingleNode(element).FirstChild.Value; var lm = node.SelectSingleNode("Properties/Last-Modified").FirstChild.Value; dict["Last-Modified"] = lm; } dicts.Add(dict); } XmlNode next_marker_node = doc.SelectSingleNode("//NextMarker"); if (next_marker_node != null && next_marker_node.HasChildNodes) next_marker = next_marker_node.FirstChild.Value; else next_marker = null; return dicts; }
// alternate for data as string public TableStorageStringResponse(HttpResponse http_response, string str) : base(http_response, null_bytes: false) { this._str = str; }
// encapsulate the http response from the table store, plus data as a list of dict<str,obj> public TableStorageListDictResponse(HttpResponse http_response, List<Dictionary<string,object>> list_dict_obj) : base(http_response, null_bytes: true) { this._list_dict_obj = list_dict_obj; }
// alternate version for int responses public TableStorageIntResponse(HttpResponse http_response, int i) : base(http_response, null_bytes:true) { this._i = i; }
public TableStorageHttpResponse(HttpResponse http_response, bool null_bytes) { this._http_response = http_response; if (null_bytes == true) this._http_response.bytes = null; }
// alternate version for boolean responses public TableStorageBoolResponse(HttpResponse http_response, bool boolean) : base(http_response, null_bytes:true) { this._boolean = boolean; }
// package azure table response as list of dict<str,obj> private static List<Dictionary<string, object>> GetTsDicts(HttpResponse http_response) { return GenUtils.GetOdataDicts(http_response.bytes); }
// for tracing, used everywhere public TableStorageHttpResponse WriteLogMessage(string type, string message, string data) { HttpResponse http_response; type = type ?? ""; message = message ?? ""; data = data ?? ""; var entity = new Dictionary<string, object>(); entity.Add("PartitionKey", "log"); entity.Add("RowKey", DateTime.Now.ToUniversalTime().Ticks.ToString()); entity.Add("type", type); entity.Add("message", message); entity.Add("data", data); try { http_response = this.InsertEntity(Configurator.azure_log_table, entity).http_response; } catch (Exception e) { http_response = new HttpResponse(HttpStatusCode.Unused, "unable to write log message, " + e.Message, null, null); } return new TableStorageHttpResponse(http_response, null_bytes: true); }
public static bool CompletedIfStatusEqualsExpected(HttpResponse r, Object o) { return r.status == (HttpStatusCode) o; }