Exemple #1
0
 public void AddLinks(Shipment shipment, Connection connection)
 {
     if (shipment == null || connection == null)
     {
         throw new Exception("Shipment or Connection cannot be null");
     }
     AddLink(ObjectPlusPlus.GetAssociation(Role.Execution_Shipment), shipment);
     AddLink(ObjectPlusPlus.GetAssociation(Role.Execution_Connection), connection);
 }
Exemple #2
0
 public void AddPart(Association association, ObjectPlusPlus partObject)
 {
     if (AllParts.Contains(partObject))
     {
         throw new Exception("Given part object is already linked");
     }
     AddLink(association, partObject);
     AllParts.Add(partObject);
 }
Exemple #3
0
 public void AddPart(Association association, ObjectPlusPlus partObject)
 {
     /// sprawdzenie czy zbiór części zawiera podany obiekt
     if (AllParts.Contains(partObject))
     {
         throw new Exception("Given part object is already linked");
     }
     AddLink(association, partObject);
     AllParts.Add(partObject);
 }
Exemple #4
0
        static void Main(string[] args)
        {
            // zdefiniowanie assocjacji dla programu
            ObjectPlusPlus.DefineAssociations();

            Shipment sh1 = new Shipment("Shipment 1");

            Address add1 = new Address("Liliowa", "25A", "Warszawa", "Polska", "05-666");
            Address add2 = new Address("Tulipanowa", "2", "9", "Olsztyn", "Polska", "21-370");
            Address add3 = new Address("Kasztanowa", "13", "Płock", "Polska", "01-234");

            sh1.AddLink(ObjectPlusPlus.GetAssociation(Role.ShipmentPickupAddress), add3); // asocjacja binarna skierowana
            sh1.AddLink(ObjectPlusPlus.GetAssociation(Role.ShipmentSenderAddress), add1);

            sh1.ShowLinks(Role.ShipmentPickupAddress);
            sh1.ShowLinks(Role.ShipmentSenderAddress);

            Connection c1 = new Connection("Warszawa-Płock", 110);

            c1.AddLink(ObjectPlusPlus.GetAssociation(Role.ConnectionStartAddress), add1);
            c1.AddLink(ObjectPlusPlus.GetAssociation(Role.ConnectionEndAddress), add3);

            Schedule sch1 = Schedule.CreateSchedule(c1, "Schedule for " + c1.Name); // Kompozycja

            c1.ShowLinks(Role.ConnectionShedule);
            sch1.ShowLinks(Role.ScheduleConnection);

            Connection c2 = new Connection("Płock-Olsztyn", 180);

            c2.AddLink(ObjectPlusPlus.GetAssociation(Role.ConnectionStartAddress), add3);
            c2.AddLink(ObjectPlusPlus.GetAssociation(Role.ConnectionEndAddress), add2);

            Schedule sch2 = Schedule.CreateSchedule(c2, "Schedule for " + c2.Name);

            DatePair dp1 = new DatePair(new DateTime(2019, 4, 20, 11, 0, 0), new DateTime(2019, 4, 20, 13, 0, 0));
            DatePair dp2 = new DatePair(new DateTime(2019, 4, 20, 18, 0, 0), new DateTime(2019, 4, 20, 21, 0, 0));

            sch1.AddLink(ObjectPlusPlus.GetAssociation(Role.Schedule_DatePair), dp1, "Estimated 1"); // Asocjacja kwalifikowana
            sch2.AddLink(ObjectPlusPlus.GetAssociation(Role.Schedule_DatePair), dp2, "Estimated 2"); // Asocjacja kwalifikowana

            Execution exe1 = new Execution((DatePair)sch1.GetLinknedObject(Role.Schedule_DatePair, "Estimated 1"));
            Execution exe2 = new Execution((DatePair)sch2.GetLinknedObject(Role.Schedule_DatePair, "Estimated 2"));

            exe1.AddLinks(sh1, c1); //Asocjacja z atrybutem pomiędzy shipment i connection
            exe2.AddLinks(sh1, c2); //Asocjacja z atrybutem pomiędzy shipment i connection

            sh1.ShowLinks(Role.Shipment_Execution);
            c1.ShowLinks(Role.Connection_Execution);
        }
Exemple #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;
            }
            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;
                }
            }
        }
Exemple #6
0
 public void AddLink(Association association, ObjectPlusPlus linkedObject)
 {
     AddLink(association, linkedObject, linkedObject, 2);
 }
Exemple #7
0
 public void AddLink(Association association, ObjectPlusPlus linkedObject, object qualifier)
 {
     AddLink(association, linkedObject, qualifier, 2);
 }
Exemple #8
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;
                }
            }
        }