Example #1
0
 private bool CanContainItemsFromRange(
     IRepoFileContainerDescriptor folder,
     DateTime rangeStart,
     DateTime rangeEnd)
 {
     return(folder.Start < rangeEnd && folder.End > rangeStart);
 }
Example #2
0
        private List <IRepoFileContainerDescriptor> EnumerateMonths(
            IRepoFileContainerDescriptor yearDir)
        {
            Check.DoAssertLambda(yearDir.Level == FolderLevelYear, () => new ArgumentException("Year level expected in yearDir"));

            List <IRepoFileContainerDescriptor> retval = new List <IRepoFileContainerDescriptor>();

            string root = Path.Combine(this.RootPath, yearDir.RelativePath);

            if (_directoryProvider.Exists(root))
            {
                IEnumerable <string> monthDirs = _directoryProvider.EnumerateDirectories(
                    root
                    , _dirLevelTraits[FolderLevelMonth].DirNameMask);
                foreach (string monthDir in monthDirs)
                {
                    int month = 0;
                    if (_dirLevelTraits[FolderLevelMonth].IsValidDir(_directoryProvider.GetLastPathComponent(monthDir), ref month))
                    {
                        IRepoFileContainerDescriptor descrMonth =
                            _dirLevelTraits[FolderLevelMonth].GetFolderDescriptorByRange(
                                yearDir.Start.AddMonths(month - 1));

                        retval.Add(descrMonth);
                    }
                }         // foreach (string monthDir in monthDirs)
            }             // if (Directory.Exists(this.RootPath))
            return(retval);
        }
Example #3
0
 internal RepoFileContainerBrowser(
     IFolder folder
     , IRepoFileContainerDescriptor dataFileContainer)
 {
     _folder    = folder;
     _container = dataFileContainer;
 }
        // 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(IRepoFileContainerDescriptor 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));
 }
Example #6
0
        /// <summary>
        ///		Get browser which provides access to data files in a leaf data folder.
        /// </summary>
        /// <param name="folder">
        ///		The repository folder for which the browser is required.
        /// </param>
        /// <param name="fileContainer">
        ///		Descriptor of leaf data folder.
        /// </param>
        /// <returns>
        ///		New browser instance.
        /// </returns>
        public virtual IRepoFileContainerBrowser GetDataFileBrowser(IFolder folder, IRepoFileContainerDescriptor fileContainer)
        {
            CheckHelper.CheckRepositoryNotDisposed(Repository);
            Check.DoRequireArgumentNotNull(folder, "folder");
            Check.DoRequireArgumentNotNull(fileContainer, "fileContainer");

            return(new RepoFileContainerBrowser(folder, fileContainer));
        }
Example #7
0
        protected virtual IRepoFileContainerDescriptor GetFolderDescriptor(IRepoFileContainerDescriptor parent, string folderName)
        {
            int monthNumber = 0;

            if (IsValidDir(folderName, ref monthNumber))
            {
                return(GetFolderDescriptorByRange(parent.Start.AddMonths(monthNumber - 1)));
            }
            return(null);
        }
 private static string GetRelativePath(IRepoFileContainerDescriptor parentFolder, string folderName)
 {
     if (parentFolder == null)
     {
         return(folderName);
     }
     else
     {
         return(Path.Combine(parentFolder.RelativePath, folderName));
     }
 }
        protected override IRepoFileContainerDescriptor GetFolderDescriptor(IRepoFileContainerDescriptor parent, string folderName)
        {
            Check.Require(null == parent);
            int monthNumber = 0;

            if (IsValidDir(folderName, ref monthNumber))
            {
                return(GetFolderDescriptorByRange(parent.Start.AddMonths(monthNumber - 1)));
            }
            return(null);
        }
        /// <summary>
        ///		Enumerate child data folders in the [sub]tree with root at <see cref="RootPath"/>.
        /// </summary>
        /// <param name="root">
        ///		Descriptor of the data folder whose children to enumerate
        /// </param>
        /// <param name="level">
        ///		Level at which to find data folders; must be the child of the <paramref name="root"/>, i.e. equal to <code>root.Level - 1</code>.
        /// </param>
        /// <returns>
        ///		List of children of <paramref name="root"/>.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///     <paramref name="level"/> does not represent <paramref name="root"/>'s children.
        /// </exception>
        public List <IRepoFileContainerDescriptor> Enumerate(IRepoFileContainerDescriptor root, int level)
        {
            if (root == null)
            {
                return(Enumerate(level));
            }

            Check.DoCheckArgument(level >= Constants.DataFolderLevelLeaf, "Leaf level folders do not have child folders");

            Check.DoCheckArgument(level == root.Level - 1, "This implementation enumerates children only");
            return(EnumerateChildren(root, root.Level - 1));
        }
Example #11
0
        /// <summary>
        ///		Enumerate descendant data folders in the [sub]tree with root at <paramref name="root"/>
        /// </summary>
        /// <param name="root">
        ///		One of the descendants of <see cref="RootPath"/> among the descendants of which
        ///		to search; specify <see langword="null"/> to search in <see cref="RootPath"/>
        /// </param>
        /// <param name="level">
        ///		Level at which to find data folders
        ///			0 - leaf level
        ///			1 - months
        ///			2 - years
        /// </param>
        /// <returns>
        ///		List of data file container descriptors containing data items falling
        ///		into the specified range (<paramref name="rangeStart"/> - <paramref name="rangeEnd"/>)
        /// </returns>
        public List <IRepoFileContainerDescriptor> Enumerate(
            IRepoFileContainerDescriptor root, int level)
        {
            if (null == root)
            {
                return(Enumerate(level));
            }

            // naturally this must be dropped/revised when adding more levels
            Check.Require(root.Level == FolderLevelYear && level == FolderLevelMonth
                          , "Month level expected. Can only enumerate months in a year root in year-month scheme.");

            return(EnumerateMonths(root));
        }
Example #12
0
        internal List <IRepoFileContainerDescriptor> Enumerate(
            IDirectoryProvider dirProvider, string rootPath, IRepoFileContainerDescriptor parent)
        {
            IEnumerable <string> allDirPaths           = dirProvider.EnumerateDirectories(rootPath, DirNameMask);
            List <IRepoFileContainerDescriptor> retval = new List <IRepoFileContainerDescriptor>();

            foreach (string name in allDirPaths.Select((p) => dirProvider.GetLastPathComponent(p)))
            {
                IRepoFileContainerDescriptor descr = GetFolderDescriptor(parent, name);
                if (null != descr)
                {
                    retval.Add(descr);
                }
            }

            return(retval);
        }
Example #13
0
        /// <summary>
        ///		Find existing leaf data folder and [optionally] create if it is
        ///		missing. Primarily intended for use by writers.
        /// </summary>
        /// <param name="itemTimestamp">
        ///		The timestamp of an item for which to find the existing
        ///		or create new leaf folder
        /// </param>
        /// <returns>
        ///		Existing leaf folder
        ///		null if the folder is missing and <paramref name="createIfMissing"/>
        ///		is <see langword="false"/>
        /// </returns>
        public IDataFolder GetLeafFolder(DateTime itemTimestamp, bool createIfMissing)
        {
            IDataFolder retval = null;

            if (this.IsLeafFolder)
            {
                if (this.Start <= itemTimestamp && this.End > itemTimestamp)
                {
                    retval = this;
                }
            }
            else             // if (this.IsLeafFolder)
            {
                LoadSubFolders(false);
                retval = _childDataFolders.GetOwner(itemTimestamp);
                if (retval == null && createIfMissing)
                {
                    // creating target subfolder; this will be a child folder of this data folder
                    IRepoFileContainerDescriptor descr = _repoFolder.DataFoldersExplorer.GetTargetFolder(
                        itemTimestamp, this.Level - 1);

                    retval = new DataFolder(this, descr);

                    retval.EnsureDirectoryExists();

                    _childDataFolders.Add(retval);
                }
                if (retval != null)
                {
                    if (retval.Level > 0)
                    {
                        // not a leaf folder yet - drilling down all the way
                        retval = retval.GetLeafFolder(itemTimestamp, createIfMissing);
                    }
                }
            }

            Check.Ensure(null != retval || !createIfMissing);
            Check.Ensure(null == retval || retval.IsLeafFolder);
            Check.Ensure(null == retval || (retval.Start <= itemTimestamp && retval.End > itemTimestamp));

            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)
            });
        }
Example #15
0
        /// <summary>
        ///		Enumerate descendant data folders in the [sub]tree with root at <see cref="RootPath"/>
        /// </summary>
        /// <param name="level">
        ///		Level at which to find data folders
        ///			0 - leaf level
        ///			1 - months
        ///			2 - years
        /// </param>
        /// <returns>
        ///		List of data file container descriptors containing data items falling
        ///		into the specified range (<paramref name="rangeStart"/> - <paramref name="rangeEnd"/>)
        /// </returns>
        public List <IRepoFileContainerDescriptor> Enumerate(int level)
        {
            if (level < 0 || level >= this.LevelCount)
            {
                throw new ArgumentOutOfRangeException("level");
            }

            List <IRepoFileContainerDescriptor> retval = new List <IRepoFileContainerDescriptor>();

            if (_directoryProvider.Exists(this.RootPath))
            {
                IEnumerable <string> yearDirs = _directoryProvider.EnumerateDirectories(
                    this.RootPath
                    , _dirLevelTraits[FolderLevelYear].DirNameMask);
                foreach (string yearDir in yearDirs)
                {
                    string dirName = _directoryProvider.GetLastPathComponent(yearDir);
                    int    year    = 0;
                    if (_dirLevelTraits[FolderLevelYear].IsValidDir(dirName, ref year))
                    {
                        IRepoFileContainerDescriptor descrYear =
                            _dirLevelTraits[FolderLevelYear].GetFolderDescriptorByRange(
                                new DateTime(year, 1, 1));

                        if (level == YearMonthHistoricalFoldersTraits.FolderLevelYear)
                        {
                            retval.Add(descrYear);
                        }
                        else                         // if (level == YearMonthHistoricalFoldersTraits.FolderLevelYear)
                        {
                            retval.AddRange(EnumerateMonths(descrYear));
                        } // else // if (level == YearMonthHistoricalFoldersTraits.FolderLevelYear)
                    }     // if (_dirLevelTraits[FolderLevelYear].IsValidDir(yearDir.Name, ref year))
                }         // foreach (string yearDir in yearDirs)
            }             // if (root.Exists)
            return(retval);
        }
Example #16
0
 /// <summary>
 ///		Real existing data folder
 /// </summary>
 /// <param name="parentDataFolder"></param>
 /// <param name="folderDescriptor"></param>
 public DataFolder(DataFolder parentDataFolder, IRepoFileContainerDescriptor folderDescriptor)
 {
     _parentDataFolder = parentDataFolder;
     _folderDescriptor = folderDescriptor;
     _repoFolder       = parentDataFolder.RepoFolder;
 }
Example #17
0
 public CalendarHistoricalFolderInternalDescriptor GetDescriptor(IRepoFileContainerDescriptor 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));
 }
 public static int CompareFileContainers(
     IRepoFileContainerDescriptor c1, IRepoFileContainerDescriptor c2)
 {
     return(DateTime.Compare(c1.Start, c1.Start));
 }
 /// <summary>
 ///		Get absolute path of a data folder
 /// </summary>
 /// <param name="folder">
 ///		Descriptor of the data folder; <see langword="null"/> considered data folders root.
 /// </param>
 /// <returns></returns>
 private string GetAbsolutePath(IRepoFileContainerDescriptor folder)
 {
     return(GetAbsolutePath(folder == null ? string.Empty : folder.RelativePath));
 }
 /// <summary>
 ///		Get full path of a data folder by its descriptor
 /// </summary>
 /// <param name="dataFolder"></param>
 /// <returns></returns>
 private string GetFullPath(IRepoFileContainerDescriptor dataFolder)
 {
     return(Path.Combine(RootPath, dataFolder.RelativePath));
 }
 /// <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(IRepoFileContainerDescriptor parent, string folderName)
 {
     Check.Require(parent == null, "Year must be top level folder");
     return(GetDescriptor(folderName));
 }