-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBuildingBlockChangeCommandBase.cs
More file actions
71 lines (59 loc) · 2.41 KB
/
Copy pathBuildingBlockChangeCommandBase.cs
File metadata and controls
71 lines (59 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using MoBi.Core.Domain;
using MoBi.Core.Domain.Extensions;
using MoBi.Core.Domain.Model;
using MoBi.Core.Services;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
namespace MoBi.Core.Commands
{
public abstract class BuildingBlockChangeCommandBase : MoBiReversibleCommand, IWillConvertPKSimModuleToExtensionModule
{
public abstract bool WillConvertPKSimModuleToExtensionModule { get; }
public abstract Module Module { get; }
}
public abstract class BuildingBlockChangeCommandBase<T> : BuildingBlockChangeCommandBase where T : class, IBuildingBlock
{
public bool ShouldIncrementVersion { get; set; }
public bool HasChangedModuleType { get; private set; }
public PKSimModuleConversion ConversionOption { get; set; } = PKSimModuleConversion.SetAsExtensionModule;
protected T _buildingBlock;
protected readonly string _buildingBlockId;
protected BuildingBlockChangeCommandBase(T buildingBlock)
{
ShouldIncrementVersion = true;
_buildingBlock = buildingBlock;
if (buildingBlock != null)
_buildingBlockId = _buildingBlock.Id;
}
protected override void ExecuteWith(IMoBiContext context)
{
if (_buildingBlock == null)
return;
var originalPkSimModuleState = _buildingBlock.IsPkSimModule();
var buildingBlockVersionUpdater = context.Resolve<IBuildingBlockVersionUpdater>();
buildingBlockVersionUpdater.UpdateBuildingBlockVersion(_buildingBlock, ShouldIncrementVersion, ConversionOption);
HasChangedModuleType = originalPkSimModuleState != _buildingBlock.IsPkSimModule();
}
protected override void ClearReferences() =>
_buildingBlock = default;
public override void RestoreExecutionData(IMoBiContext context)
{
if (_buildingBlockId != null)
_buildingBlock = context.Get<T>(_buildingBlockId);
}
public override Module Module => _buildingBlock?.Module;
public override bool WillConvertPKSimModuleToExtensionModule
{
get
{
// not a module building block
if (_buildingBlock?.Module == null)
return false;
// already an extension module
if (!_buildingBlock.Module.IsPKSimModule)
return false;
return ConversionOption == PKSimModuleConversion.SetAsExtensionModule;
}
}
}
}