我正在寻找使用EWS Managed 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: Accessing an appointments recurrence pattern,但解决方案似乎并不完整。
答案 0 :(得分: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
}
希望能帮到你......
答案 1 :(得分:1)
Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern pattern = (Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern)microsoftAppointment.Recurrence;
这是你在找什么?
答案 2 :(得分:1)
我的2美分。我会通过检查类型来实现它:
if(app.Recurrence.GetType() == typeof(Recurrence.DailyPattern))
{
// do something
}
else if(app.Recurrence.GetType() == typeof(Recurrence.WeeklyPattern))
{
// do something
}
...
答案 3 :(得分: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;
}