コード例 #1
0
        private IList <T> DeserializeList <T>(string response, string jsonRoot, out int totalCount) where T : class, new()
        {
            Type type = typeof(T);

            if (mimeFormat == MimeFormat.json)
            {
                if (type == typeof(IssuePriority))
                {
                    jsonRoot = RedmineKeys.ISSUE_PRIORITIES;
                }
                if (type == typeof(TimeEntryActivity))
                {
                    jsonRoot = RedmineKeys.TIME_ENTRY_ACTIVITIES;
                }
                return(RedmineSerialization.JsonDeserializeToList <T>(response, jsonRoot, out totalCount));
            }

            using (var text = new StringReader(response))
            {
                using (var xmlReader = new XmlTextReader(text))
                {
                    xmlReader.WhitespaceHandling = WhitespaceHandling.None;
                    xmlReader.Read();
                    xmlReader.Read();

                    totalCount = xmlReader.ReadAttributeAsInt("total_count");

                    return(xmlReader.ReadElementContentAsCollection <T>());
                }
            }
        }
コード例 #2
0
        private IList <T> DeserializeList <T>(
            string response,
            string jsonRoot,
            out int totalCount) where T : class, new()
        {
            var type = typeof(T);

            if (_mimeFormat == MimeFormat.JSON)
            {
                if (type == typeof(IssuePriority))
                {
                    jsonRoot = "issue_priorities";
                }
                if (type == typeof(TimeEntryActivity))
                {
                    jsonRoot = "time_entry_activities";
                }
                return(RedmineSerialization.JsonDeserializeToList <T>(
                           response,
                           jsonRoot,
                           out totalCount));
            }
            using (var text = new StringReader(response))
            {
                using (var xmlReader = new XmlTextReader(text))
                {
                    xmlReader.WhitespaceHandling = WhitespaceHandling.None;
                    xmlReader.Read();
                    xmlReader.Read();
                    totalCount = xmlReader.ReadAttributeAsInt("total_count");
                    return(xmlReader.ReadElementContentAsCollection <T>());
                }
            }
        }
コード例 #3
0
        private void ShowAsyncResult(string response, Type responseType, RedmineMethod method, string jsonRoot)
        {
            var aev = new AsyncEventArgs();

            try
            {
                // #if RUNNING_ON_35_OR_ABOVE
                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);
                }
                //#endif
            }
            catch (ThreadAbortException ex)
            {
                aev.Error = ex.Message;
            }
            catch (Exception ex)
            {
                aev.Error = ex.Message;
            }
            if (DownloadCompleted != null)
            {
                DownloadCompleted(this, aev);
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        private IList <T> DeserializeList <T>(string response, string jsonRoot, out int totalCount) where T : class, new()
        {
            if (mimeFormat == MimeFormat.json)
            {
                return(RedmineSerialization.JsonDeserializeToList <T>(response, jsonRoot, out totalCount));
            }

            using (var text = new StringReader(response))
            {
                using (var xmlReader = new XmlTextReader(text))
                {
                    xmlReader.WhitespaceHandling = WhitespaceHandling.None;
                    xmlReader.Read();
                    xmlReader.Read();

                    totalCount = xmlReader.ReadAttributeAsInt("total_count");

                    return(xmlReader.ReadElementContentAsCollection <T>());
                }
            }
        }