Exemple #1
0
        public void Exec(SubCommandRunningContext context)
        {
            _metadataCommand.Exec(context);

            // 2. convert.
            var inputModels = _metadataCommand.InputModels;
            var outputFile  = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");

            if (string.IsNullOrWhiteSpace(_options.BaseUrl))
            {
                throw new InvalidOptionException("BaseUrl cannot be empty.", "BaseUrl");
            }

            var baseUri = new Uri(_options.BaseUrl);

            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }
            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                package.AddProjects(inputModels.SelectMany(s => s.Items).Select(s => s.Key).ToList());
            }
        }
Exemple #2
0
        public ParseResult Exec(RunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");

            try
            {
                var baseUri = new Uri(_options.BaseUrl);
                if (!baseUri.IsAbsoluteUri)
                {
                    return(new ParseResult(ResultLevel.Error, "BaseUrl should be absolute url."));
                }
                var source = _options.Source.TrimEnd('/', '\\');
                using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
                {
                    var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                    if (_options.FlatMode)
                    {
                        package.AddFiles(string.Empty, files);
                    }
                    else
                    {
                        foreach (var g in from f in files
                                 group f by Path.GetDirectoryName(f) into g
                                 select new
                        {
                            Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                            Files = g.ToList(),
                        })
                        {
                            if (g.Folder.Length == 0)
                            {
                                package.AddFiles(string.Empty, g.Files);
                            }
                            else
                            {
                                package.AddFiles(g.Folder + "/", g.Files);
                            }
                        }
                    }
                }
                return(ParseResult.SuccessResult);
            }
            catch (Exception ex)
            {
                return(new ParseResult(ResultLevel.Error, ex.ToString()));
            }
        }
Exemple #3
0
        public void Exec(SubCommandRunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");
            var baseUri    = new Uri(_options.BaseUrl);

            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }

            var source = _options.Source.TrimEnd('/', '\\');

            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                if (_options.FlatMode)
                {
                    ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, files);
                }
                else
                {
                    foreach (var g in from f in files
                             group f by Path.GetDirectoryName(f) into g
                             select new
                    {
                        Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                        Files = g.ToList(),
                    })
                    {
                        if (g.Folder.Length == 0)
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, g.Files);
                        }
                        else
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, g.Folder + "/", g.Files);
                        }
                    }
                }
            }
        }
Exemple #4
0
        public ParseResult Exec(RunningContext context)
        {
            if (_helpMessage != null)
            {
                Console.WriteLine(_helpMessage);
                return(ParseResult.SuccessResult);
            }

            var extractMetadataResult = _metadataCommand.Exec(context);

            Logger.Log(extractMetadataResult);
            if (extractMetadataResult.ResultLevel == ResultLevel.Error)
            {
                return(extractMetadataResult);
            }

            // 2. convert.
            var inputModels = _metadataCommand.InputModels;
            var outputFile  = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");

            if (string.IsNullOrWhiteSpace(_options.BaseUrl))
            {
                return(new ParseResult(ResultLevel.Error, "BaseUrl cannot be empty."));
            }
            try
            {
                var baseUri = new Uri(_options.BaseUrl);
                if (!baseUri.IsAbsoluteUri)
                {
                    return(new ParseResult(ResultLevel.Error, "BaseUrl should be absolute url."));
                }
                using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
                {
                    package.AddProjects(inputModels.SelectMany(s => s.Items).Select(s => s.Key).ToList());
                }

                return(ParseResult.SuccessResult);
            }
            catch (Exception ex)
            {
                return(new ParseResult(ResultLevel.Error, ex.ToString()));
            }
        }