当前位置: 首页>>代码示例>>C#>>正文


C# IMediator.Send方法代码示例

本文整理汇总了C#中IMediator.Send方法的典型用法代码示例。如果您正苦于以下问题:C# IMediator.Send方法的具体用法?C# IMediator.Send怎么用?C# IMediator.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMediator的用法示例。


在下文中一共展示了IMediator.Send方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildModule

        public BuildModule(IMediator mediator)
            : base("/api")
        {
            this.Get["/builds/{teamProject?}/{buildDefinition?}/{buildNumber?}"] = parameters =>
            {
                var query = this.Bind<BuildsQuery>();

                var result = mediator.Send(query);

                return this.Response.AsJson(result);
            };

            this.Get["/builds/stats"] = parameters =>
            {
                var query = this.Bind<BuildStatsQuery>();

                var result = mediator.Send(query);

                return this.Response.AsJson(result);
            };

            this.Get["/builds/perDay"] = parameters =>
            {
                var query = this.Bind<BuildsPerDayQuery>();

                var response = mediator.Send(query);

                return this.Response.AsJson(response);
            };
        }
开发者ID:Firebuild,项目名称:Firebuild,代码行数:30,代码来源:BuildsModule.cs

示例2: TodoItemsModule

        public TodoItemsModule(IMediator mediator) : base("/todo-items")
        {
            _mediator = mediator;
            Get["/"] = parameters =>
            {
                var todoItems = _mediator.Send(new GetTodoItems());

                return Response.AsJson(todoItems);
            };

            Get["/{id}"] = parameters =>
            {
                var todoItem = _mediator.Send(new GetTodoItemById(parameters.id));

                return Response.AsJson(todoItem);
            };

            Post["/"] = parameters =>
            {
                var createTodoItem = this.Bind<CreateTodoItem>();
                var item =_mediator.Send(createTodoItem);
                return item;
            };

            Put["/{id}/complete"] = parameters =>
            {
                var id = parameters.id;
                var todoItem = _mediator.Send(new MarkTodoItemCompleted(id));
                return todoItem;
            };
        }
开发者ID:jenspettersson,项目名称:Mediocr,代码行数:31,代码来源:TodoItemsModule.cs

示例3: BuildDefinitionModule

        public BuildDefinitionModule(IMediator mediator, IDocumentSession session)
            : base("/api")
        {
            this.Get["/build-definitions/{teamProject?}"] = parameters =>
            {
                var query = this.Bind<GetBuildDefinitions>();

                var results = mediator.Send(query);

                return this.Response.AsJson(results);
            };

            this.Get["/build-definitions/stats/{teamProject?}"] = parameters =>
            {
                var query = this.Bind<GetBuildDefinitionsStats>();

                var results = mediator.Send(query);

                return this.Response.AsJson(results);

                //string teamProject = parameters.TeamProject;

                //var query = session.Query<BuildDefinitionStats, BuildDefinitionStatusIndex>()
                //    .AsQueryable();

                //if (!string.IsNullOrEmpty(teamProject))
                //{
                //    query = query.Where(k => k.TeamProject == teamProject);
                //}

                //var results = query.ToList();

                //return this.Response.AsJson(results);
            };
        }
开发者ID:Firebuild,项目名称:Firebuild,代码行数:35,代码来源:BuildDefinitionsModule.cs

示例4: RequestHandlerModule

        public RequestHandlerModule(IMediator mediator, RequestTypeProvider requestTypeProvider)
            : base("/RequestHandler/request")
        {
            Post["/{requestType}", true] = async (parameters, ct) =>
            {
                Console.WriteLine("Call to AsyncRequestHandlerModule");
                var requestTypeString = (string)parameters.requestType;

                var requestType = requestTypeProvider.FindByFullName(requestTypeString);

                if (requestType == null)
                {
                    return (int)HttpStatusCode.NotAcceptable;
                }

                dynamic deserializedRequest = this.Bind(requestType);

                var isAsyncRequest = requestType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IAsyncRequest<>));

                if (requestType.BaseType != typeof(object) && requestType.BaseType == typeof(FileRequest))
                {
                    var response = new Response { StatusCode = HttpStatusCode.OK, ContentType = "application/octet-stream", Contents = async s => {
                        ((FileRequest)deserializedRequest).SetStream(s);
                        if (isAsyncRequest)
                        {
                            await mediator.SendAsync(deserializedRequest);
                        }
                        else
                        {
                            mediator.Send(deserializedRequest);
                        }
                    } };

                    return response;
                }

                try
                {
                    if (isAsyncRequest)
                    {
                        return await mediator.SendAsync(deserializedRequest);
                    }

                    return mediator.Send(deserializedRequest);
                }
                catch (Exception exc)
                {
                    //todo:log, etc.
                    var errorResponse = Response.AsText(exc.Message);
                    errorResponse.StatusCode = HttpStatusCode.InternalServerError;

                    return errorResponse;
                }
            };
        }
开发者ID:BredStik,项目名称:DistributedMediator,代码行数:55,代码来源:RequestHandlerModule.cs

示例5: BuildControllersModule

        public BuildControllersModule(IMediator mediator)
            : base("/api")
        {
            this.Get["/build-controllers"] = parameters =>
            {
                var results = mediator.Send(new GetBuildControllersQuery());

                return this.Response.AsJson(results);
            };

            this.Get["/build-controllers/stats"] = parameters =>
            {
                var results = mediator.Send(new BuildControllersCountByStatusQuery());

                return this.Response.AsJson(results);
            };
        }
开发者ID:Firebuild,项目名称:Firebuild,代码行数:17,代码来源:BuildControllersModule.cs

示例6: QueuedBuildsModule

        public QueuedBuildsModule(IMediator mediator)
            : base("/api")
        {
            this.Get["/queue"] = parameters =>
            {
                var results = mediator.Send(new GetQueuedBuildsQuery());

                return this.Response.AsJson(results);
            };

            this.Get["/queue/stats"] = parameters =>
            {
                var results = mediator.Send(new QueuedBuildsCountByStatusQuery());

                return this.Response.AsJson(results);
            };
        }
开发者ID:Firebuild,项目名称:Firebuild,代码行数:17,代码来源:QueuedBuildsModule.cs

示例7: Run

        public static async Task Run(IMediator mediator, TextWriter writer)
        {
            await writer.WriteLineAsync("Sample mediator implementation using send, publish and post-request handlers in sync and async version.");
            await writer.WriteLineAsync("---------------");

            await writer.WriteLineAsync("Sending Ping...");
            var pong = await mediator.Send(new Ping { Message = "Ping" });
            await writer.WriteLineAsync("Received: " + pong.Message);

            await writer.WriteLineAsync("Sending Ping async...");
            var response = await mediator.Send(new PingAsync { Message = "Ping" });
            await writer.WriteLineAsync("Received async: " + response.Message);

            await writer.WriteLineAsync("Publishing Pinged...");
            await mediator.Publish(new Pinged());

            await writer.WriteLineAsync("Publishing Pinged async...");
            await mediator.Publish(new PingedAsync());
        }
开发者ID:jbogard,项目名称:MediatR,代码行数:19,代码来源:Runner.cs

示例8: ServersModule

        public ServersModule(IMediator mediator)
            : base("/api")
        {
            this.Get["/servers"] = parameters =>
            {
                var servers = mediator.Send(new ServersQuery());

                return this.Response.AsJson(servers);
            };
        }
开发者ID:Firebuild,项目名称:Firebuild,代码行数:10,代码来源:ServersModule.cs

示例9: TeamProjectsModule

        public TeamProjectsModule(IMediator mediator)
            : base("/api")
        {
            this.Get["/projects"] = parameters =>
            {
                var results = mediator.Send(new GetTeamProjectsQuery());

                var response = results.ToArray();
                
                return this.Response.AsJson(response);
            };
        }
开发者ID:Firebuild,项目名称:Firebuild,代码行数:12,代码来源:ProjectsModule.cs

示例10: Run

        public static void Run(IMediator mediator, TextWriter writer)
        {
            writer.WriteLine("Sample mediator implementation using send, publish and post-request handlers in sync and async version.");
            writer.WriteLine("---------------");
            
            writer.WriteLine("Sending Ping...");
            var pong = mediator.Send(new Ping { Message = "Ping" });
            writer.WriteLine("Received: " + pong.Message);

            writer.WriteLine("Sending Ping async...");
            var response = mediator.SendAsync(new PingAsync { Message = "Ping" });
            Task.WaitAll(response);
            writer.WriteLine("Received async: " + response.Result.Message);

            writer.WriteLine("Publishing Pinged...");
            mediator.Publish(new Pinged());

            writer.WriteLine("Publishing Pinged async...");
            var publishResponse = mediator.PublishAsync(new PingedAsync());
            Task.WaitAll(publishResponse);
        }
开发者ID:BredStik,项目名称:MediatR,代码行数:21,代码来源:Runner.cs

示例11: ToModel

        public static AllReadyTask ToModel(this TaskViewModel taskViewModel, IMediator mediator)
        {
            var campaignEvent = mediator.Send(new EventByIdQuery { EventId = taskViewModel.EventId });
            if (campaignEvent == null)
            {
                return null;
            }

            var newTask = true;
            AllReadyTask dbtask;
            if (taskViewModel.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask = mediator.Send(new TaskByTaskIdQuery { TaskId = taskViewModel.Id });
                newTask = false;
            }

            dbtask.Id = taskViewModel.Id;
            dbtask.Description = taskViewModel.Description;
            dbtask.Event = campaignEvent;
            dbtask.EndDateTime = taskViewModel.EndDateTime.HasValue ? taskViewModel.EndDateTime.Value.UtcDateTime : new DateTime?();
            dbtask.StartDateTime = taskViewModel.EndDateTime.HasValue ? taskViewModel.StartDateTime.Value.UtcDateTime : new DateTime?();
            dbtask.Name = taskViewModel.Name;
            dbtask.RequiredSkills = dbtask.RequiredSkills ?? new List<TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List<int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // Workaround:  POST is bringing in empty AssignedVolunteers.  Clean this up. Discussing w/ Kiran Challa.
            // Workaround: the if statement is superflous, and should go away once we have the proper fix referenced above.
            if (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround

            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = taskViewModel.AssignedVolunteers.Select(tvm => new TaskSignup
                {
                    Task = dbtask,
                    User = mediator.Send(new UserByUserIdQuery { UserId = tvm.UserId })
                }).ToList();

                // We may be updating an existing task
                if (newTask || dbtask.AssignedVolunteers.Count == 0)
                {
                    dbtask.AssignedVolunteers = taskUsersList;
                }
                else
                {
                    // Can probably rewrite this more efficiently.
                    foreach (var taskUsers in taskUsersList)
                    {
                        if (!(from entry in dbtask.AssignedVolunteers
                              where entry.User.Id == taskUsers.User.Id
                              select entry).Any())
                        {
                            dbtask.AssignedVolunteers.Add(taskUsers);
                        }
                    }
                }
            }

            return dbtask;
        }
开发者ID:pottereric,项目名称:allReady,代码行数:79,代码来源:TaskViewModel.cs


注:本文中的IMediator.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。