public IotHubClientSettings(ISettingsProvider settingsProvider) { int inboundMessages; if (!settingsProvider.TryGetIntegerSetting(MaxPendingInboundMessagesSetting, out inboundMessages) || inboundMessages <= 0) { inboundMessages = MaxPendingInboundMessagesDefaultValue; } this.MaxPendingInboundMessages = Math.Min(inboundMessages, ushort.MaxValue); // reflects packet id domain per MQTT spec. int outboundMessages; if (!settingsProvider.TryGetIntegerSetting(MaxPendingOutboundMessagesSetting, out outboundMessages) || outboundMessages <= 0) { outboundMessages = MaxPendingOutboundMessagesDefaultValue; } this.MaxPendingOutboundMessages = Math.Min(outboundMessages, ushort.MaxValue >> 2); // limited due to separation of packet id domains for QoS 1 and 2. int qos; this.DefaultPublishToClientQoS = settingsProvider.TryGetIntegerSetting(DefaultPublishToClientQoSSetting, out qos) ? (QualityOfService)qos : QualityOfService.AtLeastOnce; string connectionString = settingsProvider.GetSetting(IotHubConnectionStringSetting); if (connectionString.IndexOf("DeviceId=", StringComparison.OrdinalIgnoreCase) == -1) { connectionString += ";DeviceId=stub"; } this.IotHubConnectionString = connectionString; int retransmissionCount; if (!settingsProvider.TryGetIntegerSetting(MaxOutboundRetransmissionCountSetting, out retransmissionCount) || (retransmissionCount < 0)) { retransmissionCount = NoMaxOutboundRetransmissionCountValue; } this.MaxOutboundRetransmissionCount = retransmissionCount; this.PassThroughUnmatchedMessages = settingsProvider.GetBooleanSetting(PassThroughUnmatchedMessagesSetting, false); this.ServicePropertyPrefix = settingsProvider.GetSetting(ServicePropertyPrefixSetting, string.Empty); }
public Settings(ISettingsProvider settingsProvider) { int inboundMessages; if (!settingsProvider.TryGetIntegerSetting(MaxPendingInboundMessagesSetting, out inboundMessages) || inboundMessages <= 0) { inboundMessages = MaxPendingInboundMessagesDefaultValue; } this.MaxPendingInboundMessages = Math.Min(inboundMessages, ushort.MaxValue); // reflects packet id domain per MQTT spec. int outboundMessages; if (!settingsProvider.TryGetIntegerSetting(MaxPendingOutboundMessagesSetting, out outboundMessages) || outboundMessages <= 0) { outboundMessages = MaxPendingOutboundMessagesDefaultValue; } this.MaxPendingOutboundMessages = Math.Min(outboundMessages, ushort.MaxValue >> 2); // limited due to separation of packet id domains for QoS 1 and 2. TimeSpan timeout; this.ConnectArrivalTimeout = settingsProvider.TryGetTimeSpanSetting(ConnectArrivalTimeoutSetting, out timeout) && timeout > TimeSpan.Zero ? (TimeSpan?)timeout : null; int qos; this.DefaultPublishToClientQoS = settingsProvider.TryGetIntegerSetting(DefaultPublishToClientQoSSetting, out qos) ? (QualityOfService)qos : QualityOfService.AtLeastOnce; this.IotHubConnectionString = settingsProvider.GetSetting(IotHubConnectionStringSetting); this.MaxKeepAliveTimeout = settingsProvider.TryGetTimeSpanSetting(MaxKeepAliveTimeoutSetting, out timeout) ? timeout : (TimeSpan?)null; if (!settingsProvider.TryGetSetting(RetainPropertyNameSetting, out this.retainPropertyName)) { this.retainPropertyName = RetainPropertyNameDefaultValue; } if (!settingsProvider.TryGetSetting(DupPropertyNameSetting, out this.dupPropertyName)) { this.dupPropertyName = DupPropertyNameDefaultValue; } if (!settingsProvider.TryGetSetting(QoSPropertyNameSetting, out this.qosPropertyName)) { this.qosPropertyName = QoSPropertyNameDefaultValue; } this.deviceReceiveAckTimeout = settingsProvider.TryGetTimeSpanSetting(DeviceReceiveAckTimeoutSetting, out timeout) && timeout > TimeSpan.Zero ? timeout : (TimeSpan?)null; int retransmissionCount; if (!settingsProvider.TryGetIntegerSetting(MaxOutboundRetransmissionCountSetting, out retransmissionCount) || (retransmissionCount < 0)) { retransmissionCount = NoMaxOutboundRetransmissionCountValue; } this.MaxOutboundRetransmissionCount = retransmissionCount; this.PassThroughUnmatchedMessages = settingsProvider.GetBooleanSetting(PassThroughUnmatchedMessagesSetting, false); this.ServicePropertyPrefix = settingsProvider.GetSetting(ServicePropertyPrefixSetting, string.Empty); }