Esempio n. 1
0
 static void Main(string[] args)
 {
     using (var stack = new KunoStack())
     {
         stack.RunWebHost();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityFrameworkSearchModule" /> class.
        /// </summary>
        /// <param name="stack">The configured stack.</param>
        /// <param name="options">The options to use.</param>
        public EntityFrameworkSearchModule(KunoStack stack, EntityFrameworkOptions options)
        {
            Argument.NotNull(options, nameof(options));

            _stack   = stack;
            _options = options;
        }
Esempio n. 3
0
        /// <summary>
        /// Gets an endpoint from the request.
        /// </summary>
        /// <param name="stack">The stack.</param>
        /// <param name="request">The current request.</param>
        /// <returns>Returns an endpoint from the request.</returns>
        internal static EndPoint GetEndPoint(this HttpRequest request, KunoStack stack)
        {
            var path      = request.Path.Value.Trim('/');
            var inventory = stack.Container.Resolve <ServiceRegistry>();

            return(inventory.EndPoints.Find(path));
        }
Esempio n. 4
0
        /// <summary>
        /// Configures all the Azure Service Bus components.
        /// </summary>
        /// <param name="instance">The this instance.</param>
        /// <returns>A task for asynchronous programming.</returns>
        public static KunoStack UseAzureServiceBus(this KunoStack instance)
        {
            var settings = new AzureServiceBusSettings();

            instance.Configuration.GetSection("kuno:azureServiceBus")?.Bind(settings);

            instance.Use(builder =>
            {
                if (settings.EventPublisher?.TopicName != null)
                {
                    builder.RegisterModule(new TopicEventPublishingModule(settings));
                }
                if (settings.Subscriptions.Any())
                {
                    builder.RegisterModule(new TopicSubscriptionModule(settings));
                }
            });

            if (settings.Subscriptions.Any())
            {
                instance.Container.Resolve <TopicSubscription>();
            }

            return(instance);
        }
Esempio n. 5
0
        /// <summary>
        /// Configures the stack to use Akka.NET Messaging.
        /// </summary>
        /// <param name="instance">The this instance.</param>
        /// <param name="configuration">The configuration routine.</param>
        /// <returns>KunoStack.</returns>
        public static KunoStack UseAkka(this KunoStack instance, Action <MessagingOptions> configuration = null)
        {
            var options = new MessagingOptions();

            configuration?.Invoke(options);

            var system = ActorSystem.Create(options.SystemName, @"akka {  
            actor {              
              serializers {
                wire = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion""
              }
              serialization-bindings {
                ""System.Object"" = wire
              }
            }
          }");

            new AutoFacDependencyResolver(instance.Container, system);

            instance.Use(builder =>
            {
                builder.RegisterModule(new AkkaModule(instance));

                builder.Register(c => system).AsSelf().SingleInstance();
            });

            system.ActorOf(system.DI().Props <ServicesCoordinator>(), "_services");

            return(instance);
        }
Esempio n. 6
0
 static void Main(string[] args)
 {
     using (var stack = new KunoStack())
     {
         stack.Publish("SomeEvent", "asdf");
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Schedules the request to run repeatedly using the specified delay and interval.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="delay">The time to delay delay.</param>
        /// <param name="interval">The time between sends.</param>
        /// <param name="message">The message to send.</param>
        /// <returns>KunoStack.</returns>
        public static KunoStack Schedule(this KunoStack instance, TimeSpan delay, TimeSpan interval, object message)
        {
            var system         = instance.Container.Resolve <ActorSystem>();
            var actorSelection = system.ActorSelection("user/_services/schedule");

            system.Scheduler.ScheduleTellRepeatedly(delay, interval, actorSelection, message, ActorRefs.NoSender);
            return(instance);
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            Console.Title = "Remote Client";

            using (var stack = new KunoStack())
            {
                stack.RunAkkaHost();
            }
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            using (var stack = new KunoStack())
            {
                stack.Send(new SomeEvent());

                stack.Shutdown().Wait();

                stack.GetRequests().OutputToJson();
            }
        }
Esempio n. 10
0
        private static void Subscribe(KunoStack stack, SubscriptionSettings options)
        {
            var target = stack.Container.Resolve <RemoteServiceInventory>();

            using (var client = new HttpClient())
            {
                foreach (var url in options.Remote)
                {
                    if (!String.IsNullOrWhiteSpace(options.Local))
                    {
                        try
                        {
                            var message = new StringContent(JsonConvert.SerializeObject(new
                            {
                                url = options.Local
                            }), Encoding.UTF8, "application/json");
                            client.PostAsync(url + "/_system/events/subscribe", message).Wait();
                        }
                        catch (Exception exception)
                        {
                            stack.Logger.Warning(exception, $"Failed to subscribe to {url}");
                            continue;
                        }
                    }

                    try
                    {
                        var result = client.GetAsync(url + "/_system/endpoints").Result;
                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            var content   = result.Content.ReadAsStringAsync().Result;
                            var endPoints = JsonConvert.DeserializeObject <RemoteService>(content);
                            target.Add(endPoints);
                        }
                    }
                    catch (Exception exception)
                    {
                        stack.Logger.Warning(exception, $"Failed to get remote endpoints at {url}");
                        continue;
                    }
                }
            }
            Task.Run(async() =>
            {
                await Task.Delay(TimeSpan.FromSeconds(15));

                Subscribe(stack, options);
            });
        }
Esempio n. 11
0
        /// <summary>
        /// Adds Entity Framework.
        /// </summary>
        /// <param name="instance">The container instance.</param>
        /// <param name="configuration">The configuration routine.</param>
        /// <returns>Returns the container instance for method chaining.</returns>
        public static KunoStack UseEntityFramework(this KunoStack instance, Action <EntitySettings> configuration = null)
        {
            Argument.NotNull(instance, nameof(instance));

            var options = new EntityFrameworkOptions();

            configuration?.Invoke(options.Data);
            instance.Configuration.GetSection("Kuno:EntityFramework").Bind(options);
            options.Assemblies = instance.Assemblies;

            instance.Include(typeof(EntityContext));

            instance.Use(e => { e.RegisterModule(new EntityFrameworkEntitiesModule(instance, options)); });
            return(instance);
        }
Esempio n. 12
0
        /// <summary>
        /// Configures the stack to use HTTP messaging.
        /// </summary>
        /// <param name="stack">The this instance.</param>
        /// <param name="configuration">The configuration routine.</param>
        /// <returns>Returns the instance for method chaining.</returns>
        public static KunoStack UseHttpMessaging(this KunoStack stack, Action <AspNetCoreOptions> configuration = null)
        {
            var options = new AspNetCoreOptions();

            configuration?.Invoke(options);
            stack.Configuration.GetSection("Kuno:AspNetCore").Bind(options);

            stack.Use(e =>
            {
                e.RegisterType <HttpRouter>().AsImplementedInterfaces().AsSelf().SingleInstance();
            });

            if (options.Subscriptions != null && options.Subscriptions.Remote.Any())
            {
                Subscribe(stack, options.Subscriptions);
            }

            return(stack);
        }
Esempio n. 13
0
        /// <summary>
        /// Starts and runs an API to access the stack.
        /// </summary>
        /// <param name="stack">The this instance.</param>
        /// <param name="configuration">The configuration routine.</param>
        /// <returns>Returns the instance for method chaining.</returns>
        public static KunoStack RunWebHost(this KunoStack stack, Action <AspNetCoreOptions> configuration = null)
        {
            stack.UseHttpMessaging();
            stack.Use(e =>
            {
                e.RegisterType <AspNetCoreRequestContext>().As <IRequestContext>().AsSelf();
            });

            var options = new AspNetCoreOptions();

            configuration?.Invoke(options);
            stack.Configuration.GetSection("Kuno:AspNetCore").Bind(options);

            Startup.Stack   = stack;
            Startup.Options = options;

            var builder = new WebHostBuilder()
                          .UseKestrel()
                          .UseContentRoot(Directory.GetCurrentDirectory())
                          .UseIISIntegration()
                          .UseStartup <Startup>();

            if (options.Urls?.Any() ?? false)
            {
                builder.UseUrls(options.Urls);
            }

            var host = builder.Build();

            if (options.Subscriptions != null && options.Subscriptions.Remote.Any())
            {
                Task.Run(() => Subscribe(stack, options.Subscriptions));
            }

            host.Run();

            return(stack);
        }
Esempio n. 14
0
        public static void Main(string[] args)
        {
            Console.Title = "Console Client";

            try
            {
                using (var stack = new KunoStack())
                {
                    stack.UseAkka();

                    for (int i = 0; i < 10; i++)
                    {
                        stack.Send("go");
                    }

                    stack.Shutdown().Wait();
                    Console.ReadKey();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Esempio n. 15
0
 public EntityFrameworkEntitiesModule(KunoStack stack, EntityFrameworkOptions options)
 {
     _stack   = stack;
     _options = options;
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReflectionModule" /> class.
 /// </summary>
 /// <param name="stack">The stack.</param>
 public ReflectionModule(KunoStack stack)
 {
     _stack = stack;
 }
Esempio n. 17
0
 /// <summary>
 /// Configures the application to use Kuno.
 /// </summary>
 /// <param name="app">The application to configure.</param>
 /// <param name="stack">The current stack.</param>
 /// <returns>This instance for method chaining.</returns>
 public static IApplicationBuilder UseKuno(this IApplicationBuilder app, KunoStack stack)
 {
     return(app.UseMiddleware <KunoMiddleware>(stack));
 }
Esempio n. 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServicesModule" /> class.
 /// </summary>
 public ServicesModule(KunoStack stack)
 {
     _stack = stack;
 }
Esempio n. 19
0
 /// <summary>
 /// Gets the response entries that fall within the specified time frame.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <param name="start">The start.</param>
 /// <param name="end">The end.</param>
 /// <returns>Returns the response entries that fall within the specified time frame.</returns>
 public static IEnumerable <ResponseEntry> GetResponses(this KunoStack instance, DateTimeOffset?start = null, DateTimeOffset?end = null)
 {
     return(instance.Container.Resolve <IResponseLog>().GetEntries(start, end).Result);
 }
Esempio n. 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KunoMiddleware"/> class.
 /// </summary>
 /// <param name="next">The next delegate.</param>
 /// <param name="stack">The configured stack.</param>
 public KunoMiddleware(RequestDelegate next, KunoStack stack)
 {
     _next  = next;
     _stack = stack;
 }
Esempio n. 21
0
        /// <summary>
        /// Configures the stack to use Akka.NET Messaging and runs the Akka host.
        /// </summary>
        /// <param name="instance">The this instance.</param>
        /// <param name="configuration">The configuration routine.</param>
        /// <returns>KunoStack.</returns>
        public static void RunAkkaHost(this KunoStack instance, Action <MessagingOptions> configuration = null)
        {
            instance.UseAkka(configuration);

            instance.GetExit().Wait();
        }
Esempio n. 22
0
        /// <summary>
        /// Configures the container to use a local cache.
        /// </summary>
        /// <param name="container">The current container.</param>
        public static void UseLocalCache(this KunoStack container)
        {
            Argument.NotNull(container, nameof(container));

            container.Container.Update(builder => { builder.RegisterModule(new LocalCacheModule()); });
        }
Esempio n. 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AkkaModule" /> class.
        /// </summary>
        /// <param name="stack">The current stack.</param>
        public AkkaModule(KunoStack stack)
        {
            _stack = stack;

            _stack.Include(this.GetType());
        }
Esempio n. 24
0
 /// <summary>
 /// Gets the exit task to be executed on termination.
 /// </summary>
 /// <param name="instance">The this instance.</param>
 /// <returns>Task.</returns>
 public static Task GetExit(this KunoStack instance)
 {
     return(instance.Container.Resolve <ActorSystem>().WhenTerminated);
 }
Esempio n. 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchModule" /> class.
 /// </summary>
 /// <param name="stack">The current stack.</param>
 public SearchModule(KunoStack stack)
 {
     _stack = stack;
 }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainModule" /> class.
 /// </summary>
 /// <param name="stack">The stack.</param>
 public DomainModule(KunoStack stack)
 {
     _stack = stack;
 }
Esempio n. 27
0
 /// <summary>
 /// Gets the event entries that fall within the specified time frame.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <param name="start">The start.</param>
 /// <param name="end">The end.</param>
 /// <returns>Returns the event entries that fall within the specified time frame.</returns>
 public static IEnumerable <EventEntry> GetEvents(this KunoStack instance, DateTimeOffset?start = null, DateTimeOffset?end = null)
 {
     return(instance.Container.Resolve <IEventStore>().GetEvents(start, end).Result);
 }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationModule" /> class.
 /// </summary>
 /// <param name="stack">The current stack.</param>
 public ConfigurationModule(KunoStack stack)
 {
     _stack = stack;
 }