示例#1
0
 private void InitExprDeclaredCacheCollection()
 {
     if (_exprDeclCacheCollection == null)
     {
         _exprDeclCacheCollection = new IdentityDictionary <Object, compat.WeakReference <ExpressionResultCacheEntry <EventBean[], ICollection <EventBean> > > >();
     }
 }
示例#2
0
 private void InitEnumMethodCache()
 {
     if (_enumMethodCache == null)
     {
         _enumMethodCache = new IdentityDictionary <Object, compat.WeakReference <ExpressionResultCacheEntry <long[], Object> > >();
     }
 }
示例#3
0
        public virtual IRevertChangesSavepoint CreateSavepoint(Object source)
        {
            if (source == null)
            {
                return(null);
            }
            List <Object>  objList = new List <Object>();
            List <IObjRef> objRefs = new List <IObjRef>();

            FindAllObjectsToBackup(source, objList, objRefs, new IdentityHashSet <Object>());

            IDictionary <Object, RevertChangesSavepoint.IBackup> originalToValueBackup = new IdentityDictionary <Object, RevertChangesSavepoint.IBackup>();

            // Iterate manually through the list because the list itself should not be 'backuped'
            for (int a = objList.Count; a-- > 0;)
            {
                BackupObjects(objList[a], originalToValueBackup);
            }
            WeakDictionary <Object, RevertChangesSavepoint.IBackup> weakObjectsToBackup = new WeakDictionary <Object, RevertChangesSavepoint.IBackup>(new IdentityEqualityComparer <Object>());

            DictionaryExtension.Loop(originalToValueBackup, delegate(Object obj, RevertChangesSavepoint.IBackup backup)
            {
                if (backup != null)
                {
                    weakObjectsToBackup.Add(obj, backup);
                }
            });

            return(BeanContext.RegisterBean <RevertChangesSavepoint>().PropertyValue("Changes", weakObjectsToBackup).Finish());
        }
示例#4
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="engineURI">The engine URI.</param>
 /// <param name="isReuseViews">indicator on whether stream and view resources are to be reused between statements</param>
 public StreamFactorySvcImpl(String engineURI, bool isReuseViews)
 {
     _engineURI = engineURI;
     _eventStreamsRefCounted = new RefCountedMap <FilterSpecCompiled, StreamEntry>();
     _eventStreamsIdentity   = new IdentityDictionary <Object, StreamEntry>();
     _isReuseViews           = isReuseViews;
 }
示例#5
0
        public static IDictionary<FilterSpecActivatable, FilterValueSetParam[][]> ComputeAddendumForStatement(
            ContextControllerStatementDesc statementDesc,
            ContextControllerFactory[] controllerFactories,
            object[] allPartitionKeys,
            AgentInstanceContext agentInstanceContextCreate)
        {
            IDictionary<int, FilterSpecActivatable> filters =
                statementDesc.Lightweight.StatementContext.FilterSpecActivatables;
            IDictionary<FilterSpecActivatable, FilterValueSetParam[][]> map =
                new IdentityDictionary<FilterSpecActivatable, FilterValueSetParam[][]>();
            foreach (var filter in filters) {
                var addendum = ComputeAddendum(
                    allPartitionKeys,
                    filter.Value,
                    true,
                    statementDesc,
                    controllerFactories,
                    agentInstanceContextCreate);
                if (addendum != null && addendum.Length > 0) {
                    map.Put(filter.Value, addendum);
                }
            }

            return map;
        }
示例#6
0
        /// <summary>Find elements matching selector.</summary>
        /// <param name="query">CSS selector</param>
        /// <param name="roots">root elements to descend into</param>
        /// <returns>matching elements, empty if none</returns>
        public static Elements Select(String query, IEnumerable <iText.StyledXmlParser.Jsoup.Nodes.Element> roots)
        {
            Validate.NotEmpty(query);
            Validate.NotNull(roots);
            Evaluator evaluator = QueryParser.Parse(query);
            List <iText.StyledXmlParser.Jsoup.Nodes.Element> elements = new List <iText.StyledXmlParser.Jsoup.Nodes.Element
                                                                                  >();
            IdentityDictionary <iText.StyledXmlParser.Jsoup.Nodes.Element, bool?> seenElements = new IdentityDictionary
                                                                                                 <iText.StyledXmlParser.Jsoup.Nodes.Element, bool?>();

            // dedupe elements by identity, not equality
            foreach (iText.StyledXmlParser.Jsoup.Nodes.Element root in roots)
            {
                Elements found = Select(evaluator, root);
                foreach (iText.StyledXmlParser.Jsoup.Nodes.Element el in found)
                {
                    if (!seenElements.ContainsKey(el))
                    {
                        elements.Add(el);
                        seenElements.Put(el, true);
                    }
                }
            }
            return(new Elements(elements));
        }
示例#7
0
        public static void LoopModifiable <TKey, TValue>(IDictionary <TKey, TValue> dictionary, BreakableKeyValueCallback <TKey, TValue> keyValueCallback)
        {
            if (dictionary == null || dictionary.Count == 0)
            {
                return;
            }
            Dictionary <TKey, TValue> cloneDict;

            if (dictionary is IdentityDictionary <TKey, TValue> )
            {
                cloneDict = new IdentityDictionary <TKey, TValue>(dictionary);
            }
            else
            {
                cloneDict = new Dictionary <TKey, TValue>(dictionary);
            }
            using (IEnumerator <KeyValuePair <TKey, TValue> > dictIter = cloneDict.GetEnumerator())
            {
                while (dictIter.MoveNext())
                {
                    KeyValuePair <TKey, TValue> entry = dictIter.Current;
                    if (!keyValueCallback.Invoke(entry.Key, entry.Value))
                    {
                        return;
                    }
                }
            }
        }
        /// <summary>
        ///     Ctor.
        /// </summary>
        /// <param name="rootStream">is the stream supplying the lookup event</param>
        /// <param name="rootStreamName">is the name of the stream supplying the lookup event</param>
        /// <param name="numStreams">is the number of streams</param>
        /// <param name="lookupInstructions">is a list of lookups to perform</param>
        /// <param name="requiredPerStream">indicates which streams are required and which are optional in the lookup</param>
        /// <param name="assemblyInstructionFactories">factories for assembly</param>
        public LookupInstructionExecNode(
            int rootStream,
            string rootStreamName,
            int numStreams,
            LookupInstructionExec[] lookupInstructions,
            bool[] requiredPerStream,
            BaseAssemblyNodeFactory[] assemblyInstructionFactories)
        {
            this._rootStream = rootStream;
            this._rootStreamName = rootStreamName;
            this._numStreams = numStreams;
            this._lookupInstructions = lookupInstructions;
            this._requiredPerStream = requiredPerStream;

            // We have a list of factories that are pointing to each other in a tree, i.e.:
            // F1 (=>F3), F2 (=>F3), F3
            IDictionary<BaseAssemblyNodeFactory, BaseAssemblyNode> nodes =
                new IdentityDictionary<BaseAssemblyNodeFactory, BaseAssemblyNode>();
            foreach (var factory in assemblyInstructionFactories) {
                var node = factory.MakeAssemblerUnassociated();
                nodes.Put(factory, node);
            }

            // re-associate each node after allocation
            foreach (var nodeWithFactory in nodes) {
                var parentFactory = nodeWithFactory.Key.ParentNode;
                if (parentFactory != null) {
                    var parent = nodes.Get(parentFactory);
                    nodeWithFactory.Value.ParentAssembler = parent;
                }

                foreach (var childNodeFactory in nodeWithFactory.Key.ChildNodes) {
                    var child = nodes.Get(childNodeFactory);
                    nodeWithFactory.Value.AddChild(child);
                }
            }

            _assemblyInstructions = new BaseAssemblyNode[assemblyInstructionFactories.Length];
            for (var i = 0; i < assemblyInstructionFactories.Length; i++) {
                _assemblyInstructions[i] = nodes.Get(assemblyInstructionFactories[i]);
            }

            _myResultAssembler = new MyResultAssembler(rootStream);
            _assemblyInstructions[_assemblyInstructions.Length - 1].ParentAssembler = _myResultAssembler;

            // Determine up to which instruction we are dealing with optional results.
            // When dealing with optional results we don't do fast exists if we find no lookup results
            _requireResultsInstruction = 1; // we always require results from the very first lookup
            for (var i = 1; i < lookupInstructions.Length; i++) {
                var fromStream = lookupInstructions[i].FromStream;
                if (requiredPerStream[fromStream]) {
                    _requireResultsInstruction =
                        i + 1; // require results as long as the from-stream is a required stream
                }
                else {
                    break;
                }
            }
        }
示例#9
0
 private AuxiliaryTree(Tree tree, Tree foot, Dictionary<string, Tree> namesToNodes, string originalTreeString)
 {
     this.originalTreeString = originalTreeString;
     this.Tree = tree;
     this.Foot = foot;
     this.pnamesToNodes = namesToNodes;
     nodesToNames = null;
 }
 public override TregexMatcher Matcher(Tree root, Tree tree,
                                       IdentityDictionary <Tree, Tree> nodesToParents,
                                       Dictionary <string, Tree> namesToNodes,
                                       VariableStrings variableStrings,
                                       IHeadFinder headFinder)
 {
     return(new CoordinationMatcher(this, root, tree, nodesToParents, namesToNodes, variableStrings, headFinder));
 }
示例#11
0
 public override TregexMatcher Matcher(Tree root, Tree tree,
     IdentityDictionary<Tree, Tree> nodesToParents,
     Dictionary<string, Tree> namesToNodes,
     VariableStrings variableStrings,
     IHeadFinder headFinder)
 {
     return new CoordinationMatcher(this, root, tree, nodesToParents, namesToNodes, variableStrings, headFinder);
 }
示例#12
0
 private AuxiliaryTree(Tree tree, Tree foot, Dictionary <string, Tree> namesToNodes, string originalTreeString)
 {
     this.originalTreeString = originalTreeString;
     this.Tree          = tree;
     this.Foot          = foot;
     this.pnamesToNodes = namesToNodes;
     nodesToNames       = null;
 }
示例#13
0
 public TregexMatcher(Tree root, Tree tree, IdentityDictionary<Tree, Tree> nodesToParents,
     Dictionary<string, Tree> namesToNodes, VariableStrings variableStrings, IHeadFinder headFinder)
 {
     this.root = root;
     this.tree = tree;
     this.nodesToParents = nodesToParents;
     this.namesToNodes = namesToNodes;
     this.variableStrings = variableStrings;
     this.headFinder = headFinder;
 }
示例#14
0
 public TregexMatcher(Tree root, Tree tree, IdentityDictionary <Tree, Tree> nodesToParents,
                      Dictionary <string, Tree> namesToNodes, VariableStrings variableStrings, IHeadFinder headFinder)
 {
     this.root            = root;
     this.tree            = tree;
     this.nodesToParents  = nodesToParents;
     this.namesToNodes    = namesToNodes;
     this.variableStrings = variableStrings;
     this.headFinder      = headFinder;
 }
示例#15
0
 public DescriptionMatcher(DescriptionPattern n, Tree root, Tree tree,
                           IdentityDictionary <Tree, Tree> nodesToParents,
                           Dictionary <string, Tree> namesToNodes,
                           VariableStrings variableStrings,
                           IHeadFinder headFinder) :
     base(root, tree, nodesToParents, namesToNodes, variableStrings, headFinder)
 {
     myNode = n;
     // no need to reset anything - everything starts out as null or false.
     // lazy initialization of children to save time.
     // resetChildIter();
 }
示例#16
0
 public AuxiliaryTree(Tree tree, bool mustHaveFoot)
 {
     originalTreeString = tree.ToString();
     this.Tree          = tree;
     this.Foot          = FindFootNode(tree);
     if (Foot == null && mustHaveFoot)
     {
         throw new TsurgeonParseException("Error -- no foot node found for " + originalTreeString);
     }
     pnamesToNodes = new Dictionary <string, Tree>();
     nodesToNames  = new IdentityDictionary <Tree, string>();
     InitializeNamesNodesMaps(tree);
 }
示例#17
0
 public AuxiliaryTree(Tree tree, bool mustHaveFoot)
 {
     originalTreeString = tree.ToString();
     this.Tree = tree;
     this.Foot = FindFootNode(tree);
     if (Foot == null && mustHaveFoot)
     {
         throw new TsurgeonParseException("Error -- no foot node found for " + originalTreeString);
     }
     pnamesToNodes = new Dictionary<string, Tree>();
     nodesToNames = new IdentityDictionary<Tree, string>();
     InitializeNamesNodesMaps(tree);
 }
	    private void  InitBlock()
	    {
	        sizes = new IdentityDictionary<Type, int>()
	                    {
	                        {typeof (bool), 1},
	                        {typeof (byte), 1},
                            {typeof(sbyte), 1},
	                        {typeof (char), 2},
	                        {typeof (short), 2},
	                        {typeof (int), 4},
	                        {typeof (float), 4},
	                        {typeof (double), 8},
	                        {typeof (long), 8}
	                    };
	    }
示例#19
0
        private AgentInstanceFilterProxy GetMergedFilterAddendums(
            ContextControllerStatementDesc statement,
            ContextController originator,
            Object partitionKey,
            int contextId)
        {
            var result = new IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]>();

            originator.Factory.PopulateFilterAddendums(result, statement, partitionKey, contextId);
            var originatorEntry = _subcontexts.Get(originator);

            if (originatorEntry != null)
            {
                RecursivePopulateFilterAddendum(statement, originatorEntry, contextId, result);
            }
            return(new AgentInstanceFilterProxyImpl(result));
        }
            // do all con/dis-juncts have to be considered to determine a match?
            // i.e. true if conj and not negated or disj and negated

            public CoordinationMatcher(CoordinationPattern n, Tree root, Tree tree,
                                       IdentityDictionary <Tree, Tree> nodesToParents,
                                       Dictionary <string, Tree> namesToNodes,
                                       VariableStrings variableStrings,
                                       IHeadFinder headFinder) :
                base(root, tree, nodesToParents, namesToNodes, variableStrings, headFinder)
            {
                myNode   = n;
                children = new TregexMatcher[myNode.children.Count];
                // lazy initialize the children... don't set children[i] yet

                //for (int i = 0; i < children.length; i++) {
                //  TregexPattern node = myNode.children.get(i);
                //  children[i] = node.matcher(root, tree, nodesToParents,
                //                             namesToNodes, variableStrings);
                //}
                currChild   = 0;
                considerAll = myNode.isConj ^ myNode.IsNegated();
            }
示例#21
0
        public Tree GetParent(Tree node)
        {
            if (node is IHasParent)
            {
                return(node.Parent());
            }
            if (nodesToParents == null)
            {
                nodesToParents = new IdentityDictionary <Tree, Tree>();
            }
            if (nodesToParents.Count == 0)
            {
                FillNodesToParents(root, null);
            }
            Tree parent;

            nodesToParents.TryGetValue(node, out parent);
            return(parent);
        }
示例#22
0
        private AgentInstance StartStatement(int contextId, ContextControllerStatementDesc statementDesc, ContextController originator, Object partitionKey, IDictionary <String, Object> contextProperties, bool isRecoveringResilient)
        {
            // build filters
            var filterAddendum = new IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]>();

            originator.Factory.PopulateFilterAddendums(filterAddendum, statementDesc, partitionKey, contextId);
            AgentInstanceFilterProxy proxy = new AgentInstanceFilterProxyImpl(filterAddendum);

            // build built-in context properties
            contextProperties.Put(ContextPropertyEventType.PROP_CTX_NAME, _contextName);
            contextProperties.Put(ContextPropertyEventType.PROP_CTX_ID, contextId);
            var contextBean = (MappedEventBean)_servicesContext.EventAdapterService.AdapterForTypedMap(contextProperties, _contextDescriptor.ContextPropertyRegistry.ContextEventType);

            // activate
            var result = StatementAgentInstanceUtil.Start(_servicesContext, statementDesc.Statement, false, contextId, contextBean, proxy, isRecoveringResilient);

            // save only instance data
            return(new AgentInstance(result.StopCallback, result.AgentInstanceContext, result.FinalView));
        }
示例#23
0
        protected IDictionary <ICacheRetriever, IList <IObjRelation> > AssignObjRelsToCacheRetriever(IDictionary <Type, IList <IObjRelation> > sortedIObjRefs)
        {
            IDictionary <ICacheRetriever, IList <IObjRelation> > serviceToAssignedObjRefsDict = new IdentityDictionary <ICacheRetriever, IList <IObjRelation> >();

            DictionaryExtension.Loop(sortedIObjRefs, delegate(Type type, IList <IObjRelation> objRefs)
            {
                ICacheRetriever cacheRetriever       = GetRetrieverForType(type);
                IList <IObjRelation> assignedObjRefs = DictionaryExtension.ValueOrDefault(serviceToAssignedObjRefsDict, cacheRetriever);
                if (assignedObjRefs == null)
                {
                    assignedObjRefs = new List <IObjRelation>();
                    serviceToAssignedObjRefsDict.Add(cacheRetriever, assignedObjRefs);
                }
                foreach (IObjRelation objRef in objRefs)
                {
                    assignedObjRefs.Add(objRef);
                }
            });
            return(serviceToAssignedObjRefsDict);
        }
示例#24
0
        private void RecursivePopulateFilterAddendum(
            ContextControllerStatementDesc statement,
            ContextControllerTreeEntry originatorEntry,
            int contextId,
            IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]> result)
        {
            if (originatorEntry.Parent == null)
            {
                return;
            }
            originatorEntry.Parent.Factory.PopulateFilterAddendums(
                result, statement, originatorEntry.InitPartitionKey, contextId);

            var parentEntry = _subcontexts.Get(originatorEntry.Parent);

            if (parentEntry != null)
            {
                RecursivePopulateFilterAddendum(statement, parentEntry, contextId, result);
            }
        }
示例#25
0
        /// <summary>
        /// Gets called by the ObjectCopierState on custom / default behavior switches
        /// </summary>
        internal T CloneRecursive <T>(T source, ObjectCopierState ocState)
        {
            // Don't clone a null object or immutable objects. Return the identical reference in these cases
            if (source == null || ImmutableTypeSet.IsImmutableType(source.GetType()))
            {
                return(source);
            }
            Type objType = source.GetType();
            IdentityDictionary <Object, Object> objectToCloneDict = ocState.objectToCloneDict;
            Object clone = DictionaryExtension.ValueOrDefault(ocState.objectToCloneDict, source);

            if (clone != null)
            {
                // Object has already been cloned. Cycle detected - we are finished here
                return((T)clone);
            }
            if (objType.IsArray)
            {
                return((T)CloneArray(source, ocState));
            }
            if (source is IEnumerable && !(source is String))
            {
                return((T)CloneCollection(source, ocState));
            }
            // Check whether the object will be copied by custom behavior
            IObjectCopierExtension extension = extensions.GetExtension(objType);

            if (extension != null)
            {
                clone = extension.DeepClone(source, ocState);
                objectToCloneDict.Add(source, clone);
                return((T)clone);
            }
            // Copy by default behavior
            return((T)CloneDefault(source, ocState));
        }
示例#26
0
 public abstract TregexMatcher Matcher(Tree root, Tree tree,
     IdentityDictionary<Tree, Tree> nodesToParents,
     Dictionary<string, Tree> namesToNodes,
     VariableStrings variableStrings,
     IHeadFinder headFinder);
示例#27
0
 public ContextInternalFilterAddendum()
 {
     _filterAddendum = new IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]>();
 }
示例#28
0
 public DescriptionMatcher(DescriptionPattern n, Tree root, Tree tree,
     IdentityDictionary<Tree, Tree> nodesToParents,
     Dictionary<string, Tree> namesToNodes,
     VariableStrings variableStrings,
     IHeadFinder headFinder) :
         base(root, tree, nodesToParents, namesToNodes, variableStrings, headFinder)
 {
     myNode = n;
     // no need to reset anything - everything starts out as null or false.  
     // lazy initialization of children to save time.
     // resetChildIter();
 }
示例#29
0
            // do all con/dis-juncts have to be considered to determine a match?
            // i.e. true if conj and not negated or disj and negated

            public CoordinationMatcher(CoordinationPattern n, Tree root, Tree tree,
                IdentityDictionary<Tree, Tree> nodesToParents,
                Dictionary<string, Tree> namesToNodes,
                VariableStrings variableStrings,
                IHeadFinder headFinder) :
                    base(root, tree, nodesToParents, namesToNodes, variableStrings, headFinder)
            {
                myNode = n;
                children = new TregexMatcher[myNode.children.Count];
                // lazy initialize the children... don't set children[i] yet

                //for (int i = 0; i < children.length; i++) {
                //  TregexPattern node = myNode.children.get(i);
                //  children[i] = node.matcher(root, tree, nodesToParents,
                //                             namesToNodes, variableStrings);
                //}
                currChild = 0;
                considerAll = myNode.isConj ^ myNode.IsNegated();
            }
示例#30
0
 public abstract TregexMatcher Matcher(Tree root, Tree tree,
                                       IdentityDictionary <Tree, Tree> nodesToParents,
                                       Dictionary <string, Tree> namesToNodes,
                                       VariableStrings variableStrings,
                                       IHeadFinder headFinder);
示例#31
0
 public AgentInstanceFilterProxyImpl(IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums)
 {
     _addendumMap = addendums;
 }
        public virtual void DataChanged(IDataChange dataChange, DateTime dispatchTime, long sequenceId)
        {
            dataChange = dataChange.Derive(InterestedEntityTypes);
            if (dataChange.IsEmpty)
            {
                return;
            }
            ISet <Object> directObjectsToDelete = null;

            ISet <Type> requestedTypes = new HashSet <Type>();
            IDictionary <Type, IEntityMetaData> typeToMetaDataDict = new Dictionary <Type, IEntityMetaData>();

            GuiThreadHelper.InvokeInGuiAndWait(delegate()
            {
                IList <T> entities = Model.Objects;

                for (int i = entities.Count; i-- > 0;)
                {
                    Object entity = entities[i];

                    requestedTypes.Add(entity.GetType());
                }
            });

            IList <IDataChangeEntry> dataChangeEntries = dataChange.Inserts;

            for (int a = dataChangeEntries.Count; a-- > 0;)
            {
                requestedTypes.Add(dataChangeEntries[a].EntityType);
            }
            dataChangeEntries = dataChange.Updates;
            for (int a = dataChangeEntries.Count; a-- > 0;)
            {
                requestedTypes.Add(dataChangeEntries[a].EntityType);
            }
            dataChangeEntries = dataChange.Deletes;
            for (int a = dataChangeEntries.Count; a-- > 0;)
            {
                requestedTypes.Add(dataChangeEntries[a].EntityType);
            }

            IList <IEntityMetaData> metaDatas = EntityMetaDataProvider.GetMetaData(ListUtil.ToList(requestedTypes));

            foreach (IEntityMetaData metaData in metaDatas)
            {
                typeToMetaDataDict[metaData.EntityType] = metaData;
            }

            bool consistsOnlyOfDirectDeletes = false;

            if (dataChange.Deletes.Count > 0)
            {
                consistsOnlyOfDirectDeletes = true;
                foreach (IDataChangeEntry deleteEntry in dataChange.Deletes)
                {
                    if (deleteEntry is DirectDataChangeEntry)
                    {
                        if (directObjectsToDelete == null)
                        {
                            directObjectsToDelete = new IdentityHashSet <Object>();
                        }
                        directObjectsToDelete.Add(((DirectDataChangeEntry)deleteEntry).Entry);
                    }
                    else
                    {
                        consistsOnlyOfDirectDeletes = false;
                    }
                }
            }

            IList <T> interestingEntities = null;

            Object[]                contextInformation = GetContextInformation();
            IFilterDescriptor       filterDescriptor   = GetFilterDescriptor();
            IList <ISortDescriptor> sortDescriptors    = GetSortDescriptors();
            IPagingRequest          pagingRequest      = GetPagingRequest();

            IPagingResponse         pagingResponse  = null;
            List <IDataChangeEntry> modifiedEntries = new List <IDataChangeEntry>();

            modifiedEntries.AddRange(dataChange.All);

            if (!consistsOnlyOfDirectDeletes)
            {
                interestingEntities = CacheContext.ExecuteWithCache(CacheProvider.GetCurrentCache(), delegate()
                {
                    ConfigureCacheWithEagerLoads(Cache);
                    if (Refresher is IPagingRefresher <T> )
                    {
                        interestingEntities = new List <T>();
                        pagingResponse      = ((IPagingRefresher <T>)Refresher).Refresh(modifiedEntries, filterDescriptor, sortDescriptors, pagingRequest, contextInformation);
                        foreach (Object obj in pagingResponse.Result)
                        {
                            interestingEntities.Add((T)obj);
                        }
                        return(interestingEntities);
                    }
                    else
                    {
                        if (filterDescriptor != null || sortDescriptors != null)
                        {
                            contextInformation    = new Object[2];
                            contextInformation[0] = filterDescriptor;
                            contextInformation[1] = sortDescriptors;
                        }

                        return(((IRefresher <T>)Refresher).Refresh(modifiedEntries, contextInformation));
                    }
                });
            }
            GuiThreadHelper.InvokeInGuiAndWait(delegate()
            {
                IList <T> entities = Model.Objects;

                ISet <T> entitiesToAdd                           = null;
                ISet <T> entitiesToRemove                        = null;
                IDictionary <T, T> entitiesToReplace             = null;
                IDictionary <IObjRef, T> oldObjRefToOldEntityMap = null;
                bool mergeModel = false;

                if (interestingEntities != null && interestingEntities.Count > 0)
                {
                    entitiesToAdd           = new IdentityHashSet <T>(interestingEntities);
                    entitiesToRemove        = new IdentityHashSet <T>(entities);
                    entitiesToReplace       = new IdentityDictionary <T, T>();
                    oldObjRefToOldEntityMap = new Dictionary <IObjRef, T>();
                    mergeModel = true;
                }
                for (int i = entities.Count; i-- > 0;)
                {
                    T oldEntity = entities[i];
                    if (directObjectsToDelete != null && directObjectsToDelete.Contains(oldEntity))
                    {
                        if (entitiesToRemove != null)
                        {
                            entitiesToRemove.Remove(oldEntity);
                        }
                        Model.RemoveAt(i);
                        continue;
                    }
                    Type oldEntityType       = ProxyHelper.GetRealType(oldEntity.GetType());
                    PrimitiveMember idMember = typeToMetaDataDict[oldEntityType].IdMember;
                    Object oldEntityId       = idMember.GetValue(oldEntity, false);
                    if (oldEntityId == null)
                    {
                        if (entitiesToRemove != null)
                        {
                            entitiesToRemove.Remove(oldEntity);
                        }
                        // Unpersisted object. This object should not be removed
                        // only because of a background DCE
                        continue;
                    }
                    bool entryRemoved = false;
                    foreach (IDataChangeEntry deleteEntry in dataChange.Deletes)
                    {
                        if (deleteEntry is DirectDataChangeEntry)
                        {
                            continue;
                        }
                        Object id = deleteEntry.Id;
                        if (!EqualsItems(oldEntityType, oldEntityId, deleteEntry.EntityType, id))
                        {
                            continue;
                        }
                        if (entitiesToRemove != null)
                        {
                            entitiesToRemove.Remove(oldEntity);
                        }
                        Model.RemoveAt(i);
                        entryRemoved = true;
                        break;
                    }
                    if (entryRemoved)
                    {
                        continue;
                    }
                    if (mergeModel)
                    {
                        IObjRef oldObjRef   = new ObjRef(oldEntityType, ObjRef.PRIMARY_KEY_INDEX, oldEntityId, null);
                        T existingOldEntity = DictionaryExtension.ValueOrDefault(oldObjRefToOldEntityMap, oldObjRef);
                        if (existingOldEntity == null)
                        {
                            oldObjRefToOldEntityMap.Add(oldObjRef, oldEntity);
                        }
                        else if (!Object.ReferenceEquals(existingOldEntity, oldEntity))
                        {
                            // Force duplicate key exception
                            oldObjRefToOldEntityMap.Add(oldObjRef, oldEntity);
                        }
                    }
                }
                if (oldObjRefToOldEntityMap != null && oldObjRefToOldEntityMap.Count > 0)
                {
                    IDictionary <IObjRef, T> newObjRefToNewEntityMap = new Dictionary <IObjRef, T>();
                    for (int a = interestingEntities.Count; a-- > 0;)
                    {
                        T newEntity              = interestingEntities[a];
                        Type newEntityType       = ProxyHelper.GetRealType(newEntity.GetType());
                        PrimitiveMember idMember = typeToMetaDataDict[newEntityType].IdMember;
                        Object newEntityId       = idMember.GetValue(newEntity, false);

                        IObjRef newObjRef = new ObjRef(newEntityType, ObjRef.PRIMARY_KEY_INDEX, newEntityId, null);
                        newObjRefToNewEntityMap.Add(newObjRef, newEntity);
                    }
                    DictionaryExtension.Loop(oldObjRefToOldEntityMap, delegate(IObjRef objRef, T oldEntity)
                    {
                        T newEntity = DictionaryExtension.ValueOrDefault(newObjRefToNewEntityMap, objRef);
                        if (newEntity == null)
                        {
                            // Nothing to do if current oldEntity has no corresponding newEntity
                            return;
                        }
                        entitiesToAdd.Remove(newEntity);
                        if (!Object.ReferenceEquals(oldEntity, newEntity) &&
                            (dataChange.IsLocalSource || !(oldEntity is IDataObject) || !((IDataObject)oldEntity).ToBeUpdated))
                        {
                            entitiesToReplace[oldEntity] = newEntity;
                        }
                        entitiesToRemove.Remove(oldEntity);
                    });
                }

                if (mergeModel)
                {
                    for (int a = entities.Count; a-- > 0;)
                    {
                        T item = entities[a];
                        if (entitiesToRemove.Contains(item))
                        {
                            Model.RemoveAt(a);
                            continue;
                        }
                        T replacingItem = DictionaryExtension.ValueOrDefault(entitiesToReplace, item);
                        if (replacingItem != null)
                        {
                            Model.Replace(a, replacingItem);
                            continue;
                        }
                    }
                    IEnumerator <T> enumerator = entitiesToAdd.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        T entityToAdd = enumerator.Current;
                        Model.Add(entityToAdd);
                    }

                    if (hasPagedViewModel)
                    {
                        UpdatePagingInformation(pagingResponse);
                    }
                    UpdateAfterDCE();
                }
            });
        }
示例#33
0
 internal static Type GetMessageType(Command command, SubCommand subcommand)
 {
     return(IdentityDictionary.GetValue(command, subcommand));
 }
示例#34
0
 public Tree GetParent(Tree node)
 {
     if (node is IHasParent)
     {
         return node.Parent();
     }
     if (nodesToParents == null)
     {
         nodesToParents = new IdentityDictionary<Tree, Tree>();
     }
     if (nodesToParents.Count == 0)
     {
         FillNodesToParents(root, null);
     }
     Tree parent;
     nodesToParents.TryGetValue(node, out parent);
     return parent;
 }