DevExpress Winforms使用技巧教程:Scheduler - 與Google日歷同步
下載DevExpress v20.1完整版 DevExpress v20.1漢化資源獲取
DevExpress Winforms Controls 內(nèi)置140多個(gè)UI控件和庫(kù),完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。想要體驗(yàn)?點(diǎn)擊下載>>
從v18.2版本開(kāi)始,DevExpress Winforms可以使用Google日歷進(jìn)行新的Scheduler同步,本文主要為大家介紹此功能。
DXGoogleCalendarSync組件
要同步Scheduler和Google Calendars Appointments(在Google文檔中,這些稱(chēng)為Events),您需要一個(gè)DXGoogleCalendarSync組件。 單擊Add DX Google Calendar Synchronizer Smart Tag鏈接時(shí),Scheduler會(huì)自動(dòng)添加它,該組件需要幾個(gè)NuGet軟件包。

DXGoogleCalendarSync在Scheduler存儲(chǔ)(支持SchedulerDataStorage及其先前的SchedulerStorage)與選定的Google日歷之間傳輸數(shù)據(jù),可以將存儲(chǔ)同時(shí)綁定到任何受支持的數(shù)據(jù)源。

您不僅限于導(dǎo)入或?qū)С鰯?shù)據(jù),同步是一個(gè)雙向過(guò)程,可同時(shí)處理兩個(gè)任務(wù)。
局限性
DXGoogleCalendarSync組件可以正確識(shí)別和同步Scheduler支持的所有Appointment類(lèi)型:常規(guī)Appointment和定期Appointment、all-day events、假期等,該組件唯一無(wú)法自動(dòng)同步的內(nèi)容類(lèi)型是顏色信息:Appointment標(biāo)簽和狀態(tài)不轉(zhuǎn)換默認(rèn)為事件顏色。狀態(tài)是唯一的Appointment屬性,沒(méi)有匹配的事件屬性(Google事件僅提供兩個(gè)“statuses” - Busy和Free),您可以通過(guò)處理某些組件事件來(lái)手動(dòng)將標(biāo)簽與事件顏色同步(請(qǐng)參見(jiàn)此)。
第二個(gè)限制是DXGoogleCalendarSync一次只能使用一個(gè)日歷,而Google日歷用戶(hù)可以預(yù)訂多個(gè)不同的日歷:個(gè)人日歷、工作日歷、假期日歷、家庭日歷、同事之間共享的公司日歷等,當(dāng)然,您可以輕松地檢索日歷列表,并實(shí)現(xiàn)一個(gè)UI在運(yùn)行時(shí)在它們之間進(jìn)行切換。
技術(shù)細(xì)節(jié)
顯示運(yùn)行中的同步組件。
要管理Google Calendar Events,您需要訪問(wèn)Google Calendar API。 請(qǐng)單擊Google文檔中,然后按照步驟13b下載您自己的credentials.json文件,這應(yīng)該包含在您的項(xiàng)目中,GitHub示例對(duì)此文件使用名稱(chēng)。
組件上需要設(shè)置三個(gè)核心屬性:
- Storage - 存儲(chǔ)Appointments的Scheduler Storage對(duì)象。 在示例中,此屬性是在設(shè)計(jì)時(shí)分配的()
gcSyncComponent.Storage = schedulerStorage;
-
CalendarService - 允許組件訪問(wèn)和修改日歷,必須授權(quán)當(dāng)前用戶(hù)訪問(wèn)Google帳戶(hù)(這是示例方法)。
... GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, new String[] { CalendarService.Scope.Calendar }, "user", CancellationToken.None, new FileDataStore(credPath, true));
然后可以實(shí)例化CalendarService(在示例的中)。
... gcSyncComponent.CalendarService = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = this.credential, ApplicationName = "GoogleCalendarSyncSample" }); ...
-
CalendarID - 同步GoogleCalendar identifier,這是一些示例代碼,可檢索所有Google日歷并填充組合框。然后您可以處理SelectedIndexChanged組合框事件,來(lái)將有效ID分配給CalendarID屬性。
CalendarList calendarList; string activeCalendarId; async Task UpdateCalendarListUI() { var listRequest = this.service.CalendarList.List(); this.calendarList = await listRequest.ExecuteAsync(); this.ricbCalendarList.Items.Clear(); foreach (CalendarListEntry item in this.calendarList.Items) this.ricbCalendarList.Items.Add(item.Summary); if (!String.IsNullOrEmpty(this.activeCalendarId)) { var itemToSelect = this.calendarList.Items.FirstOrDefault( x => x.Id == this.activeCalendarId); this.gcSyncComponent.CalendarId = this.activeCalendarId; if (this.ricbCalendarList.Items.Contains(itemToSelect.Summary)) this.beiCalendarList.EditValue = itemToSelect.Summary; else this.activeCalendarId = String.Empty; } }
一切設(shè)置完成后,可以隨時(shí)在DXGoogleCalendarSync組件上調(diào)用Synchronize或SynchronizeAsync來(lái)觸發(fā)同步進(jìn)程。首次啟動(dòng)時(shí),默認(rèn)的網(wǎng)絡(luò)瀏覽器將顯示一個(gè)頁(yè)面,要求您登錄要用于同步的Google帳戶(hù)。
除了上述基本設(shè)置外,DXGoogleCalendarSync組件還提供其他功能,包括:
- 會(huì)話狀態(tài)日志記錄,來(lái)幫助確定Scheduler Appointments和Google Events的優(yōu)先級(jí)
- 發(fā)生次要同步?jīng)_突時(shí),將觸發(fā)一個(gè)專(zhuān)用事件,處理它來(lái)手動(dòng)確定有效性
- 自定義字段,用于存儲(chǔ)Google事件ID和eTag值
- ProgressChanged事件,用于跟蹤自定義進(jìn)度指示器的同步狀態(tài)
有關(guān)Google日歷同步功能的完整文檔,請(qǐng)?jiān)L問(wèn)。
中國(guó)區(qū)首發(fā) · DevExpress v20.1新版發(fā)布會(huì)報(bào)名開(kāi)啟,名額有限先到先得哦~
DevExpress技術(shù)交流群2:775869749 歡迎一起進(jìn)群討論