/// <summary>
        /// 初始化一个<see cref="AuthorizationResult"/>类型的实例
        /// </summary>
        /// <param name="raw">授权接口返回的原始消息</param>
        /// <param name="success">是否成功</param>
        /// <param name="type">参数解析器类型</param>
        public AuthorizationResult(string raw, Func <AuthorizationResult, bool> success,
                                   ParameterParserType type = ParameterParserType.Json)
        {
            Raw = raw;
            IParameterParserFactory factory = new ParameterParserFactory();

            _parser = factory.CreateParameterParser(type);
            _parser.LoadData(raw);
            Success = success(this);
        }
Пример #2
0
        /// <summary>
        /// 创建参数解析器
        /// </summary>
        /// <param name="type">参数解析器类型</param>
        public IParameterParser CreateParameterParser(ParameterParserType type)
        {
            switch (type)
            {
            case ParameterParserType.Url:
                return(new UrlParameterParser());

            case ParameterParserType.Json:
                return(new JsonParameterParser());

            case ParameterParserType.Jsonp:
                return(new JsonpParameterParser());

            default:
                throw new NotImplementedException();
            }
        }
        /// <summary>
        /// Post请求结果
        /// </summary>
        /// <param name="config">授权配置</param>
        /// <param name="builder">授权参数生成器</param>
        /// <param name="type">参数解析器类型</param>
        /// <param name="success">请求成功条件</param>
        /// <returns></returns>
        protected virtual async Task <AuthorizationResult> PostRequestResult(TAuthorizationConfig config,
                                                                             AuthorizationParameterBuilder builder, ParameterParserType type, Func <AuthorizationResult, bool> success)
        {
            var result = new AuthorizationResult(await PostRequest(builder), success, type);

            result.Parameter = builder.ToString();
            result.Message   = GetMessage(result);
            WriteLog(config, builder, result);
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 请求结果
        /// </summary>
        /// <param name="config">授权配置</param>
        /// <param name="builder">授权参数生成器</param>
        /// <param name="type">参数解析器类型</param>
        /// <param name="success">请求成功条件</param>
        /// <returns></returns>
        protected override async Task <AuthorizationResult> RequestResult(GithubAuthorizationConfig config, AuthorizationParameterBuilder builder, ParameterParserType type,
                                                                          Func <AuthorizationResult, bool> success)
        {
            var result = new AuthorizationResult(await Request(builder, config.ApplicationName), success, type);

            result.Parameter = builder.ToString();
            result.Message   = GetMessage(result);
            WriteLog(config, builder, result);
            return(result);
        }