public RtTicket ParseTicketGetResponse(RtResponse response)
        {
            IDictionary<string, string> ticketData = new Dictionary<string, string>();

            string fieldName = null;
            var tmp = new StringBuilder();
            foreach (var ticketLine in response.Body.Split(TicketLinesDelimiter, true))
            {
                var m = KeyValueRegex.Matches(ticketLine);
                if (m.Count > 0)
                {
                    var match = m[0];
                    var groupCollection = match.Groups;

                    if (fieldName != null)
                    {
                        ticketData[fieldName] = tmp.ToString();
                        tmp.Length = 0;
                    }

                    fieldName = groupCollection[1].ToString();
                    tmp.Append(groupCollection[2]);
                }
                else
                {
                    tmp.Append(ticketLine);
                }
            }
            if (fieldName != null)
                ticketData[fieldName] = tmp.ToString();

            return ProcessTicketData(ticketData);
        }
        public IEnumerable<RtTicket> ParseTicketSearchResponse(RtResponse response)
        {
            var resultData = new List<IDictionary<string, string>>();
            if (response.Body == NoMatchingResults)
                return ProcessResultData(resultData);

            foreach (var ticketString in response.Body.Split(TicketsDelimiter, true))
            {
                IDictionary<string, string> ticketData = new Dictionary<string, string>();

                string fieldName = null;
                var tmp = new StringBuilder();
                foreach (var ticketLine in ticketString.Split(TicketLinesDelimiter, true))
                {
                    var m = KeyValueRegex.Matches(ticketLine);
                    if (m.Count > 0)
                    {
                        var match = m[0];
                        var groupCollection = match.Groups;

                        if (fieldName != null)
                        {
                            ticketData[fieldName] = tmp.ToString();
                            tmp.Length = 0;
                        }

                        fieldName = groupCollection[1].ToString();
                        tmp.Append(groupCollection[2]);
                    }
                    else
                    {
                        tmp.Append(ticketLine);
                    }
                }
                if (fieldName != null)
                    ticketData[fieldName] = tmp.ToString();

                resultData.Add(ticketData);
            }

            return ProcessResultData(resultData);
        }
Пример #3
0
        private RtResponse GetResponse(string url, Dictionary<string, string> parameters)
        {
            string responseBody;
            if (parameters.Any())
            {
                var postData = new StringBuilder();
                foreach (var item in parameters)
                    postData.Append(String.Format("{0}={1}&", item.Key, HttpUtility.UrlEncode(item.Value)));
                responseBody = _httpClient.UploadString(BaseUrl + url, postData.ToString());
            }
            else
                responseBody = _httpClient.DownloadString(BaseUrl + url);

            var matcher = ResponseBodyRegex.Matches(responseBody);

            if (matcher.Count > 0)
            {
                var match = matcher[0];
                var groupCollection = match.Groups;

                var response = new RtResponse
                {
                    Version = groupCollection[1].ToString(),
                    StatusCode = Convert.ToInt64(groupCollection[2].ToString()),
                    StatusMessage = groupCollection[3].ToString(),
                    Body = groupCollection[4].ToString().Trim()
                };
                return response;
            }
            Console.Error.WriteLine("not matched");
            return new RtResponse();
        }