/// <summary>
        /// Keeps the Known TaskLists in sync with the server.
        /// </summary>
        private async void OnUpdatedTaskListGuidsAsync(object source, ServerPollerEventArgs e)
        {
            if (e.Result is List <TaskListSummary> taskListSummaries)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    // Add or update TaskLists
                    for (int i = 0; i < taskListSummaries.Count; i++)
                    {
                        try
                        {
                            if (i == TaskListCollection.Count)
                            {
                                TaskListCollection.Insert(i, taskListSummaries[i]);
                            }
                            else if (!TaskListCollection[i].Equals(taskListSummaries[i]))
                            {
                                TaskListCollection[i] = taskListSummaries[i];
                            }
                        }
                        catch (ArgumentOutOfRangeException ex)
                        {
                            Debug.WriteLine(ex.AllExceptionsToString());
                        }
                    }

                    // Prune existing list
                    int j = taskListSummaries.Count;
                    while (TaskListCollection.Count > taskListSummaries.Count)
                    {
                        TaskListCollection.RemoveAt(j);
                    }
                });
            }
        }
        private async void MoveDownButton_Click(object sender, RoutedEventArgs e)
        {
            var button        = sender as Button;
            var selectedIndex = TaskListCollection.IndexOf(GetTaskListFromButton(button));

            if (selectedIndex + 1 < TaskListCollection.Count)
            {
                var itemToMoveDown = TaskListCollection[selectedIndex];
                TaskListCollection.RemoveAt(selectedIndex);
                TaskListCollection.Insert(selectedIndex + 1, itemToMoveDown);
                var newOrder = new List <Guid>();
                newOrder.AddRange(TaskListCollection.Select(x => x.Guid));
                await Client.ReorderTaskLists(newOrder);
            }
        }
Esempio n. 3
0
        private async void OnUpdatedTaskListGuidAndStatusAsync(object source, ServerPollerEventArgs e)
        {
            var newSummaries = (List <TaskListSummary>)e.Result;

            // Get the new TaskLists
            if (newSummaries != null)
            {
                int newCount = newSummaries.Count;

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    try
                    {
                        if (newSummaries.Any(x => x.IsRunningOrPending))
                        {
                            RunAllButton.Content = resourceLoader.GetString("AbortAllButton/Content");
                            ToolTipService.SetToolTip(RunAllButton, resourceLoader.GetString("AbortAllButton/ToolTipService/ToolTip"));
                            AutomationProperties.SetName(RunAllButton, resourceLoader.GetString("AbortAllButton/ToolTipService/ToolTip"));
                        }
                        else
                        {
                            RunAllButton.Content = resourceLoader.GetString("RunAllButton/Content");
                            ToolTipService.SetToolTip(RunAllButton, resourceLoader.GetString("RunAllButton/ToolTipService/ToolTip"));
                            AutomationProperties.SetName(RunAllButton, resourceLoader.GetString("RunAllButton/ToolTipService/ToolTip"));
                        }

                        if (newCount == 0)
                        {
                            // No TaskLists exist, clear everything
                            LoadingTasksRing.IsActive = false;
                            TaskListCollection.Clear();
                            ActiveListCollection.Clear();
                            return;
                        }

                        if (_trackExecution)
                        {
                            // Find the latest running list. If none are running find the first run pending list.
                            var latestList = newSummaries.Where(x => x.Status == TaskStatus.Running).DefaultIfEmpty(new TaskListSummary()).LastOrDefault();
                            if (latestList.Guid == Guid.Empty)
                            {
                                latestList = newSummaries.Where(x => x.Status == TaskStatus.RunPending).DefaultIfEmpty(new TaskListSummary()).FirstOrDefault();
                            }

                            if (latestList.Guid != Guid.Empty)
                            {
                                _selectedTaskListGuid = latestList.Guid;
                            }
                        }

                        bool selectedListFound = false;
                        for (int i = 0; i < newSummaries.Count; i++)
                        {
                            var newSummary = newSummaries[i];

                            if (newSummary.Guid == _selectedTaskListGuid)
                            {
                                selectedListFound = true;
                            }

                            // Update the TaskListCollection
                            if (i == TaskListCollection.Count)
                            {
                                TaskListCollection.Insert(i, newSummary);
                            }
                            else if (!TaskListCollection[i].Equals(newSummary))
                            {
                                // Template reselected automatically
                                TaskListCollection[i] = newSummary;
                            }

                            // Ensure correct list is selected
                            if ((_selectedTaskListGuid == newSummary.Guid) && (TaskListsView.SelectedIndex != i))
                            {
                                TaskListsView.SelectedIndex = i;
                            }
                        }

                        // Prune non-existent Lists
                        int j = newSummaries.Count;
                        while (TaskListCollection.Count > newSummaries.Count)
                        {
                            TaskListCollection.RemoveAt(j);
                        }

                        if (!selectedListFound && _selectedTaskList != -1)
                        {
                            // The selected list was deleted
                            _selectedTaskList     = -1;
                            _selectedTaskListGuid = Guid.Empty;

                            TaskListsView.SelectedIndex = -1;
                            ActiveListCollection.Clear();
                            LoadingTasksRing.IsActive = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.AllExceptionsToString());
                    }
                });
            }
            else
            {
                // No TaskLists exist, clear everything
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    LoadingTasksRing.IsActive = false;
                    TaskListCollection.Clear();
                    ActiveListCollection.Clear();
                    EndTrackExecution();
                });
            }
        }