Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4838


Ignore:
Timestamp:
11/18/10 16:47:16 (14 years ago)
Author:
epitzer
Message:

Better reflect single successor operation generation inside user visible code. (#1275)

Location:
trunk/sources/HeuristicLab.Operators.Programmable/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperator.cs

    r4828 r4838  
    193193    [StorableHook(HookType.AfterDeserialization)]
    194194    private void AfterDeserialization() {
     195      // ensure default namespaces and assemblies are present if deserializing old operators
     196      namespaces.Add("HeuristicLab.Operators.Programmable");
     197      Assemblies[typeof(HeuristicLab.Operators.Operator).Assembly] = true;
     198      Assemblies[typeof(HeuristicLab.Operators.Programmable.ProgrammableOperator).Assembly] = true;
    195199      RegisterEvents();
    196200    }
     
    254258      typeof(System.Text.StringBuilder).Assembly,
    255259      typeof(System.Data.Linq.DataContext).Assembly,
     260      typeof(System.ComponentModel.INotifyPropertyChanged).Assembly,
    256261      typeof(HeuristicLab.Common.IDeepCloneable).Assembly,
    257262      typeof(HeuristicLab.Core.Item).Assembly,
     
    259264      typeof(HeuristicLab.Parameters.ValueParameter<IItem>).Assembly,
    260265      typeof(HeuristicLab.Collections.ObservableList<IItem>).Assembly,
    261       typeof(System.ComponentModel.INotifyPropertyChanged).Assembly,
    262 
     266      typeof(HeuristicLab.Operators.Operator).Assembly,
     267      typeof(HeuristicLab.Operators.Programmable.ProgrammableOperator).Assembly,
    263268    };
    264269
     
    293298        "HeuristicLab.Data",
    294299        "HeuristicLab.Parameters",
     300        "HeuristicLab.Operators.Programmable",
    295301        "System",
    296302        "System.Collections.Generic",
     
    399405        var sb = new StringBuilder()
    400406        .Append("public static IOperation Execute(")
    401         .Append(TypeNameParser.Parse(typeof(IOperator).FullName).GetTypeNameInCode(namespaces))
     407        .Append(TypeNameParser.Parse(GetType().FullName).GetTypeNameInCode(namespaces))
    402408        .Append(" op, ")
    403409        .Append(TypeNameParser.Parse(typeof(IExecutionContext).FullName).GetTypeNameInCode(namespaces))
     
    421427      method.ReturnType = new CodeTypeReference(typeof(IOperation));
    422428      method.Attributes = MemberAttributes.Public | MemberAttributes.Static;
    423       method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IOperator), "op"));
     429      method.Parameters.Add(new CodeParameterDeclarationExpression(GetType(), "op"));
    424430      method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IExecutionContext), "context"));
    425431      foreach (var param in Parameters)
     
    429435        codeLines[i] = string.Format("#line {0} \"ProgrammableOperator\"{1}{2}", i + 1, "\r\n", codeLines[i]);
    430436      }
    431       method.Statements.Add(new CodeSnippetStatement(
    432         string.Join("\r\n", codeLines) +
    433         "\r\nreturn null;"));
     437      method.Statements.Add(new CodeSnippetStatement(string.Join("\r\n", codeLines) + MethodSuffix));
    434438      return method;
     439    }
     440
     441    public virtual string MethodSuffix {
     442      get { return "return null;"; }
    435443    }
    436444
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.cs

    r4477 r4838  
    7171      } else {
    7272        codeEditor.Prefix = GetGeneratedPrefix();
    73         codeEditor.Suffix = @"    return null;
    74   }
    75 }";
     73        codeEditor.Suffix = String.Format("    {0}\n  }}\n}}", ProgrammableOperator.MethodSuffix);
    7674        codeEditor.UserCode = ProgrammableOperator.Code;
    7775        if (codeEditor.UserCode == "")
     
    121119        ProgrammableOperator.Compile();
    122120        MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
    123       }
    124       catch (Exception ex) {
     121      } catch (Exception ex) {
    125122        ErrorHandling.ShowErrorDialog(this, ex);
    126123      }
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableSingleSuccessorOperator.cs

    r4828 r4838  
    99  [StorableClass]
    1010  public class ProgrammableSingleSuccessorOperator : ProgrammableOperator {
     11
     12    public IOperator Successor {
     13      get {
     14        IParameter parameter;
     15        Parameters.TryGetValue("Successor", out parameter);
     16        OperatorParameter successorParameter = parameter as OperatorParameter;
     17        if (successorParameter == null)
     18          return null;
     19        return successorParameter.Value;
     20      }
     21      set {
     22        ((OperatorParameter)Parameters["Successor"]).Value = value;
     23      }
     24    }
    1125
    1226    [StorableConstructor]
     
    2438    }
    2539
    26     public override IOperation Apply() {
    27       IOperation operation = base.Apply();
    28       if (operation != null)
    29         return operation;
    30       IParameter parameter;
    31       Parameters.TryGetValue("Successor", out parameter);
    32       OperatorParameter successorParameter = parameter as OperatorParameter;
    33       if (successorParameter != null && successorParameter.Value != null)
    34         return ExecutionContext.CreateOperation(successorParameter.Value);
    35       else
    36         return null;
     40    public override string MethodSuffix {
     41      get { return "return op.Successor == null ? null : context.CreateOperation(op.Successor);"; }
    3742    }
    3843  }
Note: See TracChangeset for help on using the changeset viewer.