示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
            }
        }
示例#4
0
 public ConfigFileTextReader(ConfigFileLocationType locationType, params string[] configPaths)
 {
     _path = ConfigFilePathHelper.GetPath(locationType, configPaths);
 }
示例#5
0
 public ConfigFileLineEnumerator(ConfigFileLocationType locationType, params string[] configPaths)
 {
     _path = ConfigFilePathHelper.GetPath(locationType, configPaths);
 }