Ejemplo n.º 1
0
        public static void SetTask(string key, Task value)
        {
            TaskStorage storage = TaskStorage.Global;

            if (storage == null)
            {
                return;
            }

            storage.Put(key, value);
        }
Ejemplo n.º 2
0
        public static Task GetTask(string key)
        {
            TaskStorage storage = TaskStorage.Global;

            if (storage == null)
            {
                return(default(Task));
            }

            return(storage.Get(key));
        }
Ejemplo n.º 3
0
        protected override void OnTick()
        {
            Process thisProcess = Process.GetCurrentProcess();
            Task    thisTask    = new Task(thisProcess);

            TaskStorage storage = TaskStorage.Global;

            ArrayList tasks = new ArrayList();

            foreach (KeyValuePair <string, Task> taskEntry in storage.StorageMap)
            {
                Task task = taskEntry.Value;
                if (task == null || !task.IsValid())
                {
                    continue;
                }

                tasks.Add(task);
            }

            Dictionary <Task, Process> processes = GetProcessesByTasks(tasks);

            ArrayList handledTasks = new ArrayList();

            foreach (Task task in tasks)
            {
                if (task == null || thisTask.Equals(task))
                {
                    continue;
                }
                if (!task.IsValid())
                {
                    continue;
                }

                if (task.Name == null)
                {
                    continue;
                }

                if (handledTasks.Contains(task.Name))
                {
                    continue;
                }
                handledTasks.Add(task.Name);

                processes.TryGetValue(task, out Process process);
                if (process == null)
                {
                    task.Start();
                }
            }
        }
Ejemplo n.º 4
0
        private void TaskListBox_Text_FilePath_OnClick(object sender, MouseButtonEventArgs args)
        {
            try
            {
                Task task = ((sender as FrameworkElement).DataContext as Task.TaskListItem).Task;
                if (task == null)
                {
                    return;
                }

                if (DialogWindow != null && DialogWindow.IsVisible)
                {
                    DialogWindow.Close();
                    DialogWindow = null;
                }

                InputDialogWindow dialogWindow = new InputDialogWindow("Enter file path", task.FilePath);
                this.DialogWindow = dialogWindow;

                dialogWindow.Owner = this;
                dialogWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                dialogWindow.OnMessageEvent += (string message) =>
                {
                    if (message == null)
                    {
                        return;
                    }

                    if (TaskStorage == null)
                    {
                        return;
                    }
                    lock (TaskStorage)
                    {
                        TaskStorage.RemoveValue(task);

                        task.FilePath = message;
                        TaskStorage.Put(task.Id, task);

                        UpdateList();
                    }
                };

                dialogWindow.ShowDialog();
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 5
0
        private void TaskListBox_ImportTaskButton_OnClick(object sender, RoutedEventArgs args)
        {
            try
            {
                Task task = ((sender as FrameworkElement).DataContext as Task.TaskListItem).Task;
                if (task == null)
                {
                    return;
                }

                if (DialogWindow != null && DialogWindow.IsVisible)
                {
                    DialogWindow.Close();
                    DialogWindow = null;
                }

                ImportTaskWindow dialogWindow = new ImportTaskWindow(task);
                this.DialogWindow = dialogWindow;

                dialogWindow.Owner = this;
                dialogWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                dialogWindow.OnSelectEvent += (Task newTask) =>
                {
                    if (newTask == null || newTask.Id == null || newTask.Id.Length <= 0)
                    {
                        return;
                    }

                    if (TaskStorage == null)
                    {
                        return;
                    }
                    lock (TaskStorage)
                    {
                        TaskStorage.RemoveValue(task);

                        TaskStorage.Put(newTask.Id, newTask);

                        UpdateList();
                    }
                };

                dialogWindow.ShowDialog();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 6
0
        private void TaskListBox_RemoveTaskButton_OnClick(object sender, RoutedEventArgs args)
        {
            try
            {
                Task task = ((sender as FrameworkElement).DataContext as Task.TaskListItem).Task;
                if (task == null)
                {
                    return;
                }

                if (TaskStorage != null)
                {
                    TaskStorage.RemoveValue(task);
                }

                UpdateList();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 7
0
        private void SetupControls()
        {
            //Setup elements
            Title = Config.ApplicationName;
            TitleLabel.Content = Title;

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

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

            KeyDown += (object sender, KeyEventArgs args) =>
            {
                if (args.Key == Key.Escape)
                {
                    WindowState = WindowState.Minimized;
                }
            };

            IsVisibleChanged += (object sender, DependencyPropertyChangedEventArgs args) =>
            {
                if (!IsVisible)
                {
                    try
                    {
                        if (DialogWindow != null && DialogWindow.IsVisible)
                        {
                            DialogWindow.Close();
                            DialogWindow = null;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
                else
                {
                    UpdateList();
                }
            };

            //Setup events
            RunButton.Click += (object sender, RoutedEventArgs args) =>
            {
                try
                {
                    if (BackgroundTask != null)
                    {
                        BackgroundTask.Run();
                    }
                } catch (Exception e)
                {
                }
            };

            AddTaskButton.Click += (object sender, RoutedEventArgs args) =>
            {
                try
                {
                    if (DialogWindow != null && DialogWindow.IsVisible)
                    {
                        DialogWindow.Close();
                        DialogWindow = null;
                    }

                    InputDialogWindow dialogWindow = new InputDialogWindow("Enter task name");
                    this.DialogWindow = dialogWindow;

                    dialogWindow.Owner = this;
                    dialogWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                    dialogWindow.OnMessageEvent += (string message) =>
                    {
                        if (message == null || message.Length < 0)
                        {
                            return;
                        }

                        if (TaskStorage == null)
                        {
                            return;
                        }
                        lock (TaskStorage)
                        {
                            if (TaskStorage.StorageMap.ContainsKey(message))
                            {
                                return;
                            }

                            Task task = new Task();
                            task.Id = message;

                            //Import task data
                            ImportTaskWindow importTaskDialog = new ImportTaskWindow(task);
                            importTaskDialog.Owner = DialogWindow != null ? DialogWindow : this;
                            importTaskDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                            importTaskDialog.OnSelectEvent += (Task newTask) =>
                            {
                                if (newTask != null)
                                {
                                    newTask.ApplyFieldsTo(task, true);
                                }
                            };

                            importTaskDialog.ShowDialog();

                            //Set new task
                            if (task != null && task.Id != null && task.Id.Length > 0)
                            {
                                TaskStorage.Put(task.Id, task);
                            }

                            UpdateList();
                        }
                    };

                    dialogWindow.ShowDialog();
                } catch (Exception e)
                {
                }
            };

            OpenRegistryManagerButton.Click += (object sender, RoutedEventArgs args) =>
            {
                try
                {
                    if (DialogWindow != null && DialogWindow.IsVisible)
                    {
                        DialogWindow.Close();
                        DialogWindow = null;
                    }

                    RegisterWindow dialogWindow = new RegisterWindow();
                    this.DialogWindow = dialogWindow;

                    dialogWindow.Owner = this;
                    dialogWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                    dialogWindow.ShowDialog();
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            };

            //Load
            UpdateList();
        }
Ejemplo n.º 8
0
        public ManagerWindow()
        {
            //Initialize
            StartHelper.Initialize();

            //Initialize storages
            ConfigStorage = ConfigStorage.Global;
            TaskStorage   = TaskStorage.Global;

            //Initialize Window
            InitializeComponent();

            //Hide window on startup
            Hide();

            //Create context menu for notify icon
            ContextMenu contextMenu = new ContextMenu();

            bool hasExitOption = false;

            if (ConfigStorage != null)
            {
                hasExitOption = ConfigStorage.GetBool(Config.ConfigEnableExitOptionKey, Config.ConfigDefaultEnableExitOptionValue);
            }

            if (hasExitOption)
            {
                MenuItem menuExitItem = new MenuItem();
                menuExitItem.Text   = "Exit";
                menuExitItem.Click += (object sender, EventArgs e) =>
                {
                    if (IconHelper != null)
                    {
                        IconHelper.Destroy();
                    }
                    if (BackgroundTask != null)
                    {
                        BackgroundTask.Stop();
                    }

                    //Exit application
                    if (System.Windows.Forms.Application.MessageLoop)
                    {
                        // WinForms app
                        System.Windows.Forms.Application.Exit();
                    }
                    else
                    {
                        // Console app
                        Environment.Exit(1);
                    }
                };
                contextMenu.MenuItems.Add(menuExitItem);
            }

            //Create notification icon in taskbar
            NotifyIconHelper.Data data = new NotifyIconHelper.Data();
            data.ContextMenu = contextMenu;

            if (ConfigStorage != null)
            {
                data.ShowAlways     = ConfigStorage.GetBool(Config.ConfigShowIconAlwaysKey, Config.ConfigDefaultShowIconAlwaysValue);
                data.DestroyOnClose = false;

                data.NoClickEvent = !ConfigStorage.GetBool(Config.ConfigEnableGuiKey, Config.ConfigDefaultEnableGuiValue);
                data.NoMenu       = false;

                data.NoBalloonTip = !ConfigStorage.GetBool(Config.ConfigEnableBalloonTipKey, Config.ConfigDefaultEnableBalloonTipValue);
            }

            data.Icon            = Properties.Resources.ic_application;
            data.BalloonTipTitle = Title;
            data.BalloonTipText  = "The app has been minimised. Click the tray icon to show.";
            data.Text            = Title;

            IconHelper = new NotifyIconHelper(this, data);
            IconHelper.Create();

            //Create background worker
            BackgroundTask = new BackgroundTask();
            BackgroundTask.Start();

            //Setup controls
            SetupControls();
        }