Ejemplo n.º 1
0
        public void UpdateSyncData(GoogleTaskSyncData syncData, TaskSyncData syncDataSource)
        {
            syncData.GoogleTask.Title = syncDataSource.Subject;
            syncData.GoogleTask.Notes = syncDataSource.Body;
            if (syncDataSource.DueTime != null)
            {
                var dueTime          = syncDataSource.DueTime.Value;
                var dueTimeUtcFormat = new DateTime(dueTime.Year, dueTime.Month, dueTime.Day, 0, 0, 0, DateTimeKind.Utc);
                syncData.GoogleTask.Due = Rfc3339DateTime.ToString(dueTimeUtcFormat);
            }
            else
            {
                syncData.GoogleTask.Due = null;
            }

            if (syncDataSource.IsCompleted)
            {
                syncData.GoogleTask.Status = "completed";
                var currentDate          = DateTime.Now.Date;
                var currentDateUtcFormat = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 0, 0, 0, DateTimeKind.Utc);
                syncData.GoogleTask.Completed = Rfc3339DateTime.ToString(currentDateUtcFormat);
            }
            else
            {
                syncData.GoogleTask.Status    = "needsAction";
                syncData.GoogleTask.Completed = null;
            }
        }
Ejemplo n.º 2
0
        public GoogleCalendarEventSyncData CreateFrom(TaskSyncData syncDataSource)
        {
            var calendarEvent = new Event();

            calendarEvent.Summary     = syncDataSource.Subject;
            calendarEvent.Description = syncDataSource.Body;

            DateTime dueTime;

            if (syncDataSource.DueTime != null)
            {
                dueTime = syncDataSource.DueTime.Value;
            }
            else
            {
                dueTime = syncDataSource.CreateTime;
            }

            var    currentDate = dueTime.Date;
            var    startTime   = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 0, 0, 0, DateTimeKind.Utc);
            var    endTime     = startTime.AddHours(1);
            string start       = Rfc3339DateTime.ToString(startTime);
            string end         = Rfc3339DateTime.ToString(endTime);

            calendarEvent.Start = new EventDateTime()
            {
                DateTime = start
            };
            calendarEvent.End = new EventDateTime()
            {
                DateTime = end
            };

            return(new GoogleCalendarEventSyncData(calendarEvent));
        }
        public void UpdateSyncData(TaskSyncData syncData, GoogleTaskSyncData syncDataSource)
        {
            syncData.Subject = syncDataSource.GoogleTask.Title;
            syncData.Body = syncDataSource.GoogleTask.Notes;

            DateTime? dueTime = null;
            if (Utils.IsDateTime(syncDataSource.GoogleTask.Due))
            {
                dueTime = Rfc3339DateTime.Parse(syncDataSource.GoogleTask.Due);
            }
            if (dueTime != null)
            {
                var dueTimeLocalFormat = new DateTime(dueTime.Value.Year, dueTime.Value.Month, dueTime.Value.Day, 0, 0, 0, DateTimeKind.Local);
                syncData.DueTime = dueTimeLocalFormat;
            }
            else
            {
                syncData.DueTime = null;
            }

            if (syncDataSource.GoogleTask.Status == "needsAction")
            {
                syncData.IsCompleted = false;
            }
            else if (syncDataSource.GoogleTask.Status == "completed")
            {
                syncData.IsCompleted = true;
            }
        }
        public TaskSyncData CreateFrom(GoogleTaskSyncData syncDataSource)
        {
            DateTime? dueTime = null;
            if (Utils.IsDateTime(syncDataSource.GoogleTask.Due))
            {
                dueTime = Rfc3339DateTime.Parse(syncDataSource.GoogleTask.Due);
            }

            TaskSyncData taskSyncData = new TaskSyncData();

            taskSyncData.Subject = syncDataSource.GoogleTask.Title;
            taskSyncData.Body = syncDataSource.GoogleTask.Notes;

            if (dueTime != null)
            {
                var dueTimeLocalFormat = new DateTime(dueTime.Value.Year, dueTime.Value.Month, dueTime.Value.Day, 0, 0, 0, DateTimeKind.Local);
                taskSyncData.DueTime = dueTimeLocalFormat;
            }
            else
            {
                taskSyncData.DueTime = null;
            }

            if (syncDataSource.GoogleTask.Status == "needsAction")
            {
                taskSyncData.IsCompleted = false;
            }
            else if (syncDataSource.GoogleTask.Status == "completed")
            {
                taskSyncData.IsCompleted = true;
            }

            return taskSyncData;
        }
        public void UpdateSyncData(TaskSyncData syncData, GoogleCalendarEventSyncData syncDataSource)
        {
            syncData.Subject = syncDataSource.GoogleCalendarEvent.Summary;
            syncData.Body    = syncDataSource.GoogleCalendarEvent.Description;

            if (!string.IsNullOrEmpty(syncDataSource.GoogleCalendarEvent.End.DateTime))
            {
                var end = Rfc3339DateTime.Parse(syncDataSource.GoogleCalendarEvent.End.DateTime);
                end = end.ToLocalTime();
                syncData.DueTime = end;
            }
            else
            {
                syncData.DueTime = null;
            }
        }
        public TaskSyncData CreateFrom(GoogleCalendarEventSyncData syncDataSource)
        {
            TaskSyncData taskSyncData = new TaskSyncData();

            taskSyncData.Subject = syncDataSource.GoogleCalendarEvent.Summary;
            taskSyncData.Body    = syncDataSource.GoogleCalendarEvent.Description;

            if (!string.IsNullOrEmpty(syncDataSource.GoogleCalendarEvent.End.DateTime))
            {
                var end = Rfc3339DateTime.Parse(syncDataSource.GoogleCalendarEvent.End.DateTime);
                end = end.ToLocalTime();
                taskSyncData.DueTime = end;
            }

            return(taskSyncData);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent.
        /// </summary>
        /// <param name="s">A string containing a date and time to convert.</param>
        /// <returns>A <see cref="DateTime"/> equivalent to the date and time contained in <paramref name="s"/>.</returns>
        /// <remarks>
        /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="s"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception>
        /// <exception cref="FormatException"><paramref name="s"/> does not contain a valid RFC 3339 string representation of a date and time.</exception>
        public static DateTime Parse(string s)
        {
            //------------------------------------------------------------
            //  Validate parameter
            //------------------------------------------------------------
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }

            DateTime result;

            if (Rfc3339DateTime.TryParse(s, out result))
            {
                return(result);
            }
            else
            {
                throw new FormatException(String.Format(null, "{0} is not a valid RFC 3339 string representation of a date and time.", s));
            }
        }
Ejemplo n.º 9
0
        public GoogleTaskSyncData CreateFrom(TaskSyncData syncDataSource)
        {
            var task = new GoogleTask();

            task.Title = syncDataSource.Subject;
            task.Notes = syncDataSource.Body;
            if (syncDataSource.DueTime != null)
            {
                var dueTime          = syncDataSource.DueTime.Value;
                var dueTimeUtcFormat = new DateTime(dueTime.Year, dueTime.Month, dueTime.Day, 0, 0, 0, DateTimeKind.Utc);
                task.Due = Rfc3339DateTime.ToString(dueTimeUtcFormat);
            }

            if (syncDataSource.IsCompleted)
            {
                task.Status = "completed";
            }
            else
            {
                task.Status = "needsAction";
            }

            return(new GoogleTaskSyncData(task));
        }