static void Main(string[] args)
        {
            RedisServices.Init("127.0.0.1", null, string.Empty);

            CommandsAndEventsRegisterEngine.AutoRegister();

            EngineeCommandWorkerQueue.Start();
            EngineeEventWorkerQueue.Start();

            while (true)
            {
                var cmd = Console.ReadLine();
                switch (cmd.ToLower())
                {
                case "quit":
                    _stop = true;
                    Environment.Exit(0);
                    break;

                case "stop":
                    _stop = true;
                    break;

                case "start":
                    _stop = false;
                    MessiveSendCmd();
                    break;
                }
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            CommandsAndEventsRegisterEngine.Init();

            CommandsAndEventsRegisterEngine.AutoRegisterForHandlers();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseSwagger();

            app.UseSwaggerUi3(settings =>
            {
                settings.GeneratorSettings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;
            });


            app.UseMvc();
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public string Get(string typeFullName)
        {
            string cmdTemp = JsonConvert.SerializeObject(new CreateSample(Guid.NewGuid(), "V" + DateTime.Now.GetHashCode(), "{}"));

            var request = new CommandRequest();

            request.CommandTypeFullName = typeof(CreateSample).FullName;
            request.CommandDataJson     = cmdTemp;

            if (string.IsNullOrEmpty(typeFullName))
            {
                return(JsonConvert.SerializeObject(request));
            }

            Type foundType;

            var found = CommandsAndEventsRegisterEngine.TryFindCommandOrEventType(typeFullName, out foundType);

            if (!found)
            {
                return(JsonConvert.SerializeObject(request));
            }

            cmdTemp = JsonConvert.SerializeObject(Activator.CreateInstance(foundType));

            request.CommandTypeFullName = foundType.FullName;
            request.CommandDataJson     = cmdTemp;

            return(JsonConvert.SerializeObject(request));
        }
 public void Publish(IEvent e)
 {
     if (e.PublishedEventId == Guid.Empty)
     {
         e.PublishedEventId = Guid.NewGuid();
     }
     CommandsAndEventsRegisterEngine.PushEvent(e);
 }
Beispiel #5
0
        private static void Run()
        {
            var redishost = ConfigurationManagerExtensions.GetConnectionString("RedisConnectionString");

            RedisServices.Init(redishost, null, string.Empty);

            CommandsAndEventsRegisterEngine.AutoRegister();

            EngineeCommandWorkerQueue.Start();
            EngineeEventWorkerQueue.Start();
            var cmd = (Console.ReadLine() ?? string.Empty).ToLower().Trim();

            while (!cmd.Equals("quit"))
            {
                switch (cmd)
                {
                case "quit":
                    _stop = true;
                    break;

                case "stop":
                    _stop = true;
                    break;

                case "start":
                    _stop = false;
                    MessiveSendCmd(null);
                    break;

                case "pubsub":
                    CommandEventSender.Send(new SampleEventCreated()
                    {
                        PublishedEventId = Guid.NewGuid(),
                        SampleVersion    = DateTime.Now.ToString(),
                        Version          = 0
                    });
                    break;

                case "pubsubmad":
                    _stop = false;
                    MessiveSendCmd(() => {
                        CommandEventSender.Send(new SampleEventCreated()
                        {
                            PublishedEventId = Guid.NewGuid(),
                            SampleVersion    = DateTime.Now.ToString(),
                            Version          = 0
                        });
                    });
                    break;
                }
                cmd = (Console.ReadLine() ?? string.Empty).ToLower().Trim();
            }

            Console.Read();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            RedisServices.Init("127.0.0.1", null, string.Empty);

            CommandsAndEventsRegisterEngine.AutoRegisterForHandlers();

            Guid sampleId = Guid.NewGuid();

            CommandPublisher.Instance.Send(new CreateSample(sampleId, "Version.1.0", "{}"));

            CommandPublisher.Instance.Send(new ChangeVersionOfSample(sampleId, "Version.2.0"));
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            RedisServices.Init("127.0.0.1", null, string.Empty);

            CommandsAndEventsRegisterEngine.AutoRegister();

            EngineeCommandWorkerQueue.Start();
            EngineeEventWorkerQueue.Start();

            services.AddSwagger();
        }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddMvc(option => {
                // option.Filters.Add(new IotHubAuthorizeAttribute());
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //RedisServices.Init("172.16.10.166", null, string.Empty);
            var redishost = ConfigurationManagerExtensions.GetConnectionString("RedisConnectionString");

            RedisServices.Init(redishost, null, string.Empty);
            CommandsAndEventsRegisterEngine.AutoRegister();

            EngineeCommandWorkerQueue.Start();
            EngineeEventWorkerQueue.Start();

            services.AddSwagger();
        }
Beispiel #9
0
        //[Authorize]
        public CommandResponse Post(CommandRequest cmd)
        {
            try
            {
                var jobj = JsonConvert.DeserializeObject(cmd.CommandDataJson) as Newtonsoft.Json.Linq.JObject;

                Type foundType;

                var found = CommandsAndEventsRegisterEngine.TryFindCommandOrEventType(cmd.CommandTypeFullName, out foundType);

                if (!found)
                {
                    return(new CommandResponse()
                    {
                        Success = false,
                        StatusCode = HttpStatusCode.NotImplemented,
                        Message = "Not found command type",
                        CommandId = Guid.Empty
                    });
                }

                var ocmd = (ICommand)jobj.ToObject(foundType);

                CommandPublisher.Instance.Send(ocmd);

                return(new CommandResponse()
                {
                    Success = true,
                    CommandId = ocmd.PublishedCommandId.Value,
                    Message = "Success",
                    StatusCode = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                return(new CommandResponse()
                {
                    CommandId = Guid.Empty,
                    Message = ex.GetAllMessages(),
                    StatusCode = HttpStatusCode.BadGateway,
                    Success = false
                });
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            CommandsAndEventsRegisterEngine.Init();

            CommandsAndEventsRegisterEngine.AutoRegisterForHandlers();

            Console.WriteLine("Try to create sample data");
            Guid   sampleId = Guid.NewGuid();
            Random rnd      = new Random();

            while (true)
            {
                Console.WriteLine("--- Menu:Begin ---");
                Console.WriteLine("Type 'create' to create new");
                Console.WriteLine("Type 'update' to update with latest create Id with random version");
                Console.WriteLine("Type 'quit' to close console");
                Console.WriteLine("--- Menu:End ---");

                var cmd = Console.ReadLine();

                if (cmd == "quit")
                {
                    Environment.Exit(0);
                    return;
                }

                if (cmd == "create")
                {
                    sampleId = Guid.NewGuid();
                    CommandPublisher.Instance.Send(new CreateSample(sampleId, "Version.1.0", "{}"));
                }

                if (cmd == "update")
                {
                    var v = rnd.Next(1, 100);
                    CommandPublisher.Instance.Send(new ChangeVersionOfSample(sampleId, $"Version.{v}.0"));
                }
            }
        }
Beispiel #11
0
        public List <CommandRequest> ListDumyCommandRequestAvailable()
        {
            var listType = CommandsAndEventsRegisterEngine.ListAvailableCommandOrEventType();

            List <CommandRequest> result = new List <CommandRequest>();

            foreach (var type in listType)
            {
                if (typeof(ICommand).IsAssignableFrom(type) == false)
                {
                    continue;
                }

                result.Add(new CommandRequest()
                {
                    CommandTypeFullName = type.FullName,
                    CommandDataJson     = JsonConvert.SerializeObject(Activator.CreateInstance(type))
                });
            }

            return(result);
        }
 public void Publish(IEvent e)
 {
     CommandsAndEventsRegisterEngine.PushEvent(e);
 }