Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Parse the command line arguments
            ServiceArguments arguments = new ServiceArguments();

            Args.Parse(args, CommandLinePrefixes, CommandLineSeparators, arguments);

            using (ManagerLibrary library = new ManagerLibrary(Settings.Get()))
            {
                RemoteExecutorServer eraserClient = null;
                try
                {
                    eraserClient = new RemoteExecutorServiceServer();
                }
                catch (InvalidOperationException)
                {
                    //We already have another instance running.
                    return;
                }

                try
                {
                    //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)
                    {
                        File.Delete(TaskListPath);
                    }

                    //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();
                    Application.Run();

                    //Save the task list
                    if (!Directory.Exists(Program.AppDataPath))
                    {
                        Directory.CreateDirectory(Program.AppDataPath);
                    }
                    eraserClient.Tasks.SaveToFile(TaskListPath);
                }
                finally
                {
                    //Dispose the Eraser Executor instance
                    eraserClient.Dispose();
                }
            }
        }