|
24 | 24 | using Microsoft.Azure.Management.Internal.Resources.Models;
|
25 | 25 | using Microsoft.WindowsAzure.Commands.Utilities.Common;
|
26 | 26 | using Provider = Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01.Models.Provider;
|
| 27 | +using System.Linq; |
27 | 28 |
|
28 | 29 | namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
|
29 | 30 | {
|
@@ -175,44 +176,37 @@ protected string GetValidatedFilePath(string fileFullName)
|
175 | 176 | }
|
176 | 177 |
|
177 | 178 | /// <summary>
|
178 |
| - /// This overloaded function expects a folder path and a file name and combines them. Checks if resulting full file name exist. |
| 179 | + /// Returns the blueprint file path. |
179 | 180 | /// </summary>
|
180 |
| - /// <param name="inputPath"></param> |
181 |
| - /// <param name="fileName"></param> |
| 181 | + /// <param name="path"></param> |
182 | 182 | /// <returns></returns>
|
183 |
| - protected string GetValidatedFilePath(string path, string fileName) |
| 183 | + protected string GetValidatedFilePathForBlueprint(string path) |
184 | 184 | {
|
185 |
| - var resolvedPath = ResolveUserPath(path); |
186 |
| - |
187 |
| - var blueprintPath = Path.Combine(resolvedPath, fileName + ".json"); |
188 |
| - |
189 |
| - if (!AzureSession.Instance.DataStore.FileExists(blueprintPath)) |
| 185 | + var blueprintFileName = AzureSession.Instance.DataStore.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly) |
| 186 | + .Select(file => Path.GetFileName(file)) |
| 187 | + .FirstOrDefault(name => String.Equals(name, "blueprint.json", StringComparison.OrdinalIgnoreCase)); |
| 188 | + |
| 189 | + if (blueprintFileName == null) |
190 | 190 | {
|
191 | 191 | throw new Exception(
|
192 |
| - $"Cannot locate a file with the name {fileName} in: {resolvedPath}."); |
| 192 | + $"Cannot locate Blueprint.json in: {path}."); |
193 | 193 | }
|
194 | 194 |
|
195 |
| - return blueprintPath; |
| 195 | + return Path.Combine(path, blueprintFileName); |
196 | 196 | }
|
197 | 197 |
|
198 | 198 | /// <summary>
|
199 |
| - /// Combines input folder path and folder name and check if the resulting path exists. |
| 199 | + /// Returns the artifacts folder path. |
200 | 200 | /// </summary>
|
201 |
| - /// <param name="inputPath"></param> |
202 |
| - /// <param name="folderName"></param> |
| 201 | + /// <param name="path"></param> |
203 | 202 | /// <returns></returns>
|
204 |
| - protected string GetValidatedFolderPath(string path, string folderName) |
| 203 | + protected string GetValidatedFolderPathForArtifacts(string path) |
205 | 204 | {
|
206 |
| - var resolvedPath = ResolveUserPath(path); |
207 |
| - |
208 |
| - var artifactsPath = Path.Combine(resolvedPath, folderName); |
209 |
| - |
210 |
| - if (!AzureSession.Instance.DataStore.DirectoryExists(artifactsPath)) |
211 |
| - { |
212 |
| - artifactsPath = null; |
213 |
| - } |
| 205 | + var artifactsFolderName = AzureSession.Instance.DataStore.GetDirectories(path) |
| 206 | + .Select(folder => Path.GetFileName(folder)) |
| 207 | + .FirstOrDefault(name => String.Equals(name, "artifacts", StringComparison.OrdinalIgnoreCase)); |
214 | 208 |
|
215 |
| - return artifactsPath; |
| 209 | + return artifactsFolderName == null ? null : Path.Combine(path, artifactsFolderName); |
216 | 210 | }
|
217 | 211 | }
|
218 | 212 | }
|
0 commit comments