使用 EWS 托管 API 1.2 获取约会的定期模式

本文关键字:约会 模式 获取 EWS 托管 API 使用 | 更新日期: 2023-09-27 18:37:18

我正在寻找使用 EWS 托管 API 1.2 获取与约会关联的重复模式的正确方法。 我的代码看起来像这样:

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, view);
foreach (Appointment appointment in findResults)
{
    appointment.Load();
    if (appointment.IsRecurring)
    {
        // What is the recurrence pattern???
    }
}

我可以预约。Recurrence.ToString() 和我像 Microsoft.Exchange.WebServices.Data.Recurrence+WeeklyPattern 一样返回。 显然,我可以解析并确定类型,但这似乎不是很干净。 有没有更好的方法?

这里还有另一篇与此类似的帖子 - EWS:访问约会重复模式,但解决方案似乎不完整。

使用 EWS 托管 API 1.2 获取约会的定期模式

以下是模式的完整列表。没有属性的原因,你可以作为正在使用的模式,你将不得不将重复转换为模式。在我的项目中,我以这种方式解决了这个问题:

Appointment app = Appointment.Bind(service,id);
Recurrence.DailyPattern dp = app.Recurrence as Recurrence.DailyPattern;
Recurrence.DailyRegenerationPattern drp = app.Recurrence as Recurrence.DailyRegenerationPattern;
Recurrence.MonthlyPattern mp = app.Recurrence as Recurrence.MonthlyPattern;
Recurrence.MonthlyRegenerationPattern mrp = app.Recurrence as Recurrence.MonthlyRegenerationPattern;
Recurrence.RelativeMonthlyPattern rmp = app.Recurrence as Recurrence.RelativeMonthlyPattern;
Recurrence.RelativeYearlyPattern ryp = app.Recurrence as Recurrence.RelativeYearlyPattern;
Recurrence.WeeklyPattern wp = app.Recurrence as Recurrence.WeeklyPattern;
Recurrence.WeeklyRegenerationPattern wrp = app.Recurrence as Recurrence.WeeklyRegenerationPattern;
Recurrence.YearlyPattern yp = app.Recurrence as Recurrence.YearlyPattern;
Recurrence.YearlyRegenerationPattern yrp = app.Recurrence as Recurrence.YearlyRegenerationPattern;
if (dp != null)
{ 
//Do something
}
else if (drp != null)
{
//Do something
}
else if (mp != null)
{
//Do something
}
else if (mrp != null)
{
//Do something
}
else if (rmp != null)
{
//Do something
}
else if (ryp != null)
{
//Do something
}
else if (wp != null)
{
//Do something
}
else if (wrp != null)
{
//Do something
}
else if (yp != null)
{
//Do something
}
else if (yrp != null)
{
//Do something
}

希望对您有所帮助...

Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern pattern = (Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern)microsoftAppointment.Recurrence;

这是你要找的吗?

我对此

的 2 美分。我将通过检查类型来实现它:

if(app.Recurrence.GetType() == typeof(Recurrence.DailyPattern))
{
    // do something 
}
else if(app.Recurrence.GetType() == typeof(Recurrence.WeeklyPattern))
{
    // do something
}
...

我有另一种方法来解决项目中的问题。对我来说,它显然更容易阅读,但这是品味问题。

Appointment app = Appointment.Bind(service,id);
string[] split = app.Recurrence.ToString().Split('+');
if (split.Length != 2)
  return;
string pattern = split[1];
switch (pattern)
{
  case "DailyPattern":
    break;
  case "WeeklyPattern":
    break;
  case "MonthlyPattern":
    break;
  case "YearlyPattern":
    break;
}