예제 #1
0
        public GitFileEntry(IStaticAbstraction diskManager, string currentPath, string relativePath, string targetPath = null)
        {
            _diskManager = diskManager;

            string finalRelPath    = null;
            string originalRelPath = null;

            if (targetPath == null)
            {
                finalRelPath = relativePath.Replace("/", "\\");
            }
            else
            {
                originalRelPath = relativePath.Replace("/", "\\");
                finalRelPath    = targetPath?.Replace("/", "\\");
            }

            var valCurPath = GitUtils.Current.FixInvalidFileNameCharsInPath(currentPath);
            var valRelPath = GitUtils.Current.FixInvalidFileNameCharsInPath(finalRelPath);

            var dest = diskManager.Path.Combine(valCurPath, valRelPath);


            var info = _diskManager.NewFileInfo(dest);

            this.FullPath = info.FullName;
            this.Name     = info.Name;

            if (originalRelPath != null)
            {
                var sourceFullPath = diskManager.Path.Combine(currentPath, originalRelPath);
                var oInfo          = _diskManager.NewFileInfo(sourceFullPath);
                this.SourcePath = oInfo.FullName;
            }
        }
예제 #2
0
 protected void GetState(string fullPath)
 {
     this.FullPath = fullPath;
     this.Exists   = _diskManager.File.Exists(fullPath);
     if (this.Exists)
     {
         var info = _diskManager.NewFileInfo(fullPath);
         this.LastModified = info.LastWriteTime;
     }
     else
     {
         this.LastModified = DateTime.MinValue;
     }
 }
예제 #3
0
        public void With_File_Dependency()
        {
            var path       = "C:\\Some\\path\\to\\file.txt";
            var key        = "token";
            var fillerText = "Hello World!";
            var val        = new StringBuilder();

            val.Append(fillerText);

            var lastWriteTime = DateTime.Now.AddMinutes(-60);
            var info          = Substitute.For <IFileInfo>();

            info.LastWriteTime.Returns(lastWriteTime);

            _diskManager.File.Exists(path).Returns(true);
            _diskManager.NewFileInfo(path).Returns(info);
            _cache.Add(key, val, path);
            ValidateObjectReturned <StringBuilder>(key, false, fillerText);

            info.LastWriteTime.Returns(DateTime.Now);
            ValidateObjectReturned <StringBuilder>(key, true);

            // ensure that the object is really gone
            info.LastWriteTime.Returns(lastWriteTime);
            ValidateObjectReturned <StringBuilder>(key, true);
        }
예제 #4
0
        public static void TagRepoDir(string name, string path)
        {
            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(path))
            {
                return;
            }
            if (_gitDirs.ContainsKey(name) &&
                string.Compare(_gitDirs[name], path, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return;
            }

            if (!_diskManager.Directory.Exists(_infoDir))
            {
                _diskManager.Directory.CreateDirectory(_infoDir);
            }

            var fileName = _diskManager.Path.Combine(_infoDir, DWPSUtils.MakeFileSystemSafe(name + ".repo"));

            if (_diskManager.File.Exists(fileName))
            {
                var touchInfo = _diskManager.NewFileInfo(fileName);
                touchInfo.LastAccessTimeUtc = DateTime.UtcNow;
                return;
            }

            _diskManager.File.WriteAllText(fileName, path);

            _gitDirs.Add(name, path);
        }
예제 #5
0
        public void GetFullPath_whitespace_path_matches_basePath(string basePath, string fileName, string expectedValue)
        {
            var combined = string.IsNullOrWhiteSpace(fileName) ? basePath : new StAbWrapper().Path.Combine(basePath, fileName);

            _diskManager.Path.Combine(basePath, fileName).Returns(combined);
            var info = new MockFileInfo {
                FullName = combined
            };

            _diskManager.NewFileInfo(combined).Returns(info);
            var result = DWPSUtils.GetFullPath(basePath, fileName);

            Assert.AreEqual(expectedValue, result);
            _diskManager.Path.Received(0).Combine(Arg.Any <string>(), Arg.Any <string>());
            _diskManager.Received(0).NewFileInfo(Arg.Any <string>());
        }
예제 #6
0
        protected void Init(IStaticAbstraction diskManager, string defaultColorFile, string customColorFile)
        {
            _diskManager = diskManager ?? new StAbWrapper();

            var defColorFile  = string.IsNullOrWhiteSpace(defaultColorFile) ? _defaultColorFileName : defaultColorFile;
            var custColorFile = string.IsNullOrWhiteSpace(customColorFile) ? _defaultCustomColorFileName : customColorFile;

            var path     = _diskManager.NewFileInfo(_diskManager.Assembly.GetCallingAssembly().Location).DirectoryName;
            var testPath = DWPSUtils.IsFullPath(defColorFile) ? defColorFile : _diskManager.Path.Combine(path, defColorFile);

            if (_diskManager.File.Exists(testPath))
            {
                _defaultColorFilePath = testPath;
            }
            else
            {
                testPath = _diskManager.Path.Combine(path, "psscripts", defColorFile);
                if (_diskManager.File.Exists(testPath))
                {
                    _defaultColorFilePath = testPath;
                }
            }

            _customColorFilePath = DWPSUtils.IsFullPath(custColorFile) ? custColorFile : _diskManager.Path.Combine(path, custColorFile);

            RefreshColors();
        }
예제 #7
0
        protected void MockCallsForFileInfo(IFileInfo info, string[] csvLines)
        {
            dm.Path.Combine(Arg.Any <string>(), info.Name).Returns(info.FullName);

            dm.File.Exists(info.FullName).Returns(true);
            dm.NewFileInfo(info.FullName).Returns(info);
            dm.File.ReadAllLines(info.FullName).Returns(csvLines);
        }
예제 #8
0
        public void GetDirectoryPath_existingFile(string folder, string fileName, string expected)
        {
            var filePath = folder.Trim('\\') + "\\" + fileName;

            _diskManager.File.Exists(filePath).Returns(true);
            var info = Substitute.For <IFileInfo>();

            info.DirectoryName.Returns(folder);
            _diskManager.NewFileInfo(filePath).Returns(info);

            var result = DWPSUtils.GetDirectoryPath(filePath);

            Assert.AreEqual(result, expected);
        }
예제 #9
0
        protected bool IsNewer(string filePath)
        {
            if (!string.IsNullOrEmpty(filePath) && _diskManager.File.Exists(filePath))
            {
                var info = _diskManager.NewFileInfo(filePath);
                if (info.LastWriteTime > _colorLastModified)
                {
                    _colorLastModified = info.LastWriteTime;
                    return(true);
                }
            }

            return(false);
        }
예제 #10
0
        public void TestSetup()
        {
            fullPath = "C:\\Some\\Folder\\With\\Files.txt";
            fi       = new MockFileInfo()
            {
                Name          = "Files.txt",
                FullName      = fullPath,
                LastWriteTime = DateTime.Now.AddDays(-1),
                Exists        = true
            };

            dm = Substitute.For <IStaticAbstraction>();
            dm.File.Exists(Arg.Any <string>()).Returns(fi.Exists);
            dm.NewFileInfo(Arg.Any <string>()).Returns(fi);
        }
예제 #11
0
        private static void LoadGitDirs(IStaticAbstraction diskManager)
        {
            _infoDir = diskManager.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "gitsh", "localRepos");

            if (!diskManager.Directory.Exists(_infoDir))
            {
                return;
            }
            var repoNames = diskManager.Directory.GetFiles(_infoDir, "*.repo");

            foreach (var repoName in repoNames)
            {
                var repoPath = diskManager.File.ReadAllText(repoName);
                var nameInfo = diskManager.NewFileInfo(repoName);
                var name     = nameInfo.Name.Replace(nameInfo.Extension, "");
                _gitDirs.Add(name, repoPath);
            }
        }
예제 #12
0
        public void BuildRelativePath_basic(string source, string target, string expected)
        {
            _diskManager.NewDirectoryInfo(source).Returns(new MockDirectoryInfo {
                Exists = true
            });
            _diskManager.NewFileInfo(source).Returns(new MockFileInfo {
                Exists = false
            });

            _diskManager.NewDirectoryInfo(target).Returns(new MockDirectoryInfo {
                Exists = true
            });
            _diskManager.NewFileInfo(target).Returns(new MockFileInfo {
                Exists = false
            });

            var relPath = DWPSUtils.BuildRelativePath(source, target);

            Assert.AreEqual(expected, relPath);
        }
예제 #13
0
        private int GetPathAttribute(string path)
        {
            var di = _diskManager.NewDirectoryInfo(path);

            if (di.Exists)
            {
                return(FILE_ATTRIBUTE_DIRECTORY);
            }

            var fi = _diskManager.NewFileInfo(path);

            if (fi.Exists)
            {
                return(FILE_ATTRIBUTE_NORMAL);
            }
            else if (!string.IsNullOrEmpty(fi.Extension))
            {
                // guess that if it has an extension that it should be a file
                return(FILE_ATTRIBUTE_NORMAL);
            }

            throw new FileNotFoundException();
        }