Exemplo n.º 1
0
        public IList <GoogleCalendarEventSyncData> GetSyncDataList()
        {
            bool isDefaultCalendarExist = false;
            var  defaultCalendar        = GetDefaultCalendar(_token, out isDefaultCalendarExist);

            DateTime startTime = DateTime.UtcNow.Date;
            DateTime endTime   = startTime.AddMonths(GoogleSyncSettings.DefaultCalendarImportTimeMonths);

            bool isFromDefault = true;
            var  listRequest   = _calendarService.Events.List(defaultCalendar.Id);

            listRequest.MaxResults = GoogleSyncSettings.DefaultMaxCalendarEventCount;
            var evnts = listRequest.Fetch().Items;

            if (!isDefaultCalendarExist)
            {
                //默认的不存在,不从Google默认的日历读取任务
                //evnts = _calendarService.Events.List("primary").Fetch().Items;
                isFromDefault = false;
            }

            List <GoogleCalendarEventSyncData> items = new List <GoogleCalendarEventSyncData>();

            if (evnts != null && evnts.Count() > 0)
            {
                foreach (var evnt in evnts)
                {
                    //这里目前没有找到可以根据开始日期和结束日期查询的接口,
                    //只能查处所有当前日历的事件,然后在内存过滤
                    DateTime result;
                    if (Rfc3339DateTime.TryParse(evnt.End.DateTime, out result))
                    {
                        var end = result.ToLocalTime();
                        if (end >= startTime && end <= endTime)
                        {
                            var syncData = new GoogleCalendarEventSyncData(evnt);
                            syncData.IsFromDefault = isFromDefault;
                            items.Add(syncData);
                        }
                    }
                }
            }

            return(items);
        }
Exemplo n.º 2
0
 public void UpdateSyncData(GoogleCalendarEventSyncData syncData, TaskSyncData syncDataSource)
 {
     syncData.GoogleCalendarEvent.Summary     = syncDataSource.Subject;
     syncData.GoogleCalendarEvent.Description = syncDataSource.Body;
 }