示例#1
0
        private bool DoesIdentifierExists(int placeIdentifier, Foi foi)
        {
            IIterator placeIterator = foi.Places.CreateIterator(IteratorType.Sequential);
            Place     place         = placeIterator.First();

            while (place != null)
            {
                if (place.UniqueIdentifier == placeIdentifier)
                {
                    return(true);
                }

                place = placeIterator.Next();
            }

            return(false);
        }
示例#2
0
        private bool DoesPlaceNameExists(string placeName, Foi foi)
        {
            IIterator placeIterator = foi.Places.CreateIterator(IteratorType.Sequential);
            Place     place         = placeIterator.First();

            while (place != null)
            {
                if (place.Name == placeName)
                {
                    Output.GetInstance().WriteLine("Mjesto: '" + placeName + "' već postoji!", true);
                    return(true);
                }

                place = placeIterator.Next();
            }

            return(false);
        }
示例#3
0
        public Place Construct(Dictionary <string, string> placeParams, ThingsOfFoi thingsOfFoi, Foi foi)
        {
            RandomGeneratorFacade randomGeneratorFacade = new RandomGeneratorFacade();

            if (DoesPlaceNameExists(placeParams["naziv"], foi))
            {
                return(null);
            }

            int placeUniqueIdentifier = randomGeneratorFacade.GiveRandomNumber(1, 1000);

            while (DoesIdentifierExists(placeUniqueIdentifier, foi))
            {
                placeUniqueIdentifier = randomGeneratorFacade.GiveRandomNumber(1, 1000);
            }

            List <Device> devices = new List <Device>();

            devices.AddRange(GetRandomDevices(Converter.StringToInt(placeParams["broj senzora"]), thingsOfFoi.Sensors.FindAll(sen => sen.Type == Converter.StringToInt(placeParams["tip"]) || sen.Type == 2)));
            devices.AddRange(GetRandomDevices(Converter.StringToInt(placeParams["broj aktuatora"]), thingsOfFoi.Actuators.FindAll(act => act.Type == Converter.StringToInt(placeParams["tip"]) || act.Type == 2)));

            return(_builder
                   .SetUniqueIdentifier(placeUniqueIdentifier)
                   .SetName(placeParams["naziv"])
                   .SetType(Converter.StringToInt(placeParams["tip"]))
                   .SetNumberOfSensors(Converter.StringToInt(placeParams["broj senzora"]))
                   .SetNumberOfActuators(Converter.StringToInt(placeParams["broj aktuatora"]))
                   .SetDevices(devices)
                   .Build());
        }