Ejemplo n.º 1
0
        private void AddLink(IAssociation roleName, ObjectPlusPlus targetObject, object qualifier, int counter)
        {
            Dictionary <object, ObjectPlusPlus> objectLinks;

            if (roleName.VerifyInstance(this, targetObject) == false)
            {
                throw new Exception("obiekty nie pasuja do podanej asocjacji.");
            }

            if (counter < 1)
            {
                return;
            }

            if (targetObject.ContainsRole(roleName.GetOposite()))
            {
                if (roleName.GetOposite().GetMaxCardinality() != 0 && counter == 2 && !(targetObject.RoleSize(roleName.GetOposite()) < roleName.GetOposite().GetMaxCardinality()))
                {
                    throw new Exception($"Maksymalna licznosc w {roleName.Class2.Name} osiagnieta i ma juz powiazane maksymalne: {targetObject.RoleSize(roleName.GetOposite())} obiektow typu {GetType().Name}.");
                }
            }

            if (Links.ContainsKey(roleName))
            {
                objectLinks = Links[roleName];
                if (roleName.GetMaxCardinality() != 0 && !(objectLinks.Count < roleName.GetMaxCardinality()))
                {
                    throw new Exception($"Maksymalna licznosc w {GetType().Name} osiagnieta i ma juz powiazane maksymalne: {RoleSize(roleName)} obiektow typu {roleName.Class2.Name}.");
                }
            }
            else
            {
                objectLinks = new Dictionary <object, ObjectPlusPlus>();
                Links.Add(roleName, objectLinks);
            }

            if (objectLinks.ContainsKey(qualifier) == false)
            {
                objectLinks.Add(qualifier, targetObject);

                targetObject.AddLink(roleName.GetOposite(), this, this, counter - 1);
            }
        }
Ejemplo n.º 2
0
        private void RemoveLink(IAssociation roleName, ObjectPlusPlus targetObject, object qualifier, int counter)
        {
            if (counter < 1)
            {
                return;
            }
            Dictionary <object, ObjectPlusPlus> objectLinks;

            if (Links.ContainsKey(roleName) == false)
            {
                throw new Exception("Brak powiazan z rola: " + roleName);
            }
            objectLinks = Links[roleName];
            if (objectLinks.ContainsKey(qualifier))
            {
                objectLinks.Remove(qualifier);
                targetObject.RemoveLink(roleName.GetOposite(), this, this, counter - 1);
            }

            objectLinks.Remove(targetObject);
            targetObject.RemoveLink(roleName.GetOposite(), this, qualifier, counter - 1);
        }
Ejemplo n.º 3
0
 public void AddLink(IAssociation roleName, ObjectPlusPlus targetObject)
 {
     AddLink(roleName, targetObject, targetObject);
 }
Ejemplo n.º 4
0
 public void AddLink(IAssociation roleName, ObjectPlusPlus targetObject, object qualifier)
 {
     AddLink(roleName, targetObject, qualifier, 2);
 }
Ejemplo n.º 5
0
 public void RemovePart(IAssociation roleName, ObjectPlusPlus targetObject)
 {
     targetObject.RemoveObject();
     AllParts.Remove(targetObject);
 }
Ejemplo n.º 6
0
 public void RemoveLink(IAssociation roleName, ObjectPlusPlus targetObject)
 {
     RemoveLink(roleName, targetObject, targetObject, 2);
 }