Пример #1
0
        private static void Main(string[] args)
        {
            // Setup services
            IKernel kernel = new StandardKernel();

            kernel.AddRequestBus();

            // Setup request bus
            RequestBus requestBus = kernel.Get <RequestBus>();

            requestBus.RegisterAllHandlers();

            // Send request
            PresentProductsRequest request  = new PresentProductsRequest();
            List <Product>         products = requestBus.Send <PresentProductsRequest, List <Product> >(request);

            // Display response
            foreach (Product product in products)
            {
                Console.WriteLine();
                Console.WriteLine("Product: " + product.Name);
                Console.WriteLine("Price: " + product.Price);
                Console.WriteLine("Quantity: " + product.Quantity);
            }
        }
        private static void Main(string[] args)
        {
            // Setup services
            ContainerBuilder containerBuilder = new ContainerBuilder();

            containerBuilder.AddRequestBus();

            IContainer container = containerBuilder.Build();

            // Setup request bus
            RequestBus requestBus = container.Resolve <RequestBus>();

            requestBus.RegisterAllHandlers();

            // Send request
            PresentProductsRequest request  = new PresentProductsRequest();
            List <Product>         products = requestBus.Send <PresentProductsRequest, List <Product> >(request);

            // Display response
            foreach (Product product in products)
            {
                Console.WriteLine();
                Console.WriteLine("Product: " + product.Name);
                Console.WriteLine("Price: " + product.Price);
                Console.WriteLine("Quantity: " + product.Quantity);
            }
        }
            public void responds_to_request()
            {
                // ACT
                var configuration = RequestBus <GetCurrentConfigurationRequest, IConfiguration> .Post(new GetCurrentConfigurationRequest());

                // ASSERT
                Assert.NotNull(configuration);
            }
        public UseCaseWithoutResponseTests()
        {
            testUseCase = new TestUseCase();
            UseCaseFactoryMock useCaseFactory = new UseCaseFactoryMock
            {
                UseCase = testUseCase
            };

            requestBus = new RequestBus(useCaseFactory);

            requestBus.RegisterUseCase <TestUseCase>();
        }
Пример #5
0
        public void HandleUpdateRequestProperly(string section, SystemErrorsUpdateRequest.EType type)
        {
            using (FileDeleter fd = new FileDeleter(Extensions.GetTempDBFile()))
            {
                Database    db   = new Database(new Context(fd.Fi));
                Initializer init = new Initializer(null);
                init.Initialize(db);

                RequestBus        bus       = new RequestBus();
                EventLogResponder responder = new EventLogResponder()
                {
                    DB = db
                };
                bus.Subscribe(responder);

                using (SQLiteConnection conn = db.Connection)
                {
                    conn.Open();

                    string new_path = $"machine_name.{section}.max_event_log";

                    System.DateTime dt  = GenerateTime(2019, 2, 20, 12, 23, 34, 456789);
                    EventLogData    eld = new EventLogData();
                    eld.Insert(dt, 22334455);
                    eld.Insert(dt, 22334456);

                    SystemErrorsUpdateRequest req = new SystemErrorsUpdateRequest("machine_name", type);
                    req.LogData.Assign(eld);
                    bus.MakeRequest(req);
                    Assert.True(req.IsHandled);

                    Attribute attr = new Attribute();
                    string    x    = attr.Get(new_path, conn);
                    Assert.False(string.IsNullOrEmpty(x));

                    EventLogData eld2 = JsonConvert.DeserializeObject <EventLogData>(x);
                    Assert.NotNull(eld);
                    Assert.False(eld2.MaxRecordNumber.HasValue);
                    Assert.Equal(dt, eld2.MaxDate);

                    List <ulong> record_numbers = eld2.MaxDateToRecordNumbers[dt];
                    Assert.NotNull(record_numbers);
                    Assert.Equal(2, record_numbers.Count);
                    // Sort just in case they got put in the list in a different order
                    record_numbers.Sort();
                    Assert.Equal((ulong)22334455, record_numbers[0]);
                    Assert.Equal((ulong)22334456, record_numbers[1]);
                }
            }
        }
            public void responds_with_latest_configuration()
            {
                // ARRANGE
                EventBus <ServerConfigurationUpdatedEvent> .Publish(new ServerConfigurationUpdatedEvent(new ServerConfiguration
                {
                    AgentRunId = 24,
                    ApdexT = 42
                }));

                // ACT
                var configuration = RequestBus <GetCurrentConfigurationRequest, IConfiguration> .Post(new GetCurrentConfigurationRequest());

                // ASSERT
                Assert.NotNull(configuration);
                Assert.AreEqual(TimeSpan.FromSeconds(42), configuration.TransactionTraceApdexT);
            }
Пример #7
0
        public void ConvertProperly(string section, SystemErrorsInfoRequest.EType type)
        {
            using (FileDeleter fd = new FileDeleter(Extensions.GetTempDBFile()))
            {
                Database    db   = new Database(new Context(fd.Fi));
                Initializer init = new Initializer(null);
                init.Initialize(db);

                RequestBus        bus       = new RequestBus();
                EventLogResponder responder = new EventLogResponder()
                {
                    DB = db
                };
                bus.Subscribe(responder);

                using (SQLiteConnection conn = db.Connection)
                {
                    conn.Open();

                    string orig_path  = $"machine_name.{section}.max_record_number";
                    string new_path   = $"machine_name.{section}.max_event_log";
                    ulong  record_num = 234567;

                    Attribute attr = new Attribute();
                    attr.Set(orig_path, record_num.ToString(), conn);

                    SystemErrorsInfoRequest req = new SystemErrorsInfoRequest("machine_name", type);
                    bus.MakeRequest(req);
                    Assert.True(req.IsHandled);
                    Assert.True(req.LogData.MaxRecordNumber.HasValue);
                    Assert.Equal(record_num, req.LogData.MaxRecordNumber.Value);

                    string x = attr.Get(orig_path, conn);
                    Assert.True(string.IsNullOrEmpty(x));

                    x = attr.Get(new_path, conn);
                    Assert.False(string.IsNullOrEmpty(x));

                    EventLogData eld = JsonConvert.DeserializeObject <EventLogData>(x);
                    Assert.NotNull(eld);
                    Assert.True(eld.MaxRecordNumber.HasValue);
                    Assert.Equal(record_num, eld.MaxRecordNumber.Value);
                }
            }
        }
        /// <summary>
        /// Pushes out the configuration options stored in <see cref="LocalConfiguration"/> and <see cref="ServerConfiguration"/>. Will update <see cref="CurrentConfiguration"/> with the result from ConfigurationService.
        /// </summary>
        public void PushConfiguration()
        {
            // Push LocalConfigurationUpdates
            EventBus <ConfigurationDeserializedEvent> .Publish(new ConfigurationDeserializedEvent(LocalConfiguration));

            // Push ServerConfigurationUpdates
            EventBus <ServerConfigurationUpdatedEvent> .Publish(new ServerConfigurationUpdatedEvent(ServerConfiguration));

            EventBus <SecurityPoliciesConfigurationUpdatedEvent> .Publish(new SecurityPoliciesConfigurationUpdatedEvent(SecurityConfiguration));

            // Update CurrentConfiguration
            IConfiguration newConfig = null;

            RequestBus <GetCurrentConfigurationRequest, IConfiguration> .Post(new GetCurrentConfigurationRequest(), config => newConfig = config);

            if (newConfig == null)
            {
                throw new NullReferenceException("newConfig");
            }
            CurrentConfiguration = newConfig;
        }
Пример #9
0
        private static void Main(string[] args)
        {
            // Setup request bus
            RequestBus requestBus = new RequestBus();

            requestBus.RegisterUseCase <PresentProductsUseCase>();

            // Send request
            PresentProductsRequest request = new PresentProductsRequest();

            requestBus.Process(request);
            List <Product> products = requestBus.Process <PresentProductsRequest, List <Product> >(request);

            // Display response
            foreach (Product product in products)
            {
                Console.WriteLine();
                Console.WriteLine("Product: " + product.Name);
                Console.WriteLine("Price: " + product.Price);
                Console.WriteLine("Quantity: " + product.Quantity);
            }
        }
Пример #10
0
        ///<summary>
        ///setup communcation with the CLI or any other client via ZeroMQ
        ///</summary>
        public static Communication GetCommunication(string tcpConnection)
        {
            var store = new InMemoryStore();
            // upload file from the current directory
            string     json      = JsonFromConfigFile();
            ITransform transform = new JsonTransform();

            OperationResult result = transform.Parse(json);

            var socket = new RequestBus(tcpConnection);

            socket.Connect();

            return(new Communication
            {
                Storage = store,
                Socket = socket,
                JsonString = json,
                Transform = transform,
                ConfigEntities = result.Result as ConfigCollection
            });
        }
 public DisplayPotCommandModel(RequestBus requestBus)
 {
     this.requestBus = requestBus ?? throw new ArgumentNullException(nameof(requestBus));
 }
 public RemoveDuplicatesCommandModel(RequestBus requestBus)
 {
     this.requestBus = requestBus ?? throw new ArgumentNullException(nameof(requestBus));
 }
Пример #13
0
 private void OnGetCurrentConfiguration(GetCurrentConfigurationRequest requestData, RequestBus <GetCurrentConfigurationRequest, IConfiguration> .ResponseCallback callback)
 {
     callback(Configuration);
 }
 public ImportSnapshotCommandModel(RequestBus requestBus)
 {
     this.requestBus = requestBus ?? throw new ArgumentNullException(nameof(requestBus));
 }
 public CompareAllSnapshotsCommandModelModel(RequestBus requestBus)
 {
     this.requestBus = requestBus ?? throw new ArgumentNullException(nameof(requestBus));
 }
Пример #16
0
 public AddBlackListPathCommandModel(RequestBus requestBus)
 {
     this.requestBus = requestBus ?? throw new ArgumentNullException(nameof(requestBus));
 }
 public BookmarkController(RequestBus requestBus)
 {
     this.requestBus = requestBus ?? throw new ArgumentNullException(nameof(requestBus));
 }
Пример #18
0
        public static void Configure(IServiceProvider serviceProvider)
        {
            RequestBus requestBus = serviceProvider.GetService <RequestBus>();

            requestBus.RegisterAllHandlers();
        }
Пример #19
0
        public ConfigurationSubscriber()
        {
            Configuration = RequestBus <GetCurrentConfigurationRequest, IConfiguration> .Post(new GetCurrentConfigurationRequest()) ?? DefaultConfiguration.Instance;

            _configurationSubscription = new EventSubscription <ConfigurationUpdatedEvent>(OnConfigurationUpdated);
        }