예제 #1
0
 public void AddToDeletedInTrash(Tasks delete)
 {
     if (delete != null)
     {
         DeletedInTrash.Add(delete);
     }
 }
예제 #2
0
 public async static Task<Attachment> ConvertServerToLocal(Attachment remote,
     Tasks localTask)
 {
     Attachment localAttach = new Attachment();
     localAttach.SId = remote.SId;
     localAttach.UserId = localTask.UserId;
     localAttach.TaskSid = localTask.SId;
     localAttach.Description = remote.Description;
     localAttach.FileName = remote.FileName;
     string fileType = FileUtility.FileType.GetFileType(remote.FileType);
     if (fileType == null)
     {
         return null;
     }
     localAttach.FileType = fileType;
     localAttach.Status = ModelStatusEnum.SYNC_DONE;
     // TODO 可能是脏数据导致null
     localAttach.Size = remote.Size == null ? 0 : remote.Size;
     localAttach.ReferAttachmentSid = remote.RefId;
     await localAttach.InitDownloadStatus();
     //if (Log.IS_LOG_ENABLED)
     //{
     //    Log.debugSync(localAttach.toString());
     //}
     return localAttach;
 }
예제 #3
0
 public void AddToDeletedForever(Tasks delete)
 {
     if (delete != null)
     {
         DeletedForever.Add(delete);
     }
 }
예제 #4
0
 public void AddToUpdated(Tasks update)
 {
     if (update != null)
     {
         Updated.Add(update);
     }
 }
예제 #5
0
 public void AddToUpdating(Tasks updating)
 {
     if (updating != null)
     {
         Updated.Add(updating);
     }
 }
예제 #6
0
 public void AddToAdded(Tasks add)
 {
     if (add != null)
     {
         Added.Add(add);
     }
 }
예제 #7
0
        public String GetCompositeContent(Tasks task)
        {
            StringBuilder content = new StringBuilder();
            List<ChecklistItem> subTasks = task.ChecklistItems;
            if (subTasks.Count == 1 && subTasks[0].Id < 0
                    && string.IsNullOrEmpty(subTasks[0].Title))
            {
                if (string.IsNullOrEmpty(task.Title))
                {
                    // 如果只有一个默认产生的空item,且task title为空,则清除
                    task.ChecklistItems.Clear();
                }
                return content.ToString();
            }
            bool isFirst = true;
            foreach (var item in subTasks)
            {
                if (!isFirst)
                {
                    content.Append("\r\n");
                }
                else
                {
                    isFirst = false;
                }

                content.Append(item.Title);
            }
            return content.ToString();
        }
예제 #8
0
 public static List<TaskReminder> CalculateTaskReminder(Tasks task)
 {
     List<TaskReminder> taskReminders = new List<TaskReminder>();
     if (task.DueDate == null)
     {
         task.Reminders = new List<TaskReminder>();
         return taskReminders;
     }
     if (!task.HasReminder())
     {
         return taskReminders;
     }
     long dueTime = GetTaskDueTime(task.DueDate.Value, task.IsAllDay);
     foreach (TaskReminder reminder in task.Reminders)
     {
         DateTime? remindTime = DateTimeUtils.CalculateRemindTime(reminder.Duration, dueTime);
         if (remindTime != null)
         {
             TaskReminder taskReminder = new TaskReminder(reminder);
             taskReminder.RemindTime = remindTime.Value;
             taskReminders.Add(taskReminder);
         }
     }
     return taskReminders;
 }
예제 #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tasks"></param>
        /// <param name="isChecked"></param>
        /// <returns></returns>
        public async Task UpdateTaskStatus(Tasks tasks)// TODO 临时使用tasks来进行适配。。。之后换成remindertask
        {
            //if (tasks.IsCompleted == isChecked)
            //{
            //    // do nothing
            //    return;
            //}
            Tasks task = await TaskBll.GetTasksByTasksId(tasks.Id);
            if (task == null)
            {
                // Task has been deleted
                return;
            }
            // TODO -临时使用这句代替,应该使用remindertask的属性来赋值
            task.TaskStatus = tasks.TaskStatus;
            await TaskBll.UpdateTaskCompleteStatus(task);
            if (task.IsRepeatTask() && task.IsCompleted)
            {
                //Toast.makeText(application, application.getString(R.string.repeat_task_complete_toast),
                //        Toast.LENGTH_SHORT).show();
            }
            if (task.HasLocation())
            {
                //application.sendLocationAlertChangedBroadcast(task.getLocation().getGeofenceId());
            }

            //application.getPreferencesHelper().setContentChanged(true);
            //application.tryToBackgroundSync();
            //application.sendTask2ReminderChangedBroadcast();
            //application.tryToSendBroadcast();
        }
예제 #10
0
        public static TasksServer ConvertLocalToServer(Tasks localTask)
        {
            TasksServer task = new TasksServer();
            task.Id = localTask.SId;
            task.CreatedTime = localTask.CreatedTime;
            task.ModifiedTime = localTask.ModifiedTime;
            task.Etag = localTask.Etag;
            task.ProjectId = localTask.ProjectSid;
            task.Title = localTask.Title;
            task.Content = localTask.Content;
            task.SortOrder = localTask.SortOrder;
            task.Priority = localTask.Priority;
            task.DueDate = localTask.DueDate;
            task.RepeatFirstDate = localTask.RepeatFirstDate;
            //task.Reminder = localTask.Reminder;
            task.RepeatFlag = localTask.RepeatFlag;
            task.RepeatTaskId = localTask.RepeatTaskId;
            // TODO task.setUserCount=UserCount);
            task.CompletedTime = localTask.CompletedTime;
            task.Status = localTask.TaskStatus;
            task.TimeZone = localTask.TimeZone;

            if (localTask.IsChecklistMode())
            {
                task.Items = ChecklistItemTransfer.ConvertCheckListItemLocalToServer(localTask.ChecklistItems);
            }
            else
            {
                task.Items = null;
            }
            if (localTask.HasLocation())
            {
                task.Location = LocationTransfer.ConvertLocationLocalToServer(localTask.Location);
            }
            //if (localTask.Attachments != null && localTask.Attachments.Count > 0)
            //{
            //    //task.Attachments =AttachmentTransfer.ConvertAttachmentLocalToServer(localTask.Attachments);
            //}

            if (localTask.HasReminder())
            {
                //DateTime? reminderTime = localTask.SnoozeRemindTime;
                //if (reminderTime == null)
                //{
                //    reminderTime = DateTimeUtils.CalculateReminderTime(localTask.Reminder, localTask.DueDate.Value);
                //}
                //task.RemindTime = reminderTime;
                task.Reminders = ReminderTransfer.ConvertLocalToServer(localTask.Reminders);
            }
            if (localTask.DueDate != null)
            {
                task.IsAllDay = localTask.IsAllDay;
            }
            task.RemindTime = localTask.SnoozeRemindTime;
            task.RepeatFrom = localTask.RepeatFrom;
            task.Assignee = localTask.Assignee;
            //task.Tags = localTask.Tags;
            return task;
        }
예제 #11
0
 public static async Task<List<Attachment>> ConvertServerToLocal(
     List<Attachment> attachments, Tasks localTask)
 {
     List<Attachment> localAttachs = new List<Attachment>();
     foreach (Attachment remoteAttach in attachments)
     {
         localAttachs.Add(await ConvertServerToLocal(remoteAttach, localTask));
     }
     return localAttachs;
 }
예제 #12
0
 public static async Task<List<Attachment>> ConvertServerToLocal(
     List<Attachment> attachments, String userId, String taskSid)
 {
     List<Attachment> localAttachs = new List<Attachment>();
     Tasks mockTask = new Tasks();
     mockTask.UserId = userId;
     mockTask.SId = taskSid;
     foreach (Attachment remoteAttach in attachments)
     {
         localAttachs.Add(await ConvertServerToLocal(remoteAttach, mockTask));
     }
     return localAttachs;
 }
예제 #13
0
 public static bool IsDuedateChanged(Tasks task1, Tasks task2)
 {
     if (task1.DueDate == null && task2.DueDate == null)
     {
         return false;
     }
     if (task1.DueDate != null && task2.DueDate != null)
     {
         // TODO 时间插件
         //DateTime taskDueDateClean = DateUtils.clearSecondOfDay(task1.getDueDate());
         //DateTime duedateClean = DateUtils.clearSecondOfDay(task2.getDueDate());
         //return taskDueDateClean.compareTo(duedateClean) != 0;
     }
     return true;
 }
예제 #14
0
        public static void MergeTask(Tasks original, Tasks delta, Tasks revised)
        {
            try
            {
                revised.TaskStatus = GetRevisedStatus(original.TaskStatus, delta.TaskStatus, revised.TaskStatus);
                revised.Title = GetRevisedTextByDiff(original.Title, delta.Title, revised.Title);
                revised.Content = GetRevisedTextByDiff(original.Content, delta.Content, revised.Content);
                revised.SortOrder = GetRevisedSortOrder(original.SortOrder, delta.SortOrder, revised.SortOrder);
                revised.SnoozeRemindTime = GetRevisedDueDate(original.SnoozeRemindTime, delta.SnoozeRemindTime, revised.SnoozeRemindTime);

                bool dueDateReviseChange = !IsSameDate(original.DueDate, revised.DueDate);
                if (dueDateReviseChange)
                {
                    revised.SnoozeRemindTime = dueDateReviseChange ? null : delta.SnoozeRemindTime;

                }
                revised.DueDate = GetRevisedDueDate(original.DueDate, delta.DueDate, revised.DueDate);
                revised.CompletedTime = GetRevisedDueDate(original.CompletedTime, delta.CompletedTime, revised.CompletedTime);
                revised.Reminder = GetRevisedText(original.Reminder, delta.Reminder, revised.Reminder);
                revised.RepeatFlag = GetRevisedText(original.RepeatFlag, delta.RepeatFlag, revised.RepeatFlag);
                revised.Priority = GetRevisedPriority(original.Priority, delta.Priority, revised.Priority);

                if (revised.DueDate == null)
                {
                    revised.IsAllDay = false;
                }
                else
                {
                    revised.IsAllDay = GetRevisedIsAllDay(original.IsAllDay, delta.IsAllDay, revised.IsAllDay);
                }

                MergeChecklistItems(original, delta, revised);

                MergeReminders(original, delta, revised);
            }

            catch (Exception e)
            {
                //Log.e(TAG, e.getMessage(), e);
            }
        }
예제 #15
0
        // TODO 这里有问题 返回taskremindstatus
        public static int IsRemindTask(Tasks task)
        {

            if (task.DueDate == null)
            {
                return TaskRemindStatus.NO_DUE_DATE;
            }

            if (task.Deleted != ModelStatusEnum.DELETED_NO)
            {
                return TaskRemindStatus.TASK_DELETED;
            }

            if (task.IsCompleted)
            {
                return TaskRemindStatus.TASK_COMPLETED;
            }

            if (!task.HasReminder())
            {
                return TaskRemindStatus.NO_REMINDER;
            }

            if (task.IsRepeatTask())
            {
                return TaskRemindStatus.VALID;
            }

            if (HasValidReminder(task.Reminders, task.DueDate.Value, task.IsAllDay))
            {
                return TaskRemindStatus.VALID;
            }

            if (IsValidSnoozeReminder(task.SnoozeRemindTime.Value))
            {
                return TaskRemindStatus.VALID;
            }

            return TaskRemindStatus.OVERDUE;
        }
예제 #16
0
 public static async Task CollectRemoteLocations(TasksServer serverTask, Tasks localTask,LocationSyncBean locationSyncBean)
 {
     Location local = localTask.Location;
     if (HasLocation(serverTask) && local == null)
     {
         locationSyncBean.AddUpdateLocation(await LocationTransfer.ConvertServerToLocal(serverTask));
     }
     else if (HasLocation(serverTask) && local != null)
     {
         if (local.Status == ModelStatusEnum.SYNC_DONE)
         {
             locationSyncBean.AddUpdateLocation(await LocationTransfer.ConvertServerToLocal(serverTask, local));
         }
     }
     else if (!HasLocation(serverTask) && local != null)
     {
         if (local.Status == ModelStatusEnum.SYNC_DONE)
         {
             locationSyncBean.AddDeleteLocation(local);
         }
     }
 }
예제 #17
0
 public void SwitchToChecklist(Tasks task)
 {
     List<ChecklistItem> items = new List<ChecklistItem>();
     String content = task.Content;
     if (content.Contains("\n"))
     {
         if (content.Contains("\r\n"))
         {
             //先统一替换成线上版本
             content = content.Replace("\r\n", "\n");
         }
         //然后替换成C#版本
         content = content.Replace("\n", "\r\n");
     }
     if (!string.IsNullOrEmpty(content))
     {
         String[] arrayTitle = content.Split(new string[] { "\r\n" }, StringSplitOptions.None);
         for (int i = 0, size = arrayTitle.Length; i < size; i++)
         {
             if (i == 0 && string.IsNullOrEmpty(arrayTitle[i]))
             {
                 continue;
             }
             String itemTitle = string.IsNullOrEmpty(arrayTitle[i]) ? "" : arrayTitle[i];
             ChecklistItem item = new ChecklistItem();
             //item.Id = GetDefaultItemId();// TODO 为什么要改变Id
             item.Title = itemTitle;
             item.TaskId = task.Id;
             items.Add(item);
         }
     }
     else
     {
         items.Add(new ChecklistItem { Title = string.Empty, TaskId = task.Id });
     }
     task.ChecklistItems = items;
 }
예제 #18
0
 public static Tasks ConvertServerTaskToLocalWithChecklistItem(TasksServer serverTask)
 {
     Tasks task = new Tasks();
     ConvertServerTaskToLocalWithChecklistItem(task, serverTask);
     return task;
 }
예제 #19
0
        /// <summary>
        /// 删除某个tasks
        /// </summary>
        public async Task FinishTask(Tasks task)
        {
            int index = Tasks.IndexOf(task);
            int indexFinished = TasksFinished.IndexOf(task);
            if (index < 0 && indexFinished < 0)
            {
                return;
            }
            if (task.IsCompleted)
            {
                task.TaskStatus = ModelStatusEnum.NOT_COMPLETED;
                TasksFinished.RemoveAt(indexFinished);
                Tasks.Insert(0, task);
            }
            else
            {
                task.TaskStatus = ModelStatusEnum.COMPLETED;
                Tasks.RemoveAt(index);
                TasksFinished.Insert(0, task);
            }

            await ReminderTaskBll.UpdateTaskStatus(task);
        }
예제 #20
0
 public static void ConvertServerTaskToLocalWithChecklistItem(Tasks localTask, TasksServer serverTask)
 {
     ConvertServerTaskToLocal(localTask, serverTask);
     ConvertServerChecklistItemToLocal(localTask, serverTask);
     ConvertServerRemindersToLocal(localTask, serverTask);
     localTask.SetTagsInner();// TODO 此处有坑,由于不知道转换逻辑是什么,所以先不实现
 }
 private static Dictionary<String, Attachment> GetLocalAttachmentDic(Tasks localTask)
 {
     Dictionary<String, Attachment> dic = new Dictionary<String, Attachment>();
     List<Attachment> localAttachs = localTask.Attachments;
     if (localAttachs == null || localAttachs.Count <= 0)
     {
         return dic;
     }
     foreach (var attachment in localAttachs)
     {
         dic.Add(attachment.SId, attachment);
     }
     return dic;
 }
예제 #22
0
 private void MergeTaskAssignee(HashSet<String> assignTaskIds, TasksServer serverTask, Tasks localTask)
 {
     if (assignTaskIds.Contains(serverTask.Id))
     {
         //本地覆盖Server assignee
         serverTask.Assignee = localTask.Assignee;
     }
 }
예제 #23
0
 private static void ConvertServerRemindersToLocal(Tasks localTask, TasksServer serverTask)
 {
     if (serverTask.Reminder == null)
     {
         return;
     }
     List<TaskReminder> localReminders = new List<TaskReminder>();
     foreach (Reminder serverReminder in serverTask.Reminders)
     {
         if (serverReminder != null)
         {
             TaskReminder taskReminder = ReminderTransfer.ConvertServerToLocal(serverReminder);
             if (taskReminder != null)
             {
                 localReminders.Add(taskReminder);
             }
         }
     }
     localTask.Reminders = localReminders;
 }
예제 #24
0
 private static void ConvertServerChecklistItemToLocal(Tasks localTask, TasksServer serverTask)
 {
     if (serverTask.Items == null)
     {
         return;
     }
     List<ChecklistItem> localItems = new List<ChecklistItem>();
     foreach (ChecklistItem serverItem in serverTask.Items)
     {
         if (serverItem != null)
         {
             localItems.Add(ChecklistItemTransfer.ConvertServerToLocal(serverItem));
         }
     }
     localTask.ChecklistItems = localItems;
     localTask.SetContentByItemsInner();
 }
예제 #25
0
 private static void ConvertServerTaskToLocal(Tasks task, TasksServer serverTask)
 {
     DateTime? reminderTime = GetReminderTime(serverTask);
     task.SId = serverTask.Id;
     task.ProjectSid = serverTask.ProjectId;
     task.Title = serverTask.Title;
     task.Content = serverTask.Content;
     task.SortOrder = serverTask.SortOrder;
     task.Priority = serverTask.Priority;
     task.DueDate = serverTask.DueDate;
     task.RepeatFirstDate = serverTask.RepeatFirstDate;
     //task.Reminder = serverTask.Reminder;// TODO 此字段已经废弃
     task.RepeatFlag = serverTask.RepeatFlag;
     String repeatTaskId = serverTask.RepeatTaskId;
     task.RepeatTaskId = string.IsNullOrEmpty(repeatTaskId) ? task.SId : repeatTaskId;
     task.CompletedTime = serverTask.CompletedTime;
     task.TaskStatus = serverTask.Status;
     task.Etag = serverTask.Etag;
     task.Kind = GetTaskKind(serverTask);//task.setKind(getTaskKind(serverTask));
     String tz = string.IsNullOrEmpty(serverTask.TimeZone) ? NodaTime.DateTimeZoneProviders.Tzdb.GetSystemDefault().Id : serverTask.TimeZone;// TimeZone.getDefault().getID() : serverTask.getTimeZone();
     task.TimeZone = tz;
     task.ModifiedTime = serverTask.ModifiedTime;
     task.SnoozeRemindTime = reminderTime;
     //task.RepeatReminderTime = task.IsRepeatTask() ? reminderTime : DateTime.MinValue;
     String repeatFromRemote = serverTask.RepeatFrom;
     task.RepeatFrom = string.IsNullOrEmpty(repeatFromRemote) ? Constants.RepeatFromStatus.DEFAULT : repeatFromRemote;
     task.CommentCount = serverTask.CommentCount;
     task.Assignee = serverTask.Assignee == null ? Constants.Removed.ASSIGNEE : serverTask.Assignee;
     task.Deleted = serverTask.Deleted;
     task.IsAllDay = serverTask.IsAllDay != null && serverTask.IsAllDay;
 }
예제 #26
0
        private static void AppendTaskAttachments(Tasks task, SyncTaskBean syncTaskBean)
        {
            List<Attachment> addedRemotes = new List<Attachment>();
            List<Attachment> deletedRemotes = new List<Attachment>();
            foreach (Attachment localAttach in task.Attachments)
            {
                if (localAttach.Status == ModelStatusEnum.SYNC_NEW
                        && localAttach.Deleted == ModelStatusEnum.DELETED_NO)
                {
                    addedRemotes.Add(AttachmentTransfer.ConvertLocalToRemote(localAttach));
                }
                else if (localAttach.Status != ModelStatusEnum.SYNC_NEW
                        && localAttach.Deleted == ModelStatusEnum.DELETED_TRASH)
                {
                    deletedRemotes.Add(AttachmentTransfer.ConvertLocalToRemote(localAttach));
                }
            }

            if (addedRemotes.Count > 0)
            {
                Tasks remote = new Tasks();
                remote.Id = Convert.ToInt32(task.SId);
                remote.ProjectId = task.ProjectSid;
                remote.Attachments = addedRemotes;
                syncTaskBean.AddAttachments.Add(remote);
            }
            if (deletedRemotes.Count > 0)
            {
                Tasks remote = new Tasks();
                remote.Id = Convert.ToInt32(task.SId);
                remote.ProjectId = task.ProjectSid;
                remote.Attachments = deletedRemotes;
                syncTaskBean.DeleteAttachments.Add(remote);
            }
        }
예제 #27
0
 private static string GetTaskKind(Tasks serverTask)
 {
     List<ChecklistItem> items = serverTask.ChecklistItems;
     if (items == null || items.Count <= 0)
     {
         return Constants.Kind.TEXT;
     }
     else
     {
         return Constants.Kind.CHECKLIST;
     }
 }
예제 #28
0
 public static List<DateTime> GetLatestNextDueDates(Tasks task)
 {
     return GetNextDueDate(task.RepeatFlag, task.DueDate.Value, task.RepeatFrom, task.CompletedTime.Value, task.TimeZone, 3);
 }
        public static async Task CollectRemoteAttachments(TasksServer serverTask, Tasks localTask,
            AttachmentSyncBean attachmentSyncBean)
        {

            // 如果server返回的附件为null时,表示server端无修改
            if (serverTask.Attachments == null)
            {
                return;
            }
            bool hasAttachRemote = HasAttachment(serverTask);
            bool hasAttachLocal = localTask.Attachments.Count > 0;

            if (hasAttachRemote && !hasAttachLocal)
            {
                //Server存在附件,Local没有,直接新增
                attachmentSyncBean.AddAllAddeds(await AttachmentTransfer.ConvertServerToLocal(serverTask.Attachments, localTask));
                localTask.HasAttachment = true;

            }
            else if (!hasAttachRemote && hasAttachLocal)
            {
                //server没有附件,Local有,判断是否要删除
                bool hasExistAttachment = false;
                foreach (var attachment in localTask.Attachments)
                {
                    if (attachment.Status == ModelStatusEnum.SYNC_DONE)
                    {
                        attachmentSyncBean.AddDeleted(attachment);
                    }
                    else
                    {
                        hasExistAttachment = true;
                    }
                }
                //及时更新Task的hasAttachment状态
                localTask.HasAttachment = hasExistAttachment;

            }
            else if (hasAttachRemote)
            {
                //Server和Local同时存在附件,需要合并
                Dictionary<String, Attachment> localAttachDic = GetLocalAttachmentDic(localTask);
                List<Attachment> serverAttachs = serverTask.Attachments;
                foreach (Attachment attachment in serverAttachs)
                {

                    if (attachment == null)
                    {
                        //TODO,List里面不应该出现NULL,是否可以删除
                        continue;
                    }

                    Attachment localAttach = localAttachDic[attachment.SId];
                    localAttachDic.Remove(attachment.SId);

                    if (localAttach == null)
                    {
                        //本地不存在对应附件,新增Server附件到Local
                        attachmentSyncBean.AddAdded(await AttachmentTransfer.ConvertServerToLocal(attachment,
                                localTask));
                    }
                }

                //找出server不存的Local已同步附件,判定为已删除
                foreach (var attachment in localAttachDic.Values)
                {
                    if (attachment.Status == ModelStatusEnum.SYNC_DONE)
                    {
                        attachmentSyncBean.AddDeleted(attachment);
                    }
                }

                //当前情况下task肯定有附件,及时更新状态
                localTask.HasAttachment = true;
            }

        }
예제 #30
0
 private async Task MergeMoveListAction(Dictionary<String, String> moveListTasksMap, TasksServer serverTask, Tasks localTask, string projectId)
 {
     if (string.Equals(serverTask.ProjectId, localTask.ProjectSid))
     {
         if (moveListTasksMap.ContainsKey(localTask.SId))
         {
             //local和server做相同move to操作,直接删除move to同步状态
             await SyncStatusBll.DeleteSyncStatus(localTask.UserId, localTask.SId, ModelStatusEnum.SYNC_TYPE_TASK_MOVE);
         }
     }
     else
     {
         if (moveListTasksMap.ContainsKey(localTask.SId))
         {
             //需要更新moveFromProjectId,因为server也做了move操作,moveFromProjectId已经改变
             if (!string.Equals(serverTask.ProjectId, moveListTasksMap[localTask.SId]))
             {
                 await SyncStatusBll.UpdateMoveFromId(localTask.SId, localTask.UserId, serverTask.ProjectId);
             }
         }
         else
         {
             //本地没MOVE,Server的操作会覆盖本地,
             //TODO 只更新了task的project是否有问题
             localTask.ProjectId = projectId;
             localTask.ProjectSid = serverTask.ProjectId;
         }
     }
 }