示例#1
0
        public Node(GKOComponent component, GKOAttribute attribute)
        {
            if (component == null)
            {
                throw new ArgumentNullException("The component must be set!");
            }
            if (attribute != null && !component.AttributeValues.ContainsKey(attribute))
            {
                throw new InvalidOperationException("The component does not have this attribute!");
            }

            this.Component = component;
            this.Attribute = attribute;
        }
示例#2
0
 public Node(GKOComponent component)
     : this(component, null)
 {
 }
示例#3
0
        /// <summary>
        /// Checks whether an item should be added to the carthesian product when generating a configuration constraints
        /// <para>If the component of the new item matches the component of old ones the configuration constraint is ivalid</para>
        /// <para>EXCEPT: When the ComponentFilter generating the newItem actually specifies that it should be the same component as a previous one.
        /// In this case only equal components are returned as true</para>
        /// </summary>
        /// <param name="currTuple">The current relation tuple</param>
        /// <param name="newItem">The new item to add to the tuple</param>
        /// <returns></returns>
        private bool CheckNewRelationPart(List <IRelationPart> currTuple, IRelationPart newItem, Log log)
        {
            ComponentDomainRelationPart itemDomRelCompPart = this.DomainRelationParts[currTuple.Count] as ComponentDomainRelationPart;
            AttributeDomainRelationPart itemDomRelAttrPart = this.DomainRelationParts[currTuple.Count] as AttributeDomainRelationPart;

            // If it is not component or attribute relation part there are no constraints
            if (itemDomRelCompPart == null && itemDomRelAttrPart == null)
            {
                return(true);
            }
            else
            {
                int?samePartNr = null;

                // Finds whether the component part is equal to another component
                if (itemDomRelCompPart != null)
                {
                    samePartNr = itemDomRelCompPart.Filter.SameAsDomainRelationPartNr;
                }
                else if (itemDomRelAttrPart != null)
                {
                    samePartNr = itemDomRelAttrPart.Filter.SameAsDomainRelationPartNr;
                }

                // If the component part should equal to other component - it (the component) is found and checked if it matches the current one
                if (samePartNr.HasValue)
                {
                    if (currTuple.Count < samePartNr.Value || samePartNr.Value < 1)
                    {
                        log.AddItem(LogType.Warning, string.Format("The 'component same as filter' has wrong value({0} when the maximum is {1}) for domain constraint {2}. A configuration constraint cannot be generated.", samePartNr.Value, currTuple.Count, this.Name));
                        return(false);
                    }
                    else
                    {
                        ComponentRelationPart equalCompPart = currTuple[samePartNr.Value - 1] as ComponentRelationPart;
                        AttributeRelationPart equalAttrPart = currTuple[samePartNr.Value - 1] as AttributeRelationPart;

                        if (equalCompPart == null && equalAttrPart == null)
                        {
                            log.AddItem(LogType.Warning, string.Format("The 'component same as filter' points to relation part with no component included (i.e. metric part) for domain constraint {0}. A configuration constraint cannot be generated.", this.Name));
                            return(false);
                        }
                        else
                        {
                            ComponentRelationPart newItemCompPart = newItem as ComponentRelationPart;
                            AttributeRelationPart newItemAttrPart = newItem as AttributeRelationPart;

                            if (newItemCompPart == null && newItemAttrPart == null)
                            {
                                log.AddItem(LogType.Warning, string.Format("The 'component same as filter' points to relation part with no component included for domain constraint {0}. A configuration constraint cannot be generated.", this.Name));
                                return(false);
                            }
                            else
                            {
                                GKOComponent componentToComapre = null;

                                // The component from the new relation part is extracted
                                if (newItemCompPart != null)
                                {
                                    componentToComapre = newItemCompPart.Component;
                                }
                                else if (newItemAttrPart != null)
                                {
                                    componentToComapre = newItemAttrPart.Component;
                                }

                                // And finally the new component is compared with the one from the relation part it should match
                                if (equalCompPart != null)
                                {
                                    return(equalCompPart.Component.Id == componentToComapre.Id);
                                }
                                else if (equalAttrPart != null)
                                {
                                    return(equalAttrPart.Component.Id == componentToComapre.Id);
                                }

                                // this should not be reached
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    // If the value is not set to match other component then specificly exclude matching the same components
                    return(!currTuple.Any(x =>
                                          ((x is ComponentRelationPart) && (x as ComponentRelationPart).Equals(newItem)) ||
                                          ((x is AttributeRelationPart) && (x as AttributeRelationPart).Equals(newItem))
                                          ));
                }
            }
        }