hongji.li
2023-11-07 192c736b8ac4b2d84cb823ac71f17e507948a5e8
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
Quintiq file version 2.0
#parent: #root
StaticMethod CopyDatasetConditionally (String componentpositionname, LibOpt_Task task, Boolean hastocreaterobustcopy)
{
  Description:
  [*
    This method checks if a `LibOpt_DatasetCopyConditional` is attached to the `componentpositionname` component position of `task.Component()`.
    If this `LibOpt_DatasetCopyConditional` object can be found, then a dataset copy is created if:
    1: `LibOpt_Run.IsCreatingDatasetCopiesEnabled` is `true`. (This attribute can be set in the 'Toggles' context menu item in the 'Runs' form.)
    2: And the `CreateCondition` method returns `true`. This method is extensible.
    3: And the `LibOpt_DatasetCopyConditional.IsEnabled()` attribute is `true`.
  *]
  TextBody:
  [*
    component := task.Component();
    componentposition := select( component,
                                 ComponentPosition,
                                 componentposition,
                                 componentposition.Name() = componentpositionname );
    
    if( not isnull( componentposition ) )
    {  
      datasetcopyconditional := componentposition.DatasetCopyConditional();
      
      // The AE can modify the CreateCondition method himself. This means that a user error might occur there. 
      // Any error that occurs here will result in a rollback of the current component.
      // It would be nice if the rollback can be avoided.
      if( not isnull( datasetcopyconditional ) 
          and datasetcopyconditional.IsEnabled() 
          and component.Run().IsCreatingDatasetCopiesEnabled()
          and datasetcopyconditional.CreateCondition( task )      
          )
      {
        snapshot := LibOpt_DatasetCopyConditional::CopyDataset( task,
                                                                componentpositionname,
                                                                hastocreaterobustcopy
                                                                );
        snapshot.DatasetCopyConditional( relset, datasetcopyconditional );
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}