0

我们希望从用户的 Outlook 日历中接收更改通知。我们希望将这些通知限制为仅包含我们自定义属性的日历项。

创建日历事件的代码

private static async Task<Event> CreateAppointmentAsync(GraphServiceClient graphClient)
{

    var newEvent = new Microsoft.Graph.Event
    {
        Subject = "Test Calendar Appointmnt",
        Start = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T21:00:00" },
        End = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T22:00:00" },
        Location = new Location() { DisplayName = "Somewhere" },
        Body = new ItemBody { Content = "Some Random Text" },

    };

    Microsoft.Graph.Event addedEvent;
    try
    {
        newEvent.SingleValueExtendedProperties = new EventSingleValueExtendedPropertiesCollectionPage();
        newEvent.SingleValueExtendedProperties.Add(new SingleValueLegacyExtendedProperty { Id = "String {00020329-0000-0000-C000-000000000046} Name CompanyID", Value = "12345" });


        addedEvent = await graphClient.Me.Calendar.Events.Request().AddAsync(newEvent);

   

    }
    catch (Exception e)
    {
        throw e;
    }


    return addedEvent;

  

}

订阅代码片段

var subscription = new Subscription
{
    ChangeType = "created",
    NotificationUrl ="<OUR-URL>",                                   
    Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
    ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
    ClientState = "custom_data_state",
    LatestSupportedTlsVersion = "v1_2"
};

订阅已成功创建,但不会为包含上述特定自定义属性的项目发送通知。

4

1 回答 1

0

事实证明我只是在捕获“创建”通知。我忽略了添加“更新”和“删除”。

我正在测试我日历中已经存在的事件。没有触发任何事件,因为我没有创建订阅来检测更新和删除。

这是更正后的订阅:

var subscription = new Subscription
{
    ChangeType = "created,updated,deleted",
    NotificationUrl ="<OUR-URL>",                                   
    Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
    ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
    ClientState = "custom_data_state",
    LatestSupportedTlsVersion = "v1_2"
};
于 2020-11-13T18:28:19.380 回答