Free cookie consent management tool by TermsFeed Policy Generator

Changeset 513


Ignore:
Timestamp:
08/13/08 17:09:48 (16 years ago)
Author:
gkronber
Message:

Fixed the problem that sometimes an operator link was not patched before a view was created (which resulted in a NullException) by adding a property for the source database in OperatorLink! and updating this property recursively whenever an operator is loaded from the CEDMA DB.

The method for recursively setting the property is in static class OperatorLinkPatcher because the code is needed in Agent, DatabaseOperatorLibrary and OperatorLink.

(ticket #211)

Location:
trunk/sources/HeuristicLab.CEDMA.Core
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/Agent.cs

    r512 r513  
    9696        foreach(IOperator op in opGraph.Operators) OperatorGraph.AddOperator(op);
    9797        OperatorGraph.InitialOperator = opGraph.InitialOperator;
    98         PatchOperatorLinks(OperatorGraph);
     98        OperatorLinkPatcher.LinkDatabase(OperatorGraph, Database);
    9999      }
    100100      return new AgentView(this);
    101101    }
    102 
    103     private void PatchOperatorLinks(IOperatorGraph opGraph) {
    104       foreach(IOperator op in opGraph.Operators) {
    105         PatchOperatorLinks(op);
    106       }
    107     }
    108 
    109     private void PatchOperatorLinks(IOperator op) {
    110       if(op is OperatorLink) {
    111         OperatorLink link = op as OperatorLink;
    112         link.Database = Database;
    113         //if(downloaded.ContainsKey(link.Id)) {
    114         //  link.Operator = downloaded[link.Id];
    115         //} else {
    116         //  OperatorEntry targetEntry = Database.GetOperator(link.Id);
    117         //  IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
    118         //  downloaded.Add(link.Id, target);
    119         //  PatchOperatorLinks(target, downloaded);
    120         //  link.Operator = target;
    121         //}
    122       } else if(op is CombinedOperator) {
    123         PatchOperatorLinks(((CombinedOperator)op).OperatorGraph);
    124       }
    125       // also patch operator links contained (indirectly) in variables
    126       foreach(VariableInfo varInfo in op.VariableInfos) {
    127         IVariable var = op.GetVariable(varInfo.ActualName);
    128         if(var != null && var.Value is IOperatorGraph) {
    129           PatchOperatorLinks((IOperatorGraph)var.Value);
    130         } else if(var != null && var.Value is IOperator) {
    131           PatchOperatorLinks((IOperator)var.Value);
    132         }
    133       }
    134     }
    135102  }
    136103}
  • trunk/sources/HeuristicLab.CEDMA.Core/DatabaseOperatorLibrary.cs

    r512 r513  
    8585      }
    8686
    87       // patch all OperatorLinks
     87      // set the DB source for each operator
    8888      foreach(IOperator op in group.Operators) {
    89         PatchLinks(op);
    90       }
    91     }
    92 
    93     private void PatchLinks(IOperatorGraph opGraph) {
    94       foreach(IOperator op in opGraph.Operators) {
    95         PatchLinks(op);
    96       }
    97     }
    98 
    99     private void PatchLinks(IOperator op) {
    100       if(op is OperatorLink) {
    101         OperatorLink link = op as OperatorLink;
    102         link.Database = Database;
    103       }
    104       else if(op is CombinedOperator) {
    105         CombinedOperator combinedOp = op as CombinedOperator;
    106         foreach(IOperator internalOp in combinedOp.OperatorGraph.Operators) {
    107           PatchLinks(internalOp);
    108         }
    109       }
    110       // also patch operator links contained (indirectly) in variables
    111       foreach(VariableInfo varInfo in op.VariableInfos) {
    112         IVariable var = op.GetVariable(varInfo.ActualName);
    113         if(var != null && var.Value is IOperatorGraph) {
    114           PatchLinks((IOperatorGraph)var.Value);
    115         } else if(var != null && var.Value is IOperator) {
    116           PatchLinks((IOperator)var.Value);
    117         }
     89        OperatorLinkPatcher.LinkDatabase(op, Database);
    11890      }
    11991    }
  • trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj

    r418 r513  
    7070    </Compile>
    7171    <Compile Include="OperatorLink.cs" />
     72    <Compile Include="OperatorLinkPatcher.cs" />
    7273    <Compile Include="Result.cs" />
    7374    <Compile Include="IResult.cs" />
  • trunk/sources/HeuristicLab.CEDMA.Core/OperatorLink.cs

    r512 r513  
    7373        OperatorEntry targetEntry = Database.GetOperator(Id);
    7474        IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
    75         PatchOperatorLinks(target);
     75        OperatorLinkPatcher.LinkDatabase(target, Database);
    7676        Operator = target;
    7777      }
     
    9595      base.Populate(node, restoredObjects);
    9696    }
    97 
    98     private void PatchOperatorLinks(IOperatorGraph opGraph) {
    99       foreach(IOperator op in opGraph.Operators) {
    100         PatchOperatorLinks(op);
    101       }
    102     }
    103 
    104     private void PatchOperatorLinks(IOperator op) {
    105       if(op is OperatorLink) {
    106         OperatorLink link = op as OperatorLink;
    107         link.Database = Database;
    108         //if(downloaded.ContainsKey(link.Id)) {
    109         //  link.Operator = downloaded[link.Id];
    110         //} else {
    111         //  OperatorEntry targetEntry = Database.GetOperator(link.Id);
    112         //  IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
    113         //  downloaded.Add(link.Id, target);
    114         //  PatchOperatorLinks(target, downloaded);
    115         //  link.Operator = target;
    116         //}
    117       } else if(op is CombinedOperator) {
    118         PatchOperatorLinks(((CombinedOperator)op).OperatorGraph);
    119       }
    120       // also patch operator links contained (indirectily) in variables
    121       foreach(VariableInfo varInfo in op.VariableInfos) {
    122         IVariable var = op.GetVariable(varInfo.ActualName);
    123         if(var != null && var.Value is IOperatorGraph) {
    124           PatchOperatorLinks((IOperatorGraph)var.Value);
    125         } else if(var != null && var.Value is IOperator) {
    126           PatchOperatorLinks((IOperator)var.Value);
    127         }
    128       }
    129     }
    13097  }
    13198}
Note: See TracChangeset for help on using the changeset viewer.