コード例 #1
0
        /// <summary>
        /// Customizes the binding element order for outgoing and incoming messages.
        /// </summary>
        /// <param name="outgoingOrder">The outgoing order.</param>
        /// <param name="incomingOrder">The incoming order.</param>
        /// <remarks>
        /// No binding elements can be added or removed from the channel using this method.
        /// Only a customized order is allowed.
        /// </remarks>
        /// <exception cref="ArgumentException">Thrown if a binding element is new or missing in one of the ordered lists.</exception>
        protected void CustomizeBindingElementOrder(IEnumerable <IChannelBindingElement> outgoingOrder, IEnumerable <IChannelBindingElement> incomingOrder)
        {
            ErrorUtilities.VerifyArgumentNotNull(outgoingOrder, "outgoingOrder");
            ErrorUtilities.VerifyArgumentNotNull(incomingOrder, "incomingOrder");

            ErrorUtilities.VerifyArgument(this.IsBindingElementOrderValid(outgoingOrder), MessagingStrings.InvalidCustomBindingElementOrder);
            ErrorUtilities.VerifyArgument(this.IsBindingElementOrderValid(incomingOrder), MessagingStrings.InvalidCustomBindingElementOrder);

            this.outgoingBindingElements.Clear();
            this.outgoingBindingElements.AddRange(outgoingOrder);
            this.incomingBindingElements.Clear();
            this.incomingBindingElements.AddRange(incomingOrder);
        }
コード例 #2
0
        /// <summary>
        /// Copies the contents of one stream to another.
        /// </summary>
        /// <param name="copyFrom">The stream to copy from, at the position where copying should begin.</param>
        /// <param name="copyTo">The stream to copy to, at the position where bytes should be written.</param>
        /// <param name="maximumBytesToCopy">The maximum bytes to copy.</param>
        /// <returns>The total number of bytes copied.</returns>
        /// <remarks>
        /// Copying begins at the streams' current positions.
        /// The positions are NOT reset after copying is complete.
        /// </remarks>
        internal static int CopyTo(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy)
        {
            ErrorUtilities.VerifyArgumentNotNull(copyFrom, "copyFrom");
            ErrorUtilities.VerifyArgumentNotNull(copyTo, "copyTo");
            ErrorUtilities.VerifyArgument(copyFrom.CanRead, MessagingStrings.StreamUnreadable);
            ErrorUtilities.VerifyArgument(copyTo.CanWrite, MessagingStrings.StreamUnwritable, "copyTo");

            byte[] buffer = new byte[1024];
            int    readBytes;
            int    totalCopiedBytes = 0;

            while ((readBytes = copyFrom.Read(buffer, 0, Math.Min(1024, maximumBytesToCopy))) > 0)
            {
                int writeBytes = Math.Min(maximumBytesToCopy, readBytes);
                copyTo.Write(buffer, 0, writeBytes);
                totalCopiedBytes   += writeBytes;
                maximumBytesToCopy -= writeBytes;
            }

            return(totalCopiedBytes);
        }
コード例 #3
0
        /// <summary>
        /// Concatenates a list of name-value pairs as key=value&amp;key=value,
        /// taking care to properly encode each key and value for URL
        /// transmission.  No ? is prefixed to the string.
        /// </summary>
        /// <param name="args">The dictionary of key/values to read from.</param>
        /// <returns>The formulated querystring style string.</returns>
        internal static string CreateQueryString(IEnumerable <KeyValuePair <string, string> > args)
        {
            ErrorUtilities.VerifyArgumentNotNull(args, "args");
            if (args.Count() == 0)
            {
                return(string.Empty);
            }
            StringBuilder sb = new StringBuilder(args.Count() * 10);

            foreach (var p in args)
            {
                ErrorUtilities.VerifyArgument(!string.IsNullOrEmpty(p.Key), MessagingStrings.UnexpectedNullOrEmptyKey);
                ErrorUtilities.VerifyArgument(p.Value != null, MessagingStrings.UnexpectedNullValue, p.Key);
                sb.Append(HttpUtility.UrlEncode(p.Key));
                sb.Append('=');
                sb.Append(HttpUtility.UrlEncode(p.Value));
                sb.Append('&');
            }
            sb.Length--;             // remove trailing &

            return(sb.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Concatenates a list of name-value pairs as key=value&amp;key=value,
        /// taking care to properly encode each key and value for URL
        /// transmission according to RFC 3986.  No ? is prefixed to the string.
        /// </summary>
        /// <param name="args">The dictionary of key/values to read from.</param>
        /// <returns>The formulated querystring style string.</returns>
        internal static string CreateQueryString(IEnumerable <KeyValuePair <string, string> > args)
        {
            Contract.Requires <ArgumentNullException>(args != null);
            Contract.Ensures(Contract.Result <string>() != null);

            if (args.Count() == 0)
            {
                return(string.Empty);
            }
            StringBuilder sb = new StringBuilder(args.Count() * 10);

            foreach (var p in args)
            {
                ErrorUtilities.VerifyArgument(!string.IsNullOrEmpty(p.Key), MessagingStrings.UnexpectedNullOrEmptyKey);
                ErrorUtilities.VerifyArgument(p.Value != null, MessagingStrings.UnexpectedNullValue, p.Key);
                sb.Append(EscapeUriDataStringRfc3986(p.Key));
                sb.Append('=');
                sb.Append(EscapeUriDataStringRfc3986(p.Value));
                sb.Append('&');
            }
            sb.Length--;             // remove trailing &

            return(sb.ToString());
        }