예제 #1
0
 // verifies that two contexts are compatible for association
 private void _verifyContextCompatibility(BplContext context1, BplContext context2) {
    if (context1 == context2 || context1 == null || context2 == null) return;
    if (!(context1.IsA<BplGlobalContext>() ^ context2.IsA<BplGlobalContext>())) {
       BplRuntimeException.Throw("Attempt to associate objects from different contexts '{0}' and '{1}'".Substitute(context1, context2), this);
    }
 }
예제 #2
0
      // attaches a node to the given context
      private void _attachToContext(BplContextNode node, BplContext context) {
         // check that the node can and needs to be attached to the context
         // assumptions: node and context are not null and node.Context != context
         if (node.Context != null) {
            _verifyContextCompatibility(node.Context, context);
            return;
         }
         if (context.IsA<BplGlobalContext>() && !node.IsA<BplTaxonomy>()) {
            return;
         }

         // attach node to context, and index/seal it as needed
         context.AttachNode(node);

         // recursively attach the node's children
         foreach (var child in node.Children.Where(child => child.Context != context)) {
            _attachToContext(child, context);
         }

         // recursively attach the node's target associations
         if (node.HasTargets) {
            foreach (var target in node.Targets.Where(target => target.Context != context)) {
               _attachToContext(target, context);
            }
         }

         // recursively attach the node's source associations
         if (node.HasSources) {
            foreach (var source in node.Sources.Where(source => BplContext.GetOwner(source) != context)) {
               if (source.IsA<BplContext>()) {
                  _verifyContextCompatibility((BplContext)source, context);
               } else {
                  _attachToContext((BplContextNode)source, context);
               }
            }
         }
      }