lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
StaticMethod Deserialize (JSON json, LibOpt_Optimizer owner) as LibOpt_Run
{
  TextBody:
  [*
    key := [Key]json.Get( attribute( LibOpt_Run, Key ).Name() + owner.Name() ).GetString();
    identifier := [Key]json.Get( attribute( LibOpt_Run, InternalIdentifier ).Name() + owner.Name() ).GetString();
    
    run := LibOpt_Run::FindInstance( owner.MDSID(), key );
    
    if( not isnull( run  ) )
    {
      run.Delete();
    }
    
    result := null( LibOpt_Run );
    
    if( exists( owner, Run, r, r.InternalIdentifier() = identifier, r.StartedOn() <> DateTime::MinDateTime() ) )
    {
      error( Translations::LibOpt_Run_NothingToRecover() );
    }
    else
    {
      result := null( LibOpt_Run );
      importedrun := LibOpt_Message::ReadObject( json, typeof( LibOpt_Run ) ).astype( LibOpt_Run );
    
      if( not isnull( importedrun ) )
      {
        result := owner.Run( relinsert, &importedrun );
      
        // Link the scope elements to the scope
        json_scopes := json.Get( typeof( LibOpt_Scope ).Name() );
        traverse( result, Scope.astype( LibOpt_ScopeFat ), scope )
        {
          json_scope := json_scopes.Get( [String] scope.InternalIdentifier() );
          scope.DeserializeScopeElements( json_scope );
        }
        
        result.HasIterations( true );
        
        Transaction::Transaction().Propagate( method( LibOpt_Run, CreateStatisticsAndIssuesPrecondition, Boolean ) );
        if( result.CreateStatisticsAndIssuesPrecondition( true /*is fail-fast check*/ ) )
        {
          result.CreateStatisticsAndIssues();
        }
      }
    }
    
    return result;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}