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); }
internal bool ImportServiceContracts(ServiceDescriptor serviceDescriptor) { bool result = false; try { _codegenExtension.ClientGenerating(_contractGenerator); } catch (Exception e) { ToolConsole.WriteError(e); } HttpBindingTracker httpBindingTracker = FindImportExtension <HttpBindingTracker>(); foreach (ContractDescription contractDescription in serviceDescriptor.Contracts) { if (!httpBindingTracker.IsHttpBindingContract(contractDescription) || serviceDescriptor.Endpoints.Any(endpoint => endpoint.Contract == contractDescription)) { _contractGenerator.GenerateServiceContractType(contractDescription); } } try { _codegenExtension.ClientGenerated(_contractGenerator); if (_codegenExtension.ErrorDetected) { ToolConsole.ExitCode = ToolExitCode.ValidationError; } result = !_codegenExtension.ErrorDetected; } catch (NotSupportedException) { throw; } catch (Exception e) { ToolConsole.WriteError(e); } return(result); }
public void BeforeImportMetadata(ServiceDescriptor serviceDescriptor) { _nonWsdlImportErrors = _wsdlImporter.Errors.Count; _wsdlImporter.WsdlImportExtensions.Add(new BindingImportTracker()); _wsdlImporter.WsdlImportExtensions.Add(new HttpBindingTracker()); InitializationHelper.RemoveUnneededSerializers(_options, serviceDescriptor, _wsdlImporter.WsdlImportExtensions); InitializationHelper.ConfigureSerializers(_options, _codeCompileUnit, _wsdlImporter); try { _codegenExtension.WsdlImporting(_wsdlImporter); } catch (Exception e) { ToolConsole.WriteError(e); } }
private void LogMessage(string message, LogTag logTag, bool logToUI = false) { if (this.EnableTracing || logToUI) { message = message?.Trim(); if (!string.IsNullOrEmpty(message)) { if (logTag == LogTag.Error) { ToolConsole.WriteError(message, isTrace: !logToUI); } else if (logTag == LogTag.Warning) { ToolConsole.WriteWarning(message, isTrace: !logToUI); } else { ToolConsole.WriteLine(message, logToUI ? LogTag.Information : LogTag.LogMessage); } } } }
private static async Task <int> ProcessExceptionAsync(Exception ex, CommandProcessorOptions options) { int retVal = (int)ToolExitCode.Unknown; Debug.Assert(ex != null, "exception should not be null!"); if (ex != null) { try { s_processingException = true; var agex = ex as AggregateException; if (agex != null) { foreach (var ax in agex.InnerExceptions) { retVal = await ProcessExceptionAsync(ax, options); } } else if (ex is BootstrapException bootstrapEx) { ToolConsole.WriteToolError(ex); retVal = bootstrapEx.ExitCode; } else if (ex is ProcessRunner.ProcessException rpe) { ToolConsole.WriteError(rpe, null); retVal = rpe.ExitCode; } else if (ex is ToolArgumentException ae) { ToolConsole.WriteToolError(ae); retVal = (int)ae.ExitCode; } else if (ex is ToolRuntimeException rt) { ToolConsole.WriteToolError(rt); retVal = (int)rt.ExitCode; } else if (ex is DcNS.InvalidDataContractException dce) { ToolConsole.WriteError(dce); retVal = (int)ToolExitCode.RuntimeError; } else if (Utils.IsUnexpected(ex)) { ToolConsole.WriteError(SR.ErrUnexpectedError); retVal = (int)ToolExitCode.RuntimeError; } else // (Exception e) { ToolConsole.WriteError(ex); retVal = (int)ToolExitCode.Unknown; } // don't log aggregate exceptions as the internal exceptions are already logged. if (agex == null) { string exMsg = null; if (options?.Logger != null) { exMsg = Utils.GetExceptionMessage(ex, true); await options.Logger.WriteErrorAsync(exMsg, logToUI : false).ConfigureAwait(false); } // Don't log telemetry if we're running from bootstrapper or connected service. // if options = null, it must be that a parsing exception occurred. if (options == null || options.ToolContext <= OperationalContext.Global) { exMsg = exMsg ?? Utils.GetExceptionMessage(ex, true); var telemetryClient = await AppInsightsTelemetryClient.GetInstanceAsync(CancellationToken.None).ConfigureAwait(false); telemetryClient.TrackError("Exception", exMsg); } } } catch { } } return(retVal); }