Exemple #1
0
        protected override object OnCreate(string configName, Type type)
        {
            string fileFullPath = ConfigPathHelper.GetConfigFileFullPath(configName);

            object obj = LocalConfigurationManager.Instance.GetConfigInstance(fileFullPath, type);

            if (obj != null)
            {
                return(obj);
            }

            //download from remote!
            DownloadRemoteConfig(GenerateUniqueConfigName(configName, type));

            return(LocalConfigurationManager.Instance.GetConfigInstance(fileFullPath, type));
        }
Exemple #2
0
        private void DownloadRemoteConfig(string configName_Type_Key)
        {
            //get remote config download func
            var func = _RemoteFunctions.SafeGet <string, Func <object> >(configName_Type_Key) ?? throw new KeyNotFoundException($"The Configuration key[{configName_Type_Key}] is not registered!");

            string fileFullPath = ConfigPathHelper.GetConfigFileFullPath(configName_Type_Key.Substring(0, configName_Type_Key.IndexOf(ConfigurationConst.SPLITE_SYMBOL)));

            string tmpFile = fileFullPath + "." + Guid.NewGuid().ToString("N");

            try
            {
                _logger.LogDebug($"config '{fileFullPath}' pulling...");

                //get remote config
                var config = func.Invoke();
                SaveToFile(tmpFile, config);
                //backup
                //BackUpConfig(fileFullPath);

                //this sucks, but this is to reduce the confliction of writing and reading
                // because of sucks of Windows, the copyfile is non-transaction.
                // we must remove the file before change its name!!!
                if (File.Exists(fileFullPath))
                {
                    File.Delete(fileFullPath);
                }

                File.Move(tmpFile, fileFullPath);

                _logger.LogDebug($"config '{fileFullPath}' pull success.");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"config '{fileFullPath}' pull error");
            }
            finally
            {
                if (File.Exists(tmpFile))
                {
                    File.Delete(tmpFile);
                }
            }
        }
Exemple #3
0
 protected override object OnCreate(string configName, Type type)
 {
     return(GetConfigInstance(ConfigPathHelper.GetConfigFileFullPath(configName), type));
 }