Beispiel #1
0
        /// <summary>Calls the ReST service using specified HTTP verb.</summary>
        /// <typeparam name="T">Type of the result.</typeparam>
        /// <param name="verb">The HTTP verb.</param>
        /// <param name="url">Relative URL of the service to call.</param>
        /// <param name="mediaTypes">Enumeration of accepted media types.</param>
        /// <param name="contentType">Enumeration of possible content type media types.</param>
        /// <param name="uriArguments">The URI template arguments.</param>
        /// <param name="bodyArguments">The body arguments.</param>
        /// <returns>Result of the call.</returns>
        protected internal T Call <T>(Verb verb, string url, IEnumerable <string> mediaTypes, IEnumerable <string> contentType, IDictionary <string, object> uriArguments, params object[] bodyArguments)
        {
            var result = Call(verb, url, mediaTypes, contentType, typeof(T), uriArguments, bodyArguments);

            return(result == null ? default(T) : (result is T ? (T)result : (T)Convert.ChangeType(result, typeof(T))));
        }
Beispiel #2
0
 public RequestInfo(Verb method, HttpUrl url, Stream body, IClaimBasedIdentity identity, params Header[] headers) :
     this(method, url, body, identity, new HeaderCollection(headers))
 {
 }
Beispiel #3
0
 /// <summary>Calls the ReST service using specified HTTP verb.</summary>
 /// <param name="verb">The HTTP verb.</param>
 /// <param name="url">Relative URL of the service to call.</param>
 /// <param name="accept">Enumeration of accepted media types.</param>
 /// <param name="contentType">Enumeration of possible content type media types.</param>
 /// <param name="uriArguments">The URI template arguments.</param>
 /// <param name="bodyArguments">The body arguments.</param>
 protected internal void Call(Verb verb, string url, IEnumerable <string> accept, IEnumerable <string> contentType, IDictionary <string, object> uriArguments, params object[] bodyArguments)
 {
     Call(verb, url, accept, contentType, null, uriArguments, bodyArguments);
 }
Beispiel #4
0
        private double GetMatchRank(ControllerInfo controller, OperationInfo <Verb> operation, IEnumerable <string> queryString, Verb method)
        {
            var requiredQueryStringArguments = new List <string>();
            var optionalQueryStringArguments = new List <string>();
            var matchingRequiredParameters   = new List <string>();
            var matchingOptionalParameters   = new List <string>();

            foreach (var argument in operation.Arguments.Where(argument => argument.Source is FromQueryStringAttribute))
            {
                (argument.Parameter.HasDefaultValue ? optionalQueryStringArguments : requiredQueryStringArguments).Add(argument.VariableName);
                if (queryString.Contains(argument.VariableName, StringComparer.InvariantCultureIgnoreCase))
                {
                    (argument.Parameter.HasDefaultValue ? matchingOptionalParameters : matchingRequiredParameters).Add(argument.VariableName);
                }
            }

            var result = (controller.ControllerType.IsGenericType ? 0 : 1) +
                         (operation.ProtocolSpecificCommand == method ? (VerbRanks.ContainsKey(method) ? VerbRanks[method] : VerbRanks[Verb.Empty]) : 0);

            result += Math.Max(0, matchingRequiredParameters.Count - requiredQueryStringArguments.Count) +
                      (Math.Max(0, matchingOptionalParameters.Count - optionalQueryStringArguments.Count) * 10);
            return(result);
        }