/// <summary> /// Initializes a new instance of the FolderCopy class. Constructor that takes Copy flags and file extensions to be filterd out /// while copying /// </summary> /// <param name="flag">Flag specifying what type of copying needs to be done.</param> /// <param name="filterExtensions">The file extensions that need to be filtered.</param> public FolderCopy(CopyFlag flag, IEnumerable <string> filterExtensions) { if (filterExtensions != null) { foreach (string e in filterExtensions) { string extension = e; if (this.filterExtensions == null) { this.filterExtensions = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase); } // normalize; Path.GetExtension returns . + extension like ".pdb" if (extension.Length > 0 && extension[0] != '.') { extension = '.' + extension; } if (!this.filterExtensions.ContainsKey(extension)) { this.filterExtensions[extension] = true; } } } this.copyFlag = flag; }
/// <summary> /// Initializes a new instance of the CommandLineArgs class. /// </summary> internal CommandLineArgs() { this.connectionString = null; this.fileName = null; this.storeTag = null; this.localTag = null; this.XStoreMinTransferBPS = 0; this.copyFlag = CopyFlag.AtomicCopy; this.outputFile = null; }
private NativeImageStore.FABRIC_IMAGE_STORE_COPY_FLAG ToNative(CopyFlag flag) { switch (flag) { case CopyFlag.CopyIfDifferent: return(NativeImageStore.FABRIC_IMAGE_STORE_COPY_FLAG.FABRIC_IMAGE_STORE_COPY_FLAG_IF_DIFFERENT); case CopyFlag.AtomicCopy: return(NativeImageStore.FABRIC_IMAGE_STORE_COPY_FLAG.FABRIC_IMAGE_STORE_COPY_FLAG_ATOMIC); case CopyFlag.AtomicCopySkipIfExists: return(NativeImageStore.FABRIC_IMAGE_STORE_COPY_FLAG.FABRIC_IMAGE_STORE_COPY_FLAG_ATOMIC_SKIP_IF_EXISTS); default: return(NativeImageStore.FABRIC_IMAGE_STORE_COPY_FLAG.FABRIC_IMAGE_STORE_COPY_FLAG_INVALID); } }
public void UploadContent(string tag, string sourceSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag, bool acquireSourceReaderLock) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); sourceSoftLink = this.GetLocalPath(sourceSoftLink); if ((!FabricFile.Exists(sourceSoftLink)) && (!FabricDirectory.Exists(sourceSoftLink))) { throw new IOException( string.Format( CultureInfo.CurrentCulture, StringResources.ImageStoreError_DoesNotExistError, sourceSoftLink)); } try { using (XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); if (copyFlag == CopyFlag.AtomicCopy) { this.DeleteContent(tag, helper == null ? timeout : helper.GetRemainingTime()); } if (FabricFile.Exists(sourceSoftLink)) { // This is a file copy xstoreFileOperation.CopyFile( sourceSoftLink, tag, XStoreFileOperationType.CopyFromSMBToXStore, helper); } else { // this is a folder copy xstoreFileOperation.CopyFolder( sourceSoftLink, tag, XStoreFileOperationType.CopyFromSMBToXStore, copyFlag, null, null, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
private void CopyContentWrapper(string remoteSource, string remoteDestination, UInt32 timeoutMilliseconds, string[] skipFiles, CopyFlag imageCopyFlag, bool checkMarkFile) { using (var pin = new PinCollection()) { this.nativeClient.CopyContent( pin.AddObject(remoteSource), pin.AddObject(remoteDestination), timeoutMilliseconds, NativeTypes.ToNativeStringList(pin, skipFiles), ToNative(imageCopyFlag), NativeTypes.ToBOOLEAN(checkMarkFile)); } }
/// <summary> /// Downloads content from the image store to local destination. /// </summary> /// <param name="remoteSource">The relative path of source image store to be downloaded from.</param> /// <param name="localDestination">The local destination path to download the content.</param> /// <param name="progressHandler">Defines the behavior to process progress information from the downloading operation.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="imageCopyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string remoteSource, string localDestination, IImageStoreProgressHandler progressHandler, TimeSpan timeout, CopyFlag imageCopyFlag) { Utility.WrapNativeSyncInvokeInMTA(() => { this.DownloadContentWrapper(remoteSource, localDestination, progressHandler, Utility.ToMilliseconds(timeout, "timeout"), imageCopyFlag); }, "DownloadContent"); }
/// <summary> /// Copies content from a path in the ImageStore to the destination path in the ImageStore. /// </summary> /// <param name="storeSource">The relative path of source file image store to be copied from.</param> /// <param name="storeDestination">The relative path of destination image store content to be copied to.</param> /// <param name="timeout">The timeout for performing the copying operation.</param> /// <param name="skipFiles">The list of the files names to be skipped for copying.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> /// <param name="checkMarkFile">Indicats whether to check mark file during copying.</param> /// <returns></returns> public Task CopyContentAsync(string storeSource, string storeDestination, TimeSpan timeout, string[] skipFiles, CopyFlag copyFlag, bool checkMarkFile) { return(Task.Run(() => { this.CopyContent(storeSource, storeDestination, timeout, skipFiles, copyFlag, checkMarkFile); })); }
/// <summary> /// Uploads content of the local source to the native image store at the remote destination. /// </summary> /// <param name="storeDestination">Location relative to RootUri where the content needs to be uploaded.</param> /// <param name="localSource">local location of the source.</param> /// <param name="timeout">The timeout for performing the uploading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> /// <param name="acquireSourceReaderLock">Indicates whether to acquire reader lock.</param> /// <returns></returns> public Task UploadContentAsync(string storeDestination, string localSource, TimeSpan timeout, CopyFlag copyFlag, bool acquireSourceReaderLock) { return(Task.Run(() => { this.UploadContent(storeDestination, localSource, timeout, copyFlag, acquireSourceReaderLock); })); }
public async Task CopyContentAsync(string destination, string source, TimeSpan timeout, CopyFlag copyFlag = CopyFlag.AtomicCopy, bool checkFolderMarkFile = false) { await this.ImageStore.CopyContentAsync(source, destination, timeout, ManifestValidatorUtility.FabricAssemblies, copyFlag, checkFolderMarkFile); }
public void DownloadContent(string imageStoreConnectionString, string remoteSource, string localDestination, TimeSpan timeout, CopyFlag imageCopyFlag) { this.fabricClient.ThrowIfDisposed(); Requires.Argument <string>("remoteSource", remoteSource).NotNullOrEmpty(); Requires.Argument <string>("localDestination", localDestination).NotNullOrEmpty(); IImageStore imageStore = this.fabricClient.GetImageStore(imageStoreConnectionString); imageStore.DownloadContent(remoteSource, localDestination, timeout, imageCopyFlag); }
public void UploadContent(string imageStoreConnectionString, string remoteDestination, string localSource, IImageStoreProgressHandler progressHandler, TimeSpan timeout, CopyFlag imageCopyFlag, bool acquireSourceReaderLock) { this.fabricClient.ThrowIfDisposed(); Requires.Argument <string>("localSource", localSource).NotNullOrEmpty(); Requires.Argument <string>("remoteDestination", remoteDestination).NotNullOrEmpty(); Requires.Argument <string>("imageStoreConnectionString", imageStoreConnectionString).NotNullOrEmpty(); IImageStore imageStore = this.fabricClient.GetImageStore(imageStoreConnectionString); if (progressHandler == null) { imageStore.UploadContent( remoteDestination, localSource, timeout, CopyFlag.AtomicCopy, acquireSourceReaderLock); } else { imageStore.UploadContent( remoteDestination, localSource, progressHandler, timeout, imageCopyFlag, acquireSourceReaderLock); } }
public Task UploadContentAsync(string imageStoreConnectionString, string remoteDestination, string localSource, TimeSpan timeout, CopyFlag imageCopyFlag, bool acquireSourceReaderLock) { this.fabricClient.ThrowIfDisposed(); Requires.Argument <string>("localSource", localSource).NotNullOrEmpty(); Requires.Argument <string>("remoteDestination", remoteDestination).NotNullOrEmpty(); Requires.Argument <string>("imageStoreConnectionString", imageStoreConnectionString).NotNullOrEmpty(); IImageStore imageStore = this.fabricClient.GetImageStore(imageStoreConnectionString); return(imageStore.UploadContentAsync( remoteDestination, localSource, timeout, imageCopyFlag, acquireSourceReaderLock)); }
/// <summary> /// Downloads content from the XStore to local destination. /// </summary> /// <param name="tag">Location (relative to RootUri) from where to download the content.</param> /// <param name="destinationSoftLink">Physical location where to download the content.</param> /// <param name="handler">Defines the behavior to process progress information from the downloading operation.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string tag, string destinationSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); destinationSoftLink = this.GetLocalPath(destinationSoftLink); try { using (XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); bool xstoreFileExist = xstoreFileOperation.XStoreFileExists(tag, helper); bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(tag, true, helper); if ((!xstoreFileExist) && (!xstoreFolderExist)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, tag)); } if (xstoreFileExist) { // this is a single blob copy from xstore to smb xstoreFileOperation.CopyFile( tag, destinationSoftLink, XStoreFileOperationType.CopyFromXStoreToSMB, helper); } else { // this is a multiple blob (folder) copy from xstore to smb xstoreFileOperation.CopyFolder( tag, destinationSoftLink, XStoreFileOperationType.CopyFromXStoreToSMB, copyFlag, null, null, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
/// <summary> /// Downloads content from the XStore to local destination. /// </summary> /// <param name="tag">Location (relative to RootUri) from where to download the content.</param> /// <param name="destinationSoftLink">Physical location where to download the content.</param> /// <param name="timeout"> Download timeout in milliseconds.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string tag, string destinationSoftLink, TimeSpan timeout, CopyFlag copyFlag) { this.DownloadContent(tag, destinationSoftLink, null, timeout, copyFlag); }
/// <summary> /// Copies content from a path in the XStore to the destination path in the XStore /// </summary> /// <param name="remoteSource"> Location relative to RootUri where the content to be copied will be found. </param> /// <param name="remoteDestination"> Location relative to RootUri where the content needs to be copied. </param> /// <param name="timeout">The timeout for performing the copying operation.</param> /// <param name="skipFiles">The list of the blobs to be skipped for copying </param> /// <param name="copyFlag">The copying control information to specify how blob can be overwritten.</param> /// <param name="checkMarkFile">Indicats whether to check mark file during copying.</param> public void CopyContent(string remoteSource, string remoteDestination, TimeSpan timeout, string[] skipFiles, CopyFlag copyFlag, bool checkMarkFile) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); try { using ( XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { remoteSource = XStoreCommon.FormatXStoreUri(remoteSource); remoteDestination = XStoreCommon.FormatXStoreUri(remoteDestination); bool xstoreFileExist = xstoreFileOperation.XStoreFileExists(remoteSource, helper); bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(remoteSource, checkMarkFile, helper); if ((!xstoreFileExist) && (!xstoreFolderExist)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, remoteSource)); } if (copyFlag == CopyFlag.AtomicCopy) { this.DeleteContent(remoteDestination, helper == null ? timeout : helper.GetRemainingTime()); } if (xstoreFileExist) { // this is a single blob copy from xstore to xstore xstoreFileOperation.CopyFile( remoteSource, remoteDestination, XStoreFileOperationType.CopyFromXStoreToXStore, helper); } else { xstoreFileOperation.CopyFolder( remoteSource, remoteDestination, XStoreFileOperationType.CopyFromXStoreToXStore, copyFlag, null, skipFiles, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
public void UploadContent(string remoteDestination, string localSource, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag, bool acquireSourceReaderLock) { CheckForReservedImageStoreFolders(remoteDestination); MethodInfo uploadContentMethodInfo = this.XStoreType.GetMethod( "UploadContent", new[] { typeof(string), typeof(string), typeof(IImageStoreProgressHandler), typeof(TimeSpan), typeof(CopyFlag), typeof(bool) }); if (uploadContentMethodInfo == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_MethodLookupFailed, "UploadContent")); } uploadContentMethodInfo.Invoke( this.XStore, BindingFlags.InvokeMethod, Type.DefaultBinder, new object[] { remoteDestination, localSource, handler, timeout, copyFlag, acquireSourceReaderLock }, CultureInfo.CurrentCulture); }
/// <summary> /// Parses the command line arguments, applies the constraints and generates a structured accessor to the /// command line arguments. /// </summary> /// <param name="args">The command line arguments.</param> /// <returns>True if the command line arguments were proper, false otherwise.</returns> internal bool Parse(string[] args) { if (args.Length < 1 || args[0] == "/?") { return(false); } int i = 1; while (i != args.Length) { switch (args[i]) { case "-c": this.connectionString = args[++i]; break; case "-f": this.fileName = args[++i]; break; case "-x": this.storeTag = args[++i]; break; case "-l": this.localTag = args[++i]; break; case "-g": this.copyFlag = (CopyFlag)Enum.Parse(typeof(CopyFlag), args[++i]); break; case "-b": this.XStoreMinTransferBPS = int.Parse(args[++i], CultureInfo.InvariantCulture); break; case "-o": this.outputFile = args[++i]; break; default: return(false); } i++; } this.command = (Commands)Enum.Parse(typeof(Commands), args[0]); if (string.IsNullOrEmpty(this.connectionString)) { bool isEncrypted; NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); var configValue = configStore.ReadString("Management", "ImageStoreConnectionString", out isEncrypted); if (isEncrypted) { var secureString = NativeConfigStore.DecryptText(configValue); var secureCharArray = FabricValidatorUtility.SecureStringToCharArray(secureString); this.connectionString = new string(secureCharArray); } else { this.connectionString = configValue; } } if (this.command == Commands.Delete) { if (string.IsNullOrEmpty(this.storeTag) && string.IsNullOrEmpty(this.fileName)) { return(false); } } else if (this.command == Commands.Exists) { if (string.IsNullOrEmpty(this.outputFile)) { return(false); } } else { if (string.IsNullOrEmpty(this.fileName)) { if (string.IsNullOrEmpty(this.localTag) || string.IsNullOrEmpty(this.storeTag)) { return(false); } } else { if (!string.IsNullOrEmpty(this.localTag) || !string.IsNullOrEmpty(this.storeTag)) { return(false); } } } return(true); }
/// <summary> /// Copies content from a path in the XStore to the destination path in the XStore /// </summary> /// <param name="remoteSource"> Location relative to RootUri where the content to be copied will be found. </param> /// <param name="remoteDestination"> Location relative to RootUri where the content needs to be copied. </param> /// <param name="timeout">The timeout for performing the copying operation.</param> /// <param name="skipFiles">The list of the blobs to be skipped for copying </param> /// <param name="copyFlag">The copying control information to specify how blob can be overwritten.</param> /// <param name="checkMarkFile">Indicats whether to check mark file during copying.</param> public void CopyContent(string remoteSource, string remoteDestination, TimeSpan timeout, string[] skipFiles, CopyFlag copyFlag, bool checkMarkFile) { MethodInfo copyContentMethodInfo = this.XStoreType.GetMethod( "CopyContent", new[] { typeof(string), typeof(string), typeof(TimeSpan), typeof(string[]), typeof(CopyFlag), typeof(bool) }); if (copyContentMethodInfo == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_MethodLookupFailed, "CopyContent")); } copyContentMethodInfo.Invoke( this.XStore, BindingFlags.InvokeMethod, Type.DefaultBinder, new object[] { remoteSource, remoteDestination, timeout, skipFiles, copyFlag, checkMarkFile }, CultureInfo.CurrentCulture); }
/// <summary> /// Uploads content of the local source to the native image store at the remote destination. /// </summary> /// <param name="remoteDestination">Location relative to RootUri where the content needs to be uploaded.</param> /// <param name="localSource">local location of the source.</param> /// <param name="timeout">The timeout for performing the uploading operation.</param> /// <param name="imageCopyFlag">The copying control information to specify how file can be overwritten.</param> /// <param name="acquireSourceReaderLock">Indicates whether to acquire reader lock.</param> public void UploadContent(string remoteDestination, string localSource, TimeSpan timeout, CopyFlag imageCopyFlag, bool acquireSourceReaderLock) { this.UploadContent(remoteDestination, localSource, null, timeout, imageCopyFlag, acquireSourceReaderLock); }
/// <summary> /// Downloads content from the XStore to local destination. /// </summary> /// <param name="remoteSource">Location (relative to RootUri) from where to download the content.</param> /// <param name="localDestination">Physical location where to download the content.</param> /// <param name="handler">Defines the behavior to process progress information from the downloading operation.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string remoteSource, string localDestination, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag) { MethodInfo downloadContentMethodInfo = this.XStoreType.GetMethod( "DownloadContent", new[] { typeof(string), typeof(string), typeof(IImageStoreProgressHandler), typeof(TimeSpan), typeof(CopyFlag) }); if (downloadContentMethodInfo == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_MethodLookupFailed, "DownloadContent")); } downloadContentMethodInfo.Invoke( this.XStore, BindingFlags.InvokeMethod, Type.DefaultBinder, new object[] { remoteSource, localDestination, handler, timeout, copyFlag }, CultureInfo.CurrentCulture); }
/// <summary> /// Copies content from a path in the ImageStore to the destination path in the ImageStore. /// </summary> /// <param name="remoteSource">The relative path of source file image store to be copied from.</param> /// <param name="remoteDestination">The relative path of destination image store content to be copied to.</param> /// <param name="timeout">The timeout for performing the copying operation.</param> /// <param name="skipFiles">The list of the files names to be skipped for copying.</param> /// <param name="imageCopyFlag">The copying control information to specify how file can be overwritten.</param> /// <param name="checkMarkFile">Indicats whether to check mark file during copying.</param> public void CopyContent(string remoteSource, string remoteDestination, TimeSpan timeout, string[] skipFiles, CopyFlag imageCopyFlag, bool checkMarkFile) { Utility.WrapNativeSyncInvokeInMTA(() => { this.CopyContentWrapper(remoteSource, remoteDestination, Utility.ToMilliseconds(timeout, "timeout"), skipFiles, imageCopyFlag, checkMarkFile); }, "CopyContent"); }
/// <summary> /// Uploads the local source content to the image store at the remote destination. /// </summary> /// <param name="storeSource"> Location (relative to RootUri) from where to download the content. </param> /// <param name="storeDestination"> Location relative to RootUri where the content needs to be uploaded. </param> /// <param name="timeout">The timeout for copy content operation.</param> /// <param name="skipFiles">Files that do not need to be copied.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten</param> /// <param name="checkMarkFile">Flag the specified the checkmark file.</param> public void CopyContent(string storeSource, string storeDestination, TimeSpan timeout, string[] skipFiles, CopyFlag copyFlag, bool checkMarkFile) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); FileReaderLock readerLock = null; try { string smbSourcePath = this.ConvertTagToSMBPath(storeSource); string smbDestinationPath = this.ConvertTagToSMBPath(storeDestination); readerLock = new FileReaderLock(smbSourcePath); if (!readerLock.Acquire()) { throw new FabricTransientException(StringResources.Error_ImageStoreAcquireFileLockFailed, FabricErrorCode.ImageStoreAcquireFileLockFailed); } if (helper != null) { helper.ThrowIfExpired(); } #if !DotNetCoreClr using (WindowsImpersonationContext impersonationContext = this.GetImpersonationContext()) #endif { bool fabricDirectoryExists = FabricDirectory.Exists(smbSourcePath); if (fabricDirectoryExists && skipFiles.Any()) { string[] fileNames = FabricDirectory.GetFiles(smbSourcePath, "*", false, SearchOption.TopDirectoryOnly); string[] filtered = fileNames.Where(file => !skipFiles.Contains <string>(file)).ToArray <string>(); if (filtered.Count() < fileNames.Count()) { foreach (string file in filtered) { CopyCallerHoldsReaderLock(Path.Combine(smbSourcePath, file), Path.Combine(smbDestinationPath, file), copyFlag, helper); } } else { CopyCallerHoldsReaderLock(smbSourcePath, smbDestinationPath, copyFlag, helper); } } else { bool fabricFileExist = FabricFile.Exists(smbSourcePath); if ((!FabricFile.Exists(smbSourcePath)) && (!FabricDirectory.Exists(smbSourcePath))) { throw new IOException(string.Format(CultureInfo.CurrentCulture, StringResources.ImageStoreError_DoesNotExistError, smbSourcePath)); } CopyCallerHoldsReaderLock(smbSourcePath, smbDestinationPath, copyFlag, helper); } } } catch (IOException exception) { if (exception.GetType() == typeof(IOException)) { throw new FabricImageStoreIOException(exception); } else { throw; } } finally { if (readerLock != null) { readerLock.Dispose(); } } }
/// <summary> /// Downloads content from the image store to local destination. /// </summary> /// <param name="remoteSource">The relative path of source image store to be downloaded from.</param> /// <param name="localDestination">The local destination path to download the content.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="imageCopyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string remoteSource, string localDestination, TimeSpan timeout, CopyFlag imageCopyFlag) { this.DownloadContent(remoteSource, localDestination, null, timeout, imageCopyFlag); }
/// <summary> /// Downloads content from the image store to local destination. /// </summary> /// <param name="storeSource"> Location (relative to RootUri) from where to download the content. </param> /// <param name="localDestination"> Physical location where to download the content. </param> /// <param name="copyFlag">Copy control information to specify how file can be overwritten</param> /// <param name="timeout">Download timeout</param> public void DownloadContent(string storeSource, string localDestination, TimeSpan timeout, CopyFlag copyFlag) { this.DownloadContent(storeSource, localDestination, null, timeout, copyFlag); }
/// <summary> /// Downloads content from the image store to local destination. /// </summary> /// <param name="storeSource">The relative path of source image store to be downloaded from.</param> /// <param name="localDestination">The local destination path to download the content.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> /// <returns></returns> public Task DownloadContentAsync(string storeSource, string localDestination, TimeSpan timeout, CopyFlag copyFlag) { return(Task.Run(() => { this.DownloadContent(storeSource, localDestination, timeout, copyFlag); })); }
/// <summary> /// Downloads content from the file image store to local destination. /// </summary> /// <param name="storeSource">The relative path of source file image store to be downloaded from.</param> /// <param name="localDestination">The local destination path to download the content.</param> /// <param name="handler">The image store progress handler which is not supported at the file image store.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string storeSource, string localDestination, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); localDestination = this.GetLocalPath(localDestination); string tempDirectory = null; FileReaderLock readerLock = null; try { string smbTag = this.ConvertTagToSMBPath(storeSource); if ((!FabricFile.Exists(smbTag)) && (!FabricDirectory.Exists(smbTag))) { throw new IOException(string.Format(CultureInfo.CurrentCulture, StringResources.ImageStoreError_DoesNotExistError, smbTag)); } readerLock = new FileReaderLock(smbTag); if (!readerLock.Acquire()) { throw new FabricTransientException(StringResources.Error_ImageStoreAcquireFileLockFailed, FabricErrorCode.ImageStoreAcquireFileLockFailed); } if (helper != null) { helper.ThrowIfExpired(); } if (accessDescription != null && !accessDescription.HasWriteAccess) { // Copy the content from the remote Store to a temp location using the ImpersonationContext string tempLocalResource = null; #if !DotNetCoreClr using (WindowsImpersonationContext impersonationContext = accessDescription.WindowsIdentity.Impersonate()) #endif { tempDirectory = CreateAndAclDirectory(); tempLocalResource = Path.Combine(tempDirectory, Path.GetRandomFileName()); CopyCallerHoldsReaderLock(smbTag, tempLocalResource, CopyFlag.AtomicCopy, helper); } readerLock.Release(); // Copy the content from the temp location to the local destination outside the ImpersonationContext CopyCallerHoldsReaderLock(tempLocalResource, localDestination, copyFlag, helper); } #if !DotNetCoreClr using (WindowsImpersonationContext impersonationContext = this.GetImpersonationContext()) #endif { CopyCallerHoldsReaderLock(smbTag, localDestination, copyFlag, helper); } } catch (IOException exception) { if (exception.GetType() == typeof(IOException)) { throw new FabricImageStoreException(StringResources.Error_ImageStoreIOException, exception); } else { throw; } } finally { if (readerLock != null) { readerLock.Dispose(); } if (tempDirectory != null && FabricDirectory.Exists(tempDirectory)) { FabricDirectory.Delete(tempDirectory, recursive: true, deleteReadOnlyFiles: true); } } }
private void DownloadContentWrapper(string remoteSource, string localDestination, IImageStoreProgressHandler progressHandler, UInt32 timeoutMilliseconds, CopyFlag imageCopyFlag) { using (var pin = new PinCollection()) { this.nativeClient.DownloadContent2( pin.AddObject(remoteSource), pin.AddObject(localDestination), progressHandler == null ? null : new NativeImageStoreProgressEventHandlerBroker(progressHandler), timeoutMilliseconds, ToNative(imageCopyFlag)); } }
private void CopyCallerHoldsReaderLock(string source, string destination, CopyFlag copyFlag, TimeoutHelper helper) { string destinationDirectory = FabricPath.GetDirectoryName(destination); if (!string.IsNullOrEmpty(destinationDirectory) && !FabricDirectory.Exists(destinationDirectory)) { FabricDirectory.CreateDirectory(destinationDirectory); } using (FileWriterLock writerLock = new FileWriterLock(destination)) { if (!writerLock.Acquire()) { throw new FabricTransientException(StringResources.Error_ImageStoreAcquireFileLockFailed, FabricErrorCode.ImageStoreAcquireFileLockFailed); } if (helper != null) { helper.ThrowIfExpired(); } if (FabricFile.Exists(source)) { // This is a file copy if (FabricFile.Exists(destination)) { FabricFile.Delete(destination, deleteReadonly: true); } int retryCount = 0; while (helper == null || !TimeoutHelper.HasExpired(helper)) { try { bool shouldOverwrite = (copyFlag != CopyFlag.AtomicCopySkipIfExists); FabricFile.Copy(source, destination, shouldOverwrite); break; } catch (UnauthorizedAccessException) { TraceSource.WriteInfo( TraceType, "Uploading {0} to {1} caused UnauthorizedAccessException. RetryCount: {2}.", source, destination, retryCount); if (retryCount++ > 3) { throw; } // This could happen when a file is marked for delete and we try to delete // it again or try to open the file. Retrying after sometime should fix the issue. Thread.Sleep(TimeSpan.FromSeconds(retryCount)); } if (helper != null) { helper.ThrowIfExpired(); } } } else { // This is a folder copy using (FolderCopy fc = new FolderCopy(copyFlag, null)) { fc.Copy(source, destination); } } } }
/// <summary> /// Uploads content of the local source to the native image store at the remote destination. /// </summary> /// <param name="remoteDestination">Location relative to image store root where the content needs to be uploaded.</param> /// <param name="localSource">local location of the source.</param> /// <param name="progressHandler">Defines the behavior to process progress information from the uploading operation.</param> /// <param name="timeout">The timeout for performing the uploading operation.</param> /// <param name="imageCopyFlag">Copy control information to specify how file can be overwritten.</param> /// <param name="acquireSourceReaderLock">Indicates whether to acquire reader lock.</param> public void UploadContent(string remoteDestination, string localSource, IImageStoreProgressHandler progressHandler, TimeSpan timeout, CopyFlag imageCopyFlag, bool acquireSourceReaderLock) { Utility.WrapNativeSyncInvokeInMTA(() => { this.UploadContentWrapper(remoteDestination, localSource, progressHandler, Utility.ToMilliseconds(timeout, "timeout"), imageCopyFlag); }, "UploadContent"); }
/// <summary> /// Uploads content of the local source to the image store at the remote destination. /// </summary> /// <param name="tag">Location relative to RootUri where the content needs to be uploaded.</param> /// <param name="sourceSoftLink">Physical location of the source.</param> /// <param name="timeout">The timeout for performing the uploading operation.</param> /// <param name="copyFlag">The copying flag specifying copy type </param> /// <param name="acquireSourceReaderLock">Indicates whether to acquire reader lock.</param> public void UploadContent(string tag, string sourceSoftLink, TimeSpan timeout, CopyFlag copyFlag, bool acquireSourceReaderLock) { this.UploadContent(tag, sourceSoftLink, null, timeout, copyFlag, acquireSourceReaderLock); }