public override IFileInfo FromFileName(string fileName) { var pathEnc = _fileSystem.Path.GetEncryptedPath(fileName, true); var x = new FileInfoWrapper(_fileSystem, new System.IO.FileInfo(pathEnc.GetPath(_source))); return(new LinuxEncFileInfo(_fileSystem, _source, _destination, x, _encryption)); }
private void ShowShellContextMenu(FileInfoWrapper item, FrameworkElement frameworkElement) { if (!SystemConfigFlagsWrapper.Instance().ShelContextMenu) { return; } var formsHost = (Control)ShellHostPopupWnd.FindName("ShellMenuHost"); var pos = new Point((int)ShellHostPopupWnd.HorizontalOffset, (int)ShellHostPopupWnd.VerticalOffset); var path = item.Path; var fullName = item.FullName; var newItems = new List <ShellMenuItem> { new ShellMenuItem("Open Containing Folder in Explorer", 1, () => { Process.Start(path); // Opens the folder in Windows Explorer. }), new ShellMenuItem("Copy Path to Clipboard", 2, () => Clipboard.SetText(path)), new ShellMenuItem("Copy Full Path to Clipboard", 3, () => Clipboard.SetText(item.FullName)), new ShellMenuItem("Copy Filename to Clipboard", 4, () => Clipboard.SetText(item.Name)), new ShellMenuItem("Rename", 5, () => Rename(frameworkElement)) }; var replaceItems = new List <ShellMenuItem> // Replace actions of items if needed. { new ShellMenuItem("Open", 0, () => OpenFileDefault(item.FullName)) }; ShellHostPopupWnd.IsOpen = true; var shelMenuManager = new ShellMenuManager(formsHost, fullName, pos, newItems, replaceItems); shelMenuManager.Show(); }
public void CheckFileWrapperCreation() { IFileInfo fileInfo = null; Action create = () => fileInfo = new FileInfoWrapper(Path); create.Should().NotThrow(); fileInfo.FullName.Should().Be(Path); const string FullDirectoryName = "R:\\Fake-Path\\2013\\19\\08"; fileInfo.DirectoryName.Should().Be(FullDirectoryName); fileInfo.Directory.Name.Should().Be("08"); fileInfo.Directory.FullName.Should().Be(FullDirectoryName); fileInfo.Exists.Should().BeFalse(); const int ExpectedLength = -1; long length = ExpectedLength; Action action = () => { length = fileInfo.Length; }; action.Should().Throw <FileNotFoundException>(); length.Should().Be(ExpectedLength); }
public void Union_Split_FileSystemEntitiesHaveOneFile() { var fileName = Path.Combine(testFolder, "test.bin"); var bytes = new byte[] { 190, 34, 56 }; File.WriteAllBytes(fileName, bytes); var fileInfo = new FileInfo(fileName); var directoryInfo = new Mock <IDirectoryInfo>(); var fileInfoWrapper = new FileInfoWrapper(fileInfo, directoryInfo.Object); var fileEntity = new FileEntity(fileInfoWrapper); var destinationFileName = Path.Combine(testFolder, "union.bin"); unifier.Union(new[] { fileEntity }, destinationFileName); Assert.IsTrue(File.Exists(destinationFileName)); var destinationPath = Path.Combine(testFolder, "destinationPath"); unifier.Split(destinationFileName, destinationPath); Assert.IsTrue(Directory.Exists(destinationPath)); var innerFileName = Path.Combine(destinationPath, "test.bin"); Assert.IsTrue(File.Exists(innerFileName)); TestHelper.CheckFile(innerFileName, bytes); }
public void Constructor_FileDoesntExist() { var fileInfo = new FileInfo("hello"); var directoryInfo = new Mock <IDirectoryInfo>(); var info = new FileInfoWrapper(fileInfo, directoryInfo.Object); Assert.Throws(typeof(FileEntityNotFoundException), () => new FileEntity(info)); }
private void FileInfo_Save(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = fileName; FileInfoWrapper fiw = new FileInfoWrapper(fileName); fiw.SaveFile(textBox1.Text); }
public async Task <IIpAddressChangedResult> HasIpAddressChanged() { try { string currentIpAddress; currentIpAddress = await _client.GetStringAsync(IpifyUri); if (string.IsNullOrWhiteSpace(currentIpAddress)) { throw new InvalidDataException("Unable to retrieve external IP Address."); } string previousIpAddress = string.Empty; if (_fileSystem.File.Exists(PreviousIpAddressFile)) { try { previousIpAddress = _fileSystem.File.ReadAllText(PreviousIpAddressFile); } catch (Exception ex) { _logger.Error(ex, "Unable to read previous ip address from file {dataFile}", PreviousIpAddressFile); return(new IpAddressChangedResult()); } if (!string.IsNullOrWhiteSpace(previousIpAddress) && previousIpAddress.Equals(currentIpAddress, StringComparison.OrdinalIgnoreCase)) { _logger.Information("External IP Address remains unchanged from {currentIpAddress}", currentIpAddress); // IP Address unchanged, nothing to do, exit return(new IpAddressChangedResult(false, previousIpAddress, currentIpAddress)); } } var file = new FileInfo(PreviousIpAddressFile); var fileInfoWrapper = new FileInfoWrapper(_fileSystem, file); fileInfoWrapper.Directory.Create(); // If the directory already exists, this method does nothing. _logger.Information("External IP Address changed from {previousIpAddress} to {currentIpAddress}", previousIpAddress, currentIpAddress); _fileSystem.File.WriteAllText(PreviousIpAddressFile, currentIpAddress); return(new IpAddressChangedResult(true, previousIpAddress, currentIpAddress)); } catch (HttpRequestException e) { _logger.Error(e, "Unable to retrieve external IP Address from {endPoint}", IpifyUri); } catch (Exception e) { _logger.Error(e, "Error occured while determining if address had changed"); throw; } return(new IpAddressChangedResult()); }
/// <summary> /// Creates a new copy pair. /// </summary> /// <param name="source"> Source file. </param> /// <param name="target"> Traget file path. </param> public CopyPair(FileInfo source, string target) { if (target == null) { throw new ArgumentNullException("target", "Target is null."); } SourceInfo = new FileInfoWrapper(source); TargetInfo = CreateTargetFileSystemInfo(target); Initialize(SourceInfo, TargetInfo); }
private void FileInfo_Load(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.ShowDialog(); fileName = openFileDialog.FileName; FileInfoWrapper fiw = new FileInfoWrapper(fileName); textBox1.Text = fiw.OpenFile(); }
public void CanCheckIfFileExists() { //arrange var info = new FileInfoWrapper("readme.txt"); //act var exists = info.Exists; //assert Assert.True(exists); }
public IFileInfo[] GetFiles() { var fileInfos = info.GetFiles(); var files = new IFileInfo[fileInfos.Length]; for (var i = 0; i < fileInfos.Length; ++i) { files[i] = new FileInfoWrapper(fileInfos[i], this); } return(files); }
public void CanCheckIfFileIsReadOnly() { //arrange var info = new FileInfoWrapper("readme.txt"); //act var readOnly = info.IsReadOnly; //assert Assert.False(readOnly); }
public void GetDataTest() { var fileName = string.Format("{0}\\file.bin", testFolder); File.WriteAllBytes(fileName, new byte[] { 45, 190 }); var fileInfo = new FileInfo(fileName); var directoryInfo = new Mock <IDirectoryInfo>(); wrapper = new FileInfoWrapper(fileInfo, directoryInfo.Object); var data = wrapper.GetData(); TestHelper.CheckArray(new byte[] { 45, 190 }, data); }
private void HandleFileCheck(FileInfoWrapper file, bool isChecked) { if (isChecked) { deleteList.Add(file.FullName); SizeBytes += file.Length; } else { SizeBytes -= file.Length; deleteList.Remove(file.FullName); } }
protected override void FindFileInfo(System.Web.HttpContextBase httpContext) { // TODO: HttpRequestBase request = httpContext.Request; string physicalPath = "";// TODO: Path here //request.PhysicalPath; FileInfo info = GetFileInfo(physicalPath); if (info != null) { RequestFileInfo = new FileInfoWrapper(info); } }
public void FileInfoWrapper_CreateDelete() { var fileName = "c:\\FileInfoWrapper_Construct.txt"; var fileWrapper = new FileWrapper(); fileWrapper.WriteAllText(fileName, "FileInfoWrapper_Construct test test"); IFileInfo fileInfo = new FileInfoWrapper(new FileInfo(fileName)); var createTime = fileInfo.CreationTime; fileInfo.Delete(); Assert.IsTrue(createTime > (DateTime.Now.Subtract(new TimeSpan(0, 0, 30)))); Assert.IsFalse(fileWrapper.Exists(fileName)); }
static void Main() { var path = @"C:\Work1"; var destFiletxt = Path.Combine(path, "newTest.txt"); var fileInfo = new FileInfoWrapper(path); var console = new ConsoleWrapper(); var file = new FileWrapper(); var directory = new DirectoryWrapper(); var abstractHandler = new TxtHandler(file, fileInfo, console, directory); abstractHandler.Create(path); abstractHandler.Change(destFiletxt, "33"); abstractHandler.Open(destFiletxt); var destFileNametxt = Path.Combine(path, @"Test.txt"); abstractHandler.Save(destFiletxt, destFileNametxt); Directory.Delete(path, true); var pathjson = @"C:\Work3"; var destFilejson = Path.Combine(pathjson, "tsconfig1.json"); var fileInfojson = new FileInfoWrapper(pathjson); var jsonHandler = new UserHandler(file, fileInfojson, console, directory); jsonHandler.Create(pathjson); var user1 = new User(); user1.Company = "Google"; user1.Name = "Bob Gates"; user1.Age = 51; var json = JsonConvert.SerializeObject(user1, Newtonsoft.Json.Formatting.Indented); var pathJson = @"jsconfig1.json"; jsonHandler.Change(pathJson, json); jsonHandler.Open(destFilejson); var destFileNamejson = Path.Combine(pathjson, @"Json.json"); jsonHandler.Save(pathJson, destFileNamejson); //Directory.Delete(pathjson, true); Console.ReadKey(); }
private IFileSystemInfo CreateSourceFileSystemInfo(string path) { IFileSystemInfo info; if (Directory.Exists(path)) { info = new DirectoryInfoWrapper(path); IsFile = false; } else if (File.Exists(path)) { info = new FileInfoWrapper(path); IsFile = true; } else { throw new ArgumentException(string.Format("Path {0} does not exist.", path), "path"); } return(info); }
public void Union_Split_FileSystemEntitiesHaveOneFileAndOneDirectory() { const string fileName = "hello - файл"; var fileFullName = Path.Combine(testFolder, fileName); var bytes = new byte[] { 89, 50 }; File.WriteAllBytes(fileFullName, bytes); const string directoryName = "dir - папка"; var directoryFullPath = Path.Combine(testFolder, directoryName); Directory.CreateDirectory(directoryFullPath); var directoryInfo = new Mock <IDirectoryInfo>(); var fileInfo = new FileInfo(fileFullName); var fileInfoWrapper = new FileInfoWrapper(fileInfo, directoryInfo.Object); var fileEntity = new FileEntity(fileInfoWrapper); var directoryInfoWrapper = new DirectoryInfoWrapper(directoryFullPath); var directoryEntity = new DirectoryEntity(directoryInfoWrapper); var destinationFileName = Path.Combine(testFolder, "union.bin"); unifier.Union(new FileSystemEntity[] { fileEntity, directoryEntity }, destinationFileName); Assert.IsTrue(File.Exists(destinationFileName)); var destinationPath = Path.Combine(testFolder, "destinationPath"); unifier.Split(destinationFileName, destinationPath); Assert.IsTrue(Directory.Exists(destinationPath)); var innerFileName = Path.Combine(destinationPath, fileName); Assert.IsTrue(File.Exists(innerFileName)); TestHelper.CheckFile(innerFileName, bytes); var innerDirectoryName = Path.Combine(destinationPath, directoryName); Assert.IsTrue(Directory.Exists(innerDirectoryName)); }
public void Cipher_Decipher() { var outputFileName = Path.Combine(testFolder, "outputFileName.rsa"); var temporaryFileName = Path.Combine(testFolder, "temporary.bin"); environmentHelper.Setup(x => x.GetTempFileName()).Returns(temporaryFileName); var fileFactory = new FileFactory(4); var rsaFileCipher = new RsaFileCipher(fileFactory); var fileUnifier = new FileUnifier(); var manager = new CipherManager(rsaFileCipher, fileUnifier, environmentHelper.Object, messageHelper.Object); // public key: 05#B781262C2090AD // private key: 6E1A49FEAC0471#B781262C2090AD var e = BigNumber.FromInt(5); var d = BigNumber.FromBytes(new[] { 113, 4, 172, 254, 73, 26, 110 }); var n = BigNumber.FromBytes(new[] { 173, 144, 32, 44, 38, 129, 183 }); var publicKey = new PublicKey(e, n); var privateKey = new PrivateKey(d, n); var sourceFileName = Path.Combine(testFolder, "file.bin"); File.WriteAllBytes(sourceFileName, new byte[] { 45, 129, 240 }); var directoryInfoWrapper = new DirectoryInfoWrapper(testFolder); var fileInfoWrapper = new FileInfoWrapper(new FileInfo(sourceFileName), directoryInfoWrapper); var fileEntity = new FileEntity(fileInfoWrapper); manager.Cipher(publicKey, new FileSystemEntity[] { fileEntity }, outputFileName); var decipherManager = new DecipherManager(environmentHelper.Object, new RsaFileDecipher(fileFactory), messageHelper.Object, fileUnifier); var outputPath = Path.Combine(testFolder, "outputPath"); decipherManager.Decipher(privateKey, outputFileName, outputPath); Assert.IsTrue(Directory.Exists(outputPath)); var fileName = Path.Combine(outputPath, "file.bin"); Assert.IsTrue(File.Exists(fileName)); TestHelper.CheckFile(fileName, new byte[] { 45, 129, 240 }); }
public void Split_DestinationDirectoryAlreadyExistsCheckRewrite() { const string fileName = "файл.bin"; var fileFullName = Path.Combine(testFolder, fileName); var bytes = new byte[] { 190, 34, 56 }; File.WriteAllBytes(fileFullName, bytes); var fileInfo = new FileInfo(fileFullName); var directoryInfo = new Mock <IDirectoryInfo>(); var fileInfoWrapper = new FileInfoWrapper(fileInfo, directoryInfo.Object); var fileEntity = new FileEntity(fileInfoWrapper); var destinationFileName = Path.Combine(testFolder, "union.bin"); unifier.Union(new[] { fileEntity }, destinationFileName); Assert.IsTrue(File.Exists(destinationFileName)); var destinationPath = Path.Combine(testFolder, "destinationPath"); Directory.CreateDirectory(destinationPath); var innerFileName = Path.Combine(destinationPath, fileName); var secondInnerFileName = Path.Combine(destinationPath, "hi.exe"); File.WriteAllBytes(innerFileName, new byte[] { 100, 200, 250, 50 }); File.WriteAllText(secondInnerFileName, "hello"); unifier.Split(destinationFileName, destinationPath); Assert.IsTrue(Directory.Exists(destinationPath)); Assert.IsTrue(File.Exists(innerFileName)); TestHelper.CheckFile(innerFileName, bytes); Assert.IsTrue(File.Exists(secondInnerFileName)); }
public static void AddFile(this ZipArchive zipArchive, string filePath, ITracer tracer, string directoryNameInArchive = "") { var fileInfo = new FileInfoWrapper(new FileInfo(filePath)); zipArchive.AddFile(fileInfo, tracer, directoryNameInArchive); }
public void SetUp () { _tempFile = new TempFile(); FileInfo fileInfo = new FileInfo (_tempFile.FileName); _fileInfoWrapper = new FileInfoWrapper (fileInfo); }
public void SetFileProcessingAction_Retry () { var zipBuilder = new ZipFileBuilder(); zipBuilder.Progress += ((sender, e) => { }); zipBuilder.Error += ((sender, e) => zipBuilder.FileProcessingRecoveryAction = FileProcessingRecoveryAction.Retry); var fileInfoStub = MockRepository.GenerateStub<IFileInfo>(); zipBuilder.AddFile (new FileInfoWrapper (new FileInfo (_file1.FileName))); fileInfoStub.Stub (stub => stub.FullName).Return (_file2.FileName); fileInfoStub.Stub (stub => stub.Name).Return (Path.GetFileName (_file2.FileName)); fileInfoStub.Stub (stub => stub.Length).Return (_file2.Length); zipBuilder.AddFile (fileInfoStub); fileInfoStub.Expect (mock => mock.Open (FileMode.Open, FileAccess.Read, FileShare.Read)).Throw (new IOException()).Repeat.Once(); var fileInfo = new FileInfoWrapper (new FileInfo (_file2.FileName)); var stream = fileInfo.Open (FileMode.Open, FileAccess.Read, FileShare.Read); fileInfoStub.Expect (mock => mock.Open (FileMode.Open, FileAccess.Read, FileShare.Read)).Return (stream); fileInfoStub.Stub (mock => mock.Directory).Return (new DirectoryInfoWrapper (new DirectoryInfo (Path.GetDirectoryName (_file2.FileName)))); var zipFileName = Path.GetTempFileName(); using (zipBuilder.Build (zipFileName)) { } var expectedFiles = new List<string> { Path.GetFileName (_file1.FileName), Path.GetFileName (_file2.FileName) }; CheckUnzippedFiles (zipFileName, expectedFiles); }
/// <inheritdoc /> public IFile GetFile(string path) { IFile lResult = new FileInfoWrapper(path); return(lResult); }