private T Deserialize <T>(string response) where T : class, new() { var type = typeof(T); if (_mimeFormat == MimeFormat.JSON) { return(type == typeof(IssueCategory) ? RedmineSerialization.JsonDeserialize <T>(response, "issue_category") : RedmineSerialization.JsonDeserialize <T>( response, type == typeof(IssueRelation) ? "relation" : null)); } return(RedmineSerialization.FromXml <T>(response)); }
public T DeserializeResult <T>( string result, out int totalItems, string jsonRoot = null) { totalItems = 0; if (string.IsNullOrWhiteSpace(result)) { return(default(T)); } var type = typeof(T); if (type == typeof(List <T>)) { if (_mimeFormat == MimeFormat.JSON) { return ((T) RedmineSerialization.JsonDeserializeToList( result, jsonRoot, type, out totalItems)); } using (var text = new StringReader(result)) { using (var xmlReader = new XmlTextReader(text)) { xmlReader.WhitespaceHandling = WhitespaceHandling.None; xmlReader.Read(); xmlReader.Read(); totalItems = xmlReader.ReadAttributeAsInt("total_count"); return((T)(object)xmlReader.ReadElementContentAsCollection(type)); } } } if (_mimeFormat == MimeFormat.JSON) { return((T)RedmineSerialization.JsonDeserialize(result, type, jsonRoot)); } return((T)RedmineSerialization.FromXml(result, type)); }
private void ShowAsyncResult( string response, Type responseType, RedmineMethod method, string jsonRoot) { var aev = new AsyncEventArgs(); try { if (_mimeFormat == MimeFormat.JSON) { if (method == RedmineMethod.GetObjectList) { int totalItems; aev.Result = RedmineSerialization.JsonDeserializeToList( response, jsonRoot, responseType, out totalItems); aev.TotalItems = totalItems; } else { aev.Result = RedmineSerialization.JsonDeserialize( response, responseType, null); } } else if (method == RedmineMethod.GetObjectList) { using (var text = new StringReader(response)) { using (var xmlReader = new XmlTextReader(text)) { xmlReader.WhitespaceHandling = WhitespaceHandling.None; xmlReader.Read(); xmlReader.Read(); aev.TotalItems = xmlReader.ReadAttributeAsInt("total_count"); aev.Result = xmlReader.ReadElementContentAsCollection(responseType); } } } else { aev.Result = RedmineSerialization.FromXml(response, responseType); } } catch (ThreadAbortException ex) { aev.Error = ex.Message; } catch (Exception ex) { aev.Error = ex.Message; } if (DownloadCompleted != null) { DownloadCompleted(this, aev); } }