예제 #1
0
        /// <summary>Reads the data set to the specified <see cref="Stream"/>.</summary>
        /// <param name="target">A <see cref="Stream"/> to write the data set to.</param>
        void IStorageData.StoreData(Stream target)
        {
            var serializer = new XmlSerializer(typeof(RealTimeEventStorageContainer));
            var data       = new RealTimeEventStorageContainer
            {
                EarliestEvent = earliestEvent.Ticks,
            };

            AddEventToStorage(lastActiveEvent);
            AddEventToStorage(activeEvent);
            foreach (ICityEvent cityEvent in upcomingEvents)
            {
                AddEventToStorage(cityEvent);
            }

            serializer.Serialize(target, data);

            void AddEventToStorage(ICityEvent cityEvent)
            {
                if (cityEvent != null && cityEvent is RealTimeCityEvent realTimeEvent)
                {
                    data.Events.Add(realTimeEvent.GetStorageData());
                }
            }
        }
예제 #2
0
        /// <summary>Reads the data set to the specified <see cref="Stream"/>.</summary>
        /// <param name="target">A <see cref="Stream"/> to write the data set to.</param>
        void IStorageData.StoreData(Stream target)
        {
            var serializer = new XmlSerializer(typeof(RealTimeEventStorageContainer));
            var data       = new RealTimeEventStorageContainer
            {
                EarliestEvent = earliestEvent.Ticks,
            };

            AddEventsToStorage(finishedEvents);
            AddEventsToStorage(activeEvents);
            AddEventsToStorage(upcomingEvents);

            serializer.Serialize(target, data);

            void AddEventsToStorage(IEnumerable <ICityEvent> cityEvents)
            {
                foreach (var cityEvent in cityEvents.OfType <RealTimeCityEvent>())
                {
                    data.Events.Add(cityEvent.GetStorageData());
                }
            }
        }