public WeatherReport[] GetForecast(string location, int days)
        {
            var lastReport = _reportRepository.GetLastByLocation(location);
            var list       = new List <WeatherReport>();

            var memoryStream = new MemoryStream();
            var serializer   = new DataContractSerializer(typeof(WeatherReport));

            serializer.WriteObject(memoryStream, lastReport);

            for (int i = 0; i < days; i++)
            {
                memoryStream.Position = 0;
                var clone = (WeatherReport)serializer.ReadObject(memoryStream);

                clone.Id           = -1;
                clone.DateTime     = clone.DateTime.AddDays(i + 1).Date;
                clone.Temperature += GetRandomValue(0.1f, 3);
                clone.Pressure    += GetRandomValue(-10, +10);

                list.Add(clone);
            }

            return(list.ToArray());
        }
Example #2
0
        public virtual WeatherReport GetLastReportByLocation(string location)
        {
            Console.WriteLine("GetLastReport for " + location + ": request");

            var lastReport = _reportRepository.GetLastByLocation(location);

            Console.WriteLine("GetLastReport for " + location + ": returning Report ID = " + lastReport.Id);
            return(lastReport);
        }