string IUrlParameter.GetString(ITransportConfiguration settings) => Match( all => "_all", many => { if (!(settings is IConnectionSettingsValues nestSettings)) { throw new Exception(
// SERVER-SIDE CTOR // server uses: challengeController, transportConfiguration // client uses: (when-shared thru AddonManager) challegeEvidence /// <summary> /// Instantiates a new client-side <see cref="NullRegistrationController"/>. /// </summary> /// <param name="transportConfiguration">The transportation layer configuration.</param> /// <param name="challengeController">Controls access to the communication system.</param> public NullRegistrationController(ITransportConfiguration transportConfiguration, IChallengeController challengeController) : this() { TransportConfiguration = transportConfiguration ?? throw new ArgumentNullException(nameof(transportConfiguration)); ChallengeController = challengeController ?? throw new ArgumentNullException(nameof(challengeController)); }
private void Configure(ClientWebSocketOptions options, ITransportConfiguration config) { config.DefaultRequestHeaders.AsEnumerable().ForEach(i => options.SetRequestHeader(i.name, i.value)); if (!(config.Proxy is null)) { options.Proxy = config.Proxy; } if (!(config.Cookies is null)) { options.Cookies = config.Cookies; } if (!(config.RemoteCertificateValidator is null)) { options.RemoteCertificateValidationCallback = config.RemoteCertificateValidator; } if (!(config.ClientCertificates is null)) { options.ClientCertificates = config.ClientCertificates; } if (config.KeepAliveInterval.HasValue) { options.KeepAliveInterval = config.KeepAliveInterval.Value; } if (config.Credentials is null) { return; } options.Credentials = config.Credentials; options.UseDefaultCredentials = false; }
public Task <ITransport> Build(ITransportConfiguration config) { config.Logger.Debug($"{nameof(this.Build)}: '{this.Name}' transport"); var transport = new SystemWebSocketTransport(config); return(Task.FromResult <ITransport>(transport)); }
public SystemWebSocketTransport(ITransportConfiguration config) { this._config = config; this._log = config.Logger; this._socket = new ClientWebSocket(); this.Configure(this._socket.Options, config); }
public override async Task WriteAsync(Stream writableStream, ITransportConfiguration settings, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(_literalString)) { return; } var stream = InitWrite(writableStream, settings, out var buffer, out var disableDirectStreaming); var stringBytes = WrittenBytes ?? _literalString.Utf8Bytes(); WrittenBytes ??= stringBytes; if (!disableDirectStreaming) { await stream.WriteAsync(stringBytes, 0, stringBytes.Length, cancellationToken) .ConfigureAwait(false); } else { buffer = settings.MemoryStreamFactory.Create(stringBytes); } await FinishStreamAsync(writableStream, buffer, settings, cancellationToken).ConfigureAwait(false); }
public string GetString(ITransportConfiguration settings) { if (settings is not IElasticsearchClientSettings elasticsearchClientSettings) { throw new Exception("Tried to pass index name on querystring but it could not be resolved because no Elastic.Clients.Elasticsearch settings are available"); } return(elasticsearchClientSettings.Inferrer.IndexName(this)); }
public TransportConfiguration(ITransportConfiguration parent) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } _parent = parent; }
public string GetString(ITransportConfiguration settings) { if (!(settings is IConnectionSettingsValues nestSettings)) { throw new Exception("Tried to pass index name on querystring but it could not be resolved because no nest settings are available"); } return(nestSettings.Inferrer.IndexName(this)); }
public override void Write(Stream writableStream, ITransportConfiguration settings) { MemoryStream buffer = null; var stream = writableStream; BufferIfNeeded(settings, ref buffer, ref stream); _syncWriter(_state, stream); FinishStream(writableStream, buffer, settings); }
public override async Task WriteAsync(Stream writableStream, ITransportConfiguration settings, CancellationToken cancellationToken) { if (Type != PostType.EnumerableOfObject && Type != PostType.EnumerableOfString) throw new Exception( $"{nameof(PostDataMultiJson<T>)} only does not support {nameof(PostType)}.{Type.GetStringValue()}"); var stream = InitWrite(writableStream, settings, out var buffer, out _); switch (Type) { case PostType.EnumerableOfString: { if (_enumerableOfStrings == null) return; using var enumerator = _enumerableOfStrings.GetEnumerator(); if (!enumerator.MoveNext()) return; BufferIfNeeded(settings, ref buffer, ref stream); do { var bytes = enumerator.Current.Utf8Bytes(); await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false); await stream.WriteAsync(NewLineByteArray, 0, 1, cancellationToken).ConfigureAwait(false); } while (enumerator.MoveNext()); break; } case PostType.EnumerableOfObject: { if (_enumerableOfObject == null) return; using var enumerator = _enumerableOfObject.GetEnumerator(); if (!enumerator.MoveNext()) return; BufferIfNeeded(settings, ref buffer, ref stream); do { var o = enumerator.Current; await settings.RequestResponseSerializer.SerializeAsync(o, stream, SerializationFormatting.None, cancellationToken) .ConfigureAwait(false); await stream.WriteAsync(NewLineByteArray, 0, 1, cancellationToken).ConfigureAwait(false); } while (enumerator.MoveNext()); break; } default: throw new ArgumentOutOfRangeException(); } await FinishStreamAsync(writableStream, buffer, settings, cancellationToken).ConfigureAwait(false); }
public ITransport ConfigureChannels(ITransportConfiguration configuration) { foreach (var channelFactory in TransportChannelFactories) { channelFactory.Configuration = configuration; } return(this); }
/// <summary> Sets up the stream and buffer and determines if direct streaming should be disabled </summary> // ReSharper disable once MemberCanBePrivate.Global protected Stream InitWrite(Stream writableStream, ITransportConfiguration settings, out MemoryStream buffer, out bool disableDirectStreaming) { buffer = null; var stream = writableStream; disableDirectStreaming = DisableDirectStreaming ?? settings.DisableDirectStreaming; return(stream); }
public override async Task WriteAsync(Stream writableStream, ITransportConfiguration settings, CancellationToken cancellationToken) { MemoryStream buffer = null; var stream = writableStream; BufferIfNeeded(settings, ref buffer, ref stream); await _asyncWriter(_state, stream, cancellationToken).ConfigureAwait(false); await FinishStreamAsync(writableStream, buffer, settings, cancellationToken).ConfigureAwait(false); }
string IUrlParameter.GetString(ITransportConfiguration settings) { if (!(settings is IConnectionSettingsValues nestSettings)) { throw new ArgumentNullException(nameof(settings), $"Can not resolve {nameof(PropertyName)} if no {nameof(IConnectionSettingsValues)} is provided"); } return(nestSettings.Inferrer.PropertyName(this)); }
/// <summary> /// Instantiates a new <see cref="TransportController"/>. /// </summary> /// <param name="transportConfiguration">The transportation configuration for this <see cref="TransportController"/>.</param> /// <param name="registrationController">The registration controller used by this <see cref="TransportController"/>.</param> public TransportController(ITransportConfiguration transportConfiguration, IRegistrationController registrationController) : this() { if (registrationController == null) { registrationController = new RegistrationControllers.NullRegistrationController((byte[])null); } RegistrationController = registrationController; TransportConfiguration = transportConfiguration ?? throw new ArgumentNullException(nameof(transportConfiguration)); }
public void Configure(ITransportConfiguration configuration) { HttpClientTransport.SetTimeout(configuration.RequestTimeout); HttpClientTransport.SetServiceName(configuration.ServiceName); HttpClientTransport.SetBearerToken(configuration.AuthenticationKey); // Handle any supported overrides if (configuration.TransportOverrides?.ContainsKey((int)TransportOverrides.BaseUrl) ?? false) { HttpClientTransport.SetUri((string)configuration.TransportOverrides[(int)TransportOverrides.BaseUrl]); } }
/// <summary> /// Set the host application as an MVC website. /// </summary> /// <param name="transportConfiguration">The transportation configuration.</param> /// <param name="routes">The MVC route table to add the service bus actions too.</param> /// <param name="queueManager">The embedded persisted message queue.</param> /// <returns>The <see cref="IHostApplicationConfiguration"/>.</returns> public static IHostApplicationConfiguration AsMvcServiceBus(this ITransportConfiguration transportConfiguration, RouteCollection routes, IQueueManager queueManager) { Argument.CannotBeNull(routes, "routes", "Route collection must be used to add service bus HTTP methods."); routes.MapRoute( "MessageReceive", "service-bus/message", new { controller = "Message", action = "Receive" }, new[] { typeof(MessageController).Namespace }); return(new HostApplicationConfiguration(transportConfiguration, queueManager)); }
/// <summary> /// Implementation of <see cref="Write"/> may call this to make sure <paramref name="buffer"/> makes it to <see cref="WrittenBytes"/> /// if <see cref="DisableDirectStreaming"/> or <paramref name="settings"/> request to buffer the data. /// </summary> protected void FinishStream(Stream writableStream, MemoryStream buffer, ITransportConfiguration settings) { var disableDirectStreaming = DisableDirectStreaming ?? settings.DisableDirectStreaming; if (buffer == null || !disableDirectStreaming) { return; } buffer.Position = 0; buffer.CopyTo(writableStream, BufferSize); WrittenBytes ??= buffer.ToArray(); }
public override void Write(Stream writableStream, ITransportConfiguration settings) { MemoryStream buffer = null; var stream = writableStream; BufferIfNeeded(settings, ref buffer, ref stream); var indent = settings.PrettyJson ? Indented : None; settings.RequestResponseSerializer.Serialize(_serializable, stream, indent); FinishStream(writableStream, buffer, settings); }
/// <summary> /// Based on <paramref name="settings"/> or <see cref="DisableDirectStreaming"/> this will swap <paramref name="stream"/> /// with <paramref name="buffer"/> after allocating <paramref name="buffer"/>. /// <para>NOTE: <paramref name="buffer"/> is expected to be null when called and may be null when this method returns</para> /// </summary> protected void BufferIfNeeded(ITransportConfiguration settings, ref MemoryStream buffer, ref Stream stream) { var disableDirectStreaming = DisableDirectStreaming ?? settings.DisableDirectStreaming; if (!disableDirectStreaming) { return; } buffer = settings.MemoryStreamFactory.Create(); stream = buffer; }
public RequestData( HttpMethod method, string path, PostData data, ITransportConfiguration global, IRequestParameters local, IMemoryStreamFactory memoryStreamFactory ) : this(method, data, global, local?.RequestConfiguration, memoryStreamFactory) { _path = path; CustomResponseBuilder = local?.CustomResponseBuilder; PathAndQuery = CreatePathWithQueryStrings(path, ConnectionSettings, local); }
public override async Task WriteAsync(Stream writableStream, ITransportConfiguration settings, CancellationToken cancellationToken) { MemoryStream buffer = null; var stream = writableStream; BufferIfNeeded(settings, ref buffer, ref stream); var indent = settings.PrettyJson ? Indented : None; await settings.RequestResponseSerializer .SerializeAsync(_serializable, stream, indent, cancellationToken) .ConfigureAwait(false); await FinishStreamAsync(writableStream, buffer, settings, cancellationToken).ConfigureAwait(false); }
FinishStreamAsync(Stream writableStream, MemoryStream buffer, ITransportConfiguration settings, CancellationToken ctx) { var disableDirectStreaming = DisableDirectStreaming ?? settings.DisableDirectStreaming; if (buffer == null || !disableDirectStreaming) { return; } buffer.Position = 0; await buffer.CopyToAsync(writableStream, BufferSize, ctx).ConfigureAwait(false); WrittenBytes ??= buffer.ToArray(); }
string IUrlParameter.GetString(ITransportConfiguration settings) { if (this == MinusOne) { return("-1"); } if (this == Zero) { return("0"); } if (Factor.HasValue && Interval.HasValue) { return(ToString()); } return(Milliseconds.ToString()); }
public override void Write(Stream writableStream, ITransportConfiguration settings) { if (_memoryOfBytes.IsEmpty) { return; } var stream = InitWrite(writableStream, settings, out var buffer, out var disableDirectStreaming); if (!disableDirectStreaming) { stream.Write(_memoryOfBytes.Span); } else { WrittenBytes ??= _memoryOfBytes.Span.ToArray(); buffer = settings.MemoryStreamFactory.Create(WrittenBytes); } FinishStream(writableStream, buffer, settings); }
public override void Write(Stream writableStream, ITransportConfiguration settings) { if (WrittenBytes == null) { return; } var stream = InitWrite(writableStream, settings, out var buffer, out var disableDirectStreaming); if (!disableDirectStreaming) { stream.Write(WrittenBytes, 0, WrittenBytes.Length); } else { buffer = settings.MemoryStreamFactory.Create(WrittenBytes); } FinishStream(writableStream, buffer, settings); }
public override async Task WriteAsync(Stream writableStream, ITransportConfiguration settings, CancellationToken cancellationToken) { if (_memoryOfBytes.IsEmpty) { return; } var stream = InitWrite(writableStream, settings, out var buffer, out var disableDirectStreaming); if (!disableDirectStreaming) { stream.Write(_memoryOfBytes.Span); } else { WrittenBytes ??= _memoryOfBytes.Span.ToArray(); buffer = settings.MemoryStreamFactory.Create(WrittenBytes); } await FinishStreamAsync(writableStream, buffer, settings, cancellationToken).ConfigureAwait(false); }
public override async Task WriteAsync(Stream writableStream, ITransportConfiguration settings, CancellationToken cancellationToken) { if (WrittenBytes == null) { return; } var stream = InitWrite(writableStream, settings, out var buffer, out var disableDirectStreaming); if (!disableDirectStreaming) { await stream.WriteAsync(WrittenBytes, 0, WrittenBytes.Length, cancellationToken) .ConfigureAwait(false); } else { buffer = settings.MemoryStreamFactory.Create(WrittenBytes); } await FinishStreamAsync(writableStream, buffer, settings, cancellationToken).ConfigureAwait(false); }
/// <summary> /// If host/port aren't specified sets to loggly defaults based on selected transport /// </summary> public static ITransportConfiguration GetCoercedToValidConfig(this ITransportConfiguration input) { var newConfig = new TransportConfiguration(); if (input != null) { newConfig.EndpointHostname = input.EndpointHostname; newConfig.EndpointPort = input.EndpointPort; newConfig.LogTransport = input.LogTransport; newConfig.IsOmitTimestamp = input.IsOmitTimestamp; } if (string.IsNullOrEmpty(newConfig.EndpointHostname)) { newConfig.EndpointHostname = "logs-01.loggly.com"; } if (newConfig.EndpointPort == 0) { switch (newConfig.LogTransport) { case LogTransport.Https: newConfig.EndpointPort = 443; break; case LogTransport.SyslogUdp: case LogTransport.SyslogTcp: newConfig.EndpointPort = 514; break; case LogTransport.SyslogSecure: newConfig.EndpointPort = 6514; break; } } return(newConfig); }
/// <summary> /// Initialises a new instance of the <see cref="HostApplicationConfiguration"/> class. /// </summary> /// <param name="transportConfiguration">The <see cref="ITransportConfiguration"/>.</param> /// <param name="queueManager">The embedded persisted message queue.</param> public HostApplicationConfiguration(ITransportConfiguration transportConfiguration, IQueueManager queueManager) : base(transportConfiguration) { this._queueManager = queueManager; }
/// <summary> /// Initialises a new instance of the <see cref="TransportConfiguration"/> class. /// </summary> /// <param name="transportConfiguration">The previously set configuration for the transporter.</param> public TransportConfiguration(ITransportConfiguration transportConfiguration) : this(transportConfiguration.HostAddressConfigurationInstance, transportConfiguration.Transporter) { this.TransportConfigurationInstance = transportConfiguration; }