Example #1
0
        /// <summary>
        /// Runs Eraser as a GUI application.
        /// </summary>
        /// <param name="commandLine">The command line parameters passed to Eraser.</param>
        private static void GUIMain(string[] commandLine)
        {
            //Create a unique program instance ID for this user.
            string instanceId = "Eraser-BAD0DAC6-C9EE-4acc-8701-C9B3C64BC65E-GUI-" +
                                WindowsIdentity.GetCurrent().User.ToString();

            //Then initialise the instance and initialise the Manager library.
            using (GuiProgram program = new GuiProgram(commandLine, instanceId))
            {
                program.InitInstance += OnGUIInitInstance;
                program.NextInstance += OnGUINextInstance;
                program.ExitInstance += OnGUIExitInstance;
                program.Run();
            }
        }
Example #2
0
        /// <summary>
        /// Triggered when the Program is started for the first time.
        /// </summary>
        /// <param name="sender">The sender of the object.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnGUIInitInstance(object sender, InitInstanceEventArgs e)
        {
            GuiProgram program = (GuiProgram)sender;

            eraserClient = new RemoteExecutorServer();
            Application.SafeTopLevelCaptionFormat = S._("Eraser");

            //Load the task list
            try
            {
                if (File.Exists(TaskListPath))
                {
                    using (FileStream stream = new FileStream(TaskListPath, FileMode.Open,
                                                              FileAccess.Read, FileShare.Read))
                    {
                        eraserClient.Tasks.LoadFromStream(stream);
                    }
                }
            }
            catch (InvalidDataException ex)
            {
                File.Delete(TaskListPath);
                MessageBox.Show(S._("Could not load task list. All task entries have " +
                                    "been lost. The error returned was: {0}", ex.Message), S._("Eraser"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                Localisation.IsRightToLeft(null) ?
                                MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
            }

            //Decide whether to display any UI.
            GuiArguments arguments = new GuiArguments();

            Args.Parse(program.CommandLine, CommandLinePrefixes, CommandLineSeparators, arguments);
            e.ShowMainForm = !arguments.AtRestart && !arguments.Quiet;

            //Queue tasks meant for running at restart if we are given that command line.
            if (arguments.AtRestart)
            {
                eraserClient.QueueRestartTasks();
            }

            //Run the eraser client.
            eraserClient.Run();

            //Create the main form.
            program.MainForm = new MainForm();
        }
Example #3
0
        /// <summary>
        /// Triggered when a second instance of Eraser is started.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">Event argument.</param>
        private static void OnGUINextInstance(object sender, NextInstanceEventArgs e)
        {
            //Another instance of the GUI Program has been started: show the main window
            //now as we still do not have a facility to handle the command line arguments.
            GuiProgram program = (GuiProgram)sender;

            //Invoke the function if we aren't on the main thread
            if (program.MainForm.InvokeRequired)
            {
                program.MainForm.Invoke(
                    (GuiProgram.NextInstanceEventHandler)OnGUINextInstance,
                    sender, e);
                return;
            }

            program.MainForm.Show();
        }
Example #4
0
        private static void GUIMain(string[] commandLine)
        {
            string instanceId = "Eraser-BAD0DAC6-C9EE-4acc-8701-C9B3C64BC65E-GUI-" +
            WindowsIdentity.GetCurrent().User.ToString();

               using (GuiProgram program = new GuiProgram(commandLine, instanceId))
               using (ManagerLibrary library = new ManagerLibrary(new Settings()))
               {
            program.InitInstance += OnGUIInitInstance;
            program.NextInstance += OnGUINextInstance;
            program.ExitInstance += OnGUIExitInstance;
            program.Run();
               }
        }