Beispiel #1
0
        internal async Task BuildBootstrapProjectAsync(ILogger logger, CancellationToken cancellationToken)
        {
            string outputText;
            string errorMessage = null;

            try
            {
                ToolConsole.WriteLineIf(ToolConsole.Verbosity >= Verbosity.Verbose, Resource.RestoringNuGetPackagesMsg);
                var restoreResult = await this.MSBuildProj.RestoreAsync(logger, cancellationToken).ConfigureAwait(false);

                MarkupTelemetryHelper.TelemetryPostOperation(restoreResult.ExitCode == 0, "Restore bootstrapper");
                if (restoreResult.ExitCode != 0)
                {
                    ToolConsole.WriteWarning(restoreResult.OutputText);
                }

                ToolConsole.WriteLineIf(ToolConsole.Verbosity >= Verbosity.Verbose, Resource.BuildingProjectMsg);
                var buildResult = await this.MSBuildProj.BuildAsync(logger, cancellationToken).ConfigureAwait(false);

                MarkupTelemetryHelper.TelemetryPostOperation(buildResult.ExitCode == 0, "Build bootstrapper");
            }
            catch (ProcessRunner.ProcessException exception)
            {
                throw new BootstrapException(string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", exception.Message, Environment.NewLine, Resource.BootstrapErrorDisableReferences));
            }
        }
Beispiel #2
0
        public bool AfterImportMetadata(ServiceDescriptor serviceDescriptor)
        {
            try
            {
                // Convert errors to warnings to workaround the issue that many validation errors from XSD compiler
                // can be ignored.
                for (int idx = _wsdlImporter.Errors.Count - 1; idx >= _nonWsdlImportErrors; idx--)
                {
                    var error = _wsdlImporter.Errors[idx];
                    if (!error.IsWarning)
                    {
                        ToolConsole.ExitCode = ToolExitCode.ValidationErrorTurnedWarning;
                        var warning = new MetadataConversionError(error.Message, isWarning: true);
                        _wsdlImporter.Errors[idx] = warning;
                    }
                }

                MarkupTelemetryHelper.SendBindingData(serviceDescriptor.Bindings);

                Collection <ServiceEndpoint>     endpoints = new Collection <ServiceEndpoint>(serviceDescriptor.Endpoints.ToList());
                Collection <Binding>             bindings  = new Collection <Binding>(serviceDescriptor.Bindings.ToList());
                Collection <ContractDescription> contracts = new Collection <ContractDescription>(serviceDescriptor.Contracts.ToList());

                _codegenExtension.WsdlImported(_wsdlImporter, endpoints, bindings, contracts);
            }
            catch (Exception e)
            {
                ToolConsole.WriteError(e);
            }

            ToolConsole.WriteConversionErrors(_wsdlImporter.Errors);

            ImportServiceContracts(serviceDescriptor);

            ToolConsole.WriteConversionErrors(_contractGenerator.Errors);

            var contractsResolved = true;

            if (_validateMetadataImport)
            {
                _validateMetadataImport = false;
                contractsResolved       = ContractsResolved(serviceDescriptor, this.CodeCompileUnit);

                if (!contractsResolved)
                {
                    var importer1 = ServiceDescriptor.DefaultUseMessageFormat ? typeof(DataContractSerializerMessageContractImporter) : typeof(XmlSerializerMessageContractImporter);
                    var importer2 = ServiceDescriptor.DefaultUseMessageFormat ? typeof(XmlSerializerMessageContractImporter) : typeof(DataContractSerializerMessageContractImporter);
                    ToolConsole.WriteWarning(string.Format(CultureInfo.CurrentCulture, SR.WrnCouldNotGenerateContractOperationsFormat, importer1, importer2));
                }
            }

            // on false, ServiceDescriptor will attempt to use a different contract serializer.
            return(contractsResolved);
        }
Beispiel #3
0
        internal async Task <ProcessRunner.ProcessResult> BoostrapSvcutilAsync(bool keepBootstrapperDir, ILogger logger, CancellationToken cancellationToken)
        {
            bool redirectOutput = false;

            if (this.Options.ToolContext == OperationalContext.Infrastructure)
            {
                redirectOutput = true;
            }

            ProcessRunner.ProcessResult result = null;

            using (await SafeLogger.WriteStartOperationAsync(logger, "Bootstrapping svcutil ...").ConfigureAwait(false))
            {
                // guard against bootstrapping recursion.
                if (this.Options.NoBootstrapping != true)
                {
                    Debug.Fail($"The NoBootstrapping property is not set, this would cause infinite bootstrapping recursion!");
                    return(null);
                }

                if (this.Options.Project != null && StringComparer.OrdinalIgnoreCase.Compare(this.Options.Project.FileName, SvcutilBootstrapper.ProjectName) == 0)
                {
                    Debug.Fail("Bootstrapping is enabled for the bootstrapper! This would cause an infinite bootstrapping recursion!");
                    return(null);
                }

                // When in Infrastructure mode (WCF CS) it is assumed the initial progress message is to be presented by the calling tool.
                ToolConsole.WriteLineIf(ToolConsole.ToolModeLevel != OperationalContext.Infrastructure, Resource.BootstrappingApplicationMsg);

                await GenerateProjectAsync(keepBootstrapperDir, logger, cancellationToken).ConfigureAwait(false);
                await GenerateProgramFileAsync(logger, cancellationToken).ConfigureAwait(false);

                var paramsFilePath = await GenerateParamsFileAsync(logger, cancellationToken).ConfigureAwait(false);

                await BuildBootstrapProjectAsync(logger, cancellationToken).ConfigureAwait(false);

                ToolConsole.WriteLineIf(ToolConsole.Verbosity >= Verbosity.Verbose, Resource.InvokingProjectMsg);
                result = await ProcessRunner.RunAsync("dotnet", $"run \"{paramsFilePath}\"", this.MSBuildProj.DirectoryPath, redirectOutput, logger, cancellationToken).ConfigureAwait(false);

                MarkupTelemetryHelper.TelemetryPostOperation(result.ExitCode == 0, "Invoke svcutil bootstrapper");
            }

            return(result);
        }
Beispiel #4
0
        internal static void WriteToolError(Exception ex)
        {
            StringBuilder toolError = new StringBuilder();

            toolError.AppendLine(Utils.GetExceptionMessage(ex));

            if (ex is ToolMexException me)
            {
                toolError.AppendLine(string.Format(SR.WrnWSMExFailedFormat, me.ServiceUri?.AbsoluteUri));
                toolError.AppendLine();
                toolError.AppendLine(Utils.GetExceptionMessage(me.WSMexException));
            }

            if (ToolConsole.Verbosity > Verbosity.Minimal && ToolConsole.ToolModeLevel != OperationalContext.Infrastructure)
            {
                toolError.AppendLine();
                toolError.AppendLine(string.Format(SR.MoreHelpFormat, CommandProcessorOptions.Switches.Help.Abbreviation));
            }

            MarkupTelemetryHelper.TelemetryPostFault(ex);
            WriteError(toolError.ToString());
        }
Beispiel #5
0
 internal static void WriteError(Exception e, string prefix)
 {
     MarkupTelemetryHelper.TelemetryPostFault(e);
     WriteError(Utils.GetExceptionMessage(e), prefix);
 }