@@ -30,11 +30,9 @@ namespace HyperVExtension.Models;
30
30
/// <summary> Class that represents a Hyper-V virtual machine object. </summary>
31
31
public class HyperVVirtualMachine : IComputeSystem
32
32
{
33
- private readonly string errorResourceKey = "ErrorPerformingOperation" ;
33
+ private readonly string _errorResourceKey = "ErrorPerformingOperation" ;
34
34
35
- private readonly string currentCheckpointKey = "CurrentCheckpoint" ;
36
-
37
- private readonly string operationErrorString ;
35
+ private readonly string _currentCheckpointKey = "CurrentCheckpoint" ;
38
36
39
37
private readonly IStringResource _stringResource ;
40
38
@@ -88,6 +86,9 @@ public class HyperVVirtualMachine : IComputeSystem
88
86
89
87
public bool IsDeleted => _psObjectHelper . MemberNameToValue < bool > ( HyperVStrings . IsDeleted ) ;
90
88
89
+ // Temporary will need to add more error strings for different operations.
90
+ public string OperationErrorUnknownString => _stringResource . GetLocalized ( _errorResourceKey ) ;
91
+
91
92
// TODO: make getting this list dynamic so we can remove operations based on OS version.
92
93
public ComputeSystemOperations SupportedOperations => ComputeSystemOperations . Start |
93
94
ComputeSystemOperations . ShutDown |
@@ -113,7 +114,6 @@ public HyperVVirtualMachine(IHost host, IHyperVManager hyperVManager, IStringRes
113
114
_hyperVManager = hyperVManager ;
114
115
_psObjectHelper = new ( psObject ) ;
115
116
_stringResource = stringResource ;
116
- operationErrorString = _stringResource . GetLocalized ( errorResourceKey ) ;
117
117
}
118
118
119
119
public IEnumerable < HyperVVirtualMachineHardDisk > GetHardDrives ( )
@@ -193,7 +193,7 @@ private ComputeSystemOperationResult Start(string options)
193
193
{
194
194
StateChanged ( this , ComputeSystemState . Unknown ) ;
195
195
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Start ) , ex ) ;
196
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
196
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
197
197
}
198
198
}
199
199
@@ -223,7 +223,7 @@ public IAsyncOperation<ComputeSystemOperationResult> ShutDownAsync(string option
223
223
{
224
224
StateChanged ( this , ComputeSystemState . Unknown ) ;
225
225
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . ShutDown ) ) ;
226
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
226
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
227
227
}
228
228
} ) . AsAsyncOperation ( ) ;
229
229
}
@@ -254,7 +254,7 @@ public IAsyncOperation<ComputeSystemOperationResult> TerminateAsync(string optio
254
254
{
255
255
StateChanged ( this , ComputeSystemState . Unknown ) ;
256
256
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Terminate ) , ex ) ;
257
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
257
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
258
258
}
259
259
} ) . AsAsyncOperation ( ) ;
260
260
}
@@ -279,7 +279,7 @@ public IAsyncOperation<ComputeSystemOperationResult> DeleteAsync(string options)
279
279
{
280
280
StateChanged ( this , ComputeSystemState . Unknown ) ;
281
281
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Delete ) , ex ) ;
282
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
282
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
283
283
}
284
284
} ) . AsAsyncOperation ( ) ;
285
285
}
@@ -310,7 +310,7 @@ public IAsyncOperation<ComputeSystemOperationResult> SaveAsync(string options)
310
310
{
311
311
StateChanged ( this , ComputeSystemState . Unknown ) ;
312
312
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Save ) , ex ) ;
313
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
313
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
314
314
}
315
315
} ) . AsAsyncOperation ( ) ;
316
316
}
@@ -341,7 +341,7 @@ public IAsyncOperation<ComputeSystemOperationResult> PauseAsync(string options)
341
341
{
342
342
StateChanged ( this , ComputeSystemState . Unknown ) ;
343
343
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Pause ) , ex ) ;
344
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
344
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
345
345
}
346
346
} ) . AsAsyncOperation ( ) ;
347
347
}
@@ -372,7 +372,7 @@ public IAsyncOperation<ComputeSystemOperationResult> ResumeAsync(string options)
372
372
{
373
373
StateChanged ( this , ComputeSystemState . Unknown ) ;
374
374
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Resume ) , ex ) ;
375
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
375
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
376
376
}
377
377
} ) . AsAsyncOperation ( ) ;
378
378
}
@@ -394,7 +394,7 @@ public IAsyncOperation<ComputeSystemOperationResult> CreateSnapshotAsync(string
394
394
catch ( Exception ex )
395
395
{
396
396
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . CreateSnapshot ) , ex ) ;
397
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
397
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
398
398
}
399
399
} ) . AsAsyncOperation ( ) ;
400
400
}
@@ -417,7 +417,7 @@ public IAsyncOperation<ComputeSystemOperationResult> RevertSnapshotAsync(string
417
417
catch ( Exception ex )
418
418
{
419
419
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . RevertSnapshot ) , ex ) ;
420
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
420
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
421
421
}
422
422
} ) . AsAsyncOperation ( ) ;
423
423
}
@@ -440,7 +440,7 @@ public IAsyncOperation<ComputeSystemOperationResult> DeleteSnapshotAsync(string
440
440
catch ( Exception ex )
441
441
{
442
442
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . DeleteSnapshot ) , ex ) ;
443
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
443
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
444
444
}
445
445
} ) . AsAsyncOperation ( ) ;
446
446
}
@@ -458,7 +458,7 @@ public IAsyncOperation<ComputeSystemOperationResult> ConnectAsync(string options
458
458
catch ( Exception ex )
459
459
{
460
460
Logging . Logger ( ) ? . ReportError ( $ "Failed to launch vmconnect on { DateTime . Now } : VM details: { this } ", ex ) ;
461
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
461
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
462
462
}
463
463
} ) . AsAsyncOperation ( ) ;
464
464
}
@@ -488,7 +488,7 @@ public IAsyncOperation<ComputeSystemOperationResult> RestartAsync(string options
488
488
{
489
489
StateChanged ( this , ComputeSystemState . Unknown ) ;
490
490
Logging . Logger ( ) ? . ReportError ( OperationErrorString ( ComputeSystemOperations . Restart ) , ex ) ;
491
- return new ComputeSystemOperationResult ( ex , operationErrorString , ex . Message ) ;
491
+ return new ComputeSystemOperationResult ( ex , OperationErrorUnknownString , ex . Message ) ;
492
492
}
493
493
} ) . AsAsyncOperation ( ) ;
494
494
}
@@ -529,7 +529,7 @@ public IAsyncOperation<IEnumerable<ComputeSystemProperty>> GetComputeSystemPrope
529
529
ComputeSystemProperty . Create ( ComputeSystemPropertyKind . AssignedMemorySizeInBytes , MemoryAssigned ) ,
530
530
ComputeSystemProperty . Create ( ComputeSystemPropertyKind . AssignedMemorySizeInBytes , totalDiskSize ) ,
531
531
ComputeSystemProperty . Create ( ComputeSystemPropertyKind . UptimeIn100ns , Uptime ) ,
532
- ComputeSystemProperty . CreateCustom ( ParentCheckpointName , _stringResource . GetLocalized ( currentCheckpointKey ) , null ) ,
532
+ ComputeSystemProperty . CreateCustom ( ParentCheckpointName , _stringResource . GetLocalized ( _currentCheckpointKey ) , null ) ,
533
533
} ;
534
534
535
535
return properties . AsEnumerable ( ) ;
@@ -546,7 +546,7 @@ public IAsyncOperation<ComputeSystemOperationResult> ModifyPropertiesAsync(strin
546
546
{
547
547
// This is temporary until we have a proper implementation for this.
548
548
var notImplementedException = new NotImplementedException ( $ "Method not implemented by Hyper-V Compute Systems: VM details: { this } ") ;
549
- return Task . FromResult ( new ComputeSystemOperationResult ( notImplementedException , operationErrorString , notImplementedException . Message ) ) . AsAsyncOperation ( ) ;
549
+ return Task . FromResult ( new ComputeSystemOperationResult ( notImplementedException , OperationErrorUnknownString , notImplementedException . Message ) ) . AsAsyncOperation ( ) ;
550
550
}
551
551
552
552
public SDK . ApplyConfigurationResult ApplyConfiguration ( ApplyConfigurationOperation operation )
0 commit comments