示例#1
0
        protected override async Task <object> HandleAsync(object[] args, MemberAccessWrapper memberAccessWrapper)
        {
            var httpMethodString = memberAccessWrapper.GetLastCall();
            var uri            = ParseUri(httpMethodString, memberAccessWrapper.ToString(), args);
            var requestHeaders = ParseRequestHeaders(args);
            var httpContent    = ParseContent(httpMethodString, args);

            foreach (var header in memberAccessWrapper.Headers)
            {
                if (!requestHeaders.ContainsKey(header.Key)) //Only add the header if it's not in passed in the verb's header argument allowing us to override headers set via the Headers() method
                {
                    requestHeaders.Add(header.Key, header.Value);
                }
            }

            var httpResponseMessage = await memberAccessWrapper.HttpClientWrapper.Send(new HttpMethod(httpMethodString.ToUpperInvariant()), uri, requestHeaders, httpContent)
                                      .ConfigureAwait(false);

            using (var content = httpResponseMessage.Content)
            {
                string responseString;
                if (content == null)
                {
                    responseString = string.Empty;
                }
                else
                {
                    responseString = await content.ReadAsStringAsync();
                }

                return(new RestClientResponseObject(httpResponseMessage, responseString));
            }
        }
 public override bool TryGetMember(GetMemberBinder binder,
                                   out object result)
 {
     result = new MemberAccessWrapper("member accessed was "
                                      + binder.Name);
     return(true);
 }
        public override bool TryInvoke(InvokeBinder binder, object[] args,
                                       out object result)
        {
            StringBuilder builder = new StringBuilder(message).Append("(");

            for (int i = 0; i < args.Length; i++)
            {
                if (i != 0)
                {
                    builder.Append(", ");
                }
                if (args[i] == null)
                {
                    builder.Append("null");
                }
                else if (args[i] is string)
                {
                    builder.Append("@\"").Append(((string)args[i])
                                                 .Replace("\"", "\"\"")).Append("\"");
                }
                else
                {
                    builder.Append(args[i]);
                }
            }
            builder.Append(")");
            result = new MemberAccessWrapper(builder.ToString());
            return(true);
        }
 protected override object Handle(object[] args, MemberAccessWrapper next)
 {
     return(new MemberAccessWrapper
            (
                next.HttpClientWrapper,
                next.BaseUri,
                next.GetRelativeUri() + "/" + args[0],
                next.Headers
            ));
 }
示例#5
0
 protected override object Handle(object[] args, MemberAccessWrapper next)
 {
     return(new MemberAccessWrapper //Resource is our default it does the chaining .api.v1.users.etc
            (
                next.HttpClientWrapper,
                next.BaseUri,
                next.Uri + "/" + args[0],
                next.Headers
            ));
 }
示例#6
0
        protected override object Handle(object[] args, MemberAccessWrapper next)
        {
            var queryString = ToQueryString(args[0].FlattenObjectToKeyValuePairs <string>(includeThisType: Object.IsValueTypeOrPrimitiveOrStringOrGuidOrDateTime));

            return(new MemberAccessWrapper
                   (
                       next.HttpClientWrapper,
                       next.BaseUri,
                       next.GetRelativeUri() + queryString,
                       next.Headers
                   ));
        }
 private static void AddHeaders(MemberAccessWrapper next, IDictionary <string, string> headers)
 {
     foreach (var header in headers)
     {
         if (next.Headers.ContainsKey(header.Key))
         {
             next.Headers[header.Key] = header.Value;
         }
         else
         {
             next.Headers.Add(header.Key, header.Value);
         }
     }
 }
        protected override object Handle(object[] args, MemberAccessWrapper next)
        {
            if (args[0] is IDictionary <string, string> headers)
            {
                AddHeaders(next, headers);
            }
            else
            {
                AddHeaders(next, new Headers(args[0]));
            }

            return(new MemberAccessWrapper
                   (
                       next.HttpClientWrapper,
                       next.BaseUri,
                       next.GetRelativeUri(),
                       next.Headers
                   ));
        }
        protected override object Handle(object[] args, MemberAccessWrapper next)
        {
            var headers = args[0] as IDictionary <string, string>;

            if (headers != null)
            {
                AddHeaders(next, headers);
            }
            else
            {
                AddHeaders(next, args[0].GetType().GetProperties()
                           .Where(_ => _.GetValue(args[0]) != null)
                           .ToDictionary(_ => FormatHeaderName(_.Name), _ => _.GetValue(args[0]).ToString()));
            }

            return(new MemberAccessWrapper
                   (
                       next.HttpClientWrapper,
                       next.BaseUri,
                       next.GetRelativeUri(),
                       next.Headers
                   ));
        }
示例#10
0
        internal object Execute(object[] args, MemberAccessWrapper next)
        {
            Validate(args);

            return(IsAsync() ? HandleAsync(args, next) : Handle(args, next));
        }
示例#11
0
 //what happens if you have two HandleAsync in the pipleline, it should end the pipeline as it returns task
 protected virtual Task <object> HandleAsync(object[] args, MemberAccessWrapper next)
 {
     return(Task.FromResult((object)next));
 }
示例#12
0
 protected virtual object Handle(object[] args, MemberAccessWrapper next)
 {
     return(next);
 }