public override void ExecuteCmdlet() { blobChannel = this.GetBlobChannel(); destChannel = GetDestinationChannel(); IStorageFileManagement srcChannel = Channel; Action copyAction = null; string target = DestFile != null ? DestFile.Name : DestFilePath; switch (ParameterSetName) { case ContainerNameParameterSet: case ContainerParameterSet: case BlobFilePathParameterSet: case BlobFileParameterSet: copyAction = () => this.StartCopyFromBlob(); break; case ShareNameParameterSet: case ShareParameterSet: case FileFilePathParameterSet: case FileFileParameterSet: copyAction = () => this.StartCopyFromFile(); break; case UriFilePathParameterSet: case UriFileParameterSet: copyAction = () => this.StartCopyFromUri(); break; } if (copyAction != null && ShouldProcess(target, "Start file copy")) { copyAction(); } }
internal async Task <SharedAccessFilePolicies> GetPoliciesAsync(IStorageFileManagement localChannel, string shareName, string policyName) { CloudFileShare share = localChannel.GetShareReference(shareName); FileSharePermissions permissions = await localChannel.GetSharePermissionsAsync(share, null, null, null, CmdletCancellationToken); return(permissions.SharedAccessPolicies); }
public override void ExecuteCmdlet() { blobChannel = this.GetBlobChannel(); destChannel = GetDestinationChannel(); IStorageFileManagement srcChannel = Channel; switch (ParameterSetName) { case ContainerNameParameterSet: case ContainerParameterSet: case BlobFilePathParameterSet: case BlobFileParameterSet: this.StartCopyFromBlob(); break; case ShareNameParameterSet: case ShareParameterSet: case FileFilePathParameterSet: case FileFileParameterSet: this.StartCopyFromFile(); break; case UriFilePathParameterSet: case UriFileParameterSet: this.StartCopyFromUri(); break; } }
/// <summary> /// Validate the file share access policy /// </summary> /// <param name="policy">SharedAccessFilePolicy object</param> /// <param name="policyIdentifier">The policy identifier which need to be checked.</param> public static bool ValidateShareAccessPolicy(IStorageFileManagement channel, string shareName, string policyIdentifier, bool shouldNoPermission, bool shouldNoStartTime, bool shouldNoExpiryTime) { if (string.IsNullOrEmpty(policyIdentifier)) { return(true); } CloudFileShare fileShare = channel.GetShareReference(shareName); FileSharePermissions permission = fileShare.GetPermissions(); SharedAccessFilePolicy sharedAccessPolicy = GetExistingPolicy <SharedAccessFilePolicy>(permission.SharedAccessPolicies, policyIdentifier); if (shouldNoPermission && sharedAccessPolicy.Permissions != SharedAccessFilePermissions.None) { throw new InvalidOperationException(Resources.SignedPermissionsMustBeOmitted); } if (shouldNoStartTime && sharedAccessPolicy.SharedAccessStartTime.HasValue) { throw new InvalidOperationException(Resources.SignedStartTimeMustBeOmitted); } if (shouldNoExpiryTime && sharedAccessPolicy.SharedAccessExpiryTime.HasValue) { throw new InvalidOperationException(Resources.SignedExpiryTimeMustBeOmitted); } return(!sharedAccessPolicy.SharedAccessExpiryTime.HasValue); }
/// <summary> /// Set up the Channel object for destination share and file /// </summary> internal IStorageFileManagement GetDestinationChannel() { //If destChannel exits, reuse it. //If desContext exits, use it. //If Channl object exists, use it. //Otherwise, create a new channel. IStorageFileManagement destChannel = default(IStorageFileManagement); if (destChannel == null) { AzureStorageContext context = null; if (ContainerNameParameterSet == this.ParameterSetName || ContainerParameterSet == this.ParameterSetName || BlobFilePathParameterSet == this.ParameterSetName || ShareNameParameterSet == this.ParameterSetName || ShareParameterSet == this.ParameterSetName || FileFilePathParameterSet == this.ParameterSetName || UriFilePathParameterSet == this.ParameterSetName) { context = this.GetCmdletStorageContext(DestContext); } else { context = AzureStorageContext.EmptyContextInstance; } destChannel = new StorageFileManagement(context); } return(destChannel); }
private void StartCopyFromFile(IStorageFileManagement srcChannel, IStorageBlobManagement destChannel, string srcShareName, string srcFilePath, string destContainerName, string destBlobName) { NamingUtil.ValidateShareName(srcShareName, false); CloudFileShare share = srcChannel.GetShareReference(srcShareName); this.StartCopyFromFile(destChannel, share.GetRootDirectoryReference(), srcFilePath, destContainerName, destBlobName); }
/// <summary> /// Stop copy operation by CloudBlob object /// </summary> /// <param name="blob">CloudBlob object</param> /// <param name="copyId">Copy id</param> private async Task StopCopyFile(long taskId, IStorageFileManagement localChannel, CloudFile file, string copyId) { FileRequestOptions requestOptions = RequestOptions; //Set no retry to resolve the 409 conflict exception requestOptions.RetryPolicy = new NoRetry(); string abortCopyId = string.Empty; if (string.IsNullOrEmpty(copyId) || Force) { //Make sure we use the correct copy id to abort //Use default retry policy for FetchBlobAttributes FileRequestOptions options = RequestOptions; await localChannel.FetchFileAttributesAsync(file, null, options, OperationContext, CmdletCancellationToken).ConfigureAwait(false); if (file.CopyState == null || string.IsNullOrEmpty(file.CopyState.CopyId)) { ArgumentException e = new ArgumentException(String.Format(Resources.FileCopyTaskNotFound, file.SnapshotQualifiedUri.ToString())); OutputStream.WriteError(taskId, e); } else { abortCopyId = file.CopyState.CopyId; } if (!Force) { string confirmation = String.Format(Resources.ConfirmAbortFileCopyOperation, file.SnapshotQualifiedUri.ToString(), abortCopyId); if (!await OutputStream.ConfirmAsync(confirmation).ConfigureAwait(false)) { string cancelMessage = String.Format(Resources.StopCopyOperationCancelled, file.SnapshotQualifiedUri.ToString()); OutputStream.WriteVerbose(taskId, cancelMessage); } } } else { abortCopyId = copyId; } await localChannel.AbortCopyAsync(file, abortCopyId, null, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false); string message = String.Format(Resources.StopCopyFileSuccessfully, file.SnapshotQualifiedUri.ToString()); OutputStream.WriteObject(taskId, message); }
/// <summary> /// Stop copy operation by CloudBlob object /// </summary> /// <param name="blob">CloudBlob object</param> /// <param name="copyId">Copy id</param> private async Task StopCopyFile(long taskId, IStorageFileManagement localChannel, CloudFile file, string copyId) { FileRequestOptions requestOptions = RequestOptions; //Set no retry to resolve the 409 conflict exception requestOptions.RetryPolicy = new NoRetry(); string abortCopyId = string.Empty; if (string.IsNullOrEmpty(copyId) || Force) { //Make sure we use the correct copy id to abort //Use default retry policy for FetchBlobAttributes FileRequestOptions options = RequestOptions; await localChannel.FetchFileAttributesAsync(file, null, options, OperationContext, CmdletCancellationToken); if (file.CopyState == null || string.IsNullOrEmpty(file.CopyState.CopyId)) { ArgumentException e = new ArgumentException(String.Format(Resources.FileCopyTaskNotFound, file.Uri.ToString())); OutputStream.WriteError(taskId, e); } else { abortCopyId = file.CopyState.CopyId; } if (!Force) { string confirmation = String.Format(Resources.ConfirmAbortFileCopyOperation, file.Uri.ToString(), abortCopyId); if (!await OutputStream.ConfirmAsync(confirmation)) { string cancelMessage = String.Format(Resources.StopCopyOperationCancelled, file.Uri.ToString()); OutputStream.WriteVerbose(taskId, cancelMessage); } } } else { abortCopyId = copyId; } await localChannel.AbortCopyAsync(file, abortCopyId, null, requestOptions, OperationContext, CmdletCancellationToken); string message = String.Format(Resources.StopCopyFileSuccessfully, file.Uri.ToString()); OutputStream.WriteObject(taskId, message); }
/// <summary> /// Set up the Channel object for destination share and file /// </summary> internal IStorageFileManagement GetDestinationChannel() { //If destChannel exits, reuse it. //If desContext exits, use it. //If Channl object exists, use it. //Otherwise, create a new channel. IStorageFileManagement destChannel = default(IStorageFileManagement); if (destChannel == null) { if (ContainerNameParameterSet == this.ParameterSetName || ContainerParameterSet == this.ParameterSetName || BlobFilePathParameterSet == this.ParameterSetName || ShareNameParameterSet == this.ParameterSetName || ShareParameterSet == this.ParameterSetName || FileFilePathParameterSet == this.ParameterSetName || UriFilePathParameterSet == this.ParameterSetName) { if (DestContext == null) { if (Channel != null) { destChannel = Channel; } else { destChannel = base.CreateChannel(); } } else { destChannel = new StorageFileManagement(this.GetCmdletStorageContext(DestContext)); } } else { destChannel = base.CreateChannel(); } } return(destChannel); }
public override void ExecuteCmdlet() { IStorageFileManagement localChannel = Channel; CloudFile file = null; if (null != this.File) { file = this.File; } else { string[] path = NamingUtil.ValidatePath(this.FilePath); file = this.BuildFileShareObjectFromName(this.ShareName).GetRootDirectoryReference().GetFileReferenceByPath(path); } Func <long, Task> taskGenerator = (taskId) => this.StopCopyFile(taskId, localChannel, file, CopyId); RunTask(taskGenerator); }
internal string SetAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName, DateTime? startTime, DateTime? expiryTime, string permission, bool noStartTime, bool noExpiryTime) { //Get existing permissions CloudFileShare share = localChannel.GetShareReference(shareName); FileSharePermissions permissions = localChannel.GetSharePermissions(share); //Set the policy with new value if (!permissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } SharedAccessFilePolicy policy = permissions.SharedAccessPolicies[policyName]; AccessPolicyHelper.SetupAccessPolicy<SharedAccessFilePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime); permissions.SharedAccessPolicies[policyName] = policy; //Set permission back to share localChannel.SetSharePermissions(share, permissions); WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessFilePolicy>(permissions.SharedAccessPolicies, policyName)); return policyName; }
internal string SetAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime) { //Get existing permissions CloudFileShare share = localChannel.GetShareReference(shareName); FileSharePermissions permissions = localChannel.GetSharePermissions(share); //Set the policy with new value if (!permissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } SharedAccessFilePolicy policy = permissions.SharedAccessPolicies[policyName]; AccessPolicyHelper.SetupAccessPolicy <SharedAccessFilePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime); permissions.SharedAccessPolicies[policyName] = policy; //Set permission back to share localChannel.SetSharePermissions(share, permissions, null, null, OperationContext); WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessFilePolicy>(permissions.SharedAccessPolicies, policyName)); return(policyName); }
internal async Task GetAzureShareStoredAccessPolicyAsync(long taskId, IStorageFileManagement localChannel, string shareName, string policyName) { SharedAccessFilePolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, shareName, policyName); if (!String.IsNullOrEmpty(policyName)) { if (shareAccessPolicies.Keys.Contains(policyName)) { OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessFilePolicy>(shareAccessPolicies, policyName)); } else { throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } } else { foreach (string key in shareAccessPolicies.Keys) { OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessFilePolicy>(shareAccessPolicies, key)); } } }
internal async Task GetAzureShareStoredAccessPolicyAsync(long taskId, IStorageFileManagement localChannel, string shareName, string policyName) { SharedAccessFilePolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, shareName, policyName); if (!String.IsNullOrEmpty(policyName)) { if (shareAccessPolicies.Keys.Contains(policyName)) { OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessFilePolicy>(shareAccessPolicies, policyName)); } else { throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } } else { foreach (string key in shareAccessPolicies.Keys) { OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessFilePolicy>(shareAccessPolicies, key)); } } }
internal bool RemoveAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName) { bool success = false; string result = string.Empty; //Get existing permissions CloudFileShare share = localChannel.GetShareReference(shareName); FileSharePermissions permissions = localChannel.GetSharePermissions(share); //remove the specified policy if (!permissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } if (ShouldProcess(policyName, "Remove policy")) { permissions.SharedAccessPolicies.Remove(policyName); localChannel.SetSharePermissions(share, permissions); success = true; } return success; }
internal bool RemoveAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName) { bool success = false; string result = string.Empty; //Get existing permissions CloudFileShare share = localChannel.GetShareReference(shareName); FileSharePermissions permissions = localChannel.GetSharePermissions(share); //remove the specified policy if (!permissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } if (this.Force || ConfirmRemove(policyName)) { permissions.SharedAccessPolicies.Remove(policyName); localChannel.SetSharePermissions(share, permissions); success = true; } return(success); }
internal async Task<SharedAccessFilePolicies> GetPoliciesAsync(IStorageFileManagement localChannel, string shareName, string policyName) { CloudFileShare share = localChannel.GetShareReference(shareName); FileSharePermissions permissions = await localChannel.GetSharePermissionsAsync(share, null, null, null, CmdletCancellationToken); return permissions.SharedAccessPolicies; }
/// <summary> /// Set up the Channel object for destination share and file /// </summary> internal IStorageFileManagement GetDestinationChannel() { //If destChannel exits, reuse it. //If desContext exits, use it. //If Channl object exists, use it. //Otherwise, create a new channel. IStorageFileManagement destChannel = default(IStorageFileManagement); if (destChannel == null) { AzureStorageContext context = null; if (ContainerNameParameterSet == this.ParameterSetName || ContainerParameterSet == this.ParameterSetName || BlobFilePathParameterSet == this.ParameterSetName || ShareNameParameterSet == this.ParameterSetName || ShareParameterSet == this.ParameterSetName || FileFilePathParameterSet == this.ParameterSetName || UriFilePathParameterSet == this.ParameterSetName) { context = this.GetCmdletStorageContext(DestContext); } else { context = AzureStorageContext.EmptyContextInstance; } destChannel = new StorageFileManagement(context); } return destChannel; }