首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现PatternedRecurrence使Office365RESTAPI v2日历事件

如何实现PatternedRecurrence使Office365RESTAPI v2日历事件
EN

Stack Overflow用户
提问于 2016-01-19 20:16:03
回答 1查看 711关注 0票数 0

我试图使PatternedRecurrence的用户可以选择3个选项,每周,每两周和每月。然而,我尝试过的代码似乎不起作用,它没有错误地发布到API,但在测试日历上没有出现任何位置,在那里,作为非模式的代码确实出现在日历上。THis是我尝试设置每周模式的代码。

代码语言:javascript
复制
NewEvent.Recurrence = new PatternedRecurrence();
NewEvent.Recurrence.Range = new RecurrenceRange();
NewEvent.Recurrence.Pattern = new RecurrencePattern();
NewEvent.Recurrence.Pattern.DaysOfWeek = new List<Microsoft.Office365.OutlookServices.DayOfWeek>();

NewEvent.Recurrence.Range.Type = RecurrenceRangeType.EndDate;
NewEvent.Recurrence.Range.EndDate = start.AddYears(2).ToString();
NewEvent.Recurrence.Range.StartDate = start.ToString();
NewEvent.Recurrence.Pattern.Interval = 1;
NewEvent.Recurrence.Pattern.Type = RecurrencePatternType.Weekly;
NewEvent.Recurrence.Pattern.FirstDayOfWeek = Microsoft.Office365.OutlookServices.DayOfWeek.Monday;

if (StartDay.ToString() == "Monday")
{NewEvent.Recurrence.Pattern.DaysOfWeek.Add(Microsoft.Office365.OutlookServices.DayOfWeek.DayOfWeek.Monday); }
else if (StartDay.ToString() == "Tuesday")
{ NewEvent.Recurrence.Pattern.DaysOfWeek.Add(Microsoft.Office365.OutlookServices.DayOfWeek.DayOfWeek.Tuesday); }

... for the rest of the days of the week

我已经查找了参考资料,但是它们并不是很有帮助,尽管我认为我写的东西足够有意义,除了所有的if语句之外,我想不出更好的方法来从System.DayOfWeek转换到Microsoft.Office365.OutlookServices.DayOfWeek

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-22 08:17:54

你有密码来捕捉这个请求吗?请求的回应是什么?我们可以使用Fiddler跟踪响应,如果经常性任命成功创建,则响应将包含关于复发的详细信息。

例如,下面是一个成功的响应:

代码语言:javascript
复制
{"@odata.context":"https://outlook.office.com/api/v2.0/$metadata#Me/Events/$entity","@odata.id":"https://outlook.office.com/api/v2.0/Users('7f4f5db6-539f-45d2-b133-26a25318269a@60c1366c-1b8f-4fcd-a190-058bfd47bcb4')/Events('AQMkADVkMTY3YmNiLTJiMDctNGU5Yi05MmM4LTFjODZkNDgxMzhkMQBGAAAE19y4nS_cT5eu67AiEA77BwB6jcCHf_RcRZqcWLJUEog7AAACAQ0AAAB6jcCHf_RcRZqcWLJUEog7AAAAA_dGpgAAAA==')","@odata.etag":"W/\"eo3Ah3/kXEWanFiyVBKIOwAAA+SaVA==\"","Id":"AQMkADVkMTY3YmNiLTJiMDctNGU5Yi05MmM4LTFjODZkNDgxMzhkMQBGAAAE19y4nS_cT5eu67AiEA77BwB6jcCHf_RcRZqcWLJUEog7AAACAQ0AAAB6jcCHf_RcRZqcWLJUEog7AAAAA_dGpgAAAA==","CreatedDateTime":"2016-01-21T23:45:06.8317353-08:00","LastModifiedDateTime":"2016-01-21T23:45:07.0973601-08:00","ChangeKey":"eo3Ah3/kXEWanFiyVBKIOwAAA+SaVA==","Categories":[],"OriginalStartTimeZone":"Pacific Standard Time","OriginalEndTimeZone":"Pacific Standard Time","ResponseStatus":{"Response":"Organizer","Time":"0001-01-01T00:00:00Z"},"iCalUId":"040000008200E00074C5B7101A82E00800000000A996F1CFE854D101000000000000000010000000D968C3A111A417438178343B150C0974","ReminderMinutesBeforeStart":15,"IsReminderOn":true,"HasAttachments":false,"Subject":"Sync up","Body":{"ContentType":"Text","Content":"Status updates, blocking issues, and next steps"},"BodyPreview":"Status updates, blocking issues, and next steps","Importance":"Normal","Sensitivity":"Normal","Start":{"DateTime":"2016-01-22T02:30:00.0000000","TimeZone":"Pacific Standard Time"},"End":{"DateTime":"2016-01-22T03:30:00.0000000","TimeZone":"Pacific Standard Time"},"Location":{"DisplayName":"Water cooler"},"IsAllDay":false,"IsCancelled":false,"IsOrganizer":true,"Recurrence":{"Pattern":{"Type":"Weekly","Interval":1,"Month":0,"DayOfMonth":0,"DaysOfWeek":["Friday"],"FirstDayOfWeek":"Sunday","Index":"First"},"Range":{"Type":"EndDate","StartDate":"2016-01-22","EndDate":"2017-01-22","RecurrenceTimeZone":"Pacific Standard Time","NumberOfOccurrences":0}},"ResponseRequested":true,"SeriesMasterId":null,"ShowAs":"Busy","Type":"SeriesMaster","Attendees":[],"Organizer":{"EmailAddress":{"Name":"Fei Xue","Address":"fx@msdnofficedev.onmicrosoft.com"}},"WebLink":"https://outlook.office365.com/owa/?ItemID=AQMkADVkMTY3YmNiLTJiMDctNGU5Yi05MmM4LTFjODZkNDgxMzhkMQBGAAAE19y4nS%2BcT5eu67AiEA77BwB6jcCHf%2BRcRZqcWLJUEog7AAACAQ0AAAB6jcCHf%2BRcRZqcWLJUEog7AAAAA%2BdGpgAAAA%3D%3D&exvsurl=1&viewmodel=ICalendarItemDetailsViewModelFactory"}

下面是创建每周定期约会的代码:

代码语言:javascript
复制
OutlookServicesClient client = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"),
                async () =>
                {
                    // Since we have it locally from the Session, just return it here.
                    return token;
                });


            Location location = new Location
            {
                DisplayName = "Water cooler"
            };

            // Create a description for the event    
            ItemBody body = new ItemBody
            {
                Content = "Status updates, blocking issues, and next steps",
                ContentType = BodyType.Text
            };

            // Create the event object
            DateTimeTimeZone start=new DateTimeTimeZone() ;
            string dateTimeFormat = "yyyy-MM-ddThh:mm:ss";
            string timeZone = "Pacific Standard Time";//"Eastern Standard Time";

            start.DateTime = new DateTime(2016, 1, 22, 14, 30, 0).ToString(dateTimeFormat);
            start.TimeZone = timeZone;

            DateTimeTimeZone end = new DateTimeTimeZone();
            end.DateTime = new DateTime(2016, 1, 22, 15, 30, 0).ToString(dateTimeFormat);
            end.TimeZone = timeZone;

            Event newEvent = new Event
            {
                Subject = "Sync up",
                Location = location,
                Start = start,
                End = end,
                Body = body
            };

            newEvent.Recurrence = new PatternedRecurrence();
            newEvent.Recurrence.Range = new RecurrenceRange();

            string dateFormat = "yyyy-MM-dd";
            newEvent.Recurrence.Range.EndDate = DateTime.Now.AddYears(1).ToString(dateFormat);
            newEvent.Recurrence.Range.StartDate = DateTime.Now.ToString(dateFormat);
            newEvent.Recurrence.Range.NumberOfOccurrences = 11;

            newEvent.Recurrence.Pattern = new RecurrencePattern();
            newEvent.Recurrence.Pattern.Type = RecurrencePatternType.Weekly;
            newEvent.Recurrence.Pattern.Interval = 1;
            newEvent.Recurrence.Pattern.DaysOfWeek= new List<Microsoft.Office365.OutlookServices.DayOfWeek>() { Microsoft.Office365.OutlookServices.DayOfWeek.Friday };
            // Add the event to the default calendar
            await client.Me.Events.AddEventAsync(newEvent);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34886134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档