Example #1
0
        public OutlookTask UpdateTask(OutlookTask TargetTask, Outlook.TaskItem SourceTaskItem, ICollection <OutlookCategory> categories, OutlookCategory defaultCategory)
        {
            OutlookCategory category = categories.Where(x => x.Name.Equals(SourceTaskItem.Categories)).SingleOrDefault();

            if (category == null)
            {
                category = defaultCategory;
            }

            TargetTask.EntryId       = SourceTaskItem.EntryID;
            TargetTask.TaskName      = SourceTaskItem.Subject;
            TargetTask.Body          = SourceTaskItem.Body;
            TargetTask.IsComplete    = SourceTaskItem.Complete;
            TargetTask.Owner         = SourceTaskItem.Owner;
            TargetTask.CreationTime  = SourceTaskItem.CreationTime;
            TargetTask.DateCompleted = (SourceTaskItem.DateCompleted.Year == 4501 ? (DateTime?)null : SourceTaskItem.DateCompleted);
            TargetTask.StartDate     = (SourceTaskItem.StartDate.Year == 4501 ? (DateTime?)null : SourceTaskItem.StartDate);
            TargetTask.DueDate       = (SourceTaskItem.DueDate.Year == 4501 ? (DateTime?)null : SourceTaskItem.DueDate);
            TargetTask.ActualWork    = SourceTaskItem.ActualWork;
            TargetTask.Status        = fromOutlookStatus(SourceTaskItem.Status);
            TargetTask.Priority      = SourceTaskItem.SchedulePlusPriority;
            TargetTask.Category      = category;

            return(TargetTask);
        }
Example #2
0
        public static async Task AddTask(string name, string code, string userName, ILogger log)
        {
            log.LogInformation($"start adding task process");

            var payload = new IncomingWebhookPayload {
            };

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(code) || string.IsNullOrEmpty(userName))
            {
                payload.Text = $"タスク挿入に失敗しました. name={name}, code={code}, userName={userName}";
                await SendIncomingWebhook(payload);
            }

            var task = new OutlookTask
            {
                PartitionKey  = userName,
                RowKey        = code,
                Name          = name,
                IsCurrentTask = false
            };

            var result = await TableHelper.InsertTask(task);

            payload.Text = result
            ? $"タスク挿入に成功しました. task={JsonConvert.SerializeObject(task)}"
            : $"タスク挿入に失敗しました. task={JsonConvert.SerializeObject(task)}";

            await SendIncomingWebhook(payload);
        }
        private bool filter(OutlookTask taskitem)
        {
            bool retval = true;

            if (!_taskFilter.Complete)
            {
                retval = taskitem.Status != TaskStatus.TaskComplete;
            }

            if (retval && _taskFilter.DueToday)
            {
                System.DateTime today = System.DateTime.Today;
                retval = taskitem.DueDate.Equals(today);
            }

            if (retval && _taskFilter.InProgress && _taskFilter.NotStarted)
            {
                retval = taskitem.Status == TaskStatus.TaskInProgress ||
                         taskitem.Status == TaskStatus.TaskNotStarted;
            }
            else if (retval && _taskFilter.InProgress)
            {
                retval = taskitem.Status == TaskStatus.TaskInProgress;
            }
            else if (retval && _taskFilter.NotStarted)
            {
                retval = taskitem.Status == TaskStatus.TaskNotStarted;
            }

            return(retval);
        }
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            OutlookTask sourceItem = dropInfo.Data as OutlookTask;
            OutlookTask targetItem = dropInfo.TargetItem as OutlookTask;

            service.MoveToCategory(sourceItem, Category);
        }
        private XElement MakeTaskReference(OutlookTask task)
        {
            task.OneNoteTaskID = Guid.NewGuid().ToString("b").ToUpper();

            var subject = task.Subject;
            var index   = task.FolderPath.IndexOf(OutlookTask.PathDelimeter);

            if (index > 0)
            {
                var path = task.FolderPath.Substring(index + 1) + OutlookTask.PathDelimeter;
                subject = $"<span style='color:#7F7F7F'>{path}</span>{task.Subject}";
            }

            return(new XElement(ns + "OE",
                                new XElement(ns + "OutlookTask",
                                             new XAttribute("startDate", task.CreationTime.ToZuluString()),
                                             new XAttribute("dueDate", task.DueDate.ToZuluString()),
                                             new XAttribute("guidTask", task.OneNoteTaskID),
                                             new XAttribute("completed", task.Complete.ToString().ToLower()),
                                             new XAttribute("creationDate", task.CreationTime.ToZuluString())
                                             ),
                                new XElement(ns + "T",
                                             new XCData(subject))
                                ));
        }
Example #6
0
        public TaskAndCategoryLoader(Outlook.Application outlookApp)
        {
            Outlook.MAPIFolder outlookTasksFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
            outlookItems = outlookTasksFolder.Items;
            Tasks        = new List <OutlookTask>();
            Categories   = new List <OutlookCategory>();

            HashSet <OutlookCategory> cats = new HashSet <OutlookCategory>();

            DefaultCategory = new OutlookCategory()
            {
                Name = Properties.Resources.Outlook_Category_Default
            };
            cats.Add(DefaultCategory);

            foreach (Outlook.TaskItem taskitem in outlookItems)
            {
                if (!String.IsNullOrWhiteSpace(taskitem.Categories) && !cats.Any(c => c.Name == taskitem.Categories))
                {
                    cats.Add(new OutlookCategory()
                    {
                        Name = taskitem.Categories
                    });
                }

                OutlookTask newTask = new OutlookTask();
                UpdateTask(newTask, taskitem, cats, DefaultCategory);
                Tasks.Add(newTask);
            }
            cats.ToList().ForEach(Categories.Add);
        }
        public void ChangeTaskStatus(OutlookTask task, TaskStatus newStatus)
        {
            switch (newStatus)
            {
            case TaskStatus.TaskInProgress:
                task.Status        = TaskStatus.TaskInProgress;
                task.StartDate     = DateTime.Today;
                task.DueDate       = DateTime.Today;
                task.DateCompleted = null;
                break;

            case TaskStatus.TaskComplete:
                task.Status        = TaskStatus.TaskComplete;
                task.DateCompleted = DateTime.Today;
                break;

            case TaskStatus.TaskNotStarted:
                task.Status        = TaskStatus.TaskNotStarted;
                task.StartDate     = null;
                task.DueDate       = null;
                task.DateCompleted = null;
                break;

            default:
                task.Status = newStatus;
                break;
            }
            UpdateTask(task);
        }
        public void DeleteTask(OutlookTask task)
        {
            OutlookTask outlookTask = task as OutlookTask;

            Outlook.TaskItem taskitem = outlookApp.Session.GetItemFromID(outlookTask.EntryId) as Outlook.TaskItem;
            taskitem.Delete();
        }
 private void TaskDAO_TaskRemove(OutlookTask task)
 {
     foreach (ObservableCollection <OutlookTask> tasksInCategory in tasks.Values)
     {
         tasksInCategory.Remove(task);
     }
 }
 public void StartTask(OutlookTask task)
 {
     task.Status        = TaskStatus.TaskInProgress;
     task.StartDate     = DateTime.Today;
     task.DueDate       = DateTime.Today;
     task.DateCompleted = null;
     outlookService.UpdateTask(task);
 }
        public void UpdateTask(OutlookTask task)
        {
            OutlookTask outlookTask = task as OutlookTask;

            Outlook.TaskItem taskitem = outlookApp.Session.GetItemFromID(outlookTask.EntryId) as Outlook.TaskItem;
            taskitem = taskAndCategoryLoader.UpdateOutlookTaskItem(taskitem, task as OutlookTask);
            taskitem.Save();
        }
 public void ReopenTask(OutlookTask task)
 {
     task.Status        = TaskStatus.TaskNotStarted;
     task.StartDate     = null;
     task.DueDate       = null;
     task.DateCompleted = null;
     outlookService.UpdateTask(task);
 }
        private void PopulateRow(TableRow row, OutlookTask task, bool creating = true)
        {
            if (creating)
            {
                // First column contains OutlookTask with status flag. This column cannot be
                // touched at all when updating the page otherwise OneNote seems to lose context
                // and disconnects the task from Outlook
                row[0].SetContent(MakeTaskReference(task));
            }

            row[1].SetContent(statuses[(int)task.Status]);
            if (task.Status == OutlookTaskStatus.Complete)
            {
                row[1].ShadingColor = CompletedShading;
            }
            else if (now.CompareTo(task.DueDate) > 0)
            {
                row[1].ShadingColor = OverdueShading;
            }
            else if (task.Status == OutlookTaskStatus.NotStarted &&
                     now.CompareTo(task.StartDate) > 0)
            {
                row[1].ShadingColor = NotStartedShading;
            }
            // TODO: set default shading color?

            row[2].SetContent(task.StartDate.Year > OutlookTask.UnspecifiedYear
                                ? string.Empty
                                : task.DueDate.ToShortFriendlyString());

            if (task.PercentComplete == 100 && task.DateCompleted.Year < OutlookTask.UnspecifiedYear)
            {
                if (task.DueDate.Year < OutlookTask.UnspecifiedYear)
                {
                    row[3].SetContent(new XElement(ns + "OEChildren",
                                                   new Paragraph($"<span style='color:{CompletedColor}'>{task.DateCompleted.ToShortFriendlyString()}</span>"),
                                                   new Paragraph($"Due: {task.DueDate.ToShortFriendlyString()}").SetQuickStyle(citeIndex)
                                                   ));
                }
                else
                {
                    row[3].SetContent(task.DateCompleted.ToShortFriendlyString());
                }
            }
            else if (task.DueDate.Year < OutlookTask.UnspecifiedYear)
            {
                var woy = string.Format(Resx.OutlookTaskReport_Week, task.WoYear);
                row[3].SetContent(new XElement(ns + "OEChildren",
                                               new Paragraph(task.DueDate.ToShortFriendlyString()),
                                               new Paragraph(woy).SetQuickStyle(citeIndex)
                                               ));
            }

            row[4].SetContent(MakeImportance(task.Importance));
            row[5].SetContent((task.PercentComplete / 100.0).ToString("P0"));
        }
        public void MoveTaskToCategory(OutlookTask task, OutlookCategory category)
        {
            OutlookTask outlookTask = task as OutlookTask;

            if (outlookTask.Category != category)
            {
                outlookTask.Category = category as OutlookCategory;
                UpdateTask(outlookTask);
            }
        }
 public void MoveToCategory(OutlookTask sourceItem, OutlookCategory newCategory)
 {
     if (sourceItem.Category != newCategory)
     {
         tasks[sourceItem.Category].Remove(sourceItem);
         sourceItem.Category = newCategory;
         outlookService.UpdateTask(sourceItem);
         tasks[sourceItem.Category].Add(sourceItem);
     }
 }
        private void OutlookItems_ItemAdd(object Item)
        {
            if (Item is Outlook.TaskItem)
            {
                OutlookTask newTask = new OutlookTask();
                taskAndCategoryLoader.UpdateTask(newTask, Item as Outlook.TaskItem, taskAndCategoryLoader.Categories, taskAndCategoryLoader.DefaultCategory);

                taskAndCategoryLoader.Tasks.Add(newTask);
                TaskAdd?.Invoke(newTask);
            }
        }
        private void OutlookItems_ItemRemove()
        {
            IEnumerable <Outlook.TaskItem> taskEnumerator  = outlookItems.Cast <Outlook.TaskItem>();
            List <Outlook.TaskItem>        outlookTaskList = new List <Outlook.TaskItem>(taskEnumerator);
            IEnumerable <OutlookTask>      toDeleteSubset  = taskAndCategoryLoader.Tasks.Where(task => !outlookTaskList.Exists(element => element.EntryID.Equals(task.EntryId)));

            for (int index = 0; index < toDeleteSubset.Count(); index++)
            {
                OutlookTask taskToDelete = toDeleteSubset.ElementAt(index);
                taskAndCategoryLoader.Tasks.Remove(taskToDelete);
                TaskRemove?.Invoke(taskToDelete);
            }
        }
        public static async Task <bool> InsertTask(OutlookTask task)
        {
            TableOperation insert = TableOperation.InsertOrReplace(task);

            try
            {
                await GetTasksTable().ExecuteAsync(insert);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #19
0
        public static IObservable <IList <OutlookTask> > NewFolderTasks(this IOutlookTaskFolderRequestBuilder builder, int count, string title)
        {
            var dateTime = DateTime.Now;

            return(Observable.Range(0, count).SelectMany(i => {
                var task = new OutlookTask()
                {
                    Subject = $"{i}{title}",
                    CompletedDateTime = new DateTimeTimeZone {
                        DateTime = dateTime.AddHours(i).ToString(CultureInfo.InvariantCulture),
                        TimeZone = TimeZoneInfo.Local.Id
                    }
                };

                return builder.Tasks.Request().AddAsync(task);
            }).Buffer(count));
        }
        public OutlookTask CreateTaskInCategory(OutlookCategory category)
        {
            OutlookTask task = new OutlookTask()
            {
                Category     = category,
                TaskName     = Properties.Resources.Outlook_Task_New,
                IsComplete   = false,
                CreationTime = DateTime.Now,
                ActualWork   = 0,
                Status       = TaskStatus.TaskNotStarted
            };

            Outlook.TaskItem taskitem = outlookApp.CreateItem(Outlook.OlItemType.olTaskItem) as Outlook.TaskItem;
            taskitem = taskAndCategoryLoader.UpdateOutlookTaskItem(taskitem, task);
            taskitem.Save();

            return(task);
        }
        void IDropTarget.DragOver(IDropInfo dropInfo)
        {
            OutlookTask sourceItem = dropInfo.Data as OutlookTask;
            OutlookTask targetItem = dropInfo.TargetItem as OutlookTask;


            if (sourceItem != null && ((targetItem != null && sourceItem.Category != targetItem.Category) || targetItem == null))
            {
                System.Diagnostics.Debug.WriteLine("DragOver called with source:{0} and target:{1}", sourceItem, targetItem);
                //dropInfo.DestinationText = sourceItem.TaskName;
                dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
                dropInfo.Effects           = DragDropEffects.Move;
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("DragOver None");
                dropInfo.Effects = DragDropEffects.None;
            }
        }
Example #22
0
        public TaskEditModel(ITaskService service, IEventAggregator eventAggregator, [Named("OutlookClientMapper")] IMapper mapper)
        {
            this.service         = service;
            this.eventAggregator = eventAggregator;
            this.mapper          = mapper;
            this.EditMode        = false;
            this.originalTask    = null;

            OutlookTaskEditStartedEvent taskEditStartEvent = eventAggregator.GetEvent <OutlookTaskEditStartedEvent>();

            taskEditStartEvent.Subscribe(StartEdit, ThreadOption.UIThread, false, t => t == Task);
            taskEditStartEvent.Subscribe(OnCancelExecute, ThreadOption.UIThread, false, t => t != Task);
            OutlookCategoryEditStartedEvent categoryEditEvent = eventAggregator.GetEvent <OutlookCategoryEditStartedEvent>();

            categoryEditEvent.Subscribe(OnCancelExecute);

            OkCommand               = new DelegateCommand(OnOkExecute);
            CancelCommand           = new DelegateCommand(OnCancelExecute);
            DeleteCommand           = new DelegateCommand(OnDeleteExecute);
            this.DeleteConfirmation = new InteractionRequest <IConfirmation>();
        }
Example #23
0
        public Outlook.TaskItem UpdateOutlookTaskItem(Outlook.TaskItem targetOutloookTaskItem, OutlookTask sourceTask)
        {
            targetOutloookTaskItem.Subject       = sourceTask.TaskName;
            targetOutloookTaskItem.Body          = sourceTask.Body;
            targetOutloookTaskItem.Complete      = sourceTask.IsComplete;
            targetOutloookTaskItem.Owner         = sourceTask.Owner;
            targetOutloookTaskItem.DateCompleted = sourceTask.DateCompleted ?? MAX_DATE;
            targetOutloookTaskItem.StartDate     = sourceTask.StartDate ?? MAX_DATE;
            targetOutloookTaskItem.DueDate       = sourceTask.DueDate ?? MAX_DATE;

            targetOutloookTaskItem.ActualWork = sourceTask.ActualWork;

            targetOutloookTaskItem.Status = toOutlookStatus(sourceTask.Status);
            targetOutloookTaskItem.SchedulePlusPriority = sourceTask.Priority;
            targetOutloookTaskItem.Categories           = sourceTask.Category.Name;

            return(targetOutloookTaskItem);
        }
        public OutlookTask CreateNewTask(OutlookCategory category)
        {
            OutlookTask task = outlookService.CreateTaskInCategory(category);

            return(task);
        }
 public void Delete(OutlookTask task)
 {
     outlookService.DeleteTask(task);
 }
 public void Update(OutlookTask task)
 {
     outlookService.UpdateTask(task);
 }
 public void CompleteTask(OutlookTask task)
 {
     task.Status        = TaskStatus.TaskComplete;
     task.DateCompleted = DateTime.Today;
     outlookService.UpdateTask(task);
 }
 private void StopEdit(OutlookTask obj)
 {
     EditMode = false;
     EditCommand.RaiseCanExecuteChanged();
 }
        private void TaskDAO_TaskAdd(OutlookTask task)
        {
            ObservableCollection <OutlookTask> tasksInCategory = loadTasks(task.Category);

            tasksInCategory.Add(task);
        }
 private void TaskDAO_TaskChange(OutlookTask task)
 {
     // do I nedd to do anything?
 }