Пример #1
0
 internal FSDirectory(DirectoryInfo directoryInfo, FSDirectory parent, bool whatIf, bool isRoot)
     : base(directoryInfo.FullName, parent, whatIf)
 {
     this.PopulateFromInfo(directoryInfo);
     this.IsRoot = isRoot;
 }
Пример #2
0
        /// <summary>
        /// Forces an entry to be refreshed based of the Filesystem
        /// </summary>
        public void RefreshEntry(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            this.Load();


            path = HelixUtil.PathUniversal(path);

            if (Path.IsPathRooted(path))
            {
                path = RemoveRootFromPath(path, FullName);
            }

            var     split = path.Split(HelixUtil.UniversalDirectorySeparatorChar);
            FSEntry newEntry;

            FileSystemInfo info;
            string         fullPath = HelixUtil.JoinUniversal(this.FullName, split[0]);

            if (System.IO.Directory.Exists(fullPath))
            {
                info = new DirectoryInfo(fullPath);
            }
            else if (System.IO.File.Exists(fullPath))
            {
                info = new FileInfo(fullPath);
            }
            else
            {
                info = null;
            }

            if (info is DirectoryInfo dirInfo)
            {
                newEntry = new FSDirectory(dirInfo, this, this.WhatIf, isRoot: false);
            }
            else if (info is FileInfo fileInfo)
            {
                newEntry = new FSFile(fileInfo, this, this.WhatIf);
            }
            else
            {
                newEntry = null; //not found
            }

            children.TryGetValue(split[0], out FSEntry oldEntry);
            if (newEntry?.EntryType != oldEntry?.EntryType)
            {
                if (oldEntry != null)
                {
                    children.Remove(oldEntry);
                }
                if (newEntry != null)
                {
                    children.Add(newEntry);
                }
            }
            else if (newEntry != null && oldEntry != null)
            {
                oldEntry.PopulateFromInfo(newEntry.LastWriteTimeUtc, newEntry.Length);
            }
            else if (newEntry != null)
            {
                children.Add(newEntry);
                if (split.Length > 1)
                {
                    (newEntry as FSDirectory)?.RefreshEntry(HelixUtil.JoinUniversal(split.Skip(1).ToArray()));
                }
            }
        }
Пример #3
0
 public FSDirectory(string path, FSDirectory parent)
     : base(path, parent, parent.WhatIf)
 {
 }