Ejemplo n.º 1
0
        public void GetAll()
        {
            var a = this.CreateAccount();
            var list = this.CreatePersonalTasklist(a);

            var task = new Task(a);
            this._taskService.Create(task);

            task = new Task(a);
            task.SetTasklist(list);
            this._taskService.Create(task);

            task = new Task(a);
            task.SetTasklist(list);
            this._taskService.Create(task);

            Assert.AreEqual(3, this._taskService.GetTasks(a).Count());
            Assert.AreEqual(2, this._taskService.GetTasks(a, list).Count());
            Assert.AreEqual(1, this._taskService.GetTasksNotBelongAnyTasklist(a).Count());
        }
Ejemplo n.º 2
0
 public void LastUpdateTime()
 {
     var a = this.CreateAccount();
     var task = new Task(a);
     //subjet
     var old = task.LastUpdateTime;
     this.Idle();
     task.SetSubject(task.Subject);
     Assert.AreEqual(task.LastUpdateTime, old);
     task.SetSubject(string.Empty);
     Assert.Greater(task.LastUpdateTime, old);
     //body
     old = task.LastUpdateTime;
     this.Idle();
     task.SetBody(task.Body);
     Assert.AreEqual(task.LastUpdateTime, old);
     task.SetBody(string.Empty);
     Assert.Greater(task.LastUpdateTime, old);
     //dueTime
     old = task.LastUpdateTime;
     this.Idle();
     task.SetDueTime(null);
     Assert.Greater(task.LastUpdateTime, old);
     //priority
     old = task.LastUpdateTime;
     this.Idle();
     task.SetPriority(task.Priority);
     Assert.AreEqual(task.LastUpdateTime, old);
     task.SetPriority(Priority.Upcoming);
     Assert.Greater(task.LastUpdateTime, old);
     //tasklist
     old = task.LastUpdateTime;
     this.Idle();
     var list = this.CreatePersonalTasklist(a);
     task.SetTasklist(list);
     Assert.Greater(task.LastUpdateTime, old);
     old = task.LastUpdateTime;
     task.SetTasklist(list);
     Assert.AreEqual(task.LastUpdateTime, old);
 }
Ejemplo n.º 3
0
        public ActionResult Sync(string tasklistId, string tasklistChanges, string changes, string by, string sorts)
        {
            //模拟同步间隙
            //System.Threading.Thread.Sleep(2000);

            //HACK:Fetch模式不支持同步变更
            Assert.IsFalse(this._fetchTasklistHelper.IsFetchTasklist(tasklistId));

            var account = this.Context.Current;
            var list = _serializer.JsonDeserialize<ChangeLog[]>(changes);
            var idChanges = new Dictionary<string, string>();//old,new
            var tasklist = this.GetTasklist(tasklistId);

            //UNDONE:详细考虑潜在异常以及批量事务的意外问题是否会造成丢失变更
            #region 对task执行对应变更
            foreach (var c in list)
            {
                try
                {
                    //临时记录无需删除
                    if (c.Type == ChangeType.Delete && c.ID.StartsWith(TEMP))
                        continue;

                    Task t;
                    if (idChanges.ContainsKey(c.ID))
                        t = this._taskService.GetTask(long.Parse(idChanges[c.ID]));
                    else if (c.ID.StartsWith(TEMP))
                    {
                        t = new Task(account);
                        if (tasklist != null) t.SetTasklist(tasklist);
                        this._taskService.Create(t);
                        idChanges.Add(c.ID, t.ID.ToString());//添加到id变更

                        if (this._log.IsDebugEnabled)
                            this._log.DebugFormat("从临时标识#{0}新建任务#{1}{2}"
                                , c.ID, t.ID, tasklist != null ? "并加入任务表#" + tasklist.ID : string.Empty);
                    }
                    else
                        t = this._taskService.GetTask(long.Parse(c.ID));

                    if (t == null)
                    {
                        this._log.WarnFormat("执行变更时出现不存在的任务#{0}", c.ID);
                        continue;
                    }

                    if (c.Type == ChangeType.Update)
                        this.ApplyUpdate(t, c);
                    else if (c.Type == ChangeType.Delete)
                        this._taskService.Delete(t);
                }
                catch (Exception e)
                {
                    this._log.Error(string.Format("执行变更时异常:{0}|{1}|{2}", c.ID, c.Name, c.Value), e);
                }
            }
            #endregion

            //没有变更则无需提交排序数据
            if (!string.IsNullOrWhiteSpace(sorts) && sorts != "null")
            {
                #region 保存排序信息
                var temp = _serializer.JsonDeserialize<Sort[]>(sorts);
                foreach (var s in temp)
                {
                    s.Indexs = s.Indexs.Where(o =>
                        !string.IsNullOrWhiteSpace(o)).Distinct().ToArray();
                    for (var i = 0; i < s.Indexs.Length; i++)
                        //修正索引中含有的临时标识
                        if (s.Indexs[i].StartsWith(TEMP) && idChanges.ContainsKey(s.Indexs[i]))
                            s.Indexs[i] = idChanges[s.Indexs[i]];
                }
                try
                {
                    var d = _serializer.JsonSerialize(temp);

                    if (tasklist == null)
                    {
                        //更新排序信息至用户设置
                        account.SetProfile(by, d);
                        this._accountService.Update(account);
                    }
                    else
                    {
                        //更新排序信息至对应的任务表
                        tasklist[by] = d;
                        this._tasklistService.Update(tasklist);
                    }

                    if (this._log.IsDebugEnabled)
                        this._log.DebugFormat("修正后的排序数据为:{0}|{1}", by, d);
                }
                catch (Exception e)
                {
                    this._log.Error(string.Format("保存排序信息至用户设置时异常"), e);
                }
                #endregion
            }
            //返回修正列表
            return Json(idChanges.Select(o => new Correction() { OldId = o.Key, NewId = o.Value }));
        }