/// <summary> /// Attempts to load an UploadFolderMetadata object from the given file. /// </summary> /// <param name="filePath">The full path to the file where to load the metadata from</param> /// <returns></returns> /// <exception cref="System.IO.FileNotFoundException">Could not find metadata file</exception> /// <exception cref="Microsoft.Azure.Management.DataLake.StoreUploader.InvalidMetadataException">Unable to parse metadata file</exception> internal static UploadFolderMetadata LoadFrom(string filePath) { if (!File.Exists(filePath)) { throw new FileNotFoundException("Could not find metadata file", filePath); } try { using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { UploadFolderMetadata result = MetadataSerializer.ReadObject(stream) as UploadFolderMetadata; if (result != null) { result.MetadataFilePath = filePath; // populate all child metadata file paths as well var localMetadataFolder = Path.GetDirectoryName(filePath); Parallel.ForEach(result.Files, new ParallelOptions { MaxDegreeOfParallelism = -1 }, file => { var uploadMetadataPath = Path.Combine(localMetadataFolder, string.Format("{0}.upload.xml", Path.GetFileName(file.InputFilePath))); file.MetadataFilePath = uploadMetadataPath; }); } return(result); } } catch (Exception ex) { throw new InvalidMetadataException("Unable to parse metadata file", ex); } }
/// <summary> /// Attempts to load the metadata from an existing file in its canonical location. /// </summary> /// <param name="metadataFilePath">The metadata file path.</param> /// <returns></returns> public UploadFolderMetadata GetExistingMetadata(string metadataFilePath) { //load from file (based on input parameters) var metadata = UploadFolderMetadata.LoadFrom(metadataFilePath); metadata.ValidateConsistency(); return(metadata); }
/// <summary> /// Creates a new metadata based on the given input parameters, and saves it to its canonical location. /// </summary> /// <returns></returns> public UploadFolderMetadata CreateNewMetadata(string metadataFilePath) { //create metadata var metadata = new UploadFolderMetadata(metadataFilePath, _parameters, _frontend); //save the initial version metadata.Save(); return(metadata); }
/// <summary> /// Populates the specified metadata. /// </summary> /// <param name="metadata">The metadata.</param> private void Populate(UploadFolderMetadata metadata) { this.TotalFileLength = metadata.TotalFileBytes; this.TotalFileCount = metadata.FileCount; _fileProgress = new List <UploadProgress>(this.TotalFileCount); _progressBacklog = new ConcurrentQueue <UploadProgress>(); foreach (var fileMetadata in metadata.Files) { var toAdd = new UploadProgress(fileMetadata); if (fileMetadata.Status == SegmentUploadStatus.Complete) { this.UploadedByteCount += fileMetadata.FileLength; this.UploadedFileCount++; toAdd.UploadedByteCount = toAdd.TotalFileLength; foreach (var segment in toAdd._segmentProgress) { segment.UploadedByteCount = segment.Length; } } _fileProgress.Add(toAdd); } }
/// <summary> /// Initializes a new instance of the <see cref="UploadFolderProgress"/> class. /// </summary> /// <param name="metadata">The metadata.</param> internal UploadFolderProgress(UploadFolderMetadata metadata) { Populate(metadata); }