什么可能导致插件从单个事件执行 4 次?
该插件已在 Case 检索时注册,并为单个 Retrieve 触发 4 次。
protected void ExecutePostCaseRetrieve(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
// TODO: Implement your custom Plug-in business logic.
IOrganizationService service = localContext.OrganizationService;
QueryByAttribute query = new QueryByAttribute("resource");
query.Attributes.AddRange("name");
query.Values.AddRange("Employee");
EntityCollection result = service.RetrieveMultiple(query);
Guid employee = result.Entities[0].Id;
QueryScheduleRequest scheduleRequest = new QueryScheduleRequest
{
ResourceId = employee,
Start = DateTime.Now.ToLocalTime(),
End = DateTime.Now.ToLocalTime().AddMonths(1),
TimeCodes = new TimeCode[] { TimeCode.Available }
};
QueryScheduleResponse schedule = (QueryScheduleResponse)service.Execute(scheduleRequest);
DateTime today = DateTime.Now.ToLocalTime();
if (today.Date.Equals(schedule.TimeInfos[0].Start.Value.Date)) // today is a working day
{
service.Create(new Lead { FirstName = today.Hour.ToString() });
}
else // just escalate from beginning of next working day
service.Create(new Lead { FirstName = schedule.TimeInfos[0].Start.Value.ToLocalTime().ToString(), LastName=schedule.TimeInfos[0].End.Value.ToLocalTime().ToString() });
我尝试过同步和异步,同样的事情发生了。