Наследование: NanoByte.Common.Tasks.CliTaskHandler, ICommandHandler
Пример #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static int Main(string[] args)
        {
            ProgramUtils.Init();

            using (var handler = new CliCommandHandler())
                return (int)ProgramUtils.Run("0install", args.Prepend(Run.Name), handler);
        }
Пример #2
0
        /// <summary>
        /// Runs the application (called by main method or by embedding process).
        /// </summary>
        public static ExitCode Run(string[] args)
        {
            var handler = new CliCommandHandler();
            try
            {
                var command = new AddAlias(handler);
                command.Parse(args);
                return command.Execute();
            }
                #region Error handling
            catch (OperationCanceledException)
            {
                return ExitCode.UserCanceled;
            }
            catch (NeedGuiException ex)
            {
                if (ProgramUtils.GuiAssemblyName == null)
                {
                    Log.Error(ex);
                    return ExitCode.InvalidArguments;
                }
                else
                {
                    Log.Info("Switching to GUI");
                    try
                    {
                        return (ExitCode)ProcessUtils.Assembly(ProgramUtils.GuiAssemblyName, args.Prepend(AddAlias.Name)).Run();
                    }
                        #region Error handling
                    catch (OperationCanceledException)
                    {
                        return ExitCode.UserCanceled;
                    }
                    catch (IOException ex2)
                    {
                        Log.Error(ex2);
                        return ExitCode.IOError;
                    }
                    #endregion
                }
            }
            catch (NotAdminException ex)
            {
                try
                {
                    return (ExitCode)ProcessUtils.Assembly(ProgramUtils.GuiAssemblyName ?? "0install", args.Prepend(AddAlias.Name)).AsAdmin().Run();
                }
                catch (OperationCanceledException)
                {
                    return ExitCode.UserCanceled;
                }
                catch (PlatformNotSupportedException)
                {
                    Log.Error(ex);
                    return ExitCode.AccessDenied;
                }
                catch (IOException)
                {
                    Log.Error(ex);
                    return ExitCode.AccessDenied;
                }
            }
            catch (OptionException ex)
            {
                Log.Error(ex);
                Log.Error(string.Format(Resources.TryHelp, ExeName));
                return ExitCode.InvalidArguments;
            }
            catch (FormatException ex)
            {
                Log.Error(ex);
                return ExitCode.InvalidArguments;
            }
            catch (WebException ex)
            {
                Log.Error(ex);
                return ExitCode.WebError;
            }
            catch (NotSupportedException ex)
            {
                Log.Error(ex);
                return ExitCode.NotSupported;
            }
            catch (IOException ex)
            {
                Log.Error(ex);
                return ExitCode.IOError;
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Error(ex);
                return ExitCode.AccessDenied;
            }
            catch (InvalidDataException ex)
            {
                Log.Error(ex);
                return ExitCode.InvalidData;
            }
            catch (SignatureException ex)
            {
                Log.Error(ex);
                return ExitCode.InvalidSignature;
            }
            catch (DigestMismatchException ex)
            {
                Log.Error(ex);
                return ExitCode.DigestMismatch;
            }
            catch (SolverException ex)
            {
                Log.Error(ex);
                return ExitCode.SolverError;
            }
            catch (ConflictException ex)
            {
                Log.Error(ex);
                return ExitCode.Conflict;
            }
                #endregion

            finally
            {
                handler.CloseUI();
            }
        }