Exemplo n.º 1
0
        /// <summary>Reads the data set from the specified <see cref="Stream"/>.</summary>
        /// <param name="source">A <see cref="Stream"/> to read the data set from.</param>
        void IStorageData.ReadData(Stream source)
        {
            lastActiveEvent = null;
            activeEvent     = null;
            upcomingEvents.Clear();

            var serializer = new XmlSerializer(typeof(RealTimeEventStorageContainer));
            var data       = (RealTimeEventStorageContainer)serializer.Deserialize(source);

            earliestEvent = new DateTime(data.EarliestEvent);

            foreach (RealTimeEventStorage storedEvent in data.Events)
            {
                if (string.IsNullOrEmpty(storedEvent.EventName) || string.IsNullOrEmpty(storedEvent.BuildingClassName))
                {
                    continue;
                }

                CityEventTemplate template = eventProvider.GetEventTemplate(storedEvent.EventName, storedEvent.BuildingClassName);
                var realTimeEvent          = new RealTimeCityEvent(template, storedEvent.AttendeesCount);
                realTimeEvent.Configure(storedEvent.BuildingId, storedEvent.BuildingName, new DateTime(storedEvent.StartTime));

                if (realTimeEvent.EndTime < timeInfo.Now)
                {
                    lastActiveEvent = realTimeEvent;
                }
                else
                {
                    upcomingEvents.AddLast(realTimeEvent);
                }
            }

            OnEventsChanged();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RealTimeCityEvent"/> class using the specified <paramref name="eventTemplate"/>.
        /// </summary>
        /// <param name="eventTemplate">The event template this city event is created from.</param>
        /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
        public RealTimeCityEvent(CityEventTemplate eventTemplate)
        {
            this.eventTemplate = eventTemplate ?? throw new ArgumentNullException(nameof(eventTemplate));
            var incentives = eventTemplate.Incentives?.Where(i => i.ActiveWhenRandomEvent).ToList();

            if (incentives != null)
            {
                attendChanceAdjustment = incentives.Sum(i => i.PositiveEffect) - incentives.Sum(i => i.NegativeEffect);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RealTimeCityEvent"/> class using the specified
 /// <paramref name="eventTemplate"/> and the already known current <paramref name="attendeesCount"/>.
 /// </summary>
 /// <param name="eventTemplate">The event template this city event is created from.</param>
 /// <param name="attendeesCount">The current attendees count of this city event.</param>
 public RealTimeCityEvent(CityEventTemplate eventTemplate, int attendeesCount)
     : this(eventTemplate)
 {
     this.attendeesCount = attendeesCount;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RealTimeCityEvent"/> class using the specified <paramref name="eventTemplate"/>.
 /// </summary>
 /// <param name="eventTemplate">The event template this city event is created from.</param>
 /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
 public RealTimeCityEvent(CityEventTemplate eventTemplate)
 {
     this.eventTemplate = eventTemplate ?? throw new ArgumentNullException(nameof(eventTemplate));
 }