Exemplo n.º 1
0
            public Feed Find(String path, QueryOption opt)
            {
                ServiceRequestImpl request = _service.NewRequest();
                request.Method = "GET";
                request.Resource = _context + "/" + path;
                ToParameters(request, opt);

                IServiceResponse response = null;
                try
                {
                    response = _service.Execute(request);
                    if (response == null)
                        ServiceException.ThrowTimeout(null);
                    else if (response.StatusCode == 200)
                    {
                        IFeedFormatter formatter = GetFormatter(request.Format);
                        if (response.Body == null)
                            return formatter.ParseFeed(response.GetResponseStream());
                        else
                            return formatter.ParseFeed(response.Body);
                    }
                    else if (response.StatusCode != 404)
                        ServiceException.Throw(response.StatusCode);
                }
                catch (ServiceException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    ServiceException.ThrowError(e);
                }
                finally
                {
                    if (response != null)
                        Dispose(response);
                }

                return null;
            }
Exemplo n.º 2
0
        private static void ToParameters(ServiceRequestImpl request, QueryOption opt)
        {
            if (opt.Limit > -1)
                request.Parameters["limit"] = opt.Limit;
            if (opt.Offset > 0)
                request.Parameters["offset"] = opt.Offset;
            if (opt.StartTime.HasValue)
                request.Parameters["start"] = opt.StartTime.Value;
            if (opt.EndTime.HasValue)
                request.Parameters["end"] = opt.EndTime.Value;
            if (!String.IsNullOrEmpty(opt.Order))
                request.Parameters["order"] = opt.Order;
            if (opt.Desc)
                request.Parameters["desc"] = opt.Desc;
            if (opt.Depth >= 0)
                request.Parameters["depth"] = opt.Depth;

            if (opt.Content != QueryContent.Whatever)
                request.Parameters["content"] = opt.Content;
            if (opt.Sample != QuerySample.Whatever)
                request.Parameters["sample"] = opt.Sample;
            if (opt.View != QueryView.Whatever)
                request.Parameters["view"] = opt.View;

            if (opt.Status.HasValue)
                request.Parameters["status"] = opt.Status;
        }