private static T ReadXml <T>(string fileName, XmlReader reader) { try { var serializer = new XmlSerializer(typeof(T)); T obj = (T)serializer.Deserialize(reader); return(obj); } catch (InvalidOperationException xmlParseException) { if (FabricFile.Exists(fileName)) { ImageBuilder.TraceSource.WriteError( TraceType, "Invalid XML Content. File Size: {0}", FabricFile.GetSize(fileName)); } else { ImageBuilder.TraceSource.WriteError( TraceType, "File '{0}' does not exist.", fileName); } TraceAndThrowValidationErrorWithFileName( xmlParseException, TraceType, fileName, StringResources.ImageBuilderError_ErrorParsingXmlFile, fileName); } return(default(T)); }
private ImageStoreFile ConvertToImageStoreFile(string fullFilePath, string storeSource) { return(new ImageStoreFile( this.GetStoreRelativePathFromFullName(fullFilePath, storeSource), string.Empty, FabricFile.GetSize(fullFilePath), FabricFile.GetLastWriteTime(fullFilePath))); }
public long GetValueCheckpointFileSize() { if (ValueCheckpointFileSize == -1) { ValueCheckpointFileSize = FabricFile.GetSize(this.ValueCheckpointFileName); } return(ValueCheckpointFileSize); }
public long GetKeyCheckpointFileSize() { if (KeyCheckpointFileSize == -1) { KeyCheckpointFileSize = FabricFile.GetSize(this.KeyCheckpointFileName); } return(KeyCheckpointFileSize); }
public static T ReadXml <T>(string fileName, XmlReaderSettings validatingXmlReaderSettings) { #if !DotNetCoreClr // Ensure the XmlResolve is set to null validatingXmlReaderSettings.XmlResolver = null; #endif using (var stream = FabricFile.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var xmlReader = XmlReader.Create(stream, validatingXmlReaderSettings)) { T v = ReadXml <T>(fileName, xmlReader); #if DotNetCoreClr try { var applicationManifestType = v as IXmlValidator; if (applicationManifestType != null) { applicationManifestType.Validate(); } } catch (InvalidOperationException xmlParseException) { if (FabricFile.Exists(fileName)) { ImageBuilder.TraceSource.WriteError( TraceType, "Invalid XML Content. File Size: {0}", FabricFile.GetSize(fileName)); } else { ImageBuilder.TraceSource.WriteError( TraceType, "File '{0}' does not exist.", fileName); } TraceAndThrowValidationErrorWithFileName( xmlParseException, TraceType, fileName, StringResources.ImageBuilderError_ErrorParsingXmlFile, fileName); } catch (XmlException xmlException) { TraceAndThrowValidationErrorWithFileName( xmlException, TraceType, fileName, StringResources.ImageBuilderError_ErrorParsingXmlFile, fileName); } #endif return(v); } }
/// <summary> /// Compare two files and return true if they are different. /// </summary> /// <param name="firstFilename">The name of the first file to compare.</param> /// <param name="secondFilename">The name of the second file to compare.</param> /// <returns>True if the files are different, false otherwise </returns> public bool AreFilesDifferent(string firstFilename, string secondFilename) { this.ThrowIfDisposed(); if (this.copyFlag == CopyFlag.AtomicCopy || this.copyFlag == CopyFlag.AtomicCopySkipIfExists) { return(true); } else { return(FabricFile.Exists(firstFilename) != FabricFile.Exists(secondFilename) || FabricFile.GetSize(firstFilename) != FabricFile.GetSize(secondFilename) || FabricFile.GetLastWriteTime(firstFilename) != FabricFile.GetLastWriteTime(firstFilename)); } }
private void EstimateTotalByteCount(string dirFullPath) { var fileFullPaths = FabricDirectory.GetFiles(dirFullPath, "*", true, SearchOption.AllDirectories); this.totalFileCountEstimate += fileFullPaths.Length; foreach (var fileFullPath in fileFullPaths) { this.totalByteCountEstimate += FabricFile.GetSize(fileFullPath); this.UpdateProgressEstimatingPackageSizeDetails(); } this.totalFileCountEstimate += FabricDirectory.GetDirectories(dirFullPath, "*", SearchOption.AllDirectories).Length; ++this.totalFileCountEstimate; }
public void FabricFile_GetSize_FileOpenInReadShare_Succeeds() { string filePath = Path.Combine(this.testPath, this.testFileName); LogHelper.Log("FabricDirectory.Create {0}", this.testPath); FabricDirectory.CreateDirectory(this.testPath); LogHelper.Log("FabricFile.Create {0}", filePath); using (var writer = new StreamWriter(FabricFile.Create(filePath))) { writer.WriteLine(this.testString); } LogHelper.Log("FabricFile.Open {0}", filePath); using (var filestream = FabricFile.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { long fileSize = FabricFile.GetSize(filePath); LogHelper.Log("FabricFile.GetSize {0}", fileSize); Assert.IsTrue(fileSize > 0, "FabricFile.GetSize should return non-zero file size."); } }
/// <summary> /// Upload a file from SMB to xstore /// </summary> /// <param name="blobContainer"> /// Blob container /// </param> /// <param name="task"> /// Task object /// </param> private void TransferFileFromSMBToXStore(CloudBlobContainer blobContainer, XStoreFileOperationTask task) { if (!this.ShouldCopy(task.SrcUri)) { return; } Int64 size = FabricFile.GetSize(task.SrcUri); // Create the Blob and upload the file var blob = blobContainer.GetBlockBlobReference(task.DstUri); var blobWrapper = new XStoreBlobWrapper(blob); if (task.TimeoutHelper != null) { //task.TimeoutHelper.ThrowIfExpired(); blobWrapper.UploadFromFile(task.SrcUri, (int)size, task.TimeoutHelper.GetRemainingTime()); } else { blobWrapper.UploadFromFile(task.SrcUri, (int)size, TimeSpan.MaxValue); } }
public void FabricFile_EndToEndPositive() { var folderPath = this.testPath; folderPath = this.ExtendPath(folderPath); var filePath = Path.Combine(folderPath, this.testFileName); Assert.IsTrue(filePath.Length > 260); LogHelper.Log("FabricDirectory.Create {0}", folderPath); FabricDirectory.CreateDirectory(folderPath); LogHelper.Log("FabricFile.Create {0}", filePath); using (StreamWriter streamWriter = new StreamWriter(FabricFile.Create(filePath))) { LogHelper.Log("Write {0}", this.testString); streamWriter.WriteLine(this.testString); } LogHelper.Log("FabricDirectory.GetDirectories {0}", this.testPath); var result = FabricDirectory.GetDirectories(this.testPath); Assert.AreEqual(1, result.Length); LogHelper.Log("FabricDirectory.GetFiles {0}", this.testPath); result = FabricDirectory.GetFiles(this.testPath); Assert.AreEqual(0, result.Length); LogHelper.Log("FabricDirectory.GetFiles {0}, AllDirectories", this.testPath); result = FabricDirectory.GetFiles(this.testPath, "*", SearchOption.AllDirectories); Assert.AreEqual(1, result.Length); LogHelper.Log("FabricDirectory.GetDirectories {0}", folderPath); result = FabricDirectory.GetDirectories(folderPath); Assert.AreEqual(0, result.Length); LogHelper.Log("FabricDirectory.GetFiles {0}", folderPath); result = FabricDirectory.GetFiles(folderPath); Assert.AreEqual(1, result.Length); LogHelper.Log("FabricFile.Open {0}", filePath); using (StreamReader streamReader = new StreamReader(FabricFile.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))) { string actual = streamReader.ReadLine(); LogHelper.Log("Read {0}", actual); Assert.AreEqual(this.testString, actual); } LogHelper.Log("FabricFile.GetSize {0}", filePath); long size = FabricFile.GetSize(filePath); Assert.IsTrue(size > 0); LogHelper.Log("FabricPath.GetDirectoryName {0}", filePath); string directoryName = FabricPath.GetDirectoryName(filePath); Assert.AreEqual(folderPath, directoryName); LogHelper.Log("FabricFile.GetLastWriteTime {0}", filePath); DateTime oldTime = FabricFile.GetLastWriteTime(filePath); Thread.Sleep(TimeSpan.FromSeconds(1)); using (StreamWriter streamWriter = new StreamWriter(FabricFile.Open(filePath, FileMode.Open, FileAccess.Write))) { LogHelper.Log("Write {0}", this.testString); streamWriter.WriteLine(this.testString); } DateTime newTime = FabricFile.GetLastWriteTime(filePath); Assert.IsTrue(newTime > oldTime); }