public void AddToUpdated(TasksServer task) { if (task != null) { Updated.Add(task); } }
public void AddToAdded(TasksServer task) { if (task != null) { Added.Add(task); } }
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; }
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); } } }
public static async Task<Location> ConvertServerToLocal(TasksServer serverTask, Location localLocation) { Location locationRemote = serverTask.Location; Location locationLocal = localLocation; if (locationLocal == null) { locationLocal = new Location(); locationLocal.Id = Constants.EntityIdentifie.DEFAULT_LOCATION_ID; locationLocal.TaskSid = serverTask.Id; } locationLocal.Address = locationRemote.Address; locationLocal.ShortAddress = locationRemote.ShortAddress; Loc loc = locationRemote.Loc; if (loc == null) { locationLocal.Latitude = 0; locationLocal.Longitude = 0; } else { locationLocal.Latitude = loc.Latitude; locationLocal.Longitude = loc.Longitude; } if (locationRemote.Radius != null) { locationLocal.Radius = locationRemote.Radius; } if (locationRemote.TransitionType != null) { locationLocal.TransitionType = locationRemote.TransitionType; } locationLocal.Alias = locationRemote.Alias; if (LoggerHelper.IS_LOG_ENABLED) { await LoggerHelper.LogToAllChannels(null, locationLocal.ToString()); } return locationLocal; }
public static void ConvertServerTaskToLocalWithChecklistItem(Tasks localTask, TasksServer serverTask) { ConvertServerTaskToLocal(localTask, serverTask); ConvertServerChecklistItemToLocal(localTask, serverTask); ConvertServerRemindersToLocal(localTask, serverTask); localTask.SetTagsInner();// TODO 此处有坑,由于不知道转换逻辑是什么,所以先不实现 }
public void AddAddedTaskSyncedJson(TasksServer serviceTask) { TaskSyncedJsonBean.AddToAdded(serviceTask); }
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; }
private static bool HasLocation(TasksServer serverTask) { return serverTask.Location != null; }
private static bool HasAttachment(TasksServer serverTask) { return serverTask.Attachments != null && serverTask.Attachments.Count > 0; }
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; } }
private void MergeTaskAssignee(HashSet<String> assignTaskIds, TasksServer serverTask, Tasks localTask) { if (assignTaskIds.Contains(serverTask.Id)) { //本地覆盖Server assignee serverTask.Assignee = localTask.Assignee; } }
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; } } }
public static Tasks ConvertServerTaskToLocalWithChecklistItem(TasksServer serverTask) { Tasks task = new Tasks(); ConvertServerTaskToLocalWithChecklistItem(task, serverTask); return task; }
private async Task AddRemoteTaskToLocal(TaskSyncModel taskSyncModel, TasksServer serverTask, string projectId) { taskSyncModel.AddAddedTaskSyncedJson(serverTask); if (HasLocation(serverTask)) { taskSyncModel.AddUpdateLocation(await LocationTransfer.ConvertServerToLocal(serverTask)); } if (HasAttachment(serverTask)) { taskSyncModel.AddAllAddedAttachments(await AttachmentTransfer.ConvertServerToLocal(serverTask.Attachments, UserId, serverTask.Id)); } Tasks newTask = TaskTransfer.ConvertServerTaskToLocalWithChecklistItem(serverTask); newTask.ProjectId = projectId; newTask.UserId = UserId; newTask.HasAttachment = serverTask.Attachments != null && serverTask.Attachments.Count > 0; taskSyncModel.AddAddedTask(newTask); }
public static async Task<Location> ConvertServerToLocal(TasksServer serverTask) { return await ConvertServerToLocal(serverTask, null); }
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(); }
private static DateTime? GetReminderTime(TasksServer serverTask) { DateTime? reminderTimeRemote = serverTask.RemindTime; DateTime? dueDateRemote = serverTask.DueDate; return dueDateRemote == null ? null : reminderTimeRemote; }
private static string GetTaskKind(TasksServer serverTask) { List<ChecklistItem> items = serverTask.Items; if (items == null || items.Count <= 0) { return Constants.Kind.TEXT; } else { return Constants.Kind.CHECKLIST; } }
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; }