コード例 #1
0
        public static void Validate(DeviceServiceSettingsConfig deviceServiceSettingsConfig)
        {
            var errorMessages = new StringBuilder();

            ValidateDeviceServiceSettingsConfig(errorMessages, deviceServiceSettingsConfig);
            ValidateNocMeetingConfigs(errorMessages, deviceServiceSettingsConfig.DeviceConfigs);

            if (errorMessages.Length != 0)
            {
                throw new ConfigurationSettingMissingException(errorMessages.ToString());
            }
        }
        public static DeviceServiceSettings MapToWebExSettings(DeviceServiceSettingsConfig deviceServiceSettingsConfig)
        {
            var devices = new List <Device>();

            foreach (var deviceConfig in deviceServiceSettingsConfig.DeviceConfigs)
            {
                devices.Add(new Device(deviceConfig.Identifier, deviceConfig.Type, deviceConfig.OtaKey));
            }

            return(new DeviceServiceSettings(
                       deviceServiceSettingsConfig.BaseUrl,
                       deviceServiceSettingsConfig.AccessToken,
                       deviceServiceSettingsConfig.HttpProxyUrl,
                       devices));
        }
コード例 #3
0
        private DeviceServiceSettingsConfig GetDeviceServiceSettingsPreValidated()
        {
            const string deviceServiceKey            = "DeviceService";
            var          deviceServiceSettingsConfig = _configurationRoot.GetSection(deviceServiceKey).Get <DeviceServiceSettingsConfig>();

            if (deviceServiceSettingsConfig != null)
            {
                deviceServiceSettingsConfig.HttpProxyUrl = GetHttpProxyUrl();
                var deviceConfigs = _configurationRoot.GetSection($"{deviceServiceKey}:Devices").Get <DeviceConfig[]>();
                deviceServiceSettingsConfig.DeviceConfigs = deviceConfigs ?? Array.Empty <DeviceConfig>();
            }
            else
            {
                deviceServiceSettingsConfig = new DeviceServiceSettingsConfig
                {
                    DeviceConfigs = Array.Empty <DeviceConfig>()
                };
            }

            return(deviceServiceSettingsConfig);
        }
コード例 #4
0
        private static void ValidateDeviceServiceSettingsConfig(StringBuilder errorMessages, DeviceServiceSettingsConfig deviceServiceSettingsConfig)
        {
            var(baseUrl, baseUrlErrorMessage)   = ValidatorUrl.ValidateAndFix($"DeviceServiceSettings.{nameof(deviceServiceSettingsConfig.BaseUrl)}", deviceServiceSettingsConfig.BaseUrl);
            deviceServiceSettingsConfig.BaseUrl = baseUrl;
            errorMessages.AppendLineIfNotNull(baseUrlErrorMessage);
            errorMessages.AppendLineIfNotNull(ValidatorString.Validate($"DeviceServiceSettings.{nameof(deviceServiceSettingsConfig.AccessToken)}", deviceServiceSettingsConfig.AccessToken));

            if (!deviceServiceSettingsConfig.DeviceConfigs.Any())
            {
                errorMessages.AppendLine($"The property: \"DeviceServiceSettings.Devices\" collection is Empty. The collection must contain at least 1 item.");
            }
        }