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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Quintiq file version 2.0
#parent: #root
Method SynchronizeLibSCIScenarioWithScenarioMP (
  Strings existingscenariosmpdatasetname,
  Strings existingscenariompnames,
  Strings assumptions
)
{
  Description:
  [*
    Synchronize LibSCIScenarios with ScenarioMP given in parameters.
    It will Create or Update or Delete LibSCIScenarios
    The goal is to get LibSCIScenario mathcing non IsDeleted Scenario_MP
  *]
  TextBody:
  [*
    existinglibsciscenarios := this.GetAllLibSCIScenarios();
    updates := construct( LibSCIScenarios );
    
    // Introduce index because traversing scenariodatasetname and need to match element index to scenarioname list
    index := 0;
    
    traverse( existingscenariosmpdatasetname, Elements, scenariompdataset )
    {
      // Get ScenarioName
      scenarioname := existingscenariompnames.Element( index );
      assumption := assumptions.Element( index );
      assumption := assumption.TrimBoth();
      // Find existing LibSCIScenario
      objectinstance := LibSCIScenario::FindLibSCIScenarioTypeIndex( scenariompdataset ); 
      
      // If no existing LibSCIScenario is found, create one
      if( isnull( objectinstance ) )
      {
         this.CreateScenario( scenarioname, scenariompdataset, assumption );
      }
      else
      {
        objectinstance.Update( scenarioname, assumption );
        updates.Add( objectinstance );
      }
      index := index + 1;
    }
    
    // Get the set of old LibSCIScenarios to be deleted
    tobedeleted := existinglibsciscenarios.Difference( updates );
    
    // Traverse the set of LibSCIScenarios to be deleted
    traverse( tobedeleted, Elements, ele )
    {
      ele.Delete();
    }
  *]
}