コード例 #1
0
        public ResolverClient GetResolver()
        {
            string repository = _repository;

            if (Validations.IsRelativePath(repository))
            {
                repository = Path.GetFullPath(repository);
            }

            return(new ResolverClient(
                       repository,
                       new ResolverClientOptions(DependencyResolutionOption.TryFromExpanded),
                       _logger));
        }
コード例 #2
0
        private static Command BuildImportModelCommand()
        {
            var modelFileOption = CommonOptions.ModelFile;

            modelFileOption.IsRequired = true; // Option is required for this command

            Command addModel = new Command("import")
            {
                modelFileOption,
                CommonOptions.LocalRepo
            };

            addModel.Description = "Adds a model to a local repository. " +
                                   "Validates Id's, dependencies and places model content in the proper location.";
            addModel.Handler = CommandHandler.Create <FileInfo, string, IHost>(async(modelFile, localRepository, host) =>
            {
                var returnCode = ReturnCodes.Success;
                ILogger logger = GetLogger(host);

                OutputHeaders(logger);

                if (localRepository == null)
                {
                    localRepository = Path.GetFullPath(".");
                }
                else if (Validations.IsRelativePath(localRepository))
                {
                    localRepository = Path.GetFullPath(localRepository);
                }

                DirectoryInfo repoDirInfo = new DirectoryInfo(localRepository);
                Parsing parsing           = new Parsing(repoDirInfo.FullName, logger);
                try
                {
                    var newModels = await ModelImporter.ImportModels(modelFile, repoDirInfo, logger);
                    foreach (var model in newModels)
                    {
                        var validationResult = await parsing.IsValidDtdlFileAsync(model, false);

                        if (!validationResult)
                        {
                            returnCode = ReturnCodes.ValidationError;
                        }
                    }
                }
                catch (ValidationException validationEx)
                {
                    logger.LogError(validationEx.Message);
                    return(ReturnCodes.ValidationError);
                }
                catch (IOException ioEx)
                {
                    logger.LogError(ioEx.Message);
                    return(ReturnCodes.ImportError);
                }

                return(returnCode);
            });

            return(addModel);
        }