public override void Init(BoSSS.Solution.Control.AppControl control)
 {
     control.GridPartType        = BoSSS.Foundation.Grid.GridPartType.none;
     control.NoOfMultigridLevels = 1;
     base.Init(control);
 }
Esempio n. 2
0
 public override void Init(BoSSS.Solution.Control.AppControl control)
 {
     control.GridPartType = BoSSS.Foundation.Grid.GridPartType.none;
     base.Init(control);
 }
Esempio n. 3
0
        /// <summary>
        /// Loads a control object, resp. a series of control objects (in the case of a parameter study)
        /// form a C#-script.
        /// </summary>
        /// <param name="ctrlfileContent">the script.</param>
        /// <param name="t">something derived from <see cref="AppControl"/></param>
        static public void FromCode(string ctrlfileContent, Type t, out AppControl ctrl, out AppControl[] ctrl_ParamStudy)
        {
            // try to get type from first line comment (a hack).
            if (t == null)
            {
                string FirstLine = null;
                using (StringReader strR1 = new StringReader(ctrlfileContent)) {
                    FirstLine = strR1.ReadLine();
                }
                if (FirstLine != null && FirstLine.StartsWith("//"))
                {
                    FirstLine = FirstLine.Substring(2);
                    try {
                        Type t2 = Type.GetType(FirstLine);

                        if (t2 != null)
                        {
                            t = t2;
                        }
                    } catch (Exception) {
                    }
                }
            }

            if (t == null)
            {
                t = typeof(AppControl);
            }



            var Settings = new CompilerSettings();

#if DEBUG
            Settings.Optimize = false;
#else
            Settings.Optimize = false;
#endif
            CompilerContext cmpCont = new CompilerContext(Settings, new ConsoleReportPrinter());
            Evaluator       eval    = new Evaluator(cmpCont);
            eval.InteractiveBaseClass = t;

            // Start from entry assembly and _not_
            // - don't use typeof(T).Assembly since T might be located different assembly than the control file
            // - don't use Assembly.GetEntryAssembly() as it is undefined if called by Nunit
            StackTrace stackTrace    = new StackTrace();
            Assembly   entryAssembly = stackTrace.GetFrame(1).GetMethod().DeclaringType.Assembly;
            var        allAssis      = Application.GetAllAssemblies();
            foreach (var assi in allAssis)
            {
                eval.ReferenceAssembly(assi);
            }

            object controlObj = null;

            using (StringReader strR = new StringReader(ctrlfileContent)) {
                bool   result_set          = false;
                string incompleteStatement = null;
                int    lineno = 0;
                for (string line = strR.ReadLine(); line != null; line = strR.ReadLine())
                {
                    lineno++;

                    // Remove any trailing multiline delimiters (for
                    // compatibility with older control files)
                    line = line.TrimEnd().TrimEnd('\\');

                    string statement;
                    if (incompleteStatement == null)
                    {
                        statement = line;
                    }
                    else
                    {
                        statement = incompleteStatement + "\n" + line;
                    }

                    try {
                        incompleteStatement = eval.Evaluate(statement, out controlObj, out result_set);
                    } catch (Exception e) {
                        string message = String.Format(
                            "'{0}' during the interpretation of control file code, line {1}",
                            e.GetType().Name,
                            lineno);
                        throw new AggregateException(message, e);
                    }

                    if (cmpCont.Report.Errors > 0)
                    {
                        throw new ApplicationException(
                                  "Syntax error in control file line " + lineno + ": \n" + statement);
                    }
                }

                if (incompleteStatement != null)
                {
                    throw new ApplicationException(String.Format(
                                                       "Reached end of control file before statement starting with '{0}' was complete",
                                                       incompleteStatement.Substring(0, Math.Min(incompleteStatement.Length, 20))));
                }

                if (controlObj == null)
                {
                    throw new ApplicationException(
                              "Unable to create a control object from cs-script file.");
                }

                // return
                if (controlObj is System.Collections.IEnumerable)
                {
                    var enu = (System.Collections.IEnumerable)controlObj;

                    List <AppControl> _ctrl_ParameterStudy = new List <AppControl>();
                    //ctrl_ParameterStudy = new AppControl[enu.];
                    int i = 0;
                    foreach (object o in enu)
                    {
                        AppControl c = (AppControl)o;
                        c.ControlFileText       = ctrlfileContent;
                        c.GeneratedFromCode     = true;
                        c.ControlFileText_Index = i;
                        _ctrl_ParameterStudy.Add(c);
                        i++;
                    }

                    ctrl_ParamStudy = _ctrl_ParameterStudy.ToArray();
                    ctrl            = null;
                }
                else
                {
                    ctrl_ParamStudy            = null;
                    ctrl                       = (AppControl)controlObj;
                    ctrl.ControlFileText       = ctrlfileContent;
                    ctrl.ControlFileText_Index = 0;
                    ctrl.GeneratedFromCode     = true;
                }
            }
        }