【问题标题】:Get recurrence pattern for appointment using EWS Managed API 1.2使用 EWS 托管 API 1.2 获取约会的重复模式
【发布时间】:2012-06-17 19:31:42
【问题描述】:

我正在寻找正确的方法来获取与使用 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: Accessing an appointments recurrence pattern 但解决方案似乎并不完整。

【问题讨论】:

    标签: c# exchangewebservices exchange-server-2010 ews-managed-api


    【解决方案1】:
    Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern pattern = (Microsoft.Exchange.WebServices.Data.Recurrence.IntervalPattern)microsoftAppointment.Recurrence;
    

    这是你要找的吗?

    【讨论】:

    • 不,这正是另一个帖子中的人正在做的事情,让我和以前一样,转换为字符串并在“+”上拆分。
    【解决方案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
    }
    

    希望对你有所帮助...

    【讨论】:

    • 我最终做了一些非常相似的事情,希望这篇文章对未来的人有所帮助!感谢您发布代码。
    【解决方案3】:

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

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

    【讨论】:

    • 原理相同,但我改用if (app.Recurrence is Recurrence.DailyPattern)。我喜欢它。
    【解决方案4】:

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

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      相关资源
      最近更新 更多