public ConfigFile(string cfgPath, ConfigFileType cfgType) { this.id = ++count; this.path = cfgPath; this.type = cfgType; this.subConfigRef = new List<WeakReference>(); }
/// <summary> /// Find the configuration file for the given <see cref="ConfigFileType"/>. /// </summary> /// <param name="type">The type of configuration file.</param> /// <returns>A <see cref="FileInfo"/> object for the configuration file.</returns> public static FileInfo GetConfigurationFile(ConfigFileType type) { string filename = string.Empty; switch (type) { case ConfigFileType.Application: filename = "GcDashboard.config.xml"; break; case ConfigFileType.Logging: filename = "log4net.config.xml"; break; } //check config directory FileInfo f1 = new FileInfo(filename); if (f1.Exists) return f1; ////check environment directory //FileInfo f2 = new FileInfo(Combine( // "C:\\GcDashboard\\env\\", // Configuration.CommandLine.ConfigurationName, // filename)); //if (f2.Exists) // return f2; //else // log.Debug("File does not exist: " + f2.FullName); return null; }
public ConfigFileNameAttribute(string configFileName, string[] pathDirs, ConfigFileType fileType, Type levelsProvider) { if (String.IsNullOrWhiteSpace(configFileName)) { throw new ArgumentNullException("configFileName can not be null or empty."); } switch (fileType) { case ConfigFileType.Xml: case ConfigFileType.Json: // break; case ConfigFileType.UnKnown: default: throw new ArgumentNullException("fileType invalid."); //break; } this.RelativeDirNames = pathDirs; this.Name = configFileName; this.Type = fileType; bool isAssign = typeof(IConfigLevelProvider).IsAssignableFrom(levelsProvider); if (isAssign) { object obj = Activator.CreateInstance(levelsProvider); this.LevelsProvider = obj as IConfigLevelProvider; } else { throw new ArgumentException("LevelsProvider Type is invalid."); } }
public static Dictionary<string, string> GetSettings(Asset currentAsset, ConfigFileType fileType = ConfigFileType.WebConfig) { var startTime = DateTime.Now; var siteRootAsset = Asset.GetSiteRoot(currentAsset); var siteRootPath = siteRootAsset.AssetPath.ToString(); lock (_threadLock) { var configSettings = (fileType == ConfigFileType.WebConfig ? _webConfigSettings : _siteConfigSettings); var expirationDates = (fileType == ConfigFileType.WebConfig ? _webConfigExpirationDates : _siteConfigExpirationDates); var expirationDate = expirationDates.ContainsKey(siteRootPath) ? expirationDates[siteRootPath] : DateTime.MinValue; var fileName = (fileType == ConfigFileType.WebConfig ? "web.config" : "_Site Config"); if (expirationDate <= DateTime.Now) { Out.DebugWriteLine("Reloading " + fileType.ToString() + " config settings for site (" + siteRootPath + ") from asset"); Asset configAsset = null; // Attempt to load the config asset from expected location if (fileType == ConfigFileType.WebConfig) configAsset = Asset.Load(siteRootPath + "/_Site Configuration/_System Configuration Management/web.config"); else if (fileType == ConfigFileType.SiteConfig) configAsset = Asset.Load(siteRootPath + "/_Site Configuration/_Client Configuration"); // If not in expected location, try navigating up the folder hierarchy starting with the current asset location if (!configAsset.IsLoaded) configAsset = GetConfigAsset(siteRootAsset, fileName, fileType); // Populate settings cache and reset cache expiration LoadConfigSettings(siteRootPath, configAsset, configSettings, fileType); if (expirationDates.ContainsKey(siteRootPath)) expirationDates[siteRootPath] = DateTime.Now.AddSeconds(_cacheExpirationInSeconds); else expirationDates.Add(siteRootPath, DateTime.Now.AddSeconds(_cacheExpirationInSeconds)); } Out.DebugWriteLine("Ih_ConfigFileHelper.GetSettings execution time: " + (DateTime.Now - startTime).TotalMilliseconds.ToString() + "ms"); // Return setting from cache if (configSettings.ContainsKey(siteRootPath)) return configSettings[siteRootPath]; else return null; } }
private static string EnumToFileName(ConfigFileType file) { switch (file) { case ConfigFileType.SolutionsExplorer: return "SolutionsExplorer.opml.config"; default: return file + ".config"; } }
/// <summary> /// Gets the path for the specificed Config file /// </summary> /// <param name = "file">The config.file to get the path for</param> /// <param name = "overwrite">force an overwrite of the config file</param> /// <returns>fully qualified path to the file</returns> /// <remarks> /// Will copy the file from the template directory as requried /// </remarks> public static string GetPathToFile(ConfigFileType file, bool overwrite) { string fileName = EnumToFileName(file); string path = Path.Combine(Globals.ApplicationMapPath, fileName); if (!File.Exists(path) || overwrite) { //Copy from \Config string pathToDefault = Path.Combine(Globals.ApplicationMapPath + Globals.glbConfigFolder, fileName); if ((File.Exists(pathToDefault))) { File.Copy(pathToDefault, path, true); } } return path; }
/// <summary> /// Gets the path for the specificed Config file /// </summary> /// <param name = "file">The config.file to get the path for</param> /// <returns>fully qualified path to the file</returns> /// <remarks> /// Will copy the file from the template directory as requried /// </remarks> public static string GetPathToFile(ConfigFileType file) { return GetPathToFile(file, false); }
public override FileBasedConfig getConfigFile(ConfigFileType fileType) { return SystemReader.getInstance().getConfigFile(fileType); }
public ConfigFileNameAttribute(string[] pathDirs, ConfigFileType fileType) : this(null, pathDirs, fileType, typeof(DefaultConfigLevelProvider)) { }
private static void LoadConfigSettings(string siteRootPath, Asset configAsset, Dictionary<string, Dictionary<string, string>> configSettings, ConfigFileType fileType) { var clientSettings = new Dictionary<string, string>(); switch (fileType) { case ConfigFileType.WebConfig: clientSettings.Add("ih_services_endpoint", configAsset.Raw["ih_services_endpoint"]); clientSettings.Add("ih_services_proxy_endpoint", configAsset.Raw["ih_services_proxy_endpoint"]); clientSettings.Add("ih_services_auth_username", configAsset.Raw["ih_services_auth_username"]); clientSettings.Add("ih_services_auth_password", configAsset.Raw["ih_services_auth_password"]); clientSettings.Add("ih_token_cache_asset_path", configAsset.Raw["ih_token_cache_asset_path"]); break; case ConfigFileType.SiteConfig: clientSettings.Add("seopropertiesdisplayname", configAsset.Raw["seopropertiesdisplayname"]); clientSettings.Add("seopropertiescity", configAsset.Raw["seopropertiescity"]); clientSettings.Add("seopropertiesstate", configAsset.Raw["seopropertiesstate"]); clientSettings.Add("seopropertiesmarketcity", configAsset.Raw["seopropertiesmarketcity"]); clientSettings.Add("seopropertiesmarketstate", configAsset.Raw["seopropertiesmarketstate"]); break; } if (configSettings.ContainsKey(siteRootPath)) configSettings[siteRootPath] = clientSettings; else configSettings.Add(siteRootPath, clientSettings); Out.DebugWriteLine("The " + fileType.ToString() + " settings were loaded successfully"); }
/// <summary> /// 使用指定的配置文件名称、配置文件物理路径初始化 <see cref="ConfigFileChangedEventArgs"/> 类的新实例。 /// </summary> /// <param name="configFileType">发生变化的配置文件的类型。</param> /// <param name="configFileName">发生变化的配置文件的名称。</param> /// <param name="configFileContent">发生变化的配置文件的内容。</param> /// <param name="configPhysicalFilePath">发生变化的配置文件的物理路径。</param> public ConfigFileChangedEventArgs(ConfigFileType configFileType, string configFileName, string configPhysicalFilePath) { this.configFileType = configFileType; this.configFileName = configFileName; this.configPhysicalFilePath = configPhysicalFilePath; }
/// <summary> /// 创建XML配置文件 /// </summary> /// <param name="filePath">目标文件夹路径</param> /// <param name="inputType">配置文件类型</param> /// <returns>创建结果</returns> public static string CreatXml(string filePath, ConfigFileType inputType) { var dir = new DirectoryInfo(string.Format(@"{0}\", filePath)); if (!dir.Exists) { return filePath + @"路径不存在"; } var fileList = GetFiles(dir); var updateFileList = fileList.Select(item => new UpdateFile { FileName = item.Name, FileSize = (int)item.Length, }).ToList(); var xmlSerializer = new XmlSerializer(updateFileList.GetType()); var file = new FileStream(string.Format(@"{0}\dataConfig.{1}", filePath, inputType), FileMode.Create); xmlSerializer.Serialize(file, updateFileList); file.Flush(); file.Close(); return ""; }
public ConfigFileNameAttribute(ConfigFileType fileType, Type levelsProvider) : this(null, Constant.Default_RelativeDirNames, fileType, levelsProvider) { }
public ConfigFileNameAttribute(string[] pathDirs, ConfigFileType fileType, Type levelsProvider) : this(null, pathDirs, fileType, levelsProvider) { }
public override FileBasedConfig getConfigFile(ConfigFileType configType) { string filename = string.Empty; switch (configType) { case ConfigFileType.Global: filename = Path.Combine(FS.globalHome().FullName, ".gitconfig"); break; case ConfigFileType.System: filename = Path.Combine(FS.systemHome().FullName, "gitconfig"); break; case ConfigFileType.Repo: filename = Path.Combine(FS.userHome().FullName, Constants.DOT_GIT); filename = Path.Combine(filename, "config"); break; default: throw new ArgumentException("getConfigFile used unknown Config filetype."); } FileInfo info = new FileInfo(filename); if (info != null) return (new FileBasedConfig(info)); else throw new FileNotFoundException(); }
private static Asset GetConfigAsset(Asset currentAsset, string fileName, ConfigFileType fileType) { if (currentAsset.IsFolder) { List<Asset> childAssets = null; if (fileType == ConfigFileType.WebConfig) childAssets = currentAsset.GetFileList(new AssetParams() { ExcludeFilterStatus = new List<string>() { "Retired", "Archived" } }); else childAssets = currentAsset.GetFilterList(new FilterParams() { ExcludeFilterStatus = new List<string>() { "Retired", "Archived" } }); var configAssets = childAssets.Where(a => a.Label.Equals(fileName, StringComparison.OrdinalIgnoreCase)); if (configAssets.Count() > 1) throw new Exception("Multple " + fileName + " assets found at: " + currentAsset.AssetPath); var configAsset = configAssets.SingleOrDefault(); if (configAsset != null && configAsset.IsLoaded) { Out.DebugWriteLine("Found " + fileName + " asset at: " + configAsset.AssetPath); return configAsset; } } if (fileType == ConfigFileType.WebConfig && currentAsset.Parent != null) return GetConfigAsset(currentAsset.Parent, fileName, fileType); else throw new Exception("No " + fileName + " assets found"); }
/// <summary> /// Returns the GitSharp configuration file from the OS-dependant location. /// </summary> /// <returns></returns> public abstract FileBasedConfig getConfigFile(ConfigFileType configType);
public ConfigFileNameAttribute(string configFileName, ConfigFileType fileType) : this(configFileName, Constant.Default_RelativeDirNames, fileType, typeof(DefaultConfigLevelProvider)) { }