Esempio n. 1
0
        /// <summary> Creates a new task. </summary>
        public StudyTask(IStudyTasksService client, string name, string userId, TimeSpan estimate)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(nameof(name));
            }
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            this.MessageObject = new StudyTaskService()
            {
                Name = name, UserId = userId, Estimate = estimate
            };
            this.service   = client;
            this.Name      = name;
            this.Estimate  = estimate;
            this.TimeSpans = new ObservableCollection <TaskTimeSpan>();

            this.TimeSpans.CollectionChanged += OnTimeSpansChanged;
            this.PropertyChanged             += OnPropertyChanged;
        }
Esempio n. 2
0
        /// <summary> Creates a <see cref="StudyTask"/> instance representing an already existing task in the database. </summary>
        public StudyTask(IStudyTasksService service, StudyTaskService task)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (task.Id == 0)
            {
                throw new ArgumentException();
            }
            if (task.UserId == null)
            {
                throw new ArgumentNullException(nameof(task.UserId));
            }

            this.MessageObject = task;
            this.service       = service;
            this.Name          = this.MessageObject.Name;
            this.Estimate      = this.MessageObject.Estimate;

            //retrieve time spans from database:
            var timeSpans = service.GetTimeSpansFor(task.Id).Select(timeSpanDB => new TaskTimeSpan(service, timeSpanDB, this));

            this.TimeSpans = new ObservableCollection <TaskTimeSpan>(timeSpans);

            this.TimeSpans.CollectionChanged += OnTimeSpansChanged;
            this.PropertyChanged             += OnPropertyChanged;
        }
Esempio n. 3
0
        /// <summary> Creates a <see cref="TaskTimeSpan"/> from database. </summary>
        /// <param name="messageObject"> The autogenerated message object representing a time span in the database. </param>
        public TaskTimeSpan(IStudyTasksService service, TaskTimeSpanService messageObject, StudyTask task)
        {
            if (messageObject == null)
            {
                throw new ArgumentNullException(nameof(messageObject));
            }
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (messageObject.Id == 0)
            {
                throw new ArgumentException();
            }

            this.service = service;
            this.timeSpanMessageObject = messageObject;
            this.Task  = task;
            this.Start = messageObject.Start;
            this.End   = messageObject.End;

            this.PropertyChanged += OnPropertyChanged;
        }
Esempio n. 4
0
        /// <summary> Creates an empty study tasks collection that is linked to the database. </summary>
        public static StudyTaskCollection Create(IStudyTasksService client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(new StudyTaskCollection(client, Enumerable.Empty <StudyTask>()));
        }
Esempio n. 5
0
        private StudyTaskCollection(IStudyTasksService client, IEnumerable <StudyTask> initialTasks) : base(initialTasks)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.client = client;

            this.CollectionChanged += OnTasksChanged;
        }
Esempio n. 6
0
        /// <summary> Gets a study tasks collection from all tasks in the database. </summary>
        public static StudyTaskCollection FromDatabase(IStudyTasksService client, string userId)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var tasksFromDatabase = client.GetAllTasksOfUser(userId)
                                    .Select(taskService => new StudyTask(client, taskService))
                                    .ToList();

            return(new StudyTaskCollection(client, tasksFromDatabase));
        }
Esempio n. 7
0
        /// <remarks> This ctor should not add this instance to the database because the <see cref="StudyTask.TimeSpans.CollectionChanged"/> is responsible for that. </remarks>
        public TaskTimeSpan(IStudyTasksService service, StudyTask task, DateTime start)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            this.service = service;
            this.timeSpanMessageObject = new TaskTimeSpanService()
            {
                Start = start, TaskId = task.Id
            };
            this.Task  = task;
            this.Start = start;

            this.PropertyChanged += OnPropertyChanged;
        }
        public static TaskTimeSpanService ToService(this TaskTimeSpan timeSpan, IStudyTasksService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            var task = service.GetTask(timeSpan.TaskId);

            if (task == null)
            {
                throw new ArgumentException($"A task with Id {timeSpan.TaskId} does not exist in the database", nameof(timeSpan));
            }

            return(new TaskTimeSpanService
            {
                Id = timeSpan.Id,
                Start = timeSpan.Start,
                End = timeSpan.End,
                TaskId = timeSpan.TaskId
            });
        }
Esempio n. 9
0
 /// <summary> Creates a <see cref="StudyTask"/> instance representing an already existing task in the database. </summary>
 /// <param name="taskId"> The id of the task in the database to fetch. </param>
 public StudyTask(IStudyTasksService service, int taskId)
     : this(service, service.GetTask(taskId))
 {
     Contract.Assert(this.MessageObject.Id == taskId);
 }