Пример #1
0
        public InMemorySet(IIdGenerator idGenerator, ICache cache, IObjectGraph objectGraph,
                           IEnumerable <IMaterializationHook> materializationHooks)
        {
            if (idGenerator == null)
            {
                throw new ArgumentNullException("idGenerator");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (objectGraph == null)
            {
                throw new ArgumentNullException("objectGraph");
            }
            if (materializationHooks == null)
            {
                throw new ArgumentNullException("materializationHooks");
            }

            _idGenerator          = idGenerator;
            _cache                = cache;
            _objectGraph          = objectGraph;
            _materializationHooks = materializationHooks;
        }
Пример #2
0
        public void SetUp()
        {
            graph = MockRepository.GenerateMock<IObjectGraph>();
            context = MockRepository.GenerateMock<IPipelineContext>();

            arguments = new Arguments(graph, context);
        }
Пример #3
0
        public Cache(IIdGenerator idGenerator, IObjectGraph objectGraph, IEnumerable<IMaterializationHook> materializationHooks)
        {
            if (idGenerator == null) throw new ArgumentNullException("idGenerator");
            if (objectGraph == null) throw new ArgumentNullException("objectGraph");
            if (materializationHooks == null) throw new ArgumentNullException("materializationHooks");

            _idGenerator = idGenerator;
            _objectGraph = objectGraph;
            _materializationHooks = materializationHooks;
        }
Пример #4
0
        protected object LoadObject(IObjectGraph source, Dictionary <object, object> parsedObjects)
        {
            if (!source.IsAnonymous)
            {
                var instance = source.GetInstance();
                if (instance is IEntity)
                {
                    instance = GetCopyInContextOrAttach(instance as IEntity);
                }

                LoadIncludes(source, instance, parsedObjects);

                return(instance);
            }

            else
            {
                //Anonymous Types
                var anonType = source.GetInstanceType();
                var ctor     = anonType.GetConstructors().Single();

                var deserializedIncludes = new Dictionary <PropertyInfo, object>();

                foreach (var property in source.GetPropertiesNeedingContextBinding())
                {
                    if (!TypesUtil.IsNonPrimitiveCollection(property.PropertyType))
                    {
                        var propertyValue = LoadObject(source.GetObjectGraphForProperty(property), parsedObjects);
                        deserializedIncludes.Add(property, propertyValue);
                    }
                    else
                    {
                        var collectionItems = source.GetObjectGraphForCollection(property)
                                              .Select(itemInfo => LoadObject(itemInfo, parsedObjects)).ToList();

                        var propertyValue = MakeEnumerable(property.PropertyType, collectionItems);

                        deserializedIncludes.Add(property, propertyValue);
                    }
                }

                var ctorArgs = deserializedIncludes.Select(kvp => kvp.Value).ToArray();

                return(Activator.CreateInstance(anonType, ctorArgs));
            }
        }
        private void RenderImpl(TreeViewRenderForm form, IObjectGraph graph)
        {
            form.Splitter.Panel2Collapsed = true;
            form.Tree.Nodes.Clear();

            try
            {
                form.Tree.BeginUpdate();

                if (MaxDepth <= 0 || MaxNodes <= 0)
                {
                    return;
                }
                else
                {
                    var root = CreateNodeRecursive(graph, new Edge(null, null, graph.Root), new State());
                    form.Tree.Nodes.Add(root);

                    var visible = root.Flatten(n => n.Nodes.Cast <TreeNode>().Where(n1 =>
                                                                                    n1.Tag != null && ((Tag)n1.Tag).ShouldBeInitiallyVisible));
                    visible.ForEach(n => n.EnsureVisible());
                    root.EnsureVisible();
                    form.Tree.SelectedNode = null;

                    form.Tree.AfterSelect += (o, e) =>
                    {
                        var tag = e.Node.Tag as Tag;
                        form.Splitter.Panel2Collapsed = !tag.IsAbbreviated;
                        form.Details.Text             = tag.FullText;
                    };

                    form.Tree.BeforeExpand += (o, e) =>
                    {
                        var tag = e.Node.Tag as Tag;
                        (tag.DeferredExpand ?? (() => { }))();
                    };
                }
            }
            finally
            {
                form.Tree.EndUpdate();
            }
        }
Пример #6
0
 public T AttachGraphToContext <T>(IObjectGraph source)
 {
     return((T)LoadObject(source, new Dictionary <object, object>()));
 }
Пример #7
0
        protected void LoadIncludes(IObjectGraph source, object instance, Dictionary <object, object> parsedObjects)
        {
            if (parsedObjects.ContainsKey(instance))
            {
                return;
            }

            //Add it to the parsed objects list, so that we can avoid going through circular relationships.
            parsedObjects.Add(instance, null);

            if (source.IsCollection)
            {
                var sourceCollection = source.GetSourceCollection();
                var ctr = 0;
                foreach (var item in (instance as IEnumerable))
                {
                    LoadIncludes(sourceCollection[ctr++], item, parsedObjects);
                }
            }
            else
            {
                foreach (var property in source.GetPropertiesNeedingContextBinding())
                {
                    if (!TypesUtil.IsNonPrimitiveCollection(property.PropertyType))
                    {
                        //If the instance is an Entity, we treat property setting differently.
                        //  This is because setters will automatically trigger Reverse Reference setters.
                        if (instance is IEntity)
                        {
                            var propValFromSource = source.GetPropertyValue(property);
                            var loadedValue       = property.GetValue(instance);

                            //If the property is already loaded in our current instance, we should not touch it.
                            //  Yet, if they (current instance and the source) refer to the same value, we should attach includes.
                            //If they are NOT the same, we do nothing. (Since the user changed the property, can't overwrite.)
                            if (IsPropertyLoadedOnEntity(instance, property))
                            {
                                if (loadedValue != null && loadedValue is IEntity &&
                                    ((IEntity)loadedValue).IsEquivalent((IEntity)propValFromSource))
                                {
                                    LoadIncludes(source.GetObjectGraphForProperty(property), loadedValue, parsedObjects);
                                }
                            }

                            //Property is not loaded on the current instance. Go ahead and add it via Materialization methods.
                            else
                            {
                                if (source.GetPropertyValue(property) != null)
                                {
                                    var propertyValue         = LoadObject(source.GetObjectGraphForProperty(property), parsedObjects);
                                    var intermediateContainer = GetBackingContainerForProperty(instance as IEntity, property);
                                    intermediateContainer.MaterializationAddReference((propertyValue as IEntity)._getIntermediateEntity());
                                }
                            }
                        }

                        //Instance is not an IEntity, we can just set the property value.
                        else
                        {
                            if (source.GetPropertyValue(property) != null)
                            {
                                var propertyValue = LoadObject(source.GetObjectGraphForProperty(property), parsedObjects);
                                property.SetValue(instance, propertyValue);
                            }
                        }
                    }

                    //This property is a collection.
                    else
                    {
                        var entityList = source.GetObjectGraphForCollection(property)
                                         .Select(collItemSource => LoadObject(collItemSource, parsedObjects)).ToList();

                        if (IsManyToMany(property))
                        {
                            //Many-to-Many collection can only exist in Entities, hence the cast.
                            AddToManyToManyCollection((IEntity)instance, property, entityList);
                        }
                        else
                        {
                            SetEnumerableProperty(instance, property, MakeEnumerable(property.PropertyType, entityList));
                        }
                    }
                }
            }
        }
Пример #8
0
 public void Render(IObjectGraph graph)
 {
     Logic(Context, graph);
 }
 public ConstructorInfo Select(IObjectGraph objectGraph, PluginGraph pluginGraph)
 {
     return
         objectGraph.ConcreteType.Type.GetConstructors().OrderByDescending(x => x.GetParameters().Count()).
             FirstOrDefault();
 }
        private TreeNode CreateNodeRecursive(IObjectGraph graph, Edge e, State s)
        {
            s.Depth++;
            s.Nodes++;

            var       fullText   = TextRenderer(e);
            const int maxLength  = 70;
            var       shouldAbbr = fullText.Length >= maxLength || fullText.IndexOfAny(new char[] { '\r', '\n', '\t' }) != -1;
            var       fullTextPp = fullText.Replace("\r\n", " ").Replace("\n", " ").Replace("\t", " ");
            var       text       = shouldAbbr ? fullTextPp.Substring(0, Math.Min(fullTextPp.Length, maxLength - 3)) + "..." : fullText;

//            using(var sw = new StreamWriter(@"d:\recursion.log", true))
//            {
//                sw.WriteLine(new String('.', e.Target.DistanceFromRoot) + "(" + e.Target.TraversalId + ") " + (e.Name ?? "null"));
//            }

            var node = new TreeNode(text);

            node.Tag = new Tag {
                IsAbbreviated = shouldAbbr, FullText = fullText
            };
            ((Tag)node.Tag).ShouldBeInitiallyVisible = s.Depth < MaxDepth && s.Nodes < MaxNodes && e.Name != "SyncRoot";

            var subEdges = graph.OutEdges(e.Target).ToArray();

            if (!subEdges.IsEmpty())
            {
                Action expandChildren = () =>
                {
                    node.Nodes.Clear();

                    var children = subEdges.Select(e1 => CreateNodeRecursive(graph, e1, s));
                    children = children.OrderBy(c => c.Name).ToArray();
                    children.ForEach(c => node.Nodes.Add(c));

                    ((Tag)node.Tag).DeferredExpand = null;
                };

                var eagerExpansion = s.Depth < MaxDepth && s.Nodes < MaxNodes &&
                                     (ExpandAlreadyReferencedNodes || !s.Visited.ContainsKey(e.Target) ||
                                      !(s.Visited[e.Target].Any(vn => ((Tag)vn.Tag).ShouldBeInitiallyVisible)));

                if (!s.Visited.ContainsKey(e.Target))
                {
                    s.Visited[e.Target] = new List <TreeNode>();
                }
                s.Visited[e.Target].Add(node);

                if (eagerExpansion)
                {
                    expandChildren();
                }
                else
                {
                    node.Nodes.Add("dummy");
                    ((Tag)node.Tag).DeferredExpand = expandChildren;
                }
            }

            // this should be in a "finally" block
            s.Depth--;

            return(node);
        }