Ejemplo n.º 1
0
        public void Execute(CommandParameters param)
        {
            // load root dir to compare
            var oldRootItem = new RootDirItem();

            oldRootItem.Load(param.ReaderWriter, param.CLParams.CompareSnapshotFilePath);

            var newRootItem = param.RootItem;

            // if new root item to compare is not passed, search dir for items in oldRootItem.Name
            if (newRootItem == null)
            {
                newRootItem = param.DirFinderExecutor.Search(oldRootItem.Name);
            }

            // find diff and save it
            var  diffs = newRootItem.GetDiff(oldRootItem).ToList();
            long size  = diffs.Aggregate(0L, (acc, item) => acc + item.Size);

            var result = new StringBuilder("Size: ");

            result.AppendLine(size.ToString());

            if (param.CLParams.DiffSortBySize)
            {
                diffs.Sort(new DiffItemSizeComparer());
            }
            else
            {
                diffs.Sort(new DiffItemDefaultComparer());
            }

            result.Append(string.Join(Environment.NewLine, diffs));
            param.ReaderWriter.WriteAllText(param.CLParams.DiffSaveFilePath, result.ToString());
        }
Ejemplo n.º 2
0
 public CommandParameters(DirFinderExecutor dirFinderExecutor, IReaderWriter readerWritter,
                          CommandLineParams clParams, RootDirItem rootItem)
 {
     this.DirFinderExecutor = dirFinderExecutor;
     this.ReaderWriter      = readerWritter;
     this.CLParams          = clParams;
     this.RootItem          = rootItem;
 }
 /// <summary>
 /// Finds differences between two dir items
 /// </summary>
 /// <param name="other">DirItem instance that will be compared with this instance</param>
 /// <returns>IEnumerbale of DiffItem represents all differences</returns>
 public IEnumerable <DiffItem> GetDiff(RootDirItem other)
 {
     return(GetDiff(other, this.Name));
 }