当前位置: 首页>>代码示例>>C#>>正文


C# IDirectedProtocolMessage.GetType方法代码示例

本文整理汇总了C#中IDirectedProtocolMessage.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IDirectedProtocolMessage.GetType方法的具体用法?C# IDirectedProtocolMessage.GetType怎么用?C# IDirectedProtocolMessage.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDirectedProtocolMessage的用法示例。


在下文中一共展示了IDirectedProtocolMessage.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNewResponseMessage

        /// <summary>
        /// Analyzes an incoming request message payload to discover what kind of 
        /// message is embedded in it and returns the type, or null if no match is found.
        /// </summary>
        /// <param name="request">
        /// The message that was sent as a request that resulted in the response.
        /// Null on a Consumer site that is receiving an indirect message from the Service Provider.
        /// </param>
        /// <param name="fields">The name/value pairs that make up the message payload.</param>
        /// <returns>
        /// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
        /// deserialize to.  Null if the request isn't recognized as a valid protocol message.
        /// </returns>
        /// <remarks>
        /// The response messages are:
        /// UnauthorizedTokenResponse
        /// AuthorizedTokenResponse
        /// </remarks>
        public virtual IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields)
        {
            ErrorUtilities.VerifyArgumentNotNull(request, "request");
            ErrorUtilities.VerifyArgumentNotNull(fields, "fields");

            MessageBase message = null;

            // All response messages have the oauth_token field.
            if (!fields.ContainsKey("oauth_token")) {
                return null;
            }

            // All direct message responses should have the oauth_token_secret field.
            if (!fields.ContainsKey("oauth_token_secret")) {
                Logger.OAuth.Error("An OAuth message was expected to contain an oauth_token_secret but didn't.");
                return null;
            }

            var unauthorizedTokenRequest = request as UnauthorizedTokenRequest;
            var authorizedTokenRequest = request as AuthorizedTokenRequest;
            if (unauthorizedTokenRequest != null) {
                Protocol protocol = fields.ContainsKey("oauth_callback_confirmed") ? Protocol.V10a : Protocol.V10;
                message = new UnauthorizedTokenResponse(unauthorizedTokenRequest, protocol.Version);
            } else if (authorizedTokenRequest != null) {
                message = new AuthorizedTokenResponse(authorizedTokenRequest);
            } else {
                Logger.OAuth.ErrorFormat("Unexpected response message given the request type {0}", request.GetType().Name);
                throw new ProtocolException(OAuthStrings.InvalidIncomingMessage);
            }

            if (message != null) {
                message.SetAsIncoming();
            }

            return message;
        }
开发者ID:jcp-xx,项目名称:dotnetopenid,代码行数:54,代码来源:OAuthConsumerMessageFactory.cs

示例2: InstantiateAsResponse

		/// <summary>
		/// Instantiates the given request message type.
		/// </summary>
		/// <param name="messageDescription">The message description.</param>
		/// <param name="request">The request that resulted in this response.</param>
		/// <returns>The instantiated message.  Never null.</returns>
		protected virtual IDirectResponseProtocolMessage InstantiateAsResponse(MessageDescription messageDescription, IDirectedProtocolMessage request) {
			Contract.Requires<ArgumentNullException>(messageDescription != null);
			Contract.Requires<ArgumentNullException>(request != null);
			Contract.Ensures(Contract.Result<IDirectResponseProtocolMessage>() != null);

			Type requestType = request.GetType();
			var ctors = this.FindMatchingResponseConstructors(messageDescription, requestType);
			ConstructorInfo ctor = null;
			try {
				ctor = ctors.Single();
			} catch (InvalidOperationException) {
				if (ctors.Any()) {
					ErrorUtilities.ThrowInternal("More than one matching constructor for request type " + requestType.Name + " and response type " + messageDescription.MessageType.Name);
				} else {
					ErrorUtilities.ThrowInternal("Unexpected request message type " + requestType.FullName + " for response type " + messageDescription.MessageType.Name);
				}
			}
			return (IDirectResponseProtocolMessage)ctor.Invoke(new object[] { request });
		}
开发者ID:enslam,项目名称:dotnetopenid,代码行数:25,代码来源:StandardMessageFactory.cs

示例3: CreateHttpRequest

        /// <summary>
        /// Prepares an HTTP request that carries a given message.
        /// </summary>
        /// <param name="request">The message to send.</param>
        /// <returns>
        /// The <see cref="HttpRequest"/> prepared to send the request.
        /// </returns>
        protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request)
        {
            ErrorUtilities.VerifyArgumentNotNull(request, "request");
            ErrorUtilities.VerifyArgumentNamed(request.Recipient != null, "request", MessagingStrings.DirectedMessageMissingRecipient);

            IDirectedProtocolMessage oauthRequest = request as IDirectedProtocolMessage;
            ErrorUtilities.VerifyArgument(oauthRequest != null, MessagingStrings.UnexpectedType, typeof(IDirectedProtocolMessage), request.GetType());

            HttpWebRequest httpRequest;

            HttpDeliveryMethods transmissionMethod = oauthRequest.HttpMethods;
            if ((transmissionMethod & HttpDeliveryMethods.AuthorizationHeaderRequest) != 0) {
                httpRequest = this.InitializeRequestAsAuthHeader(request);
            } else if ((transmissionMethod & HttpDeliveryMethods.PostRequest) != 0) {
                httpRequest = this.InitializeRequestAsPost(request);
            } else if ((transmissionMethod & HttpDeliveryMethods.GetRequest) != 0) {
                httpRequest = InitializeRequestAsGet(request);
            } else {
                throw new NotSupportedException();
            }
            return httpRequest;
        }
开发者ID:vrushalid,项目名称:dotnetopenid,代码行数:29,代码来源:OAuthChannel.cs

示例4: GetMessageDescription

		/// <summary>
		/// Gets the message type that best fits the given incoming direct response data.
		/// </summary>
		/// <param name="request">The request message that prompted the response data.</param>
		/// <param name="fields">The data of the incoming message.</param>
		/// <returns>
		/// The message type that matches the incoming data; or <c>null</c> if no match.
		/// </returns>
		/// <exception cref="ProtocolException">May be thrown if the incoming data is ambiguous.</exception>
		protected virtual MessageDescription GetMessageDescription(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
			Contract.Requires<ArgumentNullException>(request != null);
			Contract.Requires<ArgumentNullException>(fields != null);

			var matches = (from responseMessageType in this.responseMessageTypes
			               let message = responseMessageType.Key
			               where message.CheckMessagePartsPassBasicValidation(fields)
			               let ctors = this.FindMatchingResponseConstructors(message, request.GetType())
			               where ctors.Any()
			               orderby GetDerivationDistance(ctors.First().GetParameters()[0].ParameterType, request.GetType()),
			                 CountInCommon(message.Mapping.Keys, fields.Keys) descending,
			                 message.Mapping.Count descending
			               select message).CacheGeneratedResults();
			var match = matches.FirstOrDefault();
			if (match != null) {
				if (Logger.Messaging.IsWarnEnabled && matches.Count() > 1) {
					Logger.Messaging.WarnFormat(
						"Multiple message types seemed to fit the incoming data: {0}",
						matches.ToStringDeferred());
				}

				return match;
			} else {
				// No message type matches the incoming data.
				return null;
			}
		}
开发者ID:enslam,项目名称:dotnetopenid,代码行数:36,代码来源:StandardMessageFactory.cs


注:本文中的IDirectedProtocolMessage.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。