Ejemplo n.º 1
0
        /// <summary>
        /// Sorts a <see cref="WebParameterCollection"/> by name, and then value if equal.
        /// </summary>
        /// <param name="parameters">A collection of parameters to sort</param>
        /// <returns>A sorted parameter collection</returns>
        public static WebParameterCollection SortParametersExcludingSignature(WebParameterCollection parameters)
        {
            var copy       = new WebParameterCollection(parameters.Select(x => new WebParameter(x.Name, x.Value, x.Type)));
            var exclusions = copy.Where(n => string.Equals(n.Name, "oauth_signature", StringComparison.OrdinalIgnoreCase));

            copy.RemoveAll(exclusions);
            copy.ForEach(p =>
            {
                p.Name = UrlEncodeStrict(p.Name);
                if (p.Type == WebParameterType.Query)
                {
                    // Parameter provided by the user
                    p.Value = _escapeUtility.Escape(p.Value, _encoding, UrlEscapeFlags.AllowLikeWebRequest);
                }
                else
                {
                    // Authorization or POST parameter
                    p.Value = UrlEncodeStrict(p.Value);
                }
            });
            copy.Sort(
                (x, y) =>
                string.CompareOrdinal(x.Name, y.Name) != 0
            ? string.CompareOrdinal(x.Name, y.Name)
            : string.CompareOrdinal(x.Value, y.Value));
            return(copy);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Sorts a <see cref="WebParameterCollection"/> by name, and then value if equal.
 /// </summary>
 /// <param name="parameters">A collection of parameters to sort</param>
 /// <returns>A sorted parameter collection</returns>
 public static WebParameterCollection SortParametersExcludingSignature(WebParameterCollection parameters)
 {
     var copy = new WebParameterCollection(parameters.Select(x => new WebParameter(x.Name, x.Value, x.Type)));
     var exclusions = copy.Where(n => string.Equals(n.Name, "oauth_signature", StringComparison.OrdinalIgnoreCase));
     copy.RemoveAll(exclusions);
     copy.ForEach(p =>
     {
         p.Name = UrlEncodeStrict(p.Name);
         if (p.Type == WebParameterType.Query)
         {
             // Parameter provided by the user
             p.Value = _escapeUtility.Escape(p.Value, _encoding, UrlEscapeFlags.AllowLikeWebRequest);
         }
         else
         {
             // Authorization or POST parameter
             p.Value = UrlEncodeStrict(p.Value);
         }
     });
     copy.Sort(
     (x, y) =>
     string.CompareOrdinal(x.Name, y.Name) != 0
     ? string.CompareOrdinal(x.Name, y.Name)
     : string.CompareOrdinal(x.Value, y.Value));
     return copy;
 }