コード例 #1
0
        public HttpResponseMessage ProfilePicture([FromUri] int contactPersonId)
        {
            var filePath = _queryProcessor.Handle(new GetProfilePicturePathByContactPersonId(contactPersonId));

            var response = new HttpResponseMessage();

            response.Content = new StreamContent(new FileStream(filePath, FileMode.Open)); // this file stream will be closed by lower layers of web api for you once the response is completed.
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");

            return(response);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: llenroc/Cqs
        private async static void WorkWithQueryProcessorAndAsync()
        {
            System.Console.WriteLine("\n-- Best of all worlds --");
            var broker = IoC.ThisContainer.GetInstance <IPubSub>();

            broker.Subscribe(typeof(CreateTodoCommand).Name, o => System.Console.WriteLine("Pub/Sub activation: CreateTodoCommand: {0} ", o));
            broker.Subscribe(typeof(FindTodosByCategoryQuery).Name, o => System.Console.WriteLine("Pub/Sub activation: FindTodosByCategoryQuery: {0} ", o));

            var cmd1 = new CreateTodoCommand {
                Data = new Todo {
                    Caption = "Cowboy: Good", Category = "Cowboy"
                }
            };
            var cmd2 = new CreateTodoCommand {
                Data = new Todo {
                    Caption = "Cowboy: Bad ", Category = "Cowboy"
                }
            };
            var cmd3 = new CreateTodoCommand {
                Data = new Todo {
                    Caption = "Cowboy: Ugly", Category = "Cowboy"
                }
            };

            var cmdProcessor   = new CommandProcessor();
            var queryProcessor = new QueryProcessor();

            // Force wait on all, but you can just as well just "await" them
            Task.WaitAll(
                cmdProcessor.Handle(cmd1),
                cmdProcessor.Handle(cmd2)
                );

            await cmdProcessor.Handle(cmd3).ContinueWith(p =>
            {
                // This code below will be executed truly async
                System.Console.WriteLine("- async: cmd3 handled!, this is the continuation. Cmd3.Output = " + cmd3.Output);
            });

            var query = new FindTodosByCategoryQuery {
                Category = "Cowboy"
            };

            // This code below will be executed truly async
            System.Console.WriteLine("- async: results of a find query -");
            var results = await queryProcessor.Handle(query);

            PrintResults(results);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: llenroc/Cqs
        private static void WorkWithQueryProcessor()
        {
            System.Console.WriteLine("\n-- Using QueryProcessor --");

            var queryProcessor = new QueryProcessor();
            var cmdProcessor   = new CommandProcessor();

            // Run a query with help of the query processor
            var query = new FindTodosByCategoryQuery {
                Category = "Etc"
            };
            var queryResult = queryProcessor.Handle(query).Result;

            // Run a delete command with the command processor and see how the decorator is used
            var delCommand = new DeleteTodoCommand()
            {
                Id = queryResult[0].Id
            };

            cmdProcessor.Handle(delCommand);

            PrintResults(queryResult);
        }
コード例 #4
0
ファイル: TalentController.cs プロジェクト: martijngr/skilled
        public IHttpActionResult Search([FromUri] GetTalentsQuery query)
        {
            var result = _queryProcessor.Handle(query);

            return(Ok(new { result }));
        }
コード例 #5
0
        public IActionResult Get()
        {
            var result = _queryProcessor.Handle(new GetSeedsRandomizedQuery());

            return(Ok(result));
        }
コード例 #6
0
 public IActionResult Get()
 {
     return(Ok(_queryProcessor.Handle(new GetSeedCategoriesQuery())));
 }