Ejemplo n.º 1
0
        public AppSettings()
        {
            try
            {
                var memoryCacheProvider   = MemoryCacheProvider.GetInstance();
                var declaringTypeFullName = MethodBase.GetCurrentMethod()?.DeclaringType?.FullName;
                var filePathKey           = $"{declaringTypeFullName}{@".FilePath"}";
                var filePath = (object)memoryCacheProvider.Get(filePathKey);
                if (null == filePath)
                {
                    AppSettingsRepository?.MergeAndCopyToUserDirectory(this);
                    memoryCacheProvider.Put(filePathKey, FilePath, TimeSpan.FromDays(1));
                }

                if (null != FileName && null != UserProfileDirectory)
                {
                    FilePath = (string)(filePath ?? Path.Combine(UserProfileDirectory, FileName));
                }

                var useGlobalDatabaseConnectionSettingsKey =
                    $"{declaringTypeFullName}{@".UseGlobalDatabaseConnectionSettings"}";
                var useGlobalDatabaseConnectionSettings =
                    (object)memoryCacheProvider.Get(useGlobalDatabaseConnectionSettingsKey);
                if (null == useGlobalDatabaseConnectionSettings)
                {
                    memoryCacheProvider.Put(useGlobalDatabaseConnectionSettingsKey, UseGlobalDatabaseConnectionSettings,
                                            TimeSpan.FromDays(1));
                    if (UseGlobalDatabaseConnectionSettings)
                    {
                        var appSettingsModel = new NetAppCommon.AppSettings.Models.AppSettings();
                        ConnectionString = appSettingsModel.ConnectionString;
                        AppSettingsRepository?.MergeAndSave(this);
                    }
                }
            }
            catch (Exception e)
            {
                _log4Net.Error($"\n{e.GetType()}\n{e.InnerException?.GetType()}\n{e.Message}\n{e.StackTrace}\n", e);
            }
        }