Exemple #1
0
 public virtual void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize)
 {
     if (DaprConfig.GetCurrent().UseStaticFiles)
     {
         appBuilder.UseStaticFiles();
     }
     serverHandler.BuildHandler(appBuilder, serialize);
 }
Exemple #2
0
 public virtual void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize)
 {
     if (DaprConfig.GetCurrent().UseStaticFiles)
     {
         appBuilder.UseStaticFiles();
     }
     if (DaprConfig.GetCurrent().UseCors)
     {
         appBuilder.UseCors(x => x.SetIsOriginAllowed(_ => true).AllowAnyHeader().AllowAnyMethod().AllowCredentials());
     }
     serverHandler.BuildHandler(appBuilder, serialize);
 }
Exemple #3
0
        internal static List <BaseRequestDelegate> CreateDelegate(ILogger logger, IMessageHandler messageHandler, out List <SubscribeModel> subDelegate)
        {
            var result       = new List <BaseRequestDelegate>();
            var _subDelegate = new List <SubscribeModel>();
            //获取所有标记为remote的servie
            var remoteservice = ReflectionHelper.GetTypesByAttributes(true, typeof(RemoteServiceAttribute));

            //获取所有标记为remote的method构造具体的delegate
            remoteservice.ToList().ForEach(x =>
            {
                var srvAttr = ReflectionHelper.GetAttributeProperyiesByType <RemoteServiceAttribute>(x);
                if (ReflectionHelper.GetTypeByInterface(x) != null)
                {
                    ReflectionHelper.GetMethodByFilter(x, typeof(RemoteFuncAttribute)).ToList().ForEach(y =>
                    {
                        var funcAttr = ReflectionHelper.GetAttributeProperyiesByMethodInfo <RemoteFuncAttribute>(y);
                        //生成服务调用代理
                        if (funcAttr.FuncType == FuncType.Invoke)
                        {
                            var requestDelegate = CreateRequestDelegate(x, srvAttr?.ServerName ?? x.Name, y, logger, messageHandler);
                            if (requestDelegate != null)
                            {
                                result.Add(requestDelegate);
                            }
                        }
                    });
                }
            });
            //为所有事件处理器生成代理并注册到dapr
            var eventhandlers = ReflectionHelper.GetImplTypeByInterface <IEventHandler>();

            eventhandlers.ToList().ForEach(x =>
            {
                x.GetMethods().ToList().ForEach(y =>
                {
                    if (y.ReturnType == typeof(Task <DefaultEventHandlerResponse>) && y.GetParameters().Any() &&
                        y.GetParameters().FirstOrDefault().ParameterType.IsGenericType &&
                        y.GetParameters().FirstOrDefault().ParameterType.GetGenericTypeDefinition() == typeof(EventHandleRequest <>))
                    {
                        var handlerAttr     = ReflectionHelper.GetAttributeProperyiesByMethodInfo <EventHandlerFuncAttribute>(y);
                        var requestDelegate = CreateRequestDelegate(x, x.Name, y, logger, messageHandler);
                        if (requestDelegate != null)
                        {
                            result.Add(requestDelegate);
                            _subDelegate.Add(new SubscribeModel(DaprConfig.GetCurrent().PubSubCompentName, handlerAttr.Topic, requestDelegate.Path));
                        }
                    }
                });
            });
            subDelegate = _subDelegate;
            return(result);
        }
 /// <summary>
 /// 注入web服务
 /// </summary>
 /// <param name="webHostBuilder"></param>
 /// <param name="action"></param>
 public static void StartOxygenServer <Startup>(this IWebHostBuilder webHostBuilder, Action <DaprConfig> action) where Startup : class
 {
     action(DaprConfig.GetCurrent());
     webHostBuilder
     .UseKestrel(options =>     //重写ConfigureWebHostDefaults中Kestrel配置
     {
         options.Listen(IPAddress.Any, DaprConfig.GetCurrent().Port, listenOptions =>
         {
             listenOptions.Protocols = HttpProtocols.Http1;
         });
     });
     if (DaprConfig.GetCurrent().UseStaticFiles)
     {
         webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
     }
     webHostBuilder.UseStartup <Startup>();
 }
Exemple #5
0
 public async Task <DefaultResponse> SendEvent <T>(string topic, T input)
 {
     return(await messageSender.SendMessage <DefaultResponse>(DaprConfig.GetCurrent().PubSubCompentName, $"/{topic}", input, SendType.publish));
 }
Exemple #6
0
 public async Task <DefaultResponse> SetState(StateStore input)
 {
     return(await messageSender.SendMessage <DefaultResponse>(DaprConfig.GetCurrent().StateStoreCompentName, "", new[] { new { key = input.Key, value = input.Data } }, SendType.setState));
 }
Exemple #7
0
 public async Task <T> GetState <T>(StateStore input) where T : new()
 {
     return(await messageSender.SendMessage <T>(DaprConfig.GetCurrent().StateStoreCompentName, $"/{input.Key}", null, SendType.getState));
 }
Exemple #8
0
 public async Task <DefaultResponse> DelState(StateStore input)
 {
     return(await messageSender.SendMessage <DefaultResponse>(DaprConfig.GetCurrent().StateStoreCompentName, $"/{input.Key}", null, SendType.delState));
 }