示例#1
0
            public override ExitCode Execute()
            {
                var    manifestDigest = new ManifestDigest(AdditionalArgs[0]);
                string path           = AdditionalArgs[1];

                try
                {
                    if (File.Exists(path))
                    { // One or more archives (combined/overlayed)
                        Store.AddArchives(GetArchiveFileInfos(), manifestDigest, Handler);
                        return(ExitCode.OK);
                    }
                    else if (Directory.Exists(path))
                    { // A single directory
                        if (AdditionalArgs.Count > 2)
                        {
                            throw new OptionException(Resources.TooManyArguments + Environment.NewLine + AdditionalArgs.Skip(2).JoinEscapeArguments(), null);
                        }
                        Store.AddDirectory(Path.GetFullPath(path), manifestDigest, Handler);
                        return(ExitCode.OK);
                    }
                    else
                    {
                        throw new FileNotFoundException(string.Format(Resources.FileOrDirNotFound, path), path);
                    }
                }
                catch (ImplementationAlreadyInStoreException ex)
                {
                    Log.Warn(ex);
                    return(ExitCode.NoChanges);
                }
            }
示例#2
0
        private ExitCode Add()
        {
            if (AdditionalArgs.Count < 3)
            {
                throw new OptionException(Resources.MissingArguments + Environment.NewLine + "add DIGEST (DIRECTORY | (ARCHIVE [EXTRACT [MIME-TYPE [...]]))", "");
            }

            var    manifestDigest = new ManifestDigest(AdditionalArgs[1]);
            string path           = AdditionalArgs[2];

            try
            {
                if (File.Exists(path))
                { // One or more archives (combined/overlayed)
                    Store.AddArchives(GetArchiveFileInfos(), manifestDigest, Handler);
                    return(ExitCode.OK);
                }
                else if (Directory.Exists(path))
                { // A single directory
                    if (AdditionalArgs.Count > 3)
                    {
                        throw new OptionException(Resources.TooManyArguments + Environment.NewLine + "add DIGEST (DIRECTORY | (ARCHIVE [EXTRACT [MIME-TYPE [...]]))", "");
                    }
                    Store.AddDirectory(Path.GetFullPath(path), manifestDigest, Handler);
                    return(ExitCode.OK);
                }
                else
                {
                    throw new FileNotFoundException(string.Format(Resources.NoSuchFileOrDirectory, path), path);
                }
            }
            catch (ImplementationAlreadyInStoreException ex)
            {
                Log.Warn(ex);
                return(ExitCode.NoChanges);
            }
        }