yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
StaticMethod DeleteDatasetCopiesAndUpdateSnapshotStatus (LibOpt_SnapshotReplannableCopyDatasets snapshots) as Boolean
{
  Description:
  [*
    Delete the datasets that are attached to the `LibOpt_SnapshotReplannableCopyDataset` snapshots.
    This method is called from the context menu of a `LibOpt_SnapshotReplannableCopyDataset` snapshot. `LibOpt_SnapshotReplannableCopyDataset` snapshots can be found in the 'Snapshots' and 'Replannable snapshots' forms.
    If a dataset could not be found in the dataset store, then all snapshots will be updated by calling `optimization.UpdateReplannableSnapshots()`.
    We are aware that it is against style guide to execute two separate actions in the same method. However, we have to combine these two actions to ensure that only 1 server transaction is started when this method is called from the UI.
  *]
  TextBody:
  [*
    // evr3 Apr-29-2020 (created)
    
    isanydatasetinfonull := false;
    objectinfos := MDSEditor::Editor().ObjectInfos();
    traverse( snapshots, Elements, snapshot, not snapshot.IsDatasetDeleted() and snapshot.HasCreatedDataset() )
    {
      isdatasetinfonull := snapshot.DeleteDatasetCopyManually( objectinfos );
      isanydatasetinfonull := isanydatasetinfonull or isdatasetinfonull;
    }
    
    if( isanydatasetinfonull )
    {
      // If 'isanydatasetinfonull' is true, then (for at least one snapshot) snapshot.IsDatasetDeleted() was false (so the snapshot thought that its dataset still exists), 
      // while the dataset of that snapshot was actually already deleted.
      // Therefore, we will update the status of all replannable snapshots to ensure that further mismatches won't occur. 
      optimization := select( snapshots, Elements.Run, run, true ).Optimization();
      optimization.UpdateReplannableSnapshots();
    }
    
    return isanydatasetinfonull;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}