Ejemplo n.º 1
0
        public FileObject AddFile(string relativeFileName, Stream fileContent, FileOption fileOption, int bufferSize)
        {
            var file = new FileObject(FullName + relativeFileName);

            file.Write(fileContent, fileOption, bufferSize);
            return(file);
        }
Ejemplo n.º 2
0
        public void Test_GetFileSize_Return_Correct_Size()
        {
            // Arrange
            var fileSize               = 100000000;
            var expectedSizeInByte     = $"{fileSize}B";
            var expectedSizeInKiloByte = $"100000";
            var expectedSizeInMB       = $"95.37MB";

            var content  = new string('A', fileSize);
            var stream   = content.ToStream();
            var testFile = new DotNetHelper_IO.FileObject(TestFolder.FullName + new Randomizer().String(8, 'A', 'Z'));


            // Act
            testFile.Write(stream);
            var fileSizeInBytes     = testFile.GetSize(SizeUnits.Byte);
            var fileSizeInKiloBytes = testFile.GetSize(SizeUnits.Kb);
            var fileSizeInMegaBytes = testFile.GetSize(SizeUnits.Mb);

            var fileSizeAsString = testFile.GetSize();

            // Assert
            Assert.That(fileSizeInBytes, Is.EqualTo(fileSize));
            Assert.That(fileSizeInKiloBytes, Is.EqualTo(97656));
            Assert.That(fileSizeInMegaBytes, Is.EqualTo(95));
            Assert.That(fileSizeAsString, Is.EqualTo(expectedSizeInMB));
        }
Ejemplo n.º 3
0
        public FileObject AddFile(string relativeFileName, byte[] fileContent, FileOption fileOption, int offset = 0,
                                  int?count = null)
        {
            var file = new FileObject(FullName + relativeFileName);

            file.Write(fileContent, fileOption, offset, count);
            return(file);
        }
Ejemplo n.º 4
0
        ///// <summary>
        ///// Sets the file attribute.
        ///// </summary>
        ///// <param name="option">The option.</param>
        ///// <param name="list">The list.</param>
        //public void SetFolderAttribute(AddOrRemoveEnum option, List<FileAttributes> list)
        //{

        //	if (Exist != true)
        //		return;
        //	try
        //	{
        //		if (option == AddOrRemoveEnum.Add)
        //		{
        //			foreach (var attr in list)
        //			{
        //				var di = new DirectoryInfo(FullName);
        //				di.Attributes &= ~attr;

        //			}

        //		}
        //		else if (option == AddOrRemoveEnum.Remove)
        //		{
        //			foreach (var attr in list)
        //			{
        //				var di = new DirectoryInfo(FullName);
        //				di.Attributes &= attr;
        //			}
        //		}
        //	}
        //	catch (Exception)
        //	{

        //		// ignored because this require the user to have full control permission set and we don't problems over that
        //		// if developer is doing something that require full conrol permission let the application throw the error
        //	}
        //}



        public FileObject AddFile(string relativeFileName, string fileContent, FileOption fileOption,
                                  Encoding encoding = null, int bufferSize = 4096)
        {
            var file = new FileObject(FullName + relativeFileName);

            file.Write(fileContent, fileOption, encoding, bufferSize);
            return(file);
        }