プラグインが 1 つのイベントから 4 回実行される原因は何ですか?
プラグインは Case の取得時に登録されており、1 回の取得で 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() });
同期と非同期を試しましたが、同じことが起こります。