Esempio n. 1
0
        public static Association GetAssociation(Role role)
        {
            Association ass = LegalAssociations.First(x => x.Role.Equals(role));

            if (ass == null)
            {
                throw new Exception("No association for that role");
            }
            return(ass);
        }
Esempio n. 2
0
        public static Association GetAssociation(Role role)
        {
            // próba przypisania asocjacja z list zdefiniowanych asocjacji
            Association ass = LegalAssociations.FirstOrDefault(x => x.Role.Equals(role));

            if (ass == null)
            {
                throw new Exception("No association for that role");
            }
            return(ass);
        }
Esempio n. 3
0
 public static void AddAssociation(Association association)
 {
     if (LegalAssociations == null)
     {
         LegalAssociations = new List <Association>();
     }
     if (LegalAssociations.Any(x => x.Role.Equals(association.Role)))
     {
         throw new Exception("Association for this role already exists");
     }
     else
     {
         LegalAssociations.Add(association);
     }
 }
Esempio n. 4
0
        private void AddLink(Association association, ObjectPlusPlus linkedObject, object qualifier, int counter)
        {
            if (counter < 1)
            {
                return;
            }
            if (linkedObject == null)
            {
                return;
            }
            if (association == null)
            {
                return;
            }
            if (!LegalAssociations.Any(x => x.Role.Equals(association.Role)))
            {
                throw new Exception("Association is not legal");
            }
            if (this.GetType() != association.StartClassifier)
            {
                throw new Exception("This object type is not correct");
            }
            if (linkedObject.GetType() != association.EndClassifier)
            {
                throw new Exception("Linked object type is not correct");
            }
            Dictionary <object, ObjectPlusPlus> roleLinks;

            if (Links.ContainsKey(association.Role))
            {
                roleLinks = Links[association.Role];
            }
            else
            {
                roleLinks = new Dictionary <object, ObjectPlusPlus>();
                Links.Add(association.Role, roleLinks);
            }
            if (!roleLinks.ContainsKey(linkedObject))
            {
                Association reverseAssociation = association.GetReversedAssociation();
                switch (association.EndMultiplicityLimit)
                {
                case -1:
                    roleLinks.Add(qualifier, linkedObject);
                    if (reverseAssociation != null)
                    {
                        linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    }
                    break;

                case 0:
                    if (roleLinks.Count != 0)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;

                default:
                    if (roleLinks.Count >= association.EndMultiplicityLimit)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;
                }
            }
        }
Esempio n. 5
0
        private void AddLink(Association association, ObjectPlusPlus linkedObject, object qualifier, int counter)
        {
            if (counter < 1)
            {
                return;
            }
            if (linkedObject == null)
            {
                return;
            }
            if (association == null)
            {
                return;
            }
            // sprawdzenie czy ta asocjacja została zdefiniowana
            if (!LegalAssociations.Any(x => x.Role.Equals(association.Role)))
            {
                throw new Exception("Association is not legal");
            }
            // sprawdzenie czy typ obiektu do którego dodajesz powiązanie zgadza się ze wzroem asocjacji
            if (this.GetType() != association.StartClassifier)
            {
                throw new Exception("This object type is not correct");
            }
            // sprawdzenie czy typ obiektu który chcesz powiązać zgadza się ze wzorem asocjacji
            if (linkedObject.GetType() != association.EndClassifier)
            {
                throw new Exception("Linked object type is not correct");
            }
            Dictionary <object, ObjectPlusPlus> roleLinks;

            // sprawdzenie czy istnieją powiązania dla roli
            if (Links.ContainsKey(association.Role))
            {
                roleLinks = Links[association.Role];
            }
            else
            {
                roleLinks = new Dictionary <object, ObjectPlusPlus>();
                Links.Add(association.Role, roleLinks);
            }
            // sprawdzenie czy powiązania dla roli zawierają obiekt, który chcemy powiązać
            if (!roleLinks.ContainsKey(linkedObject))
            {
                // stworzenie odwrotnej asocjacji do połączenie zwrotnego
                Association reverseAssociation = association.GetReversedAssociation();
                // sprawdzenie liczności asocjacji dla obiektu, który chcemy powiązać
                switch (association.EndMultiplicityLimit)
                {
                // jeżeli nie ma limitu liczności asocjacji
                case -1:
                    roleLinks.Add(qualifier, linkedObject);
                    if (reverseAssociation != null)
                    {
                        // stworzenie połączenia zwrotnego
                        linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    }
                    break;

                // przypadek, w którym limit liczność to 1
                case 0:
                    if (roleLinks.Count != 0)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    // stworzenie połączenia zwrotnego
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;

                // przypadek, w którym limit liczności to x
                default:
                    if (roleLinks.Count >= association.EndMultiplicityLimit)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    // stworzenie połączenia zwrotnego
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;
                }
            }
        }