/// <summary> /// Initializes a new instance of the <see cref="SealedListCollectionSourceTemplate{TSource, TItem, TValue}"/> class. /// </summary> /// <param name="path">Path to the source object.</param> /// <param name="propertyName">The name of the <see cref="ISealableList{TValue}"/> property to check in each items of the list.</param> /// <param name="startingPoint">The starting point for the path.</param> public SealedListCollectionSourceTemplate(string path, string propertyName, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { ItemProperty = BaseNodeHelper.NodeTreeHelper.GetPropertyOf(typeof(TItem), propertyName); Debug.Assert(ItemProperty != null); Debug.Assert(ItemProperty.PropertyType.GetInterface(typeof(ISealableList).Name) != null); }
/// <summary> /// Initializes a new instance of the <see cref="SourceTemplate{TSource, TValue}"/> class. /// </summary> /// <param name="path">Path to the source object.</param> /// <param name="startingPoint">The starting point for the path.</param> public SourceTemplate(string path, ITemplatePathStart <TSource> startingPoint = null) { Path = path; StartingPoint = startingPoint ?? TemplateNodeStart <TSource> .Default; List <PropertyInfo> PropertyPath = new List <PropertyInfo>(); TemplateHelper.BuildPropertyPath(StartingPoint.PropertyType, path, PropertyPath); this.PropertyPath = PropertyPath.AsReadOnly(); }
/// <summary> /// Gets the current value at the end of a property path. /// </summary> /// <typeparam name="TSource">Type of the source.</typeparam> /// <typeparam name="TValue">Type of the result.</typeparam> /// <param name="source">The node for which the value is requested.</param> /// <param name="startingPoint">The starting point to use.</param> /// <param name="propertyPath">Path from the starting point to the value to read.</param> /// <param name="isInterrupted">True is progressing through the path was interrupted.</param> public static TValue GetPropertyPathValue <TSource, TValue>(TSource source, ITemplatePathStart <TSource> startingPoint, IReadOnlyList <PropertyInfo> propertyPath, out bool isInterrupted) where TSource : ISource { isInterrupted = true; object IntermediateResult = startingPoint.GetStart(source); #if DEBUG_ENGINE try { #endif for (int i = 0; i < propertyPath.Count; i++) { if (IntermediateResult is IOnceReference AsOnceReference) { if (!AsOnceReference.IsAssigned) { isInterrupted = true; return(default);
/// <summary> /// Initializes a new instance of the <see cref="ConditionallyAssignedSealedTableSourceTemplate{TSource, TRef, TKey, TValue}"/> class. /// </summary> /// <param name="path">Path to the <see cref="IOptionalReference{TRef}"/> in the source object.</param> /// <param name="propertyName">The name of the <see cref="ISealableDictionary{TKey, TValue}"/> property to check in the optional node.</param> /// <param name="startingPoint">The starting point for the path.</param> public ConditionallyAssignedSealedTableSourceTemplate(string path, string propertyName, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { ItemProperty = BaseNodeHelper.NodeTreeHelper.GetPropertyOf(typeof(TRef), propertyName); Debug.Assert(ItemProperty != null); Debug.Assert(ItemProperty.PropertyType.GetInterface(typeof(ISealableDictionary).Name) != null); }
private bool FindRuleWithDestination(ICollection <IRuleTemplate> ruleTemplateList, IList <ISource> unresolvedSourceList, string path, Type type, ITemplatePathStart startingPoint, out IRuleTemplate matchingRule) { matchingRule = null; foreach (IRuleTemplate Rule in ruleTemplateList) { foreach (ISource Source in unresolvedSourceList) { if (!Rule.NodeType.IsAssignableFrom(Source.GetType())) { continue; } IList <IDestinationTemplate> DestinationTemplateList = Rule.GetAllDestinationTemplatesNotSet(Source); foreach (IDestinationTemplate DestinationTemplate in DestinationTemplateList) { if (DestinationTemplate.Path == path && DestinationTemplate.StartingPoint == startingPoint) { if (DestinationTemplate.DestinationType == type) { matchingRule = Rule; return(true); } } } } } return(false); }
private void ListDependencies(IList <ISource> unresolvedSourceList) { Debug.WriteLine("Performing cyclic dependencies analysis..."); Dictionary <IRuleTemplate, IList <ISource> > Analysis = new Dictionary <IRuleTemplate, IList <ISource> >(); foreach (IRuleTemplate Rule in RuleTemplateList) { /*if (Rule is IConstraintRuleTemplate AsRuleTemplate) * { * * }*/ foreach (ISource Source in unresolvedSourceList) { if (!Rule.NodeType.IsAssignableFrom(Source.GetType())) { continue; } bool IsNoDestinationSet = Rule.IsNoDestinationSet(Source); if (IsNoDestinationSet) { bool AreAllSourcesReady = Rule.AreAllSourcesReady(Source, out IDictionary <ISourceTemplate, object> DataList); if (!AreAllSourcesReady) { IList <ISourceTemplate> SourceTemplateList = Rule.GetAllSourceTemplatesNotReady(Source); Debug.Assert(SourceTemplateList.Count > 0); if (!Analysis.ContainsKey(Rule)) { Analysis.Add(Rule, new List <ISource>()); } Analysis[Rule].Add(Source); } } } } bool Exit; do { ICollection <IRuleTemplate> Rules = Analysis.Keys; IList <IRuleTemplate> ToRemove = new List <IRuleTemplate>(); foreach (KeyValuePair <IRuleTemplate, IList <ISource> > Entry in Analysis) { IRuleTemplate Rule = Entry.Key; IList <ISource> SourceList = Entry.Value; Debug.Assert(SourceList.Count > 0); foreach (ISource Source in SourceList) { IList <ISourceTemplate> SourceTemplateList = Rule.GetAllSourceTemplatesNotReady(Source); Debug.Assert(SourceTemplateList.Count > 0); foreach (ISourceTemplate SourceTemplate in SourceTemplateList) { string Path = SourceTemplate.Path; Type SourceType = SourceTemplate.SourceType; ITemplatePathStart StartingPoint = SourceTemplate.StartingPoint; if (FindRuleWithDestination(Rules, unresolvedSourceList, Path, SourceType, StartingPoint, out IRuleTemplate MatchingRule)) { if (!ToRemove.Contains(Rule)) { ToRemove.Add(Rule); } } } } } foreach (IRuleTemplate Rule in ToRemove) { Analysis.Remove(Rule); } Exit = ToRemove.Count == 0; }while (!Exit); Debug.WriteLine($"{Analysis.Count} rule(s) are waiting on a source template:"); foreach (KeyValuePair <IRuleTemplate, IList <ISource> > Entry in Analysis) { Debug.WriteLine($"{Entry.Key} on {Entry.Value.Count} node(s)"); } }
/// <summary> /// Initializes a new instance of the <see cref="SealedListSourceTemplate{TSource, TValue}"/> class. /// </summary> /// <param name="path">Path to the source object.</param> /// <param name="startingPoint">The starting point for the path.</param> public SealedListSourceTemplate(string path, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { }
/// <summary> /// Initializes a new instance of the <see cref="OnceReferenceTableSourceTemplate{TSource, TKey, TValue, TRef}"/> class. /// </summary> /// <param name="path">Path to the source object.</param> /// <param name="propertyName">The name of the <see cref="OnceReference{TRef}"/> property to check in each item of the list.</param> /// <param name="startingPoint">The starting point for the path.</param> public OnceReferenceTableSourceTemplate(string path, string propertyName, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { ItemProperty = BaseNodeHelper.NodeTreeHelper.GetPropertyOf(typeof(TValue), propertyName); Debug.Assert(ItemProperty != null); }
/// <summary> /// Initializes a new instance of the <see cref="UnsealedTableDestinationTemplate{TSource, TKey, TValue}"/> class. /// </summary> /// <param name="path">Path to the destination object.</param> /// <param name="startingPoint">The starting point for the path.</param> public UnsealedTableDestinationTemplate(string path, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { }
/// <summary> /// Initializes a new instance of the <see cref="ResolvedPathSourceTemplate{TSource}"/> class. /// </summary> /// <param name="path">Path to the source object.</param> /// <param name="startingPoint">The starting point for the path.</param> public ResolvedPathSourceTemplate(string path, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { }
/// <summary> /// Initializes a new instance of the <see cref="OnceReferenceSourceTemplate{TSource, TRef}"/> class. /// </summary> /// <param name="path">Path to the source object.</param> /// <param name="startingPoint">The starting point for the path.</param> public OnceReferenceSourceTemplate(string path, ITemplatePathStart <TSource> startingPoint = null) : base(path, startingPoint) { }