Exemplo n.º 1
0
        /// <summary>
        /// load as an asynchronous operation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>Task&lt;T&gt;.</returns>
        public async Task <T> ReadSettingAsync <T>() where T : class
        {
            try
            {
                var file = _cloudRootDirectory.GetFileReference(_fileName);

                if (await file.ExistsAsync())
                {
                    var str = await file.DownloadTextAsync();

                    Log.Debug($"Loading Azure DocumentDb Settings Data (1): {str}");
                    OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs()
                    {
                        Data = str
                    });

                    var settings = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(str);

                    return(settings);
                }

                return(null);
            }
            finally
            {
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads this instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>T.</returns>
        public T ReadSetting <T>() where T : class
        {
            OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs()
            {
                Data = _currentValue
            });

            return(_currentValue);
        }
Exemplo n.º 3
0
        public T ReadSetting <T>(string key, T defaultValue = default(T))
        {
            OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs()
            {
                Data = _currentValue
            });

            return(_currentValue[key]);
        }
        /// <summary>
        /// Loads this instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>T.</returns>
        public T ReadSetting <T>() where T : class
        {
            var response = _client.CreateDocumentQuery(_collectionLink).Select(x => x).OrderByDescending(x => x.Timestamp).ToList().FirstOrDefault();
            T   result;

            if (response == null)
            {
                return(default(T));
            }

            try
            {
                if (_jsonSettings != null)
                {
                    var str = response.ToString();

                    Log.Debug($"Loading Azure DocumentDb Settings Data (1): {str}");
                    OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs()
                    {
                        Data = str
                    });

                    result = JsonConvert.DeserializeObject <T>(str, _jsonSettings);
                }
                else
                {
                    result = (T)(dynamic)response;
                }
            }
            catch (Exception e) when(_jsonSettings != null)
            {
                Log.Warning(e, "Azure DocumentDb Failed to Load");

                try
                {
                    var str = response.ToString();

                    Log.Debug($"Loading Azure DocumentDb Settings Data (2): {str}");

                    result = JsonConvert.DeserializeObject <T>(str, _jsonSettings);
                }
                catch
                {
                    throw e;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public T ReadSetting <T>() where T : class
        {
            if (!System.IO.File.Exists(_fileName))
            {
                return(default(T));
            }

            var str = System.IO.File.ReadAllText(_fileName);

            Log.Debug($"Loading JsonNet Settings Data: {str}");

            OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs()
            {
                Data = str
            });

            var settings = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(str, _jsonSettings);

            return(settings);
        }