public NavContext(params RuleSet[] ruleSets) { _parentContext = null; _entities = null; _attributes = new ReadOnlyCollection <EntityAttribute>(CollectionsUtils <EntityAttribute> .EmptyCollection); _visibleEntities = new ReadOnlyCollection <RuleSetBase>(ruleSets.Cast <RuleSetBase>().ToArray()); }
internal XmlModelAttributesAnalyzer(NavContext context) { if (context == null) { throw new ArgumentNullException(); } _context = context; _attrsByNamespace = context.CurrElement.Attributes.GroupBy(a => context.ResolveNsPrefix(a.Name.Prefix)) .ToDictionary(ag => ag.Key, ag => ag.ToList()); }
internal XmlModelItemAnalyzer(NavContext context) { if (context == null) { throw new ArgumentNullException(); } _context = context; _childElementIndex = 0; this.Text = null; }
private bool TryEnterImpl(string entityName, out NavContext result) { if (_visibleEntities.Any(e => e.Name == entityName)) { result = new NavContext(this, entityName); } else { result = null; } return(result != null); }
public bool TryEnter(string entityName, out NavContext result) { foreach (var item in this.GetContexts()) { if (item.TryEnterImpl(entityName, out result)) { return(true); } } result = null; return(false); }
static void Main(string[] args) { int[] arr1 = { 31, 15, 10, 2, 4, 2, 14, 23, 12, 66 }; StrategySort sort = new SelectionSort(); Context context = new Context(sort, arr1); context.Sort(); context.PrintArray(); int[] arr2 = { 1, 5, 10, 2, 4, 12, 14, 23, 12, 66 }; sort = new InsertionSort(); context = new Context(sort, arr2); context.Sort(); context.PrintArray(); int[] arr3 = { 31, 15, 10, 2, 4, 2, 14, 23, 12, 66 }; sort = new BubbleSort(); context = new Context(sort, arr3); context.Sort(); context.PrintArray(); string A = "A", B = "B"; StrategyRoute route1 = new CyclingRoute(); StrategyRoute route2 = new PublicTransportRoute(); StrategyRoute route3 = new RoadRoute(); StrategyRoute route4 = new WalkingRoute(); StrategyRoute route5 = new SightseeingRoute(); NavContext navContext = new NavContext(route1); Console.WriteLine(navContext.ToString() + "\n" + navContext.BuildRoute(A, B) + "\n"); navContext = new NavContext(route2); Console.WriteLine(navContext.ToString() + "\n" + navContext.BuildRoute(A, B) + "\n"); navContext = new NavContext(route3); Console.WriteLine(navContext.ToString() + "\n" + navContext.BuildRoute(A, B) + "\n"); navContext = new NavContext(route4); Console.WriteLine(navContext.ToString() + "\n" + navContext.BuildRoute(A, B) + "\n"); navContext = new NavContext(route5); Console.WriteLine(navContext.ToString() + "\n" + navContext.BuildRoute(A, B) + "\n"); }
public NavContext(NavContext prevContext, XmlElement currElement) { _availableNamespaces = this.GetNamespaces(currElement); string ns; if (!_availableNamespaces.TryGetValue(CurrNsPrefix, out ns)) { ns = prevContext.CurrNamespace; } this.CurrElement = currElement; this.CurrNamespace = ns; this.PrevContext = prevContext; this.CurrElementNamespace = this.ResolveNsPrefix(currElement.Name.Prefix); }
private NavContext(NavContext parent, string entityName) { _parentContext = parent; _entities = new ReadOnlyCollection <RuleSetBase>(parent._visibleEntities.Where(e => e.Name == entityName).ToArray()); _attributes = new ReadOnlyCollection <EntityAttribute>(_entities.SelectMany(e => e.GetAttributes()).ToArray()); var visibleEntities = _entities.SelectMany(e => e.GetEntities()).OfType <RuleSetBase>(); foreach (var item in _entities.SelectMany(e => e.GetEntities()).OfType <RuleSetImport>()) { RuleSetBase[] importedEntities; if (item.RuleSetName.Contains('.')) { throw new NotImplementedException(); } if (!parent.TryResolveEntities(item.RuleSetName, out importedEntities)) { importedEntities = _entities.SelectMany(e => e.GetEntities()) .Where(ie => ie.Name == item.RuleSetName) .OfType <RuleSetBase>() .ToArray(); } if (importedEntities.Length > 0) { var importedContent = importedEntities.SelectMany(ie => ie.GetEntities()) .OfType <RuleSetBase>(); visibleEntities = visibleEntities.Concat(importedContent); } else { throw new InvalidOperationException(string.Format("Failed to import rule set [{0}]!", item.RuleSetName)); } } _visibleEntities = new ReadOnlyCollection <RuleSetBase>(visibleEntities.ToArray()); RuleInfo info; this.Name = entityName; this.Info = TryMakeRuleInfo(_entities, out info) ? info : null; }
public XmlModelNavigator(XmlDocument doc, string rootNodeNamespaceName, params string[] rootNodeLocalNames) { if (doc == null || rootNodeLocalNames == null || rootNodeLocalNames.Length < 1 || string.IsNullOrWhiteSpace(rootNodeNamespaceName)) { throw new ArgumentNullException(); } var state = new NavContext(doc.RootElement); if (state.CurrElementNamespace != rootNodeNamespaceName || rootNodeLocalNames.All(n => doc.RootElement.Name.LocalName != n)) { throw new InvalidOperationException("Invalid root element!"); } _doc = doc; _state.Push(state); }
private bool TryEnterInternal(string[] entityNameParts, out NavContext resultContext) { // _log.Write("entering from [{0}] to [{1}]", _stack.Peek().FullName, string.Join(".", entityNameParts)); var ctx = _stack.Peek(); foreach (var namePart in entityNameParts) { if (!ctx.TryEnter(namePart, out ctx)) { // _log.WriteLine(" ...fail"); resultContext = null; return(false); } } // _log.WriteLine(" ...ok").Push(); _stack.Push(ctx); resultContext = ctx; return(true); }
public void SetParamExpression(RuleParameter paramInfo, RuleExpression expr, NavContext paramValueContext) { if (_ruleParamExpressions == null) { _ruleParamExpressions = new Dictionary <string, RuleParameterInfo>(); } _ruleParamExpressions.Add(paramInfo.Name, new RuleParameterInfo(paramInfo, expr, paramValueContext)); }
public RuleParameterInfo(RuleParameter paramInfo, RuleExpression expression, NavContext paramValueContext) { this.paramInfo = paramInfo; this.expression = expression; this.paramValueContext = paramValueContext; }
internal XmlModelItemAnalyzer(string text) { _context = null; this.Text = text; }