Beispiel #1
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();
                }
            }
        }
Beispiel #2
0
        static int Main(string[] rawCommandLine)
        {
            //Immediately parse command line arguments. Start by substituting all
            //response files ("@filename") arguments with the arguments found in the
            //file
            List <string> commandLine = new List <string>(rawCommandLine.Length);

            foreach (string argument in rawCommandLine)
            {
                if (argument[0] == '@' && File.Exists(argument.Substring(1)))
                {
                    //The current parameter is a response file, parse the file
                    //for arguments and substitute it.
                    using (TextReader reader = new StreamReader(argument.Substring(1)))
                    {
                        commandLine.AddRange(Shell.ParseCommandLine(reader.ReadToEnd()));
                    }
                }
                else
                {
                    commandLine.Add(argument);
                }
            }

            string[] finalCommandLine             = commandLine.ToArray();
            ComLib.BoolMessageItem argumentParser = Args.Parse(finalCommandLine,
                                                               CommandLinePrefixes, CommandLineSeparators);
            Args parsedArguments = (Args)argumentParser.Item;

            //Set application defaults for consistent behaviour across GUI and
            //Console instances
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Load the Eraser.Manager library
            using (ManagerLibrary library = new ManagerLibrary(Settings.Get()))
            {
                //Set our UI language
                EraserSettings settings = EraserSettings.Get();
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(settings.Language);

                //We default to a GUI if:
                // - The parser did not succeed.
                // - The parser resulted in an empty arguments list
                // - The parser's argument at index 0 is not equal to the first argument
                //   (this is when the user is passing GUI options -- command line options
                //   always start with the action, e.g. Eraser help, or Eraser addtask
                if (!argumentParser.Success || parsedArguments.IsEmpty ||
                    parsedArguments.Positional.Count == 0 ||
                    parsedArguments.Positional[0] != parsedArguments.Raw[0])
                {
                    GUIMain(finalCommandLine);
                }
                else
                {
                    return(CommandMain(finalCommandLine));
                }
            }

            //Return zero to signify success
            return(0);
        }