@@ -43,6 +43,10 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
43
43
{
44
44
response = GetPSAzureVmJob ( serviceClientJob ) ;
45
45
}
46
+ else if ( serviceClientJob . Properties . GetType ( ) == typeof ( AzureStorageJob ) )
47
+ {
48
+ response = GetPSAzureFileShareJob ( serviceClientJob ) ;
49
+ }
46
50
47
51
return response ;
48
52
}
@@ -95,29 +99,20 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
95
99
}
96
100
97
101
response . JobId = GetLastIdFromFullId ( serviceClientJob . Id ) ;
98
- DateTime startTime = DateTime . MinValue ;
99
- if ( vmJob . StartTime . HasValue )
100
- {
101
- response . StartTime = ( DateTime ) vmJob . StartTime ;
102
- }
103
- else
104
- {
105
- throw new ArgumentNullException ( "Job Start Time is null" ) ;
106
- }
102
+ response . StartTime = GetJobStartTime ( vmJob . StartTime ) ;
107
103
response . EndTime = vmJob . EndTime ;
108
- response . Duration =
109
- vmJob . Duration . HasValue ? ( TimeSpan ) vmJob . Duration : default ( TimeSpan ) ;
104
+ response . Duration = GetJobDuration ( vmJob . Duration ) ;
110
105
response . Status = vmJob . Status ;
111
106
response . VmVersion = vmJob . VirtualMachineVersion ;
112
107
response . WorkloadName = vmJob . EntityFriendlyName ;
113
108
response . ActivityId = vmJob . ActivityId ;
114
- response . BackupManagementType = CmdletModel . EnumUtils . GetEnum < CmdletModel . BackupManagementType > (
115
- GetPSBackupManagementType ( vmJob . BackupManagementType . ToString ( ) ) ) ;
109
+ response . BackupManagementType =
110
+ CmdletModel . ConversionUtils . GetPsBackupManagementType ( vmJob . BackupManagementType ) ;
116
111
response . Operation = vmJob . Operation ;
117
112
118
113
if ( vmJob . ErrorDetails != null )
119
114
{
120
- response . ErrorDetails = new List < CmdletModel . AzureVmJobErrorInfo > ( ) ;
115
+ response . ErrorDetails = new List < CmdletModel . AzureJobErrorInfo > ( ) ;
121
116
foreach ( var vmError in vmJob . ErrorDetails )
122
117
{
123
118
response . ErrorDetails . Add ( GetPSAzureVmErrorInfo ( vmError ) ) ;
@@ -157,69 +152,146 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
157
152
return response ;
158
153
}
159
154
160
- /// <summary>
161
- /// Helper function to convert ps azure vm backup job error info from service response.
162
- /// </summary>
163
- private static CmdletModel . AzureVmJobErrorInfo GetPSAzureVmErrorInfo ( AzureIaaSVMErrorInfo serviceClientError )
155
+ private static CmdletModel . JobBase GetPSAzureFileShareJob ( JobResource serviceClientJob )
164
156
{
165
- CmdletModel . AzureVmJobErrorInfo psErrorInfo = new CmdletModel . AzureVmJobErrorInfo ( ) ;
166
- psErrorInfo . ErrorCode = serviceClientError . ErrorCode ?? default ( int ) ;
167
- psErrorInfo . ErrorMessage = serviceClientError . ErrorString ;
168
- if ( serviceClientError . Recommendations != null )
157
+ CmdletModel . AzureFileShareJob response ;
158
+
159
+ AzureStorageJob fileShareJob = serviceClientJob . Properties as AzureStorageJob ;
160
+
161
+ if ( fileShareJob . ExtendedInfo != null )
162
+ {
163
+ response = new CmdletModel . AzureFileShareJobDetails ( ) ;
164
+ }
165
+ else
166
+ {
167
+ response = new CmdletModel . AzureFileShareJob ( ) ;
168
+ }
169
+
170
+ response . JobId = GetLastIdFromFullId ( serviceClientJob . Id ) ;
171
+ response . StartTime = GetJobStartTime ( fileShareJob . StartTime ) ;
172
+ response . EndTime = fileShareJob . EndTime ;
173
+ response . Duration = GetJobDuration ( fileShareJob . Duration ) ;
174
+ response . Status = fileShareJob . Status ;
175
+ response . WorkloadName = fileShareJob . EntityFriendlyName ;
176
+ response . ActivityId = fileShareJob . ActivityId ;
177
+ response . BackupManagementType =
178
+ CmdletModel . ConversionUtils . GetPsBackupManagementType ( fileShareJob . BackupManagementType ) ;
179
+ response . Operation = fileShareJob . Operation ;
180
+
181
+ if ( fileShareJob . ErrorDetails != null )
182
+ {
183
+ response . ErrorDetails = new List < CmdletModel . AzureJobErrorInfo > ( ) ;
184
+ foreach ( var fileShareError in fileShareJob . ErrorDetails )
185
+ {
186
+ response . ErrorDetails . Add ( GetPSAzureFileShareErrorInfo ( fileShareError ) ) ;
187
+ }
188
+ }
189
+
190
+ // fill extended info if present
191
+ if ( fileShareJob . ExtendedInfo != null )
192
+ {
193
+ CmdletModel . AzureFileShareJobDetails detailedResponse =
194
+ response as CmdletModel . AzureFileShareJobDetails ;
195
+
196
+ detailedResponse . DynamicErrorMessage = fileShareJob . ExtendedInfo . DynamicErrorMessage ;
197
+ if ( fileShareJob . ExtendedInfo . PropertyBag != null )
198
+ {
199
+ detailedResponse . Properties = new Dictionary < string , string > ( ) ;
200
+ foreach ( var key in fileShareJob . ExtendedInfo . PropertyBag . Keys )
201
+ {
202
+ detailedResponse . Properties . Add ( key , fileShareJob . ExtendedInfo . PropertyBag [ key ] ) ;
203
+ }
204
+ }
205
+
206
+ if ( fileShareJob . ExtendedInfo . TasksList != null )
207
+ {
208
+ detailedResponse . SubTasks = new List < CmdletModel . AzureFileShareJobSubTask > ( ) ;
209
+ foreach ( var fileShareJobTask in fileShareJob . ExtendedInfo . TasksList )
210
+ {
211
+ detailedResponse . SubTasks . Add ( new CmdletModel . AzureFileShareJobSubTask ( )
212
+ {
213
+ Name = fileShareJobTask . TaskId ,
214
+ Status = fileShareJobTask . Status
215
+ } ) ;
216
+ }
217
+ }
218
+ }
219
+
220
+ return response ;
221
+ }
222
+
223
+ private static CmdletModel . AzureJobErrorInfo GetPSAzureFileShareErrorInfo ( AzureStorageErrorInfo fileShareError )
224
+ {
225
+ CmdletModel . AzureFileShareJobErrorInfo psErrorInfo = new CmdletModel . AzureFileShareJobErrorInfo ( ) ;
226
+ psErrorInfo . ErrorCode = GetJobErrorCode ( fileShareError . ErrorCode ) ;
227
+ psErrorInfo . ErrorMessage = fileShareError . ErrorString ;
228
+ if ( fileShareError . Recommendations != null )
169
229
{
170
230
psErrorInfo . Recommendations = new List < string > ( ) ;
171
- psErrorInfo . Recommendations . AddRange ( serviceClientError . Recommendations ) ;
231
+ psErrorInfo . Recommendations . AddRange ( fileShareError . Recommendations ) ;
172
232
}
173
233
174
234
return psErrorInfo ;
175
235
}
176
236
177
- /// <summary>
178
- /// Helper function to get last index value from full id.
179
- /// </summary>
180
- public static string GetLastIdFromFullId ( string fullId )
237
+ private static int GetJobErrorCode ( int ? errorCode )
181
238
{
182
- string [ ] splitArr = fullId . Split ( "/" . ToCharArray ( ) ) ;
183
- return splitArr [ splitArr . Length - 1 ] ;
239
+ return errorCode ?? default ( int ) ;
184
240
}
185
241
186
- #endregion
187
-
188
- #endregion
189
-
190
- #region Enum translators
242
+ private static TimeSpan GetJobDuration ( TimeSpan ? duration )
243
+ {
244
+ return duration . HasValue ? ( TimeSpan ) duration : default ( TimeSpan ) ;
245
+ }
191
246
247
+ private static DateTime GetJobStartTime ( DateTime ? startTime )
248
+ {
249
+ if ( startTime . HasValue )
250
+ {
251
+ return ( DateTime ) startTime ;
252
+ }
253
+ else
254
+ {
255
+ throw new ArgumentNullException ( "Job Start Time is null" ) ;
256
+ }
257
+ }
192
258
193
259
/// <summary>
194
- /// Helper function to get job type from ps backup management type .
260
+ /// Helper function to convert ps azure vm backup job error info from service response .
195
261
/// </summary>
196
- public static string GetJobTypeForService (
197
- CmdletModel . BackupManagementType mgmtType )
262
+ private static CmdletModel . AzureVmJobErrorInfo GetPSAzureVmErrorInfo ( AzureIaaSVMErrorInfo serviceClientError )
198
263
{
199
- switch ( mgmtType )
264
+ CmdletModel . AzureVmJobErrorInfo psErrorInfo = new CmdletModel . AzureVmJobErrorInfo ( ) ;
265
+ psErrorInfo . ErrorCode = GetJobErrorCode ( serviceClientError . ErrorCode ) ;
266
+ psErrorInfo . ErrorMessage = serviceClientError . ErrorString ;
267
+ psErrorInfo . Recommendations = GetJobErrorRecommendations ( serviceClientError . Recommendations ) ;
268
+
269
+ return psErrorInfo ;
270
+ }
271
+
272
+ private static List < string > GetJobErrorRecommendations ( IList < string > recommendations )
273
+ {
274
+ if ( recommendations != null )
200
275
{
201
- case CmdletModel . BackupManagementType . AzureVM :
202
- return BackupManagementType . AzureIaasVM . ToString ( ) ;
203
- default :
204
- throw new Exception ( "Invalid BackupManagementType provided: " + mgmtType ) ;
276
+ var psRecommendations = new List < string > ( ) ;
277
+ psRecommendations . AddRange ( recommendations ) ;
278
+ return psRecommendations ;
205
279
}
280
+
281
+ return null ;
206
282
}
207
283
208
284
/// <summary>
209
- /// Helper function to get ps backup management type from job type .
285
+ /// Helper function to get last index value from full id .
210
286
/// </summary>
211
- public static string GetPSBackupManagementType ( string jobType )
287
+ public static string GetLastIdFromFullId ( string fullId )
212
288
{
213
- if ( jobType == BackupManagementType . AzureIaasVM . ToString ( ) )
214
- {
215
- return CmdletModel . BackupManagementType . AzureVM . ToString ( ) ;
216
- }
217
- else
218
- {
219
- throw new Exception ( "Invalid JobType provided: " + jobType ) ;
220
- }
289
+ string [ ] splitArr = fullId . Split ( "/" . ToCharArray ( ) ) ;
290
+ return splitArr [ splitArr . Length - 1 ] ;
221
291
}
222
292
223
293
#endregion
294
+
295
+ #endregion
224
296
}
225
297
}
0 commit comments