Ejemplo n.º 1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            var dialog = new AddProgramDialog();
            var result = dialog.ShowDialog();

            if (result == DialogResult.OK && dialog.ProgramContainerToCreate != null)
            {
                if (_userConfig.Programs.Any(p => p.ExecutableName == dialog.ProgramContainerToCreate.ExecutableName))
                {
                    DuplicateValidationLabel.Visible = true;
                    return;
                }

                DuplicateValidationLabel.Visible = false;

                _userConfig.Programs.Add(dialog.ProgramContainerToCreate);
                ProgramListBox.DataSource = null;
                ProgramListBox.DataSource = _userConfig.Programs;

                ReadWriteHelper.CreateFolderIfMissing(_pathToConfigFolder);
                ReadWriteHelper.WriteToBinaryFile(_pathToConfig, _userConfig);

                //If service is currently running, restart it so it loads new config
                var runningProcess = Process.GetProcesses().Where(p => p.ProcessName == "SaveReminder.service").ToList();
                if (runningProcess.Any())
                {
                    runningProcess.ForEach(p => p.Kill());

                    StartService();
                }
            }
        }
Ejemplo n.º 2
0
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (ProgramListBox.SelectedItem != null)
            {
                DuplicateValidationLabel.Visible = false;

                _userConfig.Programs.RemoveAll(p =>
                                               p.ExecutableName == ((ProgramContainer)ProgramListBox.SelectedItem).ExecutableName);

                ReadWriteHelper.CreateFolderIfMissing(_pathToConfigFolder);
                ReadWriteHelper.WriteToBinaryFile(_pathToConfig, _userConfig);

                ProgramListBox.DataSource = null;
                ProgramListBox.DataSource = _userConfig.Programs;
            }
        }