예제 #1
0
 public AllorsDirectoryInfo(DirectoryInfo directoryInfo)
 {
     this.directoryInfo = directoryInfo;
     if (directoryInfo.Parent != null)
     {
         this.parent = new AllorsDirectoryInfo(directoryInfo.Parent);
     }
 }
예제 #2
0
 public AllorsDirectoryInfo(DirectoryInfo directoryInfo)
 {
     this.directoryInfo = directoryInfo;
     if (directoryInfo.Parent != null)
     {
         this.parent = new AllorsDirectoryInfo(directoryInfo.Parent);
     }
 }
예제 #3
0
        public string GetRelativeName(DirectoryInfo baseDirectoryInfo)
        {
            var baseDirectory = new AllorsDirectoryInfo(baseDirectoryInfo);
            var directory     = new AllorsDirectoryInfo(this.fileInfo.Directory);

            var relativePath = directory.GetRelativeName(baseDirectory);

            return(relativePath == null ? null : Path.Combine(relativePath, this.fileInfo.Name));
        }
예제 #4
0
        private AllorsDirectoryInfo GetCommonAncestor(AllorsDirectoryInfo destination)
        {
            if (destination.IsAncestor(this))
            {
                return(this);
            }

            return(this.parent.GetCommonAncestor(destination));
        }
예제 #5
0
 private void BuildAncestors(AllorsDirectoryInfo root, List <AllorsDirectoryInfo> ancestors)
 {
     if (!this.directoryInfo.FullName.Equals(this.directoryInfo.Root.FullName))
     {
         if (!this.directoryInfo.FullName.Equals(root.directoryInfo.FullName))
         {
             ancestors.Add(this);
             this.parent.BuildAncestors(root, ancestors);
         }
     }
 }
예제 #6
0
        public string GetRelativeName(DirectoryInfo baseDirectoryInfo)
        {
            var baseDirectory = new AllorsDirectoryInfo(baseDirectoryInfo);
            var directory = new AllorsDirectoryInfo(fileInfo.Directory);

            string relativePath = directory.GetRelativeName(baseDirectory);
            if (relativePath == null)
            {
                return null;
            }

            return Path.Combine(relativePath, this.fileInfo.Name);
        }
예제 #7
0
        private bool IsAncestor(AllorsDirectoryInfo ancestor)
        {
            if (this.directoryInfo.FullName.Equals(ancestor.directoryInfo.FullName))
            {
                return(true);
            }

            if (this.parent != null)
            {
                return(this.parent.IsAncestor(ancestor));
            }

            return(false);
        }
예제 #8
0
        public string GetRelativeName(DirectoryInfo baseDirectoryInfo)
        {
            var baseDirectory = new AllorsDirectoryInfo(baseDirectoryInfo);
            var directory     = new AllorsDirectoryInfo(fileInfo.Directory);

            string relativePath = directory.GetRelativeName(baseDirectory);

            if (relativePath == null)
            {
                return(null);
            }

            return(Path.Combine(relativePath, this.fileInfo.Name));
        }
예제 #9
0
        internal string GetRelativeName(AllorsDirectoryInfo baseDirectory)
        {
            if (this.directoryInfo.Root.FullName.Equals(baseDirectory.directoryInfo.Root.FullName))
            {
                AllorsDirectoryInfo commonAncestor = this.GetCommonAncestor(baseDirectory);

                var ancestors = new List <AllorsDirectoryInfo>();
                this.BuildAncestors(commonAncestor, ancestors);

                var baseAncestors = new List <AllorsDirectoryInfo>();
                baseDirectory.BuildAncestors(commonAncestor, baseAncestors);

                var relativePath = new StringBuilder();
                foreach (AllorsDirectoryInfo baseAncestor in baseAncestors)
                {
                    if (relativePath.Length > 0)
                    {
                        relativePath.Append(Path.DirectorySeparatorChar);
                    }

                    relativePath.Append("..");
                }

                for (int i = ancestors.Count - 1; i >= 0; --i)
                {
                    AllorsDirectoryInfo ancestor = ancestors[i];
                    if (relativePath.Length > 0)
                    {
                        relativePath.Append(Path.DirectorySeparatorChar);
                    }

                    relativePath.Append(ancestor.directoryInfo.Name);
                }

                return(relativePath.ToString());
            }

            return(null);
        }
예제 #10
0
        internal string GetRelativeName(AllorsDirectoryInfo baseDirectory)
        {
            if (this.directoryInfo.Root.FullName.Equals(baseDirectory.directoryInfo.Root.FullName))
            {
                AllorsDirectoryInfo commonAncestor = this.GetCommonAncestor(baseDirectory);

                var ancestors = new List<AllorsDirectoryInfo>();
                this.BuildAncestors(commonAncestor, ancestors);

                var baseAncestors = new List<AllorsDirectoryInfo>();
                baseDirectory.BuildAncestors(commonAncestor, baseAncestors);

                var relativePath = new StringBuilder();
                foreach (AllorsDirectoryInfo baseAncestor in baseAncestors)
                {
                    if (relativePath.Length > 0)
                    {
                        relativePath.Append(Path.DirectorySeparatorChar);
                    }

                    relativePath.Append("..");
                }

                for (int i = ancestors.Count - 1; i >= 0; --i)
                {
                    AllorsDirectoryInfo ancestor = ancestors[i];
                    if (relativePath.Length > 0)
                    {
                        relativePath.Append(Path.DirectorySeparatorChar);
                    }

                    relativePath.Append(ancestor.directoryInfo.Name);
                }

                return relativePath.ToString();
            }

            return null;
        }
 private AllorsDirectoryInfo GetCommonAncestor(AllorsDirectoryInfo destination) => destination.IsAncestor(this) ? this : this.Parent.GetCommonAncestor(destination);
예제 #12
0
        private bool IsAncestor(AllorsDirectoryInfo ancestor)
        {
            if (this.directoryInfo.FullName.Equals(ancestor.directoryInfo.FullName))
            {
                return true;
            }

            if (this.parent != null)
            {
                return this.parent.IsAncestor(ancestor);
            }

            return false;
        }
예제 #13
0
        private AllorsDirectoryInfo GetCommonAncestor(AllorsDirectoryInfo destination)
        {
            if (destination.IsAncestor(this))
            {
                return this;
            }

            return this.parent.GetCommonAncestor(destination);
        }
예제 #14
0
 private void BuildAncestors(AllorsDirectoryInfo root, List<AllorsDirectoryInfo> ancestors)
 {
     if (!this.directoryInfo.FullName.Equals(this.directoryInfo.Root.FullName))
     {
         if (!this.directoryInfo.FullName.Equals(root.directoryInfo.FullName))
         {
             ancestors.Add(this);
             this.parent.BuildAncestors(root, ancestors);
         }
     }
 }