private bool ReplicateAllBlocks(IRoot root) { Debug.Assert(ErrorList.IsEmpty); foreach (IBlock <BaseNode.IClass, BaseNode.Class> Block in root.ClassBlocks.NodeBlockList) { foreach (IClass Item in Block.NodeList) { if (string.IsNullOrEmpty(Item.ClassPath)) { ErrorList.AddError(new ErrorEmptyClassPath(Item)); } } } ReplicationContext Replication = new ReplicationContext(); IWalkCallbacks <ReplicationContext> Callbacks = new WalkCallbacks <ReplicationContext>() { HandlerNode = OnNodeIgnoreReplicates, HandlerBlockList = OnBlockListReplicate, HandlerString = OnStringReplicateText }; NodeTreeWalk.Walk <ReplicationContext>(root, Callbacks, Replication); return(ErrorList.IsEmpty); }
private void CheckReplicates(IList <ICompiledReplicate> replicateList, ReplicationContext context) { foreach (ICompiledReplicate Replicate in replicateList) { IName ReplicateName = (IName)Replicate.ReplicateName; string ReplicateNameText = ReplicateName.Text; if (!StringValidation.IsValidIdentifier(ReplicateName, ReplicateNameText, out string ValidReplicateName, out IErrorStringValidity StringError)) { ErrorList.AddError(StringError); }
private void ProcessGlobalReplicates(IRoot root, ReplicationContext context) { List <ICompiledReplicate> ReplicateList = new List <ICompiledReplicate>(); foreach (IGlobalReplicate ReplicateItem in root.Replicates) { Debug.Assert(ReplicateItem.PatternList.Count == 0); foreach (IPattern PatternItem in ReplicateItem.Patterns) { ReplicateItem.PatternList.Add(PatternItem); } ReplicateList.Add(ReplicateItem); } CheckReplicates(ReplicateList, context); Debug.Assert(context.GlobalReplicateTable.Count == 0); foreach (KeyValuePair <string, List <string> > Entry in context.ReplicateTable) { context.GlobalReplicateTable.Add(Entry.Key, Entry.Value); } }
private void ProcessClassReplicates(IClass parentClass, IWalkCallbacks <ReplicationContext> callbacks, ReplicationContext context) { BaseNode.IBlockList ClassReplicateBlocks = (BaseNode.IBlockList)parentClass.ClassReplicateBlocks; List <BaseNode.INode> ReplicatedNodeList = new List <BaseNode.INode>(); if (ReplicateBlockList(ClassReplicateBlocks, ReplicatedNodeList, callbacks, context)) { parentClass.FillReplicatedList(nameof(IClass.ClassReplicateBlocks), ReplicatedNodeList); List <ICompiledReplicate> ReplicateList = new List <ICompiledReplicate>(); foreach (BaseNode.INode Node in ReplicatedNodeList) { IClassReplicate ReplicateItem = Node as IClassReplicate; Debug.Assert(ReplicateItem != null); ReplicateList.Add(ReplicateItem); } context.ReplicateTable.Clear(); foreach (KeyValuePair <string, List <string> > Entry in context.GlobalReplicateTable) { context.ReplicateTable.Add(Entry.Key, Entry.Value); } CheckReplicates(ReplicateList, context); } }
private bool OnNodeIgnoreReplicates(BaseNode.INode node, BaseNode.INode parentNode, string propertyName, IWalkCallbacks <ReplicationContext> callbacks, ReplicationContext context) { if (node is IGlobalReplicate) { return(true); } else if (node is IRoot AsRoot) { ProcessGlobalReplicates(AsRoot, context); return(ErrorList.IsEmpty); } else if (node is IClass AsClass) { ProcessClassReplicates(AsClass, callbacks, context); return(ErrorList.IsEmpty); } else { return(parentNode == null || NodeTreeWalk.Walk <ReplicationContext>(node, callbacks, context)); } }