Ejemplo n.º 1
0
        public WMSBaseApiAccessor(Wms_warehouse warehouse, ISqlSugarClient client, SysUserDto userDto)
        {
            this.Warehouse = warehouse;
            HttpApiConfig config = new HttpApiConfig();

            config.HttpHost = new Uri(warehouse.IFAddress);
            if (!string.IsNullOrWhiteSpace(WMSProxy))
            {
                config.HttpHandler.UseProxy = true;
                config.HttpHandler.Proxy    = new HttpProxy(WMSProxy);
                WebRequest.DefaultWebProxy  = new WebProxy(WMSProxy)
                {
                    BypassProxyOnLocal = false
                };
            }

            _apiProxy     = HttpApi.Create <IWMSApiProxy>(config);
            _selfAccessor = new SelfWMSBaseApiAccessor(warehouse, client, userDto);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //IMessageBus messageBus = new InMemoryMessageBus();
            //messageBus.SubscribeAsync<SimpleMessageA>(msg => { Console.WriteLine(msg.Data); }).Wait();

            //messageBus.PublishAsync(new SimpleMessageA
            //{
            //    Data = "Hello"
            //}).Wait();

            var config = new HttpApiConfig()
            {
                HttpHost = new Uri("http://localhost:53247/"),
            };
            var apiInerceptor = new TestApiInterceptor(config);

            using (var client = HttpApiClient.Create(typeof(ITestWebApi), apiInerceptor) as ITestWebApi)
            {
                //var result = client.GetTest2Async().GetAwaiter().GetResult();
                //Console.WriteLine(result.ToString());

                //var result = client.AddTestAsync(new IdName("123", "Test")).GetAwaiter().GetResult();
                var result = client.TestPostAsync(new IdName("test", "test")).GetAwaiter();
                //Console.WriteLine("w");
            }

            //Assembly.GetAssembly(typeof(IHttpApi))
            //    .GetTypes()
            //    .Where(t => t != typeof(IHttpApi) && typeof(IHttpApi).IsAssignableFrom(t))
            //    .ForEach(serviceType =>
            //    {
            //        var client = HttpApiClient.Create(serviceType, config) as ITestWebApi;

            //    });
            //var assemblys = Assembly.GetAssembly(typeof(IServiceHttpClient))
            //                        .GetTypes()
            //                        .Where(t => t != typeof(IServiceHttpClient) && typeof(IServiceHttpClient).IsAssignableFrom(t));

            //var client = HttpApiClient.Create(typeof(ITestWebApi), apiInerceptor) as ITestWebApi;
            //Console.WriteLine("End");
            //Console.Read();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加HttpApiClient的别名HttpClient
        /// </summary>
        /// <typeparam name="TInterface">接口类型</typeparam>
        /// <param name="services"></param>
        /// <param name="configOptions">配置选项</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static IHttpClientBuilder AddHttpApiTypedClient <TInterface>(this IServiceCollection services, Action <HttpApiConfig, IServiceProvider> configOptions)
            where TInterface : class, IHttpApi
        {
            if (configOptions == null)
            {
                throw new ArgumentNullException(nameof(configOptions));
            }

            return(services
                   .AddHttpClient(typeof(TInterface).ToString())
                   .AddTypedClient((httpClient, provider) =>
            {
                var httpApiConfig = new HttpApiConfig(httpClient)
                {
                    ServiceProvider = provider
                };
                configOptions.Invoke(httpApiConfig, provider);
                return HttpApi.Create <TInterface>(httpApiConfig);
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加HttpApiClient的别名HttpClient
        /// </summary>
        /// <typeparam name="TInterface"></typeparam>
        /// <param name="services"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static IServiceCollection AddWebApiClientUseHttpClientFactory <TInterface>(this IServiceCollection services, Action <HttpApiConfig, IServiceProvider> config)
            where TInterface : class, IHttpApi
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            services.AddHttpClient <TInterface>().AddTypedClient <TInterface>((httpClient, provider) =>
            {
                var httpApiConfig = new HttpApiConfig(httpClient)
                {
                    ServiceProvider       = provider,
                    ResponseCacheProvider = new EasyCachingResponseCacheProvider(provider)
                };
                config.Invoke(httpApiConfig, provider);
                var interceptor = new EasyCachingInterceptor(httpApiConfig);
                return(HttpApiClient.Create(typeof(TInterface), interceptor) as TInterface);
            });

            return(services);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestActionContext"/> class.
 /// 请求Api的上下文
 /// </summary>
 /// <param name="httpApiConfig">关联的HttpApiConfig</param>
 /// <param name="apiActionDescriptor">关联的ApiActionDescriptor</param>
 /// <param name="parameters">参数列表</param>
 /// <exception cref="ArgumentNullException">参数null异常</exception>
 public TestActionContext(HttpApiConfig httpApiConfig, ApiActionDescriptor apiActionDescriptor, IReadOnlyList <ApiParameterDescriptor> parameters)
     : base(httpApiConfig, apiActionDescriptor, parameters)
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// EasyCaching的请求上下文
 /// </summary>
 /// <param name="httpApi"></param>
 /// <param name="httpApiConfig"></param>
 /// <param name="apiActionDescriptor"></param>
 public EasyCachingApiActionContext(IHttpApi httpApi, HttpApiConfig httpApiConfig, ApiActionDescriptor apiActionDescriptor)
     : base(httpApi, httpApiConfig, apiActionDescriptor)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// http接口调用的拦截器
 /// </summary>
 /// <param name="httpApiConfig">httpApi配置</param>
 /// <exception cref="ArgumentNullException"></exception>
 public ApiInterceptor(HttpApiConfig httpApiConfig)
 {
     this.HttpApiConfig = httpApiConfig ?? throw new ArgumentNullException(nameof(httpApiConfig));
 }
Ejemplo n.º 8
0
 public MyInterceptor(HttpApiConfig apiConfig)
 {
     this.ApiConfig = apiConfig;
 }
 public TestApiInterceptor(HttpApiConfig httpApiConfig)
     : base(httpApiConfig)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 请求Api的上下文
 /// </summary>
 /// <param name="httpApi">httpApi代理类实例</param>
 /// <param name="httpApiConfig">关联的HttpApiConfig</param>
 /// <param name="apiActionDescriptor">关联的ApiActionDescriptor</param>
 /// <exception cref="ArgumentNullException"></exception>
 public TestActionContext(IHttpApi httpApi, HttpApiConfig httpApiConfig, ApiActionDescriptor apiActionDescriptor)
     : base(httpApi, httpApiConfig, apiActionDescriptor)
 {
     this.ResponseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 重写http接口调用的拦截器
 /// </summary>
 /// <param name="httpApiConfig"></param>
 public EasyCachingInterceptor(HttpApiConfig httpApiConfig)
     : base(httpApiConfig)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// http接口调用的拦截器
 /// </summary>
 /// <param name="httpApiConfig">httpApi配置</param>
 /// <exception cref="ArgumentNullException"></exception>
 public NoneDisposeApiInterceptor(HttpApiConfig httpApiConfig)
     : base(httpApiConfig)
 {
 }