示例#1
0
        public bool Contains(string nodeId, DvText name)
        {
            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty");
            Check.Require(name != null, "name must not be null");

            LocatableBindingListView <T> namedLocatables = null;

            if (identifiedLocatables.ContainsKey(nodeId))
            {
                namedLocatables = identifiedLocatables[nodeId];
            }

            bool result = false;

            if (namedLocatables != null)
            {
                DvCodedText codedName = name as DvCodedText;
                if (codedName == null)
                {
                    result = namedLocatables.Contains(name.Value);
                }

                else
                {
                    CodePhrase definingCode = codedName.DefiningCode;
                    result = namedLocatables.Contains(definingCode.TerminologyId.Value, definingCode.CodeString);
                }
            }

            return(result);
        }
示例#2
0
        protected override void AddItem(T item)
        {
            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Pathable locatable = item as Pathable;

            Check.Assert(item != null, "item must not be null");

            if (item.Parent == null)
            {
                item.Parent = this.Parent;
            }

            else if (this.Parent == null)
            {
                this.Parent = item.Parent;
            }

            else if (!Object.ReferenceEquals(item.Parent, this.Parent))
            {
                throw new ApplicationException("item parent must have same parent as other items");
            }

            LocatableBindingListView <T> namedLocatables;

            if (identifiedLocatables.ContainsKey(item.ArchetypeNodeId))
            {
                namedLocatables = identifiedLocatables[item.ArchetypeNodeId];
            }
            else
            {
                namedLocatables = new LocatableBindingListView <T>();
                identifiedLocatables.Add(item.ArchetypeNodeId, namedLocatables);
            }

            DvCodedText codedName = item.Name as DvCodedText;

            if (codedName != null)
            {
                if (namedLocatables.Contains(codedName.DefiningCode.TerminologyId.Value, codedName.DefiningCode.CodeString))
                {
                    throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in the namedLocatable list.",
                                                                 item.ArchetypeNodeId, codedName.ToString()));
                }
            }
            else if (namedLocatables.Contains(item.Name.Value))
            {
                throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in this namedLocatable list",
                                                             item.ArchetypeNodeId, item.Name.Value));
            }

            namedLocatables.Add(item);

            base.AddItem(item);
        }
示例#3
0
        public T this[string nodeId, DvText name]
        {
            get
            {
                Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

                Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty");
                Check.Require(name != null, "name must not be null");

                Check.Assert(Contains(nodeId, name), "Set must contain item with specified name");  // precondition, but more efficient in release

                LocatableBindingListView <T> namedLocatables = null;
                if (identifiedLocatables.ContainsKey(nodeId))
                {
                    namedLocatables = identifiedLocatables[nodeId];
                }

                T result = null;
                if (namedLocatables != null)
                {
                    DvCodedText codedName = name as DvCodedText;
                    if (codedName == null)
                    {
                        string nameValue = name.Value;
                        if (namedLocatables.Contains(nameValue))
                        {
                            result = namedLocatables[nameValue];
                        }
                    }
                    else
                    {
                        string nameTerminologyId = codedName.DefiningCode.TerminologyId.Value;
                        string nameCodeString    = codedName.DefiningCode.CodeString;
                        if (namedLocatables.Contains(nameTerminologyId, nameCodeString))
                        {
                            result = namedLocatables[nameTerminologyId, nameCodeString];
                        }
                    }
                }
                Check.Ensure(result != null, "result must not be null");
                return(result);
            }
        }