2

我正在寻找正确的方法来获取与使用 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:访问约会重复模式,但解决方案似乎并不完整。

4

4 回答 4

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
}

希望对你有帮助...

于 2012-07-06T13:22:19.353 回答
1
Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern pattern = (Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern)microsoftAppointment.Recurrence;

这是你想要的?

于 2012-06-20T06:11:22.543 回答
1

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

if(app.Recurrence.GetType() == typeof(Recurrence.DailyPattern))
{
    // do something 
}
else if(app.Recurrence.GetType() == typeof(Recurrence.WeeklyPattern))
{
    // do something
}
...
于 2013-07-03T09:23:00.270 回答
0

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

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;
}
于 2014-07-08T14:06:16.303 回答