/// <summary> /// get blob content /// </summary> /// <param name="container">source container object</param> /// <param name="blobName">source blob name</param> /// <param name="fileName">destination file name</param> /// <returns>the downloaded AzureStorageBlob object</returns> internal void GetBlobContent(CloudBlobContainer container, string blobName, string fileName) { if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } // Don't need get File full path here, since will get file full path in GetBlobContent() with blob object. ValidatePipelineCloudBlobContainer(container); if (UseTrack2Sdk()) { BlobContainerClient track2container = AzureStorageContainer.GetTrack2BlobContainerClient(container, Channel.StorageContext, ClientOptions); BlobBaseClient blobClient = track2container.GetBlobBaseClient(blobName); GetBlobContent(blobClient, fileName, true); } else { AccessCondition accessCondition = null; BlobRequestOptions requestOptions = RequestOptions; CloudBlob blob = GetBlobReferenceFromServerWithContainer(Channel, container, blobName, accessCondition, requestOptions, OperationContext); GetBlobContent(blob, fileName, true); } }
/// <summary> /// Start copy using transfer mangager by source uri /// </summary> /// <param name="uri">source uri</param> /// <param name="destContainer">Destination CloudBlobContainer object</param> /// <param name="destBlobName">Destination blob name</param> /// <returns>Destination CloudBlob object</returns> private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName) { NameUtil.ValidateContainerName(destContainer.Name); NameUtil.ValidateBlobName(destBlobName); await this.StartCopyFromUri(taskId, destChannel, uri, destContainer.GetBlockBlobReference(destBlobName)); }
public static Dictionary <string, int> TaskWallOfPersonTasks() { var personToTaskCount = new Dictionary <string, int>(); var currentSprint = App.GetReleaseScrumData().CurrentSprintProxy.GetInCompleteTasks(); foreach (var task in currentSprint) { string engName = NameUtil.ConvertToEngName(task.Owner); if (!personToTaskCount.ContainsKey(engName)) { personToTaskCount[engName] = 1; } else { personToTaskCount[engName]++; } } foreach (var task in App.GetReleaseScrumData().CurrentSprintProxy.GetCompletedTasks()) { string engName = NameUtil.ConvertToEngName(task.Owner); if (!personToTaskCount.ContainsKey(engName)) { personToTaskCount[engName] = 0; } } return(personToTaskCount); }
private static void transform() { using (Pnyx p = new Pnyx()) { p.read("C:/dev/asclepius/prod_import/BHC Patients from 1-1-15 thru 10-31-2018.csv"); p.parseCsv(hasHeader: true); p.withColumns(p2 => p2.lineTransformer(new DateTransform { formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE }), 4, 5, 6); p.rowTransformerFunc(row => { String fullName = row[2]; Name name = NameUtil.parseFullName(fullName); if (name == null) { return(null); } // Expands name into 4 columns row = RowUtil.replaceColumn(row, 3, name.firstName, name.middleName, name.lastName, name.suffix); return(row); }); p.tee(p2 => { p2.removeColumns(7 + 3, 8 + 3, 9 + 3); // plus 3 from name split above p2.rowFilter(new RepeatFilter()); p2.write("C:/dev/asclepius/prod_import/bhc_discharges.csv"); }); p.widthColumns(9 + 3); // plus 3 from name split above p.write("C:/dev/asclepius/prod_import/bhc_discharges_diagnosis.csv"); p.process(); } }
private static void ccmNames() { using (Pnyx p = new Pnyx()) { p.read("C:/dev/asclepius/prod_import/ccm_names.csv"); p.parseCsv(hasHeader: true); p.rowTransformerFunc(row => { String lastName = row[1]; Tuple <String, String> lastNameSuffix = NameUtil.parseSuffix(lastName); if (lastNameSuffix.Item2 == null) { return(null); } // Expands name into 2 columns row = RowUtil.replaceColumn(row, 2, lastNameSuffix.Item1, lastNameSuffix.Item2); return(row); }); p.rowTransformerFunc(row => { for (int i = 0; i < row.Count; i++) { row[i] = TextUtil.encodeSqlValue(row[i]); } return(row); }); p.print("update bhc_patient_ccm set lastname=$2, suffix=$3 where patientid=$1;"); p.write("C:/dev/asclepius/prod_import/ccm_names_update.sql"); p.process(); } }
/// <summary> /// remove azure blob /// </summary> /// <param name="container">CloudBlobContainer object</param> /// <param name="blobName">blob name</param> /// <returns>true if the blob is removed successfully, false if user cancel the remove operation</returns> internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localChannel, CloudBlobContainer container, string blobName) { if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } ValidatePipelineCloudBlobContainer(container); AccessCondition accessCondition = null; BlobRequestOptions requestOptions = null; ICloudBlob blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition, requestOptions, OperationContext, CmdletCancellationToken); if (null == blob && container.ServiceClient.Credentials.IsSharedKey) { throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, container.Name)); } else { //Construct the blob as CloudBlockBlob no matter what's the real blob type //We can't get the blob type if Credentials only have the delete permission and don't have read permission. blob = container.GetBlockBlobReference(blobName); } await RemoveAzureBlob(taskId, localChannel, blob, true); }
public void setType(Type t) { if (String.IsNullOrEmpty(this.Name)) { this.Name = NameUtil.getSqlName(t.Name); } }
/// <summary> /// remove azure table /// </summary> /// <param name="name">table name</param> /// <returns> /// true if the table is removed, false if user cancel the operation, /// otherwise throw an exception</returns> internal bool RemoveAzureTable(string name) { if (!NameUtil.IsValidTableName(name)) { throw new ArgumentException(String.Format(Resources.InvalidTableName, name)); } TableRequestOptions requestOptions = RequestOptions; CloudTable table = Channel.GetTableReference(name); if (!Channel.DoesTableExist(table, requestOptions, TableOperationContext)) { throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, name)); } if (force || TableIsEmpty(table) || ShouldContinue(string.Format("Remove table and all content in it: {0}", name), "")) { Channel.Delete(table, requestOptions, TableOperationContext); return(true); } else { return(false); } }
/// <summary> /// get blob content /// </summary> /// <param name="containerName">source container name</param> /// <param name="blobName">source blob name</param> /// <param name="fileName">file name</param> /// <returns>the downloaded AzureStorageBlob object</returns> internal void GetBlobContent(string containerName, string blobName, string fileName) { if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } if (!NameUtil.IsValidContainerName(containerName)) { throw new ArgumentException(String.Format(Resources.InvalidContainerName, containerName)); } CloudBlobContainer container = Channel.GetContainerReference(containerName); BlobRequestOptions requestOptions = RequestOptions; AccessCondition accessCondition = null; ICloudBlob blob = Channel.GetBlobReferenceFromServer(container, blobName, accessCondition, requestOptions, OperationContext); if (null == blob) { throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, containerName)); } GetBlobContent(blob, fileName, true); }
/// <summary> /// Start copy using transfer mangager by source uri /// </summary> /// <param name="uri">source uri</param> /// <param name="destContainer">Destination CloudBlobContainer object</param> /// <param name="destBlobName">Destination blob name</param> /// <returns>Destination CloudBlob object</returns> private async Task StartCopyInTransferManager(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName) { NameUtil.ValidateContainerName(destContainer.Name); NameUtil.ValidateBlobName(destBlobName); Dictionary <string, string> BlobPath = new Dictionary <string, string>() { { "Container", destContainer.Name }, { "Blob", destBlobName } }; DataMovementUserData data = new DataMovementUserData() { Data = BlobPath, TaskId = taskId, Channel = destChannel, Record = null }; TransferJob startCopyJob = new TransferJob( new TransferLocation(uri), new TransferLocation(destContainer.GetBlockBlobReference(destBlobName)), TransferMethod.AsyncCopyInAzureStorageWithoutMonitor); await this.EnqueueStartCopyJob(startCopyJob, data); }
internal string CreateAzureQueueStoredAccessPolicy(IStorageQueueManagement localChannel, string queueName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission) { if (!NameUtil.IsValidStoredAccessPolicyName(policyName)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName)); } //Get existing permissions CloudQueue queue = Channel.GetQueueReference(queueName); QueuePermissions queuePermissions = localChannel.GetPermissions(queue); //Add new policy if (queuePermissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName)); } SharedAccessQueuePolicy policy = new SharedAccessQueuePolicy(); AccessPolicyHelper.SetupAccessPolicy <SharedAccessQueuePolicy>(policy, startTime, expiryTime, permission); queuePermissions.SharedAccessPolicies.Add(policyName, policy); //Set permissions back to queue localChannel.SetPermissions(queue, queuePermissions); return(policyName); }
public void ExtractNameString() { Assert.Null(NameUtil.extractNameString(null)); Assert.Null(NameUtil.extractNameString("")); Assert.Null(NameUtil.extractNameString(" ")); Assert.Null(NameUtil.extractNameString(" ")); Assert.Null(NameUtil.extractNameString(" *^*& ")); Assert.Null(NameUtil.extractNameString("123")); Assert.Null(NameUtil.extractNameString(" 123 ")); Assert.Equal("a", NameUtil.extractNameString("a")); Assert.Equal("a", NameUtil.extractNameString(" a")); Assert.Equal("a", NameUtil.extractNameString("a ")); Assert.Equal("a", NameUtil.extractNameString("a--")); Assert.Equal("a", NameUtil.extractNameString("a//")); Assert.Equal("a", NameUtil.extractNameString("--a ")); Assert.Equal("jimbo", NameUtil.extractNameString("jimbo1")); Assert.Equal("jimbo", NameUtil.extractNameString("$%^$^jimbo1)()*(&&++=")); Assert.Equal("jimbo", NameUtil.extractNameString(" jimbo ")); Assert.Equal("jimbo", NameUtil.extractNameString("1j1i1m1bo1")); Assert.Equal("jimbo", NameUtil.extractNameString("jimbo")); Assert.Equal("o'clark", NameUtil.extractNameString("o'clark")); Assert.Equal("o'clark", NameUtil.extractNameString("o'''clark")); Assert.Equal("jimbo otto", NameUtil.extractNameString("jimbo otto")); Assert.Equal("jimbo otto", NameUtil.extractNameString(" jimbo otto ")); Assert.Equal("jimbo otto", NameUtil.extractNameString("jimbo otto")); Assert.Equal("jimbo otto", NameUtil.extractNameString("jimbo otto")); Assert.Equal("jimbo otto", NameUtil.extractNameString("jimbo - otto")); Assert.Equal("jimbo otto", NameUtil.extractNameString("jimbo / otto")); Assert.Equal("jimbo-otto", NameUtil.extractNameString("jimbo-otto")); Assert.Equal("jimbo-otto", NameUtil.extractNameString("jimbo--otto")); Assert.Equal("jimbo-otto", NameUtil.extractNameString("-jimbo-otto-")); }
/// <summary> /// remove azure blob /// </summary> /// <param name="container">CloudBlobContainer object</param> /// <param name="blobName">blob name</param> /// <returns>true if the blob is removed successfully, false if user cancel the remove operation</returns> internal bool RemoveAzureBlob(CloudBlobContainer container, string blobName) { if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } ValidatePipelineCloudBlobContainer(container); AccessCondition accessCondition = null; BlobRequestOptions requestOptions = RequestOptions; ICloudBlob blob = Channel.GetBlobReferenceFromServer(container, blobName, accessCondition, requestOptions, OperationContext); if (null == blob && container.ServiceClient.Credentials.IsSharedKey) { throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, container.Name)); } else { //Construct the blob as CloudBlockBlob no matter what's the real blob type //We can't get the blob type if Credentials only have the delete permission and don't have read permission. blob = container.GetBlockBlobReference(blobName); } return(RemoveAzureBlob(blob, true)); }
/// <summary> /// set the access level of specified container /// </summary> /// <param name="name">container name</param> /// <param name="accessLevel">access level in ("off", "blob", "container")</param> internal void SetContainerAcl(string name, BlobContainerPublicAccessType accessLevel) { if (!NameUtil.IsValidContainerName(name)) { throw new ArgumentException(String.Format(Resources.InvalidContainerName, name)); } BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.PublicAccess = accessLevel; BlobRequestOptions requestOptions = RequestOptions; AccessCondition accessCondition = null; CloudBlobContainer container = Channel.GetContainerReference(name); if (!Channel.DoesContainerExist(container, requestOptions, OperationContext)) { throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name)); } Channel.SetContainerPermissions(container, permissions, accessCondition, requestOptions, OperationContext); AzureStorageContainer azureContainer = new AzureStorageContainer(container, permissions); if (PassThru) { WriteObjectWithStorageContext(azureContainer); } }
/// <summary> /// remove azure table /// </summary> /// <param name="name">table name</param> /// <returns> /// true if the table is removed, false if user cancel the operation, /// otherwise throw an exception</returns> internal bool RemoveAzureTable(string name) { if (!NameUtil.IsValidTableName(name)) { throw new ArgumentException(String.Format(Resources.InvalidTableName, name)); } TableRequestOptions requestOptions = RequestOptions; CloudTable table = Channel.GetTableReference(name); if (!Channel.DoesTableExist(table, requestOptions, OperationContext)) { throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, name)); } if (force || ConfirmRemove(name)) { Channel.Delete(table, requestOptions, OperationContext); return(true); } else { return(false); } }
/// <summary> /// get blob content /// </summary> /// <param name="container">source container object</param> /// <param name="blobName">source blob name</param> /// <param name="fileName">destination file name</param> /// <returns>the downloaded AzureStorageBlob object</returns> internal void GetBlobContent(CloudBlobContainer container, string blobName, string fileName) { if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } string filePath = GetFullReceiveFilePath(fileName, blobName, null); ValidatePipelineCloudBlobContainer(container); if (UseTrack2SDK()) { BlobContainerClient track2container = AzureStorageContainer.GetTrack2BlobContainerClient(container, Channel.StorageContext, ClientOptions); BlobBaseClient blobClient = track2container.GetBlobBaseClient(blobName); GetBlobContent(blobClient, filePath, true); } else { AccessCondition accessCondition = null; BlobRequestOptions requestOptions = RequestOptions; CloudBlob blob = GetBlobReferenceFromServerWithContainer(Channel, container, blobName, accessCondition, requestOptions, OperationContext); GetBlobContent(blob, filePath, true); } }
/// <summary> /// get the DataLakeFileSystemClient object by name if DataLakeFileSystem exists /// </summary> /// <param name="fileSystemName">DataLakeFileSystem name</param> /// <returns>return DataLakeFileSystemClient object if specified DataLakeFileSystem exists, otherwise throw an exception</returns> internal DataLakeFileSystemClient GetFileSystemClientByName(IStorageBlobManagement localChannel, string fileSystemName, bool skipCheckExists = false) { if (!NameUtil.IsValidContainerName(fileSystemName)) { throw new ArgumentException(String.Format(Resources.InvalidContainerName, fileSystemName)); } Uri fileSystemUri = localChannel.StorageContext.StorageAccount.CreateCloudBlobClient().GetContainerReference(fileSystemName).Uri; DataLakeFileSystemClient fileSystem; if (localChannel.StorageContext.StorageAccount.Credentials.IsToken) //Oauth { fileSystem = new DataLakeFileSystemClient(fileSystemUri, localChannel.StorageContext.Track2OauthToken, this.DataLakeClientOptions); } else if (localChannel.StorageContext.StorageAccount.Credentials.IsSAS) //SAS { fileSystem = new DataLakeFileSystemClient(new Uri(fileSystemUri.ToString() + "?" + Util.GetSASStringWithoutQuestionMark(localChannel.StorageContext.StorageAccount.Credentials.SASToken)), this.DataLakeClientOptions); } else if (localChannel.StorageContext.StorageAccount.Credentials.IsSharedKey) //Shared Key { fileSystem = new DataLakeFileSystemClient(fileSystemUri, new StorageSharedKeyCredential(localChannel.StorageContext.StorageAccountName, localChannel.StorageContext.StorageAccount.Credentials.ExportBase64EncodedKey()), this.DataLakeClientOptions); } else //Anonymous { fileSystem = new DataLakeFileSystemClient(fileSystemUri, this.DataLakeClientOptions); } return(fileSystem); }
private static List <StoryCountProgessItem> GetAllStoryProgressData() { var currentSprint = App.GetReleaseScrumData().CurrentSprintProxy.CurrentSprint; var result = new List <StoryCountProgessItem>(); foreach (var story in currentSprint.Stories) { var engName = NameUtil.ConvertToEngName(story.Owner); var currentPerson = result.FirstOrDefault(t => t.Name == engName); if (currentPerson == null) { currentPerson = new StoryCountProgessItem() { Name = engName }; result.Add(currentPerson); } currentPerson.Total++; if (story.IsComplete()) { currentPerson.Left++; } } return(result.OrderBy(t => t.Name).ToList()); }
/// <summary> /// remove an azure queue /// </summary> /// <param name="name">queue name</param> /// <returns> /// true if the queue is removed successfully, false if user cancel the remove operation, /// otherwise throw an exception /// </returns> internal bool RemoveAzureQueue(string name) { if (!NameUtil.IsValidQueueName(name)) { throw new ArgumentException(String.Format(Resources.InvalidQueueName, name)); } QueueRequestOptions requestOptions = null; CloudQueue queue = Channel.GetQueueReference(name); if (!Channel.DoesQueueExist(queue, requestOptions, OperationContext)) { throw new ResourceNotFoundException(String.Format(Resources.QueueNotFound, name)); } if (force || ConfirmRemove(name)) { Channel.DeleteQueue(queue, requestOptions, OperationContext); return(true); } else { return(false); } }
/// <summary> /// set the access level of specified container /// </summary> /// <param name="name">container name</param> /// <param name="accessLevel">access level in ("off", "blob", "container")</param> internal async Task SetContainerAcl(long taskId, IStorageBlobManagement localChannel, string name, BlobContainerPublicAccessType accessLevel) { if (!NameUtil.IsValidContainerName(name)) { throw new ArgumentException(String.Format(Resources.InvalidContainerName, name)); } BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.PublicAccess = accessLevel; BlobRequestOptions requestOptions = RequestOptions; AccessCondition accessCondition = null; CloudBlobContainer container = localChannel.GetContainerReference(name); if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false)) { throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name)); } await localChannel.SetContainerPermissionsAsync(container, permissions, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false); if (PassThru) { WriteCloudContainerObject(taskId, localChannel, container, permissions); } }
/// <summary> /// create a new azure container /// </summary> /// <param name="name">container name</param> internal AzureStorageContainer CreateAzureContainer(string name, BlobContainerPublicAccessType accesslevel) { if (!NameUtil.IsValidContainerName(name)) { throw new ArgumentException(String.Format(Resources.InvalidContainerName, name)); } BlobRequestOptions requestOptions = RequestOptions; AccessCondition accessCondition = null; CloudBlobContainer container = Channel.GetContainerReference(name); bool created = Channel.CreateContainerIfNotExists(container, requestOptions, OperationContext); if (!created) { throw new ResourceAlreadyExistException(String.Format(Resources.ContainerAlreadyExists, name)); } BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.PublicAccess = accessLevel; if (accessLevel == BlobContainerPublicAccessType.Container || accessLevel == BlobContainerPublicAccessType.Blob) { Channel.SetContainerPermissions(container, permissions, accessCondition, requestOptions, OperationContext); } else { permissions = Channel.GetContainerPermissions(container, accessCondition, requestOptions, OperationContext); } AzureStorageContainer azureContainer = new AzureStorageContainer(container, permissions); return(azureContainer); }
internal string CreateAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission) { if (!NameUtil.IsValidStoredAccessPolicyName(policyName)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName)); } //Get existing permissions CloudTable table = localChannel.GetTableReference(tableName); TablePermissions tablePermissions = localChannel.GetTablePermissions(table, null, TableOperationContext); //Add new policy if (tablePermissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName)); } SharedAccessTablePolicy policy = new SharedAccessTablePolicy(); AccessPolicyHelper.SetupAccessPolicy <SharedAccessTablePolicy>(policy, startTime, expiryTime, permission); tablePermissions.SharedAccessPolicies.Add(policyName, policy); //Set permissions back to table localChannel.SetTablePermissions(table, tablePermissions, null, TableOperationContext); return(policyName); }
internal string CreateAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission) { if (!NameUtil.IsValidStoredAccessPolicyName(policyName)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName)); } //Get existing permissions CloudBlobContainer container = localChannel.GetContainerReference(containerName); BlobContainerPermissions blobContainerPermissions = localChannel.GetContainerPermissions(container); //Add new policy if (blobContainerPermissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName)); } SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy(); AccessPolicyHelper.SetupAccessPolicy <SharedAccessBlobPolicy>(policy, startTime, expiryTime, permission); blobContainerPermissions.SharedAccessPolicies.Add(policyName, policy); //Set permissions back to container localChannel.SetContainerPermissions(container, blobContainerPermissions); return(policyName); }
/// <summary> /// Start copy using transfer mangager by source uri /// </summary> /// <param name="uri">source uri</param> /// <param name="destContainer">Destination CloudBlobContainer object</param> /// <param name="destBlobName">Destination blob name</param> /// <returns>Destination CloudBlob object</returns> private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName) { NameUtil.ValidateContainerName(destContainer.Name); NameUtil.ValidateBlobName(destBlobName); CloudBlob sourceBlob = new CloudBlob(uri); BlobType destBlobType = BlobType.BlockBlob; try { await sourceBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken); //When the source Uri is a file Uri, will get BlobType.Unspecified, and should use block blob in destination if (sourceBlob.BlobType != BlobType.Unspecified) { destBlobType = sourceBlob.BlobType; } } catch (StorageException) { //use block blob by default destBlobType = BlobType.BlockBlob; } CloudBlob destBlob = GetDestBlob(destChannel, destContainer.Name, destBlobName, destBlobType); await this.StartCopyFromUri(taskId, destChannel, uri, destBlob); }
/// <summary> /// Check whether the container name is valid. If not throw an exception /// </summary> /// <param name="name">Container name</param> protected void ValidateContainerName(string name) { if (!NameUtil.IsValidContainerName(name)) { throw new ArgumentException(String.Format(Resources.InvalidContainerName, name)); } }
private CloudBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, BlobType blobType) { NameUtil.ValidateContainerName(destContainerName); NameUtil.ValidateBlobName(destBlobName); CloudBlobContainer container = destChannel.GetContainerReference(destContainerName); CloudBlob destBlob = null; if (BlobType.PageBlob == blobType) { destBlob = container.GetPageBlobReference(destBlobName); } else if (BlobType.BlockBlob == blobType) { destBlob = container.GetBlockBlobReference(destBlobName); } else if (BlobType.AppendBlob == blobType) { destBlob = container.GetAppendBlobReference(destBlobName); } else { throw new ArgumentException(String.Format(Resources.InvalidBlobType, blobType, destBlobName)); } return(destBlob); }
public override void ExecuteCmdlet() { if (String.IsNullOrEmpty(ShareName) || String.IsNullOrEmpty(Policy)) { return; } NamingUtil.ValidateShareName(this.ShareName, false); if (!NameUtil.IsValidStoredAccessPolicyName(this.Policy)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, this.Policy)); } //Get existing permissions CloudFileShare fileShare = this.Channel.GetShareReference(this.ShareName); FileSharePermissions fileSharePermissions = fileShare.GetPermissions(); //Add new policy if (fileSharePermissions.SharedAccessPolicies.Keys.Contains(this.Policy)) { throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, this.Policy)); } SharedAccessFilePolicy policy = new SharedAccessFilePolicy(); AccessPolicyHelper.SetupAccessPolicy <SharedAccessFilePolicy>(policy, this.StartTime, this.ExpiryTime, this.Permission); fileSharePermissions.SharedAccessPolicies.Add(this.Policy, policy); //Set permissions back to container fileShare.SetPermissions(fileSharePermissions); WriteObject(Policy); }
/// <summary> /// get full file path according to the specified file name /// </summary> /// <param name="fileName">File name</param> /// <param name="blobName">Source blob name</param> /// <param name="snapshotTime">Source blob snapshot time</param> /// <returns>full file path if file path is valid, otherwise throw an exception</returns> internal string GetFullReceiveFilePath(string fileName, string blobName, DateTimeOffset?snapshotTime) { String filePath = Path.Combine(CurrentPath(), fileName); fileName = Path.GetFileName(filePath); String dirPath = Path.GetDirectoryName(filePath); if (!String.IsNullOrEmpty(dirPath) && !Directory.Exists(dirPath)) { throw new ArgumentException(String.Format(Resources.DirectoryNotExists, dirPath)); } if (string.IsNullOrEmpty(fileName) || Directory.Exists(filePath)) { fileName = fileNameResolver.ResolveFileName(blobName, snapshotTime); filePath = Path.Combine(filePath, fileName); } fileName = Path.GetFileName(filePath); if (!NameUtil.IsValidFileName(fileName)) { throw new ArgumentException(String.Format(Resources.InvalidFileName, fileName)); } //there is no need to check the read/write permission on the specified file path, the datamovement libraray will do that return(filePath); }
/// <summary> /// list blobs by blob name and container name /// </summary> /// <param name="containerName">container name</param> /// <param name="blobName">blob name pattern</param> /// <returns>An enumerable collection of IListBlobItem</returns> internal IEnumerable <IListBlobItem> ListBlobsByName(string containerName, string blobName) { CloudBlobContainer container = null; BlobRequestOptions requestOptions = null; AccessCondition accessCondition = null; bool useFlatBlobListing = true; string prefix = string.Empty; BlobListingDetails details = BlobListingDetails.Snapshots | BlobListingDetails.Metadata | BlobListingDetails.Copy; if (String.IsNullOrEmpty(blobName) || WildcardPattern.ContainsWildcardCharacters(blobName)) { container = GetCloudBlobContainerByName(containerName); IEnumerable <IListBlobItem> blobs = Channel.ListBlobs(container, prefix, useFlatBlobListing, details, requestOptions, OperationContext); WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.Compiled; WildcardPattern wildcard = null; if (!String.IsNullOrEmpty(blobName)) { wildcard = new WildcardPattern(blobName, options); } foreach (IListBlobItem blobItem in blobs) { ICloudBlob blob = blobItem as ICloudBlob; if (blob == null) { continue; } if (wildcard == null || wildcard.IsMatch(blob.Name)) { yield return(blob); } } } else { container = GetCloudBlobContainerByName(containerName, true); if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } ICloudBlob blob = Channel.GetBlobReferenceFromServer(container, blobName, accessCondition, requestOptions, OperationContext); if (null == blob) { throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, containerName)); } else { yield return(blob); } } }
private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, BlobBaseClient sourceBlob, BlobBaseClient destBlob) { NameUtil.ValidateBlobName(sourceBlob.Name); NameUtil.ValidateContainerName(destBlob.BlobContainerName); NameUtil.ValidateBlobName(destBlob.Name); await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob).ConfigureAwait(false); }