本文整理汇总了C#中IMediator.SendAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMediator.SendAsync方法的具体用法?C# IMediator.SendAsync怎么用?C# IMediator.SendAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMediator
的用法示例。
在下文中一共展示了IMediator.SendAsync方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FacilityControllerTests
public FacilityControllerTests()
{
mediator = A.Fake<IMediator>();
A.CallTo(() => mediator.SendAsync(A<GetCountries>._)).Returns(new List<CountryData>
{
new CountryData
{
Id = new Guid("4345FB05-F7DF-4E16-939C-C09FCA5C7D7B"),
Name = "United Kingdom"
},
new CountryData
{
Id = new Guid("29B0D09E-BA77-49FB-AF95-4171408C07C9"),
Name = "Germany"
}
});
A.CallTo(
() =>
mediator.SendAsync(A<GetNotificationBasicInfo>.That.Matches(p => p.NotificationId == notificationId)))
.Returns(new NotificationBasicInfo
{
CompetentAuthority = UKCompetentAuthority.England,
NotificationId = notificationId,
NotificationNumber = "GB 0001 002000",
NotificationType = NotificationType.Recovery
});
facilityController = new FacilityController(mediator, new AddAddressBookEntryMap());
}
示例2: 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;
}
};
}
示例3: BindCountryList
public static async Task BindCountryList(this Controller controller, IMediator mediator,
bool setDefaultAsUnitedKingdom = true)
{
var response = await mediator.SendAsync(new GetCountries());
BindCountriesToViewBag(controller, response, setDefaultAsUnitedKingdom);
}
示例4: ProducerControllerTests
public ProducerControllerTests()
{
mediator = A.Fake<IMediator>();
A.CallTo(() => mediator.SendAsync(A<GetCountries>._)).Returns(new List<CountryData>
{
new CountryData
{
Id = new Guid("4345FB05-F7DF-4E16-939C-C09FCA5C7D7B"),
Name = "United Kingdom"
},
new CountryData
{
Id = new Guid("29B0D09E-BA77-49FB-AF95-4171408C07C9"),
Name = "Germany"
}
});
A.CallTo(() => mediator.SendAsync(A<GetProducerForNotification>._)).Returns(CreateProducer(producerId));
producerController = new ProducerController(mediator, new AddAddressBookEntryMap());
}
示例5: DecisionControllerTests
public DecisionControllerTests()
{
mediator = A.Fake<IMediator>();
decisionController = new DecisionController(mediator);
A.CallTo(() => mediator.SendAsync(A<GetImportNotificationAssessmentDecisionData>.Ignored))
.Returns(new ImportNotificationAssessmentDecisionData
{
AcknowledgedOnDate = acknowledgedOnDate
});
}
示例6: QuantityReceivedControllerTests
public QuantityReceivedControllerTests()
{
mediator = A.Fake<IMediator>();
controller = new QuantityReceivedController(mediator);
A.CallTo(() =>
mediator.SendAsync(A<GetMovementUnitsByMovementId>.That.Matches(r => r.Id == AnyGuid)))
.Returns(ShipmentQuantityUnits.Kilograms);
viewModel = new QuantityReceivedViewModel
{
Unit = ShipmentQuantityUnits.Kilograms,
Quantity = "250"
};
}
示例7: KeyDatesControllerTests
public KeyDatesControllerTests()
{
mediator = A.Fake<IMediator>();
A.CallTo(
() => mediator.SendAsync(A<GetKeyDates>.That.Matches(p => p.ImportNotificationId == notificationId)))
.Returns(new KeyDatesData
{
NotificationReceived = notificationReceivedDate,
PaymentReceived = paymentReceivedDate,
AcknowlegedDate = acknowledgedDate,
DecisionRequiredByDate = decisionRequiredDate
});
controller = new KeyDatesController(mediator);
}
示例8: 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);
}
示例9: ToModel
public async Task<AllReadyTask> ToModel(TaskViewModel taskViewModel, IMediator mediator)
{
var @event = await mediator.SendAsync(new EventByEventIdQuery { EventId = taskViewModel.EventId });
if (@event == null)
{
return null;
}
var newTask = true;
AllReadyTask allReadyTask;
if (taskViewModel.Id == 0)
{
allReadyTask = new AllReadyTask();
}
else
{
allReadyTask = await mediator.SendAsync(new TaskByTaskIdQuery { TaskId = taskViewModel.Id });
newTask = false;
}
allReadyTask.Id = taskViewModel.Id;
allReadyTask.Description = taskViewModel.Description;
allReadyTask.Event = @event;
allReadyTask.EndDateTime = taskViewModel.EndDateTime.UtcDateTime;
allReadyTask.StartDateTime = taskViewModel.StartDateTime.UtcDateTime;
allReadyTask.Name = taskViewModel.Name;
allReadyTask.RequiredSkills = allReadyTask.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 assignedVolunteers = taskViewModel.AssignedVolunteers.ToList();
var taskUsersList = await assignedVolunteers.ToTaskSignups(allReadyTask, _mediator);
// We may be updating an existing task
if (newTask || allReadyTask.AssignedVolunteers.Count == 0)
{
allReadyTask.AssignedVolunteers = taskUsersList;
}
else
{
// Can probably rewrite this more efficiently.
foreach (var taskUsers in taskUsersList)
{
if (!(from entry in allReadyTask.AssignedVolunteers
where entry.User.Id == taskUsers.User.Id
select entry).Any())
{
allReadyTask.AssignedVolunteers.Add(taskUsers);
}
}
}
}
return allReadyTask;
}
示例10: ToTaskSignups
public static async Task<List<TaskSignup>> ToTaskSignups(this List<ViewModels.Event.TaskSignupViewModel> viewModels, AllReadyTask task, IMediator mediator)
{
var taskSignups = new List<TaskSignup>();
foreach (var viewModel in viewModels)
{
taskSignups.Add(new TaskSignup
{
Task = task,
User = await mediator.SendAsync(new UserByUserIdQuery { UserId = viewModel.UserId })
});
}
return taskSignups;
}