public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <DynamicTypeEntity>() .WithQuery(dqm, () => e => new { Entity = e, e.Id, e.TypeName, e.BaseType, }); AvailableEmbeddedEntities = sb.GlobalLazy(() => { var namespaces = DynamicCode.GetNamespaces().ToHashSet(); return(DynamicCode.GetAssemblies() .SelectMany(a => Assembly.LoadFile(a).GetTypes()) .Where(t => typeof(EmbeddedEntity).IsAssignableFrom(t) && namespaces.Contains(t.Namespace)) .ToHashSet()); }, new InvalidateWith(typeof(TypeEntity))); DynamicTypeGraph.Register(); DynamicLogic.GetCodeFiles += GetCodeFiles; DynamicLogic.OnWriteDynamicStarter += WriteDynamicStarter; } }
protected override CompilationResult Compile() { var parent = this.GetParentEntity <WorkflowScriptEntity>(); var script = this.Script.Trim(); var WorkflowEntityTypeName = parent.MainEntityType.ToType().FullName; return(Compile(DynamicCode.GetCoreMetadataReferences() .Concat(DynamicCode.GetMetadataReferences()), DynamicCode.GetUsingNamespaces() + @" namespace Signum.Entities.Workflow { class MyWorkflowScriptEvaluator : IWorkflowScriptExecutor { public void ExecuteUntyped(ICaseMainEntity mainEntity, WorkflowScriptContext ctx) { this.Execute((" + WorkflowEntityTypeName + @")mainEntity, ctx); } void Execute(" + WorkflowEntityTypeName + @" e, WorkflowScriptContext ctx) { " + script + @" } } " + CustomTypes + @" }")); }
protected override CompilationResult Compile() { var script = this.Script.Trim(); script = script.Contains(';') ? script : ("return " + script + ";"); var parentEntity = this.TryGetParentEntity <Entity>() !; var query = parentEntity is WordTemplateEntity wt ? wt.Query : parentEntity is EmailTemplateEntity et ? et.Query : throw new UnexpectedValueException(parentEntity); var entityTypeName = (QueryEntity.GetEntityImplementations(query).Types.Only() ?? typeof(Entity)).Name; return(Compile(DynamicCode.GetCoreMetadataReferences() .Concat(DynamicCode.GetMetadataReferences()), DynamicCode.GetUsingNamespaces() + @" namespace Signum.Entities.Templating { class Evaluator : Signum.Entities.Templating.ITemplateApplicable { public bool ApplicableUntyped(Entity? e) { return this.Applicable((" + entityTypeName + @")e); } bool Applicable(" + entityTypeName + @" e) { " + script + @" } } }")); }
/// <summary> /// Set the user-defined options (or replace the default settings with the user-defined values) /// </summary> /// <param name="options"></param> public virtual void SetOptions(ConverterOptionList options) { if (options == null || options.Count == 0) { return; } #region Cast the value element into its underlying type var pis = new List <PropertyInfo>(this.Options.GetType().GetProperties()); foreach (ConverterOption item in options) { var mypis = pis.FindAll(pi => pi.Name == item.Key); if (mypis.Count != 1) { throw new ArgumentException(string.Format("Expected one property to match key of '{0}'; but, found {2}", item.Key, item.Value, mypis.Count)); } Type t = mypis[0].PropertyType.UnderlyingSystemType; if (item.Value.GetType() != t) { item.Value = Convert.ChangeType(item.Value, t); } } #endregion DynamicCode.SetProperty(this.Options, options.ToHashTable()); }
protected override CompilationResult Compile() { var parent = (WorkflowLaneEntity)this.GetParentEntity(); var script = this.Script.Trim(); script = script.Contains(';') ? script : ("return " + script + ";"); var WorkflowEntityTypeName = parent.Pool.Workflow.MainEntityType.ToType().FullName; return(Compile(DynamicCode.GetAssemblies(), DynamicCode.GetUsingNamespaces() + @" namespace Signum.Entities.Workflow { class MyWorkflowLaneActorEvaluator : IWorkflowLaneActorsEvaluator { public List<Lite<Entity>> GetActors(ICaseMainEntity mainEntity, WorkflowTransitionContext ctx) { return this.Evaluate((" + WorkflowEntityTypeName + @")mainEntity, ctx); } List<Lite<Entity>> Evaluate(" + WorkflowEntityTypeName + @" e, WorkflowTransitionContext ctx) { " + script + @" } } }")); }
/// <summary> /// Create a new instance with given attributes /// </summary> /// <param name="dt"></param> public PivotMaster(DataTable dt) { foreach (DataRow dr in dt.Rows) { string id = dr["ID"].ToString(); string value = dr["Value"].ToString(); object value2 = null; #region Convert to proper data type switch (id.ToUpper()) { case "PIVOT": case "ENTRYCOLUMN": case "BASECOLUMN": case "KEYCOLUMN": case "VALUECOLUMN": case "INPUTTABLENAME": case "ELAPSED": case "GROUPCOLUMN": value2 = value; break; case "VALUETYPE": value2 = Type.GetType(value); break; case "GS": value2 = (GroupSignificant)Enum.Parse(typeof(GroupSignificant), value); break; case "START": value2 = DateTime.Parse(value); break; case "INPUTROWCOUNT": case "INPUTCOLUMNCOUNT": case "RESULTROWCOUNT": case "RESULTCOLUMNCOUNT": value2 = DataConvert.ToInt32(value); break; default: throw new ArgumentOutOfRangeException("id=" + id); } #endregion try { DynamicCode.SetProperty(this, id, value2); } catch (Exception ex) { throw; } } }
public static PHP.Core.AST.DirectFcnCall.EvaluateInfo CreateFunction_Analyze( Analyzer analyzer, PHP.Core.AST.CallSignature callSignature, string args, string body) { if (analyzer.IsInsideIncompleteClass()) { return(null); // in this case, the DirectFnCall will not be Emitted. Therefore the lambda routine will not be declared and compilation will fail when emitting not fully declared lambda FunctionDecl. } // has to be a valid identifier: // actually this name is never used then string function_name = "__" + Guid.NewGuid().ToString().Replace('-', '_'); //DynamicCode.GenerateLambdaName(args, body); string prefix1, prefix2; DynamicCode.GetLamdaFunctionCodePrefixes(function_name, args, out prefix1, out prefix2); PHP.Core.Parsers.Position pos_args = callSignature.Parameters[0].Position; PHP.Core.Parsers.Position pos_body = callSignature.Parameters[1].Position; // function __XXXXXX(<args>){<fill><body>} string fill = GetInlinedLambdaCodeFill(pos_args, pos_body); string code = String.Concat(prefix2, fill, body, "}"); // the position of the first character of the parsed code: // (note that escaped characters distort position a little bit, which cannot be eliminated so easily) PHP.Core.Parsers.Position pos = PHP.Core.Parsers.Position.Initial; pos.FirstOffset = pos_args.FirstOffset - prefix1.Length + 1; pos.FirstColumn = pos_args.FirstColumn - prefix1.Length + 1; pos.FirstLine = pos_args.FirstLine; // parses function source code: var counter = new PHP.Core.Parsers.Parser.ReductionsCounter(); var ast = analyzer.BuildAst(pos, code, counter); if (ast == null || ast.Statements == null) { return(null); // the function cannot be parsed } Debug.Assert(counter.FunctionCount == 1); var decl_node = (PHP.Core.AST.FunctionDecl)ast.Statements[0]; // adds declaration to the end of the global code statement list: analyzer.AddLambdaFcnDeclaration(decl_node); // return(new PHP.Core.AST.DirectFcnCall.EvaluateInfo() { //.inlined = InlinedFunction.CreateFunction; emitDeclareLamdaFunction = true, // modify declaration: newRoutine = decl_node.ConvertToLambda(analyzer), }); }
private static void ToTableTest() { var df = new DataFactory(crudwork.Models.DataAccess.DatabaseProvider.SqlClient, "data source=\"sql.vnesoft.com\"; user id=\"Va!dO!#!167892g\"; password=\"H@#d@Tag#6\"; initial catalog=\"ARMLoyaltyUsers\""); df.TestConnection(); var cdl = df.Database.GetColumns("EbmContactAddress", QueryFilter.Exact, null, QueryFilter.None); var dt = DynamicCode.ToTable <ColumnDefinition>(cdl); }
private static void ShouldThrowEx() { try { var c = new ClassThatThrow(); DynamicCode.GetProperty(c, "IThrowAnException"); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private static void MispelledProperty() { try { var c = new ClassThatThrow(); DynamicCode.GetProperty(c, "IDoNotExist"); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public RuleTracker Run(Rule rule) { var tracker = new RuleTracker() { Name = rule.Name, Priority = rule.Priority }; try { var code = DynamicCode.Build(_properties, rule.Conditions, _parameters); tracker.Passed = code.Execute <bool>(); } catch { tracker.Passed = false; } var results = new Dictionary <string, object>(); foreach (var parameter in _parameters) { results.Add(parameter.Key, parameter.Value); } if (tracker.Passed) { foreach (var property in rule.Results) { if (results.ContainsKey(property.Name)) { results.Remove(property.Name); } //copy a parameter value and set to result value if (property.Type.ToLower() == "copy") { var parameterValue = _parameters.FirstOrDefault(x => x.Key == property.Value.ToString()).Value; results.Add(property.Name, parameterValue); } else { results.Add(property.Name, property.Value.ToType(property.Type)); } } } tracker.Results = results; return(tracker); }
public void Precompile(Type type) { if (type.IsGenericTypeDefinition) { throw new ArgumentException("Cannot compile for a generic type definition", nameof(type)); } lock (VirtualReadMethods) { ref var readMethod = ref VirtualReadMethods.GetOrAddValueRef(type); if (readMethod == null) { readMethod = DynamicCode <TStream, Binary <TStream, TSettingGen> > .GenerateReadMethod <ReadObject>(type, Settings, true, false); } }
protected override CompilationResult Compile() { var script = this.Script.Trim(); return(Compile(DynamicCode.GetCoreMetadataReferences() .Concat(DynamicCode.GetMetadataReferences()), DynamicCode.GetUsingNamespaces() + @" namespace Signum.Entities.Dynamic { class Evaluator : ControllerBase, Signum.Entities.Dynamic.IDynamicApiEvaluator { " + script + @" public bool DummyEvaluate() => true; } }")); }
protected override CompilationResult Compile() { var script = this.Script.Trim(); script = script.Contains(';') ? script : ("return " + script + ";"); return(Compile(DynamicCode.GetCoreMetadataReferences() .Concat(DynamicCode.GetMetadataReferences()), DynamicCode.GetUsingNamespaces() + @" namespace Signum.Entities.Workflow { class MyWorkflowEventTaskConditionEvaluator : IWorkflowEventTaskConditionEvaluator { public bool Evaluate() { " + script + @" } } }")); }
public TerminalConsole(DisplaySystem screen, Terminal terminal) { _terminal = terminal; _screen = screen; Typer = new TextTyper(screen, this); _runEventsTimer = new Timer(_outDeltaTime, RunEvents); _buffer = new CommandBuffer(10); _dynamicCode = new DynamicCode(this, screen); _clipTimer = new Timer(_startClipDelay, StartClip); _tick = _tickDelay; _fileController = new FileController(this); _fileController.UpdateDirsList(); _fileController.UpdateFileList(); _runner = new CommandRunner(Typer, _fileController, this); Writter = new ConsoleWriter(Typer); Invoker = new ActionInvoker(); _screen.BlackScreen(); _screen.Apply(); }