Esempio n. 1
0
        public ImportTaskWindow(Task task)
        {
            //Initialize Window
            InitializeComponent();

            //Setup elements
            TitleLabel.Content = Title;

            DialogTask         = task;
            DialogSelectedItem = null;

            //Setup drag behavior
            ToolbarLayout.MouseDown += (object sender, MouseButtonEventArgs args) =>
            {
                DragMove();
            };

            //Setup close behavior
            CloseButton.Click += (object sender, RoutedEventArgs args) =>
            {
                if (OnDeny())
                {
                    Close();
                }
            };

            KeyDown += (object sender, KeyEventArgs args) =>
            {
                if (args.Key == Key.Return)
                {
                    args.Handled = true;

                    if (OnAccept())
                    {
                        Close();
                    }
                }

                if (args.Key == Key.Escape)
                {
                    if (OnDeny())
                    {
                        Close();
                    }
                }
            };

            IsVisibleChanged += (object sender, DependencyPropertyChangedEventArgs args) =>
            {
                if (!IsVisible)
                {
                    AbortUpdate();
                }
                else
                {
                    UpdateList();
                }
            };

            Closing += (object sender, CancelEventArgs args) =>
            {
                AbortUpdate();

                OnDeny();
            };

            //Setup events
            TaskListBox.SelectionChanged += (object sender, SelectionChangedEventArgs args) =>
            {
                try
                {
                    object selectedItemObject = TaskListBox.SelectedItem;

                    if (selectedItemObject != null)
                    {
                        DialogSelectedItem = selectedItemObject as Task.TaskListItem;
                    }
                    else
                    {
                        DialogSelectedItem = null;
                    }
                } catch (Exception e)
                {
                }
            };

            TaskListBox.MouseDoubleClick += (object sender, MouseButtonEventArgs args) =>
            {
                if (SelectedItem != null && SelectedItem.Task != null && OnAccept())
                {
                    Close();
                }
            };

            AcceptButton.Click += (object sender, RoutedEventArgs args) =>
            {
                if (OnAccept())
                {
                    Close();
                }
            };

            DenyButton.Click += (object sender, RoutedEventArgs args) =>
            {
                if (OnDeny())
                {
                    Close();
                }
            };

            //Load
            UpdateList();
        }
Esempio n. 2
0
        private void UpdateList()
        {
            AbortUpdate();

            if (TaskListBox == null)
            {
                return;
            }

            //Start loading
            if (GlobalListItems == null)
            {
                GlobalListItems = new List <Task.TaskListItem>();
            }

            List <Task.TaskListItem> items = new List <Task.TaskListItem>();

            try
            {
                if (TaskListBox.ItemsSource != null)
                {
                    items.AddRange(TaskListBox.ItemsSource as List <Task.TaskListItem>);
                }
            }
            catch (Exception e)
            {
            }

            if (GlobalListItems != null && (items.Count <= 0 || items.Count < GlobalListItems.Count))
            {
                lock (GlobalListItems)
                {
                    items.Clear();
                    items.AddRange(GlobalListItems);
                }
            }

            if (items.Count > 0)
            {
                try
                {
                    TaskListBox.ItemsSource = items;
                }
                catch (Exception e)
                {
                }
            }
            else
            {
                //Show loading progress bar
                if (LoadingProgressBar != null)
                {
                    LoadingProgressBar.Visibility = Visibility.Visible;
                }
            }

            //Start thread
            try
            {
                TaskLoaderThread = new Thread(() =>
                {
                    try
                    {
                        Thread currentThread = Thread.CurrentThread;
                        if (currentThread != null && !currentThread.IsAlive)
                        {
                            return;
                        }
                    } catch (Exception e)
                    {
                    }

                    bool itemsChanged = false;

                    try
                    {
                        foreach (Process process in Process.GetProcesses())
                        {
                            try
                            {
                                Thread currentThread = Thread.CurrentThread;
                                if (currentThread != null && !currentThread.IsAlive)
                                {
                                    return;
                                }
                            }
                            catch (Exception e)
                            {
                            }

                            if (process == null)
                            {
                                continue;
                            }

                            Task newTask = new Task(process);
                            if (!newTask.IsValid())
                            {
                                continue;
                            }

                            Task.TaskListItem newTaskItem = new Task.TaskListItem(newTask);
                            if (!items.Contains(newTaskItem))
                            {
                                items.Add(newTaskItem);
                                itemsChanged = true;
                            }
                        }
                    } catch (Exception e)
                    {
                    }

                    try
                    {
                        if (itemsChanged && TaskListBox != null && items != null)
                        {
                            SortItems(items);

                            if (GlobalListItems == null)
                            {
                                GlobalListItems = new List <Task.TaskListItem>();
                            }
                            lock (GlobalListItems)
                            {
                                GlobalListItems.Clear();
                                GlobalListItems.AddRange(items);
                            }

                            try
                            {
                                Thread currentThread = Thread.CurrentThread;
                                if (currentThread != null && !currentThread.IsAlive)
                                {
                                    return;
                                }
                            }
                            catch (Exception e)
                            {
                            }

                            TaskListBox.Dispatcher.Invoke(new Action(() =>
                            {
                                try
                                {
                                    Thread currentThread = Thread.CurrentThread;
                                    if (currentThread != null && !currentThread.IsAlive)
                                    {
                                        return;
                                    }
                                }
                                catch (Exception e)
                                {
                                }

                                try
                                {
                                    TaskListBox.ItemsSource = items;
                                }
                                catch (Exception ex)
                                {
                                }
                            }));
                        }
                    } catch (Exception e)
                    {
                    }

                    //Hide loading progress bar
                    try
                    {
                        if (LoadingProgressBar != null)
                        {
                            LoadingProgressBar.Dispatcher.Invoke(new Action(() =>
                            {
                                if (LoadingProgressBar != null)
                                {
                                    LoadingProgressBar.Visibility = Visibility.Collapsed;
                                }
                            }));
                        }
                    } catch (Exception e)
                    {
                    }
                });
                TaskLoaderThread.Start();
            }
            catch (Exception e)
            {
            }
        }