private Sort[] ParseSortsByPriority(Account account, Sort[] sorts, params TaskInfo[] tasks) { Sort today, upcoming, later; today = sorts.FirstOrDefault(o => o.Key == "0") ?? new Sort() { By = "priority", Key = "0" }; today.Name = this.Lang().priority_today; upcoming = sorts.FirstOrDefault(o => o.Key == "1") ?? new Sort() { By = "priority", Key = "1" }; upcoming.Name = this.Lang().priority_upcoming; later = sorts.FirstOrDefault(o => o.Key == "2") ?? new Sort() { By = "priority", Key = "2" }; later.Name = this.Lang().priority_later; //修正索引 this.RepairIndexs(today, this.Parse(tasks, o => o.Priority == (int)Priority.Today)); this.RepairIndexs(upcoming, this.Parse(tasks, o => o.Priority == (int)Priority.Upcoming)); this.RepairIndexs(later, this.Parse(tasks, o => o.Priority == (int)Priority.Later)); return new Sort[] { today, upcoming, later }; }
private void RepairIndexs(Sort sort, IDictionary<string, TaskInfo> tasks) { var temp = (sort.Indexs ?? new string[0]).ToList(); if (this._log.IsDebugEnabled) this._log.DebugFormat("原始排序为{0}|{1}|{2}|{3}", sort.By, sort.Key, sort.Name, string.Join(",", temp)); //移除索引中不存在的项 temp.RemoveAll(o => string.IsNullOrWhiteSpace(o) || !tasks.ContainsKey(o)); if (this._log.IsDebugEnabled) this._log.DebugFormat("过滤后排序为{0}", string.Join(",", temp)); //合并未在索引中出现的项 sort.Indexs = temp.Union(tasks.Select(o => o.Value.ID)).ToArray(); if (this._log.IsDebugEnabled) this._log.DebugFormat("合并后排序为{0}", string.Join(",", sort.Indexs)); }
private Sort[] ParseSortsByDueTime(Account account, Sort[] sorts, params TaskInfo[] tasks) { Sort due, today, upcoming, later; due = sorts.FirstOrDefault(o => o.Key == "dueTime") ?? new Sort() { By = "", Key = "dueTime" }; due.Name = this.Lang().sort_by_dueTime; today = sorts.FirstOrDefault(o => o.Key == "0") ?? new Sort() { By = "priority", Key = "0" }; today.Name = this.Lang().priority_today; upcoming = sorts.FirstOrDefault(o => o.Key == "1") ?? new Sort() { By = "priority", Key = "1" }; upcoming.Name = this.Lang().priority_upcoming; later = sorts.FirstOrDefault(o => o.Key == "2") ?? new Sort() { By = "priority", Key = "2" }; later.Name = this.Lang().priority_later; //修正索引 this.RepairIndexs(due, this.Parse(tasks, o => !string.IsNullOrEmpty(o.DueTime))); this.RepairIndexs(today, this.Parse(tasks, o => string.IsNullOrEmpty(o.DueTime) && o.Priority == (int)Priority.Today)); this.RepairIndexs(upcoming, this.Parse(tasks, o => string.IsNullOrEmpty(o.DueTime) && o.Priority == (int)Priority.Upcoming)); this.RepairIndexs(later, this.Parse(tasks, o => string.IsNullOrEmpty(o.DueTime) && o.Priority == (int)Priority.Later)); return new Sort[] { due, today, upcoming, later }; }