EWS通过提醒< =当前时间获得约会

时间:2013-07-11 12:37:41

标签: c# exchangewebservices

我正在尝试查询Exchenge以获取已将提醒设置为当前时间的应用约会 我创建了一个简单的方法,它返回一个将在不久的将来开始的约会:

    public Appointment getMyAppointments()
    {
        try
        {
            CalendarFolder cfolder = CalendarFolder.Bind(service, WellKnownFolderName.Calendar);
            CalendarView calendarView = new CalendarView(DateTime.Now, DateTime.Now.AddHours(1));every appointment in one hour
            calendarView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Subject, ItemSchema.Categories);
            FindItemsResults<Appointment> findResults = cfolder.FindAppointments(calendarView);

            List<Item> items = new List<Item>();

            if (findResults.Items.Count > 0) // Prevent the exception
            {
                items.AddRange(findResults.Cast<Item>());
            }
            else
            {
                return null;
            }
            service.LoadPropertiesForItems(items, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Subject, ItemSchema.Categories, ItemSchema.Body));
            return findResults.Items[0];
        }
        catch (Exception e)
        {
            return null;
        }
    }

这将返回我将在最近的未来开始并在当前时间内有效的前一个约会:

如果我计划从14:00开始并在14:30结束的约会,如果我在13:01开始,我的方法将返回该约会,但如果我在14:22开始,它也将返回该约会。

我想更改该方法,以便返回所有在当前时间之前设置提醒并且未启动的会议:

所以,如果我计划在15:00预约,并将提醒设置为15分钟,我会在14:45拨打我的方法,我将接受预约。

我的想法是让所有约会进行8小时,然后迭代它们并检查它们是否IsReminderSet并检查Start - ReminderMinutesBeforeStart是否小于当前时间。

编辑 - 这是我的临时解决方案

    public OWAAppointment GetMyAppointments(int minutes)
    {
        try
        {
            CalendarFolder cfolder = CalendarFolder.Bind(service, WellKnownFolderName.Calendar);
            CalendarView calendarView = new CalendarView(DateTime.Now, DateTime.Now.AddHours(10));
            calendarView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Subject, ItemSchema.Categories);
            FindItemsResults<Appointment> findResults = cfolder.FindAppointments(calendarView);

            List<Item> items = new List<Item>();

            if (findResults.Items.Count > 0)
            {
                items.AddRange(findResults.Cast<Item>());
            }
            else
            {
                return null;
            }

            service.LoadPropertiesForItems(items, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Subject, ItemSchema.Categories, ItemSchema.Body, ItemSchema.ReminderDueBy, ItemSchema.ReminderMinutesBeforeStart));


            var appointment = findResults.Items
            .Where(item => item.Start >= DateTime.Now)
            .FirstOrDefault(item => item.Start.AddMinutes(-1*minutes) < DateTime.Now);

            return appointment // this will return appointment or null
        }
        catch (Exception e)
        {
            return null;
        }
    }

但也许这可以通过EWS更容易完成?

1 个答案:

答案 0 :(得分:1)

是的,这可以更轻松地完成。 EWS的GetReminders操作(不是EWS托管API)是在Exchange 2013中引入的。可以在此处找到信息:GetReminders operation。要检索所有当前提醒,请将ReminderType设置为All,将EndTime设置为当前时间。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" 
           xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" 
           xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013" />
  </soap:Header>
  <soap:Body>
   <m:GetReminders>
      <m:EndTime>2014-05-06T21:00:00Z</m:EndTime>
      <m:ReminderType>All</m:ReminderType>
    </m:GetReminders>
  </soap:Body>
</soap:Envelope>
相关问题