|
17 | 17 | using Microsoft.Azure.Commands.Sql.Location_Capabilities.Services;
|
18 | 18 | using Microsoft.WindowsAzure.Commands.Utilities.Common;
|
19 | 19 | using System.Linq;
|
| 20 | +using System.Text; |
20 | 21 |
|
21 | 22 | namespace Microsoft.Azure.Commands.Sql.Location_Capabilities.Cmdlet
|
22 | 23 | {
|
@@ -90,33 +91,144 @@ public override void ExecuteCmdlet()
|
90 | 91 | {
|
91 | 92 | AzureSqlCapabilitiesAdapter adapter = new AzureSqlCapabilitiesAdapter(Profile, Profile.Context.Subscription);
|
92 | 93 | LocationCapabilityModel model = adapter.GetLocationCapabilities(LocationName);
|
| 94 | + int depth = 0; |
93 | 95 |
|
94 | 96 | switch(ParameterSetName)
|
95 | 97 | {
|
96 | 98 | case _default:
|
97 | 99 | {
|
98 | 100 | FilterByDefaults(model);
|
| 101 | + depth = 3; |
99 | 102 | }
|
100 | 103 | break;
|
101 | 104 | case _filtered:
|
102 | 105 | {
|
103 | 106 | if (this.MyInvocation.BoundParameters.ContainsKey("ServerVersionName"))
|
104 | 107 | {
|
105 | 108 | FilterByServerVersion(model);
|
| 109 | + depth = 1; |
106 | 110 | }
|
107 | 111 | if (this.MyInvocation.BoundParameters.ContainsKey("EditionName"))
|
108 | 112 | {
|
109 | 113 | FilterByEditionName(model);
|
| 114 | + depth = 2; |
110 | 115 | }
|
111 | 116 | if (this.MyInvocation.BoundParameters.ContainsKey("ServiceObjectiveName"))
|
112 | 117 | {
|
113 | 118 | FilterByServiceObjectiveName(model);
|
| 119 | + depth = 3; |
114 | 120 | }
|
115 | 121 | }
|
116 | 122 | break;
|
117 | 123 | }
|
118 | 124 |
|
119 |
| - this.WriteObject(model); |
| 125 | + if(depth > 0) |
| 126 | + { |
| 127 | + model.ExpandedDetails = CreateExpandedDetails(model, depth); |
| 128 | + } |
| 129 | + |
| 130 | + this.WriteObject(model, true); |
| 131 | + } |
| 132 | + |
| 133 | + /// <summary> |
| 134 | + /// Given a <see cref="LocationCapabilityModel"/> constructs a formatted string of its expanded details to the desired depth. |
| 135 | + /// </summary> |
| 136 | + /// <param name="model">The model details</param> |
| 137 | + /// <param name="depth">The depth to expand to</param> |
| 138 | + /// <returns>The formatted string containing the model details</returns> |
| 139 | + private string CreateExpandedDetails(LocationCapabilityModel model, int depth) |
| 140 | + { |
| 141 | + StringBuilder builder = new StringBuilder(); |
| 142 | + |
| 143 | + foreach(var version in model.SupportedServerVersions) |
| 144 | + { |
| 145 | + string versionInfo = GetVersionInformation(version); |
| 146 | + |
| 147 | + if(depth > 1) |
| 148 | + { |
| 149 | + ExpandEdition(depth, builder, version, versionInfo); |
| 150 | + } |
| 151 | + else |
| 152 | + { |
| 153 | + builder.AppendLine(versionInfo); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + return builder.ToString(); |
| 158 | + } |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// Formats all the supported editions in <paramref name="version"/> as strings prefixed with <paramref name="prefix"/> |
| 162 | + /// and appends them to the <paramref name="builder"/> |
| 163 | + /// </summary> |
| 164 | + /// <param name="depth">How deep to expand the information</param> |
| 165 | + /// <param name="builder">The string builder to append the information</param> |
| 166 | + /// <param name="version">The version object to expand and format</param> |
| 167 | + /// <param name="prefix">The prefix to apply to the information strings</param> |
| 168 | + private void ExpandEdition(int depth, StringBuilder builder, ServerVersionCapabilityModel version, string prefix) |
| 169 | + { |
| 170 | + foreach (var edition in version.SupportedEditions) |
| 171 | + { |
| 172 | + string editionInfo = GetEditionInformation(prefix, edition); |
| 173 | + |
| 174 | + if (depth > 2) |
| 175 | + { |
| 176 | + ExpandServiceObjective(builder, edition, editionInfo); |
| 177 | + } |
| 178 | + else |
| 179 | + { |
| 180 | + builder.AppendLine(editionInfo); |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + /// <summary> |
| 186 | + /// Formats all the supported service objectives in <paramref name="edition"/> as strings prefixed with <paramref name="prefix"/> |
| 187 | + /// and appends them to the <paramref name="builder"/> |
| 188 | + /// </summary> |
| 189 | + /// <param name="builder">The string building to add the formatted string to</param> |
| 190 | + /// <param name="edition">The edition containing the supported service objectives</param> |
| 191 | + /// <param name="prefix">The prefix for the formatted string</param> |
| 192 | + private void ExpandServiceObjective(StringBuilder builder, EditionCapabilityModel edition, string prefix) |
| 193 | + { |
| 194 | + foreach (var slo in edition.SupportedServiceObjectives) |
| 195 | + { |
| 196 | + string serviceObjectiveInfo = GetServiceObjectiveInformation(prefix, slo); |
| 197 | + |
| 198 | + builder.AppendLine(serviceObjectiveInfo); |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + /// <summary> |
| 203 | + /// Gets the string formatting of the server version object |
| 204 | + /// </summary> |
| 205 | + /// <param name="version">The server version information to format as a string</param> |
| 206 | + /// <returns>The formatted string containing the server version information</returns> |
| 207 | + private string GetVersionInformation(ServerVersionCapabilityModel version) |
| 208 | + { |
| 209 | + return string.Format("Version: {0} ({1})", version.ServerVersionName, version.Status); |
| 210 | + } |
| 211 | + |
| 212 | + /// <summary> |
| 213 | + /// Gets the string formatting of the edition object |
| 214 | + /// </summary> |
| 215 | + /// <param name="baseString">The prefix before the edition information</param> |
| 216 | + /// <param name="edition">The edition information to format and append to the end of the baseString</param> |
| 217 | + /// <returns>The formatted string containing the edition information</returns> |
| 218 | + private string GetEditionInformation(string baseString, EditionCapabilityModel edition) |
| 219 | + { |
| 220 | + return string.Format("{0} -> Edition: {1} ({2})", baseString, edition.EditionName, edition.Status); |
| 221 | + } |
| 222 | + |
| 223 | + /// <summary> |
| 224 | + /// Gets the string formatting of the service objective object |
| 225 | + /// </summary> |
| 226 | + /// <param name="baseString">The prefix before the service objective information</param> |
| 227 | + /// <param name="objective">The service objective information to append</param> |
| 228 | + /// <returns>The formatted string containing the service objective information</returns> |
| 229 | + private string GetServiceObjectiveInformation(string baseString, ServiceObjectiveCapabilityModel objective) |
| 230 | + { |
| 231 | + return string.Format("{0} -> Service Objective: {1} ({2})", baseString, objective.ServiceObjectiveName, objective.Status); |
120 | 232 | }
|
121 | 233 |
|
122 | 234 | /// <summary>
|
|
0 commit comments