Ejemplo n.º 1
0
        /// <summary>
        /// DBからデータを読み込みます
        /// </summary>
        /// <param name="requestId"></param>
        public void Load(string requestId = null)
        {
            Task.Factory.StartNew(() =>
            {
               List<TaskEntity> tasks;

               Tasks.Clear();

               using (var client = new SQLiteRepositoryClient())
               {
                   tasks = client.QueryTask("ToDo", "InProgress", "Done").ToList();
               }

               foreach (var task in tasks)
               {
                   Tasks.Add(task);
               }

               // 成功を通知
               if (Responded != null)
               {
                   Responded(this, new ReadOperationEventArgs(true, requestId));
               }
           }).
           ContinueWith(result =>
           {
               // 失敗を通知
               if (Responded != null) Responded(this, new ReadOperationEventArgs(false, requestId));
           },
           TaskContinuationOptions.OnlyOnFaulted);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新しいTaskを作成します
        /// </summary>
        /// <param name="requestId"></param>
        public void CreateTask(string requestId = null)
        {
            Task.Factory.StartNew(() =>
            {
                TaskEntity entity = null;
                using (var client = new SQLiteRepositoryClient())
                {
                    entity = client.CreateTask();
                }

                Tasks.Add(entity);

                // 変更を通知
                if (EntityChanged != null) EntityChanged(this, new EntityChangedEventArgs(NotifyEntityChangedAction.Create, entity));

                // 成功を通知
                if (Responded != null)
                {
                    Responded(this, new CreateOperationEventArgs(true, requestId) { Contents = entity });
                }
            }).
            ContinueWith(result =>
            {
                // 失敗を通知
                if (Responded != null) Responded(this, new CreateOperationEventArgs(false, requestId));
            },
            TaskContinuationOptions.OnlyOnFaulted);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Taskを削除します
        /// </summary>
        /// <param name="requestId"></param>
        public void DeleteTask(int id, string requestId = null)
        {
            Task.Factory.StartNew(() =>
            {
                using (var client = new SQLiteRepositoryClient())
                {
                    client.DeleteTask(id);
                }
                
                var target = Tasks.FirstOrDefault(f => f.Id == id);
                Tasks.Remove(target);

                // 変更を通知
                if (EntityChanged != null) EntityChanged(this, new EntityChangedEventArgs(NotifyEntityChangedAction.Delete, target));

                // 成功を通知
                if (Responded != null) Responded(this, new DeleteOperationEventArgs(true, requestId));
            }).
            ContinueWith(result =>
            {
                // 失敗を通知
                if (Responded != null) Responded(this, new DeleteOperationEventArgs(false, requestId));
            },
            TaskContinuationOptions.OnlyOnFaulted);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Taskを更新します
        /// </summary>
        /// <param name="requestId"></param>
        public void UpdateTask(TaskEntity entity, string requestId = null)
        {
            Task.Factory.StartNew(() =>
            {
                TaskEntity result = null;
                using (var client = new SQLiteRepositoryClient())
                {
                    result = client.UpdateTask(entity);
                }
                
                var localEntity = Tasks.Single(s => s.Id == result.Id);
                localEntity.Copy(result);

                // 変更を通知
                if (EntityChanged != null) EntityChanged(this, new EntityChangedEventArgs(NotifyEntityChangedAction.Update, localEntity));

                // 成功を通知
                if (Responded != null) Responded(this, new UpdateOperationEventArgs(true, requestId));
            }).
            ContinueWith(result =>
            {
                // 失敗を通知
                if (Responded != null) Responded(this, new UpdateOperationEventArgs(false, requestId));
            },
            TaskContinuationOptions.OnlyOnFaulted);
        }