/// <summary>Initializes a new instance of TemplateInputComponentBase class.</summary> protected TemplateInputComponentBase(ComponentType type, object obj, string name, ITemplateInputComponent parent) { this.Type = type; this.Instance = obj; this.Class = obj.GetType(); this.Name = name ?? this.Class.Name; this.Parent = parent; this.Root = (parent != null) ? parent.Root : this; }
/// <summary>Returns <b>true</b> if field is not used to establish relation/FK to <see cref="ITemplateInputComponent.Root"/> object.</summary> /// <param name="fieldComponent">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Core.IDbColumn"/> object.</param> public static bool IsNotFkToRoot(ITemplateInputComponent fieldComponent) { IDbColumn field = fieldComponent.Instance as IDbColumn; if (!field.IsForeignKeyPart) return true; IEntity root = fieldComponent.Root.Instance as IEntity; if (root == null) return true; var relations = ArrayUtil.FindAll<List<DbRelation>, DbRelation>(field.Table.ForeignKeys, (rel) => (rel.ChildForeignKey[0].ColumnName == field.ColumnName)); if (relations.Count == 0) return true; if (relations[0].Parent.TableName == root.Table.TableName) return false; else return true; }
/// <summary>Returns <b>true</b> if return value parameter should be generated.</summary> public static bool ShouldGenerateReturnValue(ITemplateInputComponent sp) { StoredProcedure proc = (StoredProcedure)sp.Instance; return proc.ShouldGenerateReturnValue; }
/// <summary>Returns <b>true</b> if given parameter is primitive, ie. not a DataTable filled by adapter as required in Oracle and similar DBMSs.</summary> /// <param name="spParameter">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Generator.IStoredProcedureParameter"/> object.</param> public static bool IsNotDataTableFilledByAdapter(ITemplateInputComponent spParameter) { IStoredProcedureParameter par = (IStoredProcedureParameter)spParameter.Instance; return (par.PassMode != SpArgumentPassMode.DataTableFilledByAdapter); }
public ExpressionEvaluationException(string expression, Exception evalException, ITemplate template, ITemplateInputComponent inputComponent) : base(evalException.Message, evalException) { this.expression = expression; this.template = template; this.inputComponent = inputComponent; }
private void ParseAndGenerateSegment(StreamWriter output, TemplateSegment segment, ITemplateInputComponent component) { var orderedSegmentParts = segment.Parse(); foreach (SegmentPart part in orderedSegmentParts) { if (part.IsExpression) { string expressionResult = EvalExpression(component, part.Body); output.Write(expressionResult); } else { output.Write(part.Body); } } }
private ITemplateExpression CreateTemplateExpression(ITemplateInputComponent component, string expressionSource) { ITemplateExpression expression = this.compiledExpressionFactory.NewTemplateExpression(expressionSource); expression.Initialize(this, component); return expression; }
/// <summary>Generates the specified template segment for input component if it matches the specified criteria.</summary> /// <param name="segmentId">Segment ID as defined in <b>Id</b> attribute of <b>TemplateSegment</b> XML element.</param> /// <param name="component">An input component.</param> /// <param name="evaluatedComponentCriteria">An array of flags. All must be <b>true</b> to generate the segment.</param> /// <returns>Generated text. Empty string if the criterira is not matched.</returns> public string GenerateIf(string segmentId, ITemplateInputComponent component, params bool[] evaluatedComponentCriteria) { return this.template.Generate(segmentId, component, evaluatedComponentCriteria); }
/// <summary>Generates the specified template segment for the given input components if the specified condition is met.</summary> /// <param name="segmentId">Segment ID as defined in <b>Id</b> attribute of <b>TemplateSegment</b> XML element.</param> /// <param name="components">A collection of input components.</param> /// <param name="criteriaParameter">A component which is to be passed to the supplied criteria methods.</param> /// <param name="criteria">An array of predicates that define a set of criteria for the component provided as criteria parameter.</param> /// <returns>Generated text. Empty string if the criterira is not matched.</returns> public string GenerateIf(string segmentId, IEnumerable<ITemplateInputComponent> components, ITemplateInputComponent criteriaParameter, params Predicate<ITemplateInputComponent>[] criteria) { return this.template.GenerateIf(segmentId, components, criteriaParameter, criteria); }
/// <summary>Initializes expression. This method can only be called once.</summary> /// <param name="template">Template to which the current expression belongs to. This expression implementation only supports <see cref="Template"/> class.</param> /// <param name="input">Input component.</param> void ITemplateExpression.Initialize(ITemplate template, ITemplateInputComponent input) { if (this.isInitialized) throw new InvalidOperationException("The expression is already initialized."); this.template = (Template)template; this.Variables = new TemplateVariableCollection(template.Variables); this.Input = input; this.isInitialized = true; }
/// <summary>Generates the specified template segment for input component if it matches the specified criteria.</summary> /// <param name="segmentId">Segment ID as defined in <b>Id</b> attribute of <b>TemplateSegment</b> XML element.</param> /// <param name="component">An input component.</param> /// <param name="componentCriteria">An array of predicates that define a set of criteria for the input component.</param> /// <returns>Generated text. Empty string if the criterira is not matched.</returns> public string GenerateIf(string segmentId, ITemplateInputComponent component, params Predicate<ITemplateInputComponent>[] componentCriteria) { return this.template.Generate(segmentId, component, componentCriteria); }
/// <summary>Returns <b>true</b> if entity collection has single column integer PK.</summary> /// <param name="entityCollection">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Core.IEntityCollection"/> object.</param> public static bool HasIntegerPk(ITemplateInputComponent entityCollection) { IEntityCollection collection = entityCollection.Instance as IEntityCollection; bool hasSimplePk = (collection != null) && (collection.IDbTable.PrimaryKey.Count == 1) && TypeUtil.IsInteger(collection.IDbTable.PrimaryKey[0].DataType); return hasSimplePk; }
/// <summary>Returns <b>true</b> if field is not boolean field.</summary> /// <param name="fieldComponent">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Core.IDbColumn"/> object.</param> public static bool IsNotBool(ITemplateInputComponent fieldComponent) { return !IsBool(fieldComponent); }
/// <summary>Returns <b>true</b> if field is boolean field.</summary> /// <param name="fieldComponent">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Core.IDbColumn"/> object.</param> public static bool IsBool(ITemplateInputComponent fieldComponent) { IDbColumn field = fieldComponent.Instance as IDbColumn; if (field == null) return false; bool isBoolOrIsByteWhitIsPrefix = (field.DataType == typeof(bool)) || (field.DataType == typeof(byte) && field.PropertyName.StartsWith("Is", StringComparison.InvariantCulture)); return isBoolOrIsByteWhitIsPrefix; }
/// <summary>Generates code segment for the given input compoments if it matches specified criteria.</summary> private void Generate(StreamWriter output, TemplateSegment segment, ITemplateInputComponent component, params Predicate<ITemplateInputComponent>[] componentCriteria) { if (component == null) return; if (segment == null) throw new ArgumentNullException("segment", "Segment may not be null."); bool shouldGenerate = ArrayUtil.IsNullOrEmpty(componentCriteria) || MatchesCriteria(component, componentCriteria); if (!shouldGenerate) return; ParseAndGenerateSegment(output, segment, component); }
/// <summary>Writes the given text if the input component matches the specified criteria.</summary> /// <param name="text">Text to write.</param> /// <param name="component">An input component.</param> /// <param name="componentCriteria">An array of predicates that define a set of criteria for the input component.</param> /// <returns>The specified text. Empty string if the criterira is not matched.</returns> public string WriteIf(string text, ITemplateInputComponent component, params Predicate<ITemplateInputComponent>[] componentCriteria) { return Template.WriteIf(text, component, componentCriteria); }
private string ParseAndGenerateSegment(TemplateSegment segment, ITemplateInputComponent component) { StringBuilder output = new StringBuilder(); var orderedSegmentParts = segment.Parse(); foreach (SegmentPart part in orderedSegmentParts) { if (part.IsExpression) { string expressionResult = EvalExpression(component, part.Body); output.Append(expressionResult); } else { output.Append(part.Body); } } return output.ToString(); }
//public string[] ValidateInput(object obj) //{ // ITemplateInputComponent input = CreateComponent(obj); // return ValidateInput(input); //} //public string[] ValidateInput(ITemplateInputComponent input) //{ // return null; //} /// <summary>Compiles template and generates code for the given input component.</summary> public string Run(ITemplateInputComponent input) { if (this.segments.RootSegment == null) throw new InvalidOperationException("The root segment is not set."); EnsureTemplateIsCompiled(); input.CurrentTemplateData = this; return Generate(this.segments.RootSegment, input); }
private string EvalExpression(ITemplateInputComponent component, string expressionSource) { ITemplateExpression expression = CreateTemplateExpression(component, expressionSource); string output; try { output = expression.Eval(); } catch (ExpressionEvaluationException previousExceptionInStack) { throw new ExpressionEvaluationException(expressionSource, previousExceptionInStack); } catch (Exception evalException) { throw new ExpressionEvaluationException(expressionSource, evalException, this, component); } return output; }
/// <summary>Compiles template and generates code for the given input component.</summary> public void Run(StreamWriter output, ITemplateInputComponent input) { if (this.segments.RootSegment == null) throw new InvalidOperationException("The root segment is not set."); EnsureTemplateIsCompiled(); input.CurrentTemplateData = this; Generate(output, this.segments.RootSegment, input); }
internal static bool MatchesCriteria(ITemplateInputComponent component, Predicate<ITemplateInputComponent>[] criteria) { foreach (Predicate<ITemplateInputComponent> matchesCurrent in criteria) { if (!matchesCurrent(component)) return false; } return true; }
/// <summary>Generates code segments for the given input compoments if the specified condition is met.</summary> internal string GenerateIf(string segmentId, IEnumerable<ITemplateInputComponent> components, ITemplateInputComponent criteriaParameter, params Predicate<ITemplateInputComponent>[] criteria) { if (!MatchesCriteria(criteriaParameter, criteria)) return ""; TemplateSegment segment = GetSegment(segmentId, /*throw exception if not found*/ true); StringBuilder output = new StringBuilder(); foreach (ITemplateInputComponent component in components) output.Append(Generate(segment, component)); return output.ToString(); }
public ExpressionEvaluationException(string expression, ExpressionEvaluationException previousExceptionInStack) { this.expression = expression; this.previousExceptionInStack = previousExceptionInStack; this.template = previousExceptionInStack.template; this.inputComponent = previousExceptionInStack.inputComponent; }
/// <summary>Generates code segments for input components which match the specified criteria.</summary> internal string Generate(string segmentId, ITemplateInputComponent component, params Predicate<ITemplateInputComponent>[] componentCriteria) { TemplateSegment segment = GetSegment(segmentId, /*throw exception if not found*/ true); return Generate(segment, component, componentCriteria); }
/// <summary>Returns <b>true</b> if given parameter is a return value.</summary> /// <param name="spParameter">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Generator.IStoredProcedureParameter"/> object.</param> public static bool IsReturnValue(ITemplateInputComponent spParameter) { IStoredProcedureParameter par = (IStoredProcedureParameter)spParameter.Instance; return (par.Direction == ParameterDirection.ReturnValue); }
/// <summary>Generates code segments for input components which match the specified criteria.</summary> internal string Generate(string segmentId, ITemplateInputComponent component, params bool[] evaluatedComponentCriteria) { TemplateSegment segment = GetSegment(segmentId, /*throw exception if not found*/ true); if (AllVariablesAreTrue(evaluatedComponentCriteria)) return Generate(segment, component); else return ""; }
/// <summary>Returns <b>true</b> if given parameter has a <b>ref</b> or <b>out</b> .NET argument modifier.</summary> /// <param name="spParameter">Input component whose <see cref="ITemplateInputComponent.Instance"/> property must contain a <see cref="FistCore.Generator.IStoredProcedureParameter"/> object.</param> public static bool IsRefOrOut(ITemplateInputComponent spParameter) { IStoredProcedureParameter par = (IStoredProcedureParameter)spParameter.Instance; return !string.IsNullOrEmpty(par.MethodParameterKeyword); }
/// <summary>Writes the text if the input component matches the specified criteria.</summary> internal static string WriteIf(string text, ITemplateInputComponent component, params Predicate<ITemplateInputComponent>[] componentCriteria) { bool shouldGenerate = ArrayUtil.IsNullOrEmpty(componentCriteria) || MatchesCriteria(component, componentCriteria); if (!shouldGenerate) return ""; else return text ?? ""; }
private SpComponent(ComponentType type, object obj, string name, ITemplateInputComponent parent) : base(type, obj, name, parent) { }
public bool IsMatch(ITemplateInputComponent fieldComponent) { IDbColumn field = fieldComponent.Instance as IDbColumn; return (field != null) && this.rex.IsMatch(field.PropertyName); }