Esempio n. 1
0
        /// <summary>
        /// Cotinues traversing using specified segment in given index container.
        /// </summary>
        /// <param name="segment">The segment.</param>
        /// <param name="container">The container.</param>
        /// <param name="isMust">if set to <c>true</c> [is must].</param>
        private void processSegment(PathSegment segment, IReadonlyIndexContainer container, bool isMust = true)
        {
            if (segment.IsAny)
            {
                mayIndexesProcess.Add(container.UnknownIndex);
                addToMay(container.UnknownIndex);

                foreach (var index in container.Indexes)
                {
                    addToMay(index.Value);
                }
            }
            else if (segment.IsUnknown)
            {
                addToMay(container.UnknownIndex);
            }
            else if (segment.Names.Count == 1)
            {
                MemoryIndex processIndex;
                if (!container.TryGetIndex(segment.Names[0], out processIndex) && !snapshot.Structure.Locked)
                {
                    creatorVisitor.Name   = segment.Names[0];
                    creatorVisitor.IsMust = isMust;
                    segment.Accept(creatorVisitor);
                    processIndex = creatorVisitor.CreatedIndex;
                }

                if (processIndex != null)
                {
                    if (isMust)
                    {
                        addToMust(processIndex);
                    }
                    else
                    {
                        addToMay(processIndex);
                    }
                }
            }
            else
            {
                creatorVisitor.IsMust = false;

                foreach (String name in segment.Names)
                {
                    MemoryIndex processIndex;
                    if (!container.TryGetIndex(name, out processIndex) && !snapshot.Structure.Locked)
                    {
                        creatorVisitor.Name = name;
                        segment.Accept(creatorVisitor);
                        processIndex = creatorVisitor.CreatedIndex;
                    }

                    if (processIndex != null)
                    {
                        addToMay(processIndex);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates merge operations for all indexes in the target collection. Source indexes for the operation are
        /// retreived from the source collections. When there is missing index in some collection the operation set
        /// to undefined.
        ///
        /// This method is for both phases of analysis.
        /// </summary>
        public void MergeContainers()
        {
            // Process all names which has unassociated index and creates one
            foreach (string indexName in undefinedIndexes)
            {
                writeableTargetContainer.AddIndex(indexName, targetIndex.CreateIndex(indexName));
            }

            foreach (var index in targetContainer.Indexes)
            {
                MergeOperation operation = new MergeOperation(index.Value);
                worker.addOperation(operation);

                if (isUndefined)
                {
                    operation.SetUndefined();
                }

                foreach (var source in sources)
                {
                    IReadonlyIndexContainer container = source.Item1;
                    Snapshot snapshot = source.Item2;

                    MemoryIndex containerIndex;
                    if (container.TryGetIndex(index.Key, out containerIndex))
                    {
                        operation.Add(containerIndex, snapshot);
                    }
                    else
                    {
                        operation.Add(container.UnknownIndex, snapshot);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Stores given collection as the source of indexes and adds its unknown index into unknown operation.
        /// Also gets all indexes from the source collection and inserts it into target collection.
        ///
        /// This method is for the first phase of anaysis.
        /// </summary>
        /// <param name="sourceSnapshot">The source snapshot.</param>
        /// <param name="sourceIndex">Index of the source.</param>
        /// <param name="sourceContainer">The source container.</param>
        public void CollectIndexes(
            Snapshot sourceSnapshot,
            MemoryIndex sourceIndex,
            IReadonlyIndexContainer sourceContainer)
        {
            sources.Add(new Tuple <IReadonlyIndexContainer, Snapshot>(sourceContainer, sourceSnapshot));

            unknownOperation.Add(sourceContainer.UnknownIndex, sourceSnapshot);

            bool indexEquals = targetIndex.Equals(sourceIndex);

            foreach (var index in sourceContainer.Indexes)
            {
                MemoryIndex containerIndex;
                if (targetContainer.TryGetIndex(index.Key, out containerIndex))
                {
                    if (containerIndex == null && indexEquals)
                    {
                        writeableTargetContainer.AddIndex(index.Key, index.Value);
                        undefinedIndexes.Remove(index.Key);
                    }
                }
                else if (indexEquals)
                {
                    writeableTargetContainer.AddIndex(index.Key, index.Value);
                }
                else
                {
                    writeableTargetContainer.AddIndex(index.Key, null);
                    undefinedIndexes.Add(index.Key);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Enqueues the merge operation.
        /// </summary>
        /// <param name="childName">Name of the child.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="targetContainerContext">The target container context.</param>
        /// <param name="childTreeNode">The child tree node.</param>
        /// <param name="alwaysDefined">if set to <c>true</c> [always defined].</param>
        private void enqueueMergeOperation(string childName, MergeOperation operation, ITargetContainerContext targetContainerContext, MemoryIndexTreeNode childTreeNode, bool alwaysDefined)
        {
            IReadonlyIndexContainer targetContainer = targetContainerContext.getSourceContainer();
            MemoryIndex             targetIndex;

            // Use index from target collection or crete and add it to the target collection
            if (!targetContainer.TryGetIndex(childName, out targetIndex))
            {
                targetIndex = createNewTargetIndex(targetContainerContext, childName);

                if (targetIndex == null)
                {
                    return;
                }
            }

            // Set parameters and add it to collection
            operation.TreeNode = childTreeNode;
            operation.SetTargetIndex(targetIndex);

            if (!alwaysDefined)
            {
                operation.SetUndefined();
            }

            operationQueue.AddLast(operation);
        }
Esempio n. 5
0
        /// <summary>
        /// Enqueues the delete operation.
        /// </summary>
        /// <param name="childName">Name of the child.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="targetContainerContext">The target container context.</param>
        /// <param name="childTreeNode">The child tree node.</param>
        private void enqueueDeleteOperation(string childName, MergeOperation operation, ITargetContainerContext targetContainerContext, MemoryIndexTreeNode childTreeNode)
        {
            IReadonlyIndexContainer targetContainer = targetContainerContext.getSourceContainer();
            MemoryIndex             targetIndex;

            if (targetContainer.TryGetIndex(childName, out targetIndex))
            {
                // Enque delete operation only if target index exists in paret snapshot
                operation.TreeNode = childTreeNode;
                operation.SetTargetIndex(targetIndex);
                operation.SetDeleteOperation();
                operationQueue.AddLast(operation);

                // Delete child from parent container
                targetContainerContext.getWriteableSourceContainer().RemoveIndex(childName);
            }
        }
Esempio n. 6
0
        private void collectMemoryIndexNode(string name, CollectorNode node,
                                            IReadonlyIndexContainer indexContainer, bool isMust)
        {
            if (testAndProcessReturnedNode(name, node, isMust))
            {
                LocationCollectorNode nextNode;
                MemoryIndex           memoryIndex;
                if (indexContainer.TryGetIndex(name, out memoryIndex))
                {
                    nextNode = node.CreateMemoryIndexChild(name, memoryIndex);
                }
                else
                {
                    nextNode = node.CreateMemoryIndexChildFromAny(name, indexContainer.UnknownIndex);
                }

                nextNode.IsMust = isMust;
                AddNode(nextNode);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Cotinues traversing using specified segment in given index container.
        /// </summary>
        /// <param name="segment">The segment.</param>
        /// <param name="container">The container.</param>
        private void process(PathSegment segment, IReadonlyIndexContainer container)
        {
            if (segment.IsAny)
            {
                mustIndexesProcess.Add(container.UnknownIndex);
                foreach (var index in container.Indexes)
                {
                    mustIndexesProcess.Add(index.Value);
                }
            }
            else if (segment.IsUnknown)
            {
                mustIndexesProcess.Add(container.UnknownIndex);
            }
            else
            {
                bool isUnknown = false;
                foreach (String name in segment.Names)
                {
                    MemoryIndex index;
                    if (container.TryGetIndex(name, out index))
                    {
                        mustIndexesProcess.Add(index);
                    }
                    else
                    {
                        isUnknown = true;
                    }
                }

                if (isUnknown)
                {
                    IsDefined = false;
                    mustIndexesProcess.Add(container.UnknownIndex);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates the and enqueue operations.
        /// </summary>
        /// <param name="targetContainerContext">The target container context.</param>
        /// <param name="treeNode">The tree node.</param>
        /// <param name="sourceContainers">The source containers.</param>
        /// <param name="alwaysDefined">if set to <c>true</c> [always defined].</param>
        private void createAndEnqueueOperations(
            ITargetContainerContext targetContainerContext,
            MemoryIndexTreeNode treeNode,
            List <ContainerContext> sourceContainers,
            bool alwaysDefined)
        {
            IReadonlyIndexContainer targetContainer = targetContainerContext.getSourceContainer();

            // Creates and enques merge operations for all child nodes of given node
            foreach (var childNode in treeNode.ChildNodes)
            {
                string childName = childNode.Key;
                MemoryIndexTreeNode childTreeNode = childNode.Value;

                MergeOperation operation      = new MergeOperation();
                bool           isChildDefined = collectIndexes(childName, sourceContainers, operation);

                if (isChildDefined)
                {
                    // Child is defined at least in one collection - enqueue merge operation

                    MemoryIndex targetIndex;
                    // Use index from target collection or crete and add it to the target collection
                    if (!targetContainer.TryGetIndex(childName, out targetIndex))
                    {
                        targetIndex = createNewTargetIndex(targetContainerContext, childName);

                        if (targetIndex == null)
                        {
                            continue;
                        }
                    }

                    // Set parameters and add it to collection
                    operation.TreeNode = childTreeNode;
                    operation.SetTargetIndex(targetIndex);

                    if (!alwaysDefined)
                    {
                        operation.SetUndefined();
                    }

                    operationQueue.AddLast(operation);
                }
                else
                {
                    // Child is not defined - enqueue delete operation

                    MemoryIndex targetIndex;
                    if (targetContainer.TryGetIndex(childName, out targetIndex))
                    {
                        // Enque delete operation only if target index exists in paret snapshot
                        operation.TreeNode = childTreeNode;
                        operation.SetTargetIndex(targetIndex);
                        operation.SetDeleteOperation();
                        operationQueue.AddLast(operation);

                        deleteChild(targetContainerContext, childName);
                    }
                }
            }

            // Enqueue merge operation for unknown index if is defined
            if (treeNode.AnyChild != null)
            {
                MergeOperation unknownOperation = new MergeOperation();

                foreach (ContainerContext containerContext in sourceContainers)
                {
                    unknownOperation.Add(new MergeOperationContext(
                                             containerContext.IndexContainer.UnknownIndex, containerContext.SnapshotContext));
                }

                unknownOperation.TreeNode = treeNode.AnyChild;
                unknownOperation.SetTargetIndex(targetContainer.UnknownIndex);
                unknownOperation.SetUndefined();

                operationQueue.AddLast(unknownOperation);
            }
        }