Ejemplo n.º 1
0
        private void SearchAndLink(ParentChildRelation relation, SearchSpec searchSpec)
        {
            var sourceComponent = _sourceWorkspaceSession.GetChildComponent(relation);
            var components      = _searcher.Search(searchSpec).Result;

            if (components == null || !components.Any())
            {
                return;
            }

            var refType = _sourceWorkspaceSession.GetReferenceTypeForName(_ardoqReferenceName);

            var existingReferences = _sourceWorkspaceSession.GetAllSourceReferencesFromChild(relation)
                                     .Where(r => r.Type == refType)
                                     .ToList();

            foreach (var targetComponent in components)
            {
                if (existingReferences.Any(r => r.Target == targetComponent.Id))
                {
                    continue;
                }

                _sourceWorkspaceSession.AddReference(refType, sourceComponent, targetComponent);
            }
        }
        public void Link(
            ParentChildRelation relation,
            IEnumerable <string> tags,
            IBuiltComponentMapping mapping,
            string ardoqReferenceName,
            string searchFolder = null)
        {
            var component = _session.GetChildComponent(relation);

            List <global::Ardoq.Models.Tag> allTags = _reader.GetAllTagsInFolder(searchFolder).Result;
            var componentDict = new Dictionary <string, List <global::Ardoq.Models.Tag> >();

            foreach (var tag in allTags)
            {
                foreach (var compId in tag.Components)
                {
                    if (!componentDict.ContainsKey(compId))
                    {
                        componentDict[compId] = new List <global::Ardoq.Models.Tag>();
                    }
                    componentDict[compId].Add(tag);
                }
            }

            var componentIds = componentDict.Select(pair => pair.Key);

            foreach (var tag in tags)
            {
                var compsMatchingTag = componentDict
                                       .Where(pair => pair.Value.Select(t => t.Name).Contains(tag))
                                       .Select(pair => pair.Key);
                componentIds = componentIds.Intersect(compsMatchingTag);
            }

            var refType = _session.GetReferenceTypeForName(ardoqReferenceName);

            foreach (var targetComponentId in componentIds)
            {
                var refs = _session.GetAllSourceReferencesFromChild(relation);
                if (!refs.Any(r => r.Target == targetComponentId && r.Type == refType))
                {
                    _session.AddReference(refType, component.Id, targetComponentId);
                }
            }
        }