| | 1 | | // Copyright (c) Microsoft and contributors. All rights reserved. |
| | 2 | | // |
| | 3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
| | 4 | | // you may not use this file except in compliance with the License. |
| | 5 | | // You may obtain a copy of the License at |
| | 6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
| | 7 | | // |
| | 8 | | // Unless required by applicable law or agreed to in writing, software |
| | 9 | | // distributed under the License is distributed on an "AS IS" BASIS, |
| | 10 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | 11 | | // |
| | 12 | | // See the License for the specific language governing permissions and |
| | 13 | | // limitations under the License. |
| | 14 | |
|
| | 15 | | using System; |
| | 16 | | using System.Text; |
| | 17 | |
|
| | 18 | | namespace Microsoft.Azure.Batch.FileStaging |
| | 19 | | { |
| | 20 | | internal static class FileStagingNamingHelpers |
| | 21 | | { |
| | 22 | | public const int MaxContainerNameLength = 63; |
| | 23 | |
|
| | 24 | | private static string MakeDefaultNamePlusNamingFragment(string namingFragment) |
| | 25 | | { |
| 1 | 26 | | StringBuilder newNameBuilder = new StringBuilder(); |
| | 27 | |
|
| 1 | 28 | | newNameBuilder.Append(Batch.Constants.DefaultConveniencePrefix); |
| | 29 | |
|
| 1 | 30 | | if (!string.IsNullOrWhiteSpace(namingFragment)) |
| | 31 | | { |
| 1 | 32 | | newNameBuilder.Append(namingFragment); |
| 1 | 33 | | newNameBuilder.Append("-"); |
| | 34 | | } |
| | 35 | |
|
| 1 | 36 | | string newName = newNameBuilder.ToString(); |
| | 37 | |
|
| 1 | 38 | | return newName; |
| | 39 | | } |
| | 40 | |
|
| | 41 | | internal static string ConstructDefaultName(string namingFragment) |
| | 42 | | { |
| 1 | 43 | | string timeString = DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss"); |
| 1 | 44 | | string containerName = MakeDefaultNamePlusNamingFragment(namingFragment) + timeString + Guid.NewGuid().ToStr |
| | 45 | |
|
| 1 | 46 | | containerName = containerName.Length > MaxContainerNameLength ? containerName.Substring(0, MaxContainerNameL |
| | 47 | |
|
| 1 | 48 | | return containerName; |
| | 49 | | } |
| | 50 | | } |
| | 51 | | } |