internal static async Task <ToolExitCode> RunAsync(CommandProcessorOptions options, CancellationToken cancellationToken) { ImportModule importModule = null; var credsProvicer = new CmdCredentialsProvider(); ServiceDescriptor serviceDescriptor = options.Inputs.Count == 1 ? new ServiceDescriptor(options.Inputs[0].ToString(), credsProvicer, credsProvicer, credsProvicer) : new ServiceDescriptor(options.Inputs.Select(i => i.ToString()).ToList(), credsProvicer, credsProvicer, credsProvicer); // When in Infrastructure mode (WCF CS) it is assumed the metadata docs have been downloaded and passed in as wsdl files. if (options.ToolContext != OperationalContext.Infrastructure) { if (serviceDescriptor.MetadataUrl != null) { ToolConsole.WriteLine(string.Format(SR.RetreivingMetadataMsgFormat, serviceDescriptor.MetadataUrl.AbsoluteUri)); } else { var displayUri = serviceDescriptor.MetadataFiles.Count() == 1 ? serviceDescriptor.MetadataFiles.First().LocalPath : SR.WsdlOrSchemaFilesMsg; ToolConsole.WriteLine(string.Format(SR.ReadingMetadataMessageFormat, displayUri)); } } using (await SafeLogger.WriteStartOperationAsync(options.Logger, "Importing metadata ...").ConfigureAwait(false)) { try { await serviceDescriptor.ImportMetadataAsync( (wi) => importModule = new ImportModule(options, serviceDescriptor, wi), (sd) => importModule.BeforeImportMetadata(sd), (sd) => importModule.AfterImportMetadata(sd), cancellationToken).ConfigureAwait(false); } catch (Exception ex) { if (Utils.IsFatalOrUnexpected(ex)) { throw; } var exception = new ToolInputException(Utils.GetExceptionMessage(ex), ex); if (serviceDescriptor.MetadataUrl != null) { exception = new ToolMexException(exception, serviceDescriptor.MetadataUrl); } throw exception; } } using (await SafeLogger.WriteStartOperationAsync(options.Logger, "Processing Code DOM ...").ConfigureAwait(false)) { ToolConsole.WriteLine(SR.GeneratingFiles); CodeSerializer codeSerializer = new CodeSerializer(options, serviceDescriptor.MetadataDocuments); var filePath = codeSerializer.Save(importModule.CodeCompileUnit); // When in Infrastructure mode (WCF CS) it is assumed the output file path have been provided so no need to display it. ToolConsole.WriteLineIf(options.ToolContext != OperationalContext.Infrastructure, filePath, LogTag.Important); } return(ToolConsole.ExitCode); }
internal ToolMexException(ToolInputException wsMexException, Uri serviceUri) : base(string.Format(SR.ErrUnableToRetrieveMetadataFromUriFormat, serviceUri.AbsoluteUri, SR.EnableMetadataHelpMessage)) { _wsMexException = wsMexException; _serviceUri = serviceUri; }