Ejemplo n.º 1
0
        private Assembly Compile(bool fireChanged)
        {
            var assembly = base.Compile();
            var types    = assembly.GetTypes();

            if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
            {
                throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
            }
            if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
            {
                throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");
            }

            CompiledProblemDefinition inst;

            try {
                inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
            } catch (Exception e) {
                compiledProblemDefinition = null;
                throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
            }

            try {
                inst.vars = new Variables(VariableStore);
                inst.Initialize();
            } catch (Exception e) {
                compiledProblemDefinition = null;
                throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
            }

            try {
                compiledProblemDefinition = inst;
                if (fireChanged)
                {
                    OnProblemDefinitionChanged();
                }
            } catch (Exception e) {
                compiledProblemDefinition = null;
                throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e);
            }

            codeChanged = false;
            return(assembly);
        }
Ejemplo n.º 2
0
 protected override void OnCodeChanged()
 {
     base.OnCodeChanged();
     compiledProblemDefinition = null;
     codeChanged = true;
 }
 protected override void OnCodeChanged() {
   base.OnCodeChanged();
   compiledProblemDefinition = null;
   codeChanged = true;
 }
    private Assembly Compile(bool fireChanged) {
      var assembly = base.Compile();
      var types = assembly.GetTypes();
      if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
        throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
      if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
        throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");

      CompiledProblemDefinition inst;
      try {
        inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
      } catch (Exception e) {
        compiledProblemDefinition = null;
        throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
      }

      try {
        inst.vars = new Variables(VariableStore);
        inst.Initialize();
      } catch (Exception e) {
        compiledProblemDefinition = null;
        throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
      }

      try {
        compiledProblemDefinition = inst;
        if (fireChanged) OnProblemDefinitionChanged();
      } catch (Exception e) {
        compiledProblemDefinition = null;
        throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e);
      }

      codeChanged = false;
      return assembly;
    }
Ejemplo n.º 5
0
        public SolveResult Solve(IProblemDefinition gridToSolve)
        {
            var iterativeSolver = new RecursiveSolver(gridToSolve.PossibilitiesSquareGrid);

            return iterativeSolver.Solve(gridToSolve.StartingKnownSquares);
        }