public static List <string> GetFiles(ConfigFileLocationType locationType, params string[] configPaths) { var path = GetPath(locationType, configPaths); var fileList = new List <string>(); fileList.AddRange(Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)); return(fileList); }
internal static string GetPath(ConfigFileLocationType locationType, params string[] configPaths) { var dirs = new List <string>(); if (locationType == ConfigFileLocationType.Default) { var directory = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); dirs.Add(directory); } else if (locationType == ConfigFileLocationType.Web) { dirs.Add(System.AppDomain.CurrentDomain.RelativeSearchPath); } dirs.AddRange(configPaths); var path = Path.Combine(dirs.ToArray()); if (!(Directory.Exists(path) || File.Exists(path))) { throw new ArgumentException(string.Format("Directory '{0} does not exist.", path)); } return(path); }
static CalendarImpl() { if (!_cacheCalendarData) { const string filenameSuffix = ".txt"; #if !NETCOREAPP2_1 //TODO: fix it try { if (System.AppDomain.CurrentDomain.DomainManager.HostExecutionContextManager.ToString().IndexOf("System.Web") >= 0) { FileLocationType = ConfigFileLocationType.Web; } } catch { // ignore the error for now. } #endif var calendarFiles = ConfigFilePathHelper.GetFiles(FileLocationType, "Data", "Calendars") .Where(x => x.EndsWith(filenameSuffix)) .ToArray(); var calendars = calendarFiles.Select(x => { var calendarName = Path.GetFileNameWithoutExtension(x).ToUpper(); var s = File.ReadAllText(x); var calendarHolidays = DataContractJsonObjectSerializer.Deserialize <CalendarHoliday>(s); return(new CalendarImpl(calendarName, calendarHolidays)); }); AllCalendars = calendars.ToDictionary(x => x.CalendarName, x => x as ICalendar); } }
public ConfigFileTextReader(ConfigFileLocationType locationType, params string[] configPaths) { _path = ConfigFilePathHelper.GetPath(locationType, configPaths); }
public ConfigFileLineEnumerator(ConfigFileLocationType locationType, params string[] configPaths) { _path = ConfigFilePathHelper.GetPath(locationType, configPaths); }