Exemplo n.º 1
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            foreach (var file in ArgumentUtils.GetFiles(AdditionalArgs, "*.xml"))
            {
                FeedManager.ImportFeed(file.FullName);
            }

            return(ExitCode.OK);
        }
Exemplo n.º 2
0
        [STAThread] // Required for WinForms
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ErrorReportForm.SetupMonitoring(new Uri("https://0install.de/error-report/"));
            NetUtils.ApplyProxy();

            var openPgp = OpenPgpFactory.CreateDefault();

            if (args == null || args.Length == 0)
            {
                Application.Run(new WelcomeForm(openPgp));
            }
            else
            {
                try
                {
                    var files = ArgumentUtils.GetFiles(args, "*.xml");
                    if (files.Count == 1)
                    {
                        string path = files.First().FullName;
                        Application.Run(new MainForm(FeedEditing.Load(path), openPgp));
                    }
                    else
                    {
                        MassSignForm.Show(files);
                    }
                }
                #region Error handling
                catch (ArgumentException ex)
                {
                    Msg.Inform(null, ex.Message, MsgSeverity.Warn);
                }
                catch (IOException ex)
                {
                    Msg.Inform(null, ex.Message, MsgSeverity.Warn);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(null, ex.Message, MsgSeverity.Warn);
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(null, ex.Message + (ex.InnerException == null ? "" : Environment.NewLine + ex.InnerException.Message), MsgSeverity.Warn);
                }
                #endregion
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the commands specified by the command-line arguments.
        /// </summary>
        /// <returns>The error code to end the process with.</returns>
        /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
        /// <exception cref="OptionException">The specified feed file paths were invalid.</exception>
        /// <exception cref="WebException">A file could not be downloaded from the internet.</exception>
        /// <exception cref="InvalidDataException">A feed file is damaged.</exception>
        /// <exception cref="FileNotFoundException">A feed file could not be found.</exception>
        /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file or the catalog file is not permitted.</exception>
        /// <exception cref="DigestMismatchException">An existing digest does not match the newly calculated one.</exception>
        /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception>
        /// <exception cref="NotSupportedException">A MIME type doesn't belong to a known and supported archive type.</exception>
        public ExitCode Execute()
        {
            switch (_mode)
            {
            case OperationMode.Normal:
                if (_feeds.Count == 0)
                {
                    Log.Error(string.Format(Resources.MissingArguments, "0publish"));
                    return(ExitCode.InvalidArguments);
                }

                foreach (var feedEditing in _feeds.Select(file => FeedEditing.Load(file.FullName)))
                {
                    HandleModify(feedEditing);
                    SaveFeed(feedEditing);
                }
                return(ExitCode.OK);

            case OperationMode.Catalog:
                // Default to using all XML files in the current directory
                if (_feeds.Count == 0)
                {
                    _feeds = ArgumentUtils.GetFiles(new[] { Environment.CurrentDirectory }, "*.xml");
                }

                var catalog = new Catalog();
                foreach (var feed in _feeds.Select(feedFile => XmlStorage.LoadXml <Feed>(feedFile.FullName)))
                {
                    feed.Strip();
                    catalog.Feeds.Add(feed);
                }
                if (catalog.Feeds.Count == 0)
                {
                    throw new FileNotFoundException(Resources.NoFeedFilesFound);
                }

                SaveCatalog(catalog);
                return(ExitCode.OK);

            default:
                Log.Error(string.Format(Resources.UnknownMode, "0publish"));
                return(ExitCode.InvalidArguments);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses command-line arguments.
        /// </summary>
        /// <param name="args">The command-line arguments to be parsed.</param>
        /// <exception cref="OperationCanceledException">The user asked to see help information, version information, etc..</exception>
        /// <exception cref="OptionException"><paramref name="args"/> contains unknown options.</exception>
        public PublishRun(IEnumerable <string> args)
        {
            #region Sanity checks
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            #endregion

            var additionalArgs = BuildOptions().Parse(args);
            try
            {
                _feeds = ArgumentUtils.GetFiles(additionalArgs, "*.xml");
            }
            #region Error handling
            catch (FileNotFoundException ex)
            {
                // Report as an invalid command-line argument
                throw new OptionException(ex.Message, ex.FileName);
            }
            #endregion
        }