예제 #1
0
        public void Map(string dirPath, IOutputer outputer)
        {
            if (!Directory.Exists(dirPath))
            {
                throw new InvalidOperationException($"invalid directory: <\"{dirPath}\">.");
            }
            dirPath = Path.GetFullPath(dirPath);

            var lastChar = dirPath[dirPath.Length - 1];

            if (lastChar == Path.DirectorySeparatorChar || lastChar == Path.AltDirectorySeparatorChar)
            {
                dirPath = dirPath.Substring(0, dirPath.Length - 1);
            }

            var dirPath2 = dirPath + Path.DirectorySeparatorChar;
            var removed  = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var added    = new List <string>();

            this.Paths.RemoveAll(z =>
            {
                if (z.Equals(dirPath, StringComparison.OrdinalIgnoreCase) ||
                    z.StartsWith(dirPath2, StringComparison.OrdinalIgnoreCase))
                {
                    removed.Add(z);
                    return(true);
                }
                return(false);
            });

            foreach (var item in Directory.GetDirectories(dirPath))
            {
                if (!removed.Remove(item))
                {
                    added.Add(item);
                }
                this.Paths.Add(item);
            }

            outputer.WriteLine(OutputLevel.Normal, $"Added ({added.Count}):");
            foreach (var item in added)
            {
                outputer.WriteLine(OutputLevel.Normal, $"   {item}");
            }
            outputer.WriteLine(OutputLevel.Normal, $"Removed ({removed.Count}):");
            foreach (var item in removed)
            {
                outputer.WriteLine(OutputLevel.Normal, $"   {item}");
            }

            this.Save();
        }
예제 #2
0
        public virtual void Remove(string value, IOutputer outputer)
        {
            var exists = this.Paths.FirstOrDefault(z => Comparer.Equals(z, value));

            if (exists == null)
            {
                throw new InvalidOperationException($"value not exists: <{value}>");
            }
            this.Paths.Remove(exists);
            this.Save();
            outputer.WriteLine(OutputLevel.Normal, $"Removed <{value}> from {this._target} envvar <{this._name}>.");
        }
예제 #3
0
        public virtual void Add(string value, IOutputer outputer)
        {
            var exists = this.Paths.FirstOrDefault(z => Comparer.Equals(z, value));

            if (exists != null)
            {
                throw new InvalidOperationException($"exists value: <{exists}>");
            }
            this.Paths.Add(value);
            this.Save();
            outputer.WriteLine(OutputLevel.Normal, $"Added <{value}> into {this._target} envvar <{this._name}>.");
        }
예제 #4
0
 public void Sort(IOutputer outputer)
 {
     this.Paths.Sort();
     this.Save();
     outputer.WriteLine(OutputLevel.Normal, $"Sorted {this._target} envvar <{this._name}>.");
 }
예제 #5
0
 public void List(IOutputer outputer)
 {
     outputer.WriteLine(OutputLevel.Normal, this.ToString());
 }