// implementation
        /// <summary>
        ///		Enumerate child data folders in a parent data folder
        /// </summary>
        /// <param name="parentFolder">
        ///		A folder in a tree whose children to enumerate.
        /// </param>
        /// <param name="level">
        ///		The level number of folders being enumerated, according to the current depth (not an index in <see cref="_levelTraits"/>)
        /// </param>
        /// <returns></returns>
        private List <IRepoFileContainerDescriptor> EnumerateChildren(IRepoFileContainerDescriptor parentFolder, int level)
        {
            Check.Require(level >= Constants.DataFolderLevelLeaf && level < LevelCount);

            ICalendarHistoricalFolderTraits traits = GetLevelTraits(level);

            string parentAbsolutePath = GetAbsolutePath(parentFolder);

            IEnumerable <string> allDirPaths           = DirectoryProvider.EnumerateDirectories(parentAbsolutePath, traits.NameMask);
            List <IRepoFileContainerDescriptor> retval = new List <IRepoFileContainerDescriptor>();

            foreach (string name in allDirPaths.Select((p) => DirectoryProvider.GetLastPathComponent(p)))
            {
                CalendarHistoricalFolderInternalDescriptor internalDesc = traits.GetDescriptor(parentFolder, name);
                if (null != internalDesc)
                {
                    IRepoFileContainerDescriptor descr = GetDescriptor(parentFolder, internalDesc);
                    retval.Add(descr);
                }
                else
                {
                    _log.WarnFormat("Data folder name {0}/{1} is malformed, ignoring", parentFolder == null ? "" : parentFolder.RelativePath, name);
                }
            }

            return(retval);
        }
 /// <summary>
 ///		Get descriptor of an [existing] folder by its name and parent folder.
 /// </summary>
 /// <param name="parent">
 ///		Descriptor of a parent folder
 /// </param>
 /// <param name="folderName">
 ///		The folder name
 /// </param>
 /// <returns>
 ///		<see langword="null"/> if the folder is not a valid historical data folder.
 ///		<see cref="CalendarHistoricalFolderInternalDescriptor"/> instance otherwise
 /// </returns>
 public CalendarHistoricalFolderInternalDescriptor GetDescriptor(CalendarHistoricalFolderInternalDescriptor parent, string folderName)
 {
     Check.RequireArgumentNotNull(parent, "parent");
     Check.Require(parent.Start == new DateTime(parent.Start.Year, parent.Start.Month, 1) &&
                   parent.End.AddMonths(-1) == parent.Start, "Parent of day must be month");
     return(GetDescriptor(parent.Start.Year, parent.Start.Month, folderName));
 }
        /// <summary>
        ///     Get descriptor of a data folder which would contain data item with the specified timestamp at the specified level in
        ///     the data folders tree.
        /// </summary>
        /// <returns>
        ///     Descriptor instance.
        /// </returns>
        /// <param name='timestamp'>
        ///     Data item timestamp.
        /// </param>
        /// <param name='level'>
        ///     Target level.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     The tree does not contain <paramref name="level"/>.
        /// </exception>
        public IRepoFileContainerDescriptor GetTargetFolder(DateTime timestamp, int level)
        {
            Check.DoAssertLambda(level >= Constants.DataFolderLevelLeaf && level <= RelativeTopLevelIndex, () => new ArgumentOutOfRangeException("level"));
            CalendarHistoricalFolderInternalDescriptor descr = GetLevelTraits(level).GetDescriptor(timestamp);

            string relativePath;

            if (level < RelativeTopLevelIndex)
            {
                // not top level - construct path
                StringBuilder bld = GetRelativePath(timestamp, level + 1);
                bld.Append(descr.Name);
                relativePath = bld.ToString();
            }
            else
            {
                relativePath = descr.Name;
            }

            return(new RepoFileContainerDescriptor()
            {
                Start = descr.Start,
                End = descr.End,
                Level = level,
                RelativePath = relativePath
            });
        }
Esempio n. 4
0
        //---------------------------------------------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <param name="year"></param>
        /// <param name="folderName">
        ///		2-digit 1 - based month number
        /// </param>
        /// <returns>
        ///		<see langword="null"/> if folder name is invalid
        /// </returns>
        private CalendarHistoricalFolderInternalDescriptor GetDescriptor(int year, string folderName)
        {
            CalendarHistoricalFolderInternalDescriptor retval = null;

            if (_folderNameRegex.IsMatch(folderName))
            {
                int month = int.Parse(folderName);
                if (month > 0 && month <= 12)
                {
                    retval = GetDescriptor(year, month);
                }
            }
            return(retval);
        }
Esempio n. 5
0
        //---------------------------------------------------------------------------------

        private CalendarHistoricalFolderInternalDescriptor GetDescriptor(int year, int month, int day, string folderName)
        {
            CalendarHistoricalFolderInternalDescriptor retval = null;

            if (_folderNameRegex.IsMatch(folderName))
            {
                int hour = int.Parse(folderName);

                if (hour >= 0 && hour < 24)
                {
                    retval = GetDescriptor(year, month, day, hour);
                }
            }
            return(retval);
        }
        //---------------------------------------------------------------------------------

        /// <summary>
        ///		Returns <see langword="null"/> if folder name is invalid
        /// </summary>
        /// <param name="folderName">
        ///		4-digit year string representing a positive integer
        /// </param>
        /// <returns>
        /// </returns>
        private CalendarHistoricalFolderInternalDescriptor GetDescriptor(string folderName)
        {
            CalendarHistoricalFolderInternalDescriptor retval = null;

            if (_folderNameRegex.IsMatch(folderName))
            {
                int year = int.Parse(folderName);

                if (year > 0)
                {
                    retval = GetDescriptor(year);
                }
            }
            return(retval);
        }
        //---------------------------------------------------------------------------------

        /// <returns>
        ///		<see langword="null"/> if folder name is invalid
        /// </returns>
        /// <exception cref="System.ArgumentOutOfRangeException">
        ///		year is less than 1 or greater than 9999.  -or- month is less than 1 or greater
        ///		than 12.  -or- day is less than 1 or greater than the number of days in month.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        ///		The specified parameters evaluate to less than System.DateTime.MinValue or
        ///		more than System.DateTime.MaxValue.
        /// </exception>
        private static CalendarHistoricalFolderInternalDescriptor GetDescriptor(int year, int month, string folderName)
        {
            CalendarHistoricalFolderInternalDescriptor retval = null;

            if (_folderNameRegex.IsMatch(folderName))
            {
                int day = int.Parse(folderName);

                if (day < 32 && day > 0)
                {
                    try
                    {
                        retval = GetDescriptor(year, month, day);
                    }
                    catch (ArgumentException)
                    {
                        _log.ErrorFormat("Data folder name invalid: {0}", folderName);
                    }
                }
            }
            return(retval);
        }
        private IRepoFileContainerDescriptor GetDescriptor(IRepoFileContainerDescriptor parentFolder, CalendarHistoricalFolderInternalDescriptor folder)
        {
            int level;

            if (parentFolder == null)
            {
                level = RelativeTopLevelIndex;
            }
            else
            {
                level = parentFolder.Level - 1;
            }
            return(new RepoFileContainerDescriptor()
            {
                Start = folder.Start,
                End = folder.End,
                Level = level,
                RelativePath = GetRelativePath(parentFolder, folder.Name)
            });
        }
Esempio n. 9
0
 public CalendarHistoricalFolderInternalDescriptor GetDescriptor(CalendarHistoricalFolderInternalDescriptor parent, string folderName)
 {
     Check.Require(parent.Start == DayDataFolderTraits.GetRangeStartImpl(parent.Start) &&
                   parent.End.AddHours(-1) == parent.Start, "Parent of hour must be day");
     return(GetDescriptor(parent.Start.Year, parent.Start.Month, parent.Start.Day, folderName));
 }
Esempio n. 10
0
 /// <summary>
 ///		Get descriptor of an [existing] folder by its name and parent folder.
 /// </summary>
 /// <param name="parent">
 ///		Descriptor of a parent folder
 /// </param>
 /// <param name="folderName">
 ///		The folder name
 /// </param>
 /// <returns>
 ///		<see langword="null"/> if the folder is not a valid historical data folder.
 ///		<see cref="CalendarHistoricalFolderInternalDescriptor"/> instance otherwise
 /// </returns>
 public CalendarHistoricalFolderInternalDescriptor GetDescriptor(CalendarHistoricalFolderInternalDescriptor parent, string folderName)
 {
     Check.Require(parent.Start == new DateTime(parent.Start.Year, 1, 1) && parent.End.AddYears(-1) == parent.Start, "Parent of month must be year");
     return(GetDescriptor(parent.Start.Year, folderName));
 }
 /// <summary>
 ///		Get descriptor of an [existing] folder by its name and parent folder.
 /// </summary>
 /// <param name="parent">
 ///		Descriptor of a parent folder
 /// </param>
 /// <param name="folderName">
 ///		The folder name
 /// </param>
 /// <returns>
 ///		<see langword="null"/> if the folder is not a valid historical data folder.
 ///		<see cref="CalendarHistoricalFolderInternalDescriptor"/> instance otherwise
 /// </returns>
 public CalendarHistoricalFolderInternalDescriptor GetDescriptor(CalendarHistoricalFolderInternalDescriptor parent, string folderName)
 {
     Check.Require(parent == null, "Year must be top level folder");
     return(GetDescriptor(folderName));
 }