Ejemplo n.º 1
0
        public virtual void Page_Load(object sender, EventArgs e)
        {
            Facebook.Instance.ApiKey = fb_api_key;
            Facebook.Instance.Secret = fb_secret;
            if (!Facebook.Instance.RequireAdd(this))
                return;

            fb_uid = Convert.ToInt64(Request.Params.Get("fb_sig_user"));
            fb_session_key = Request.Params.Get("fb_sig_session_key");
            forecaster = new WeatherForecast();

            ///Console.WriteLine(Users.GetInfo());
            User user = Users.GetInfo(new string[] {"name", "current_location", "affiliations"});

            //Console.WriteLine(FQL.Query(String.Format("SELECT name, affiliations FROM user WHERE uid = {0}", fb_uid)));

            Profile.SetFbml(String.Format("<strong>Last updated the profile at {0}</strong>", DateTime.Now));
            Notifications.Get();

            LoadWeatherData(user);

            // XXX: Silly load testing stuff
            /*
            for (int i = 0; i < 50; ++i)
            {
                DateTime start = DateTime.Now;
                Users.GetInfo();
                TimeSpan diff = (DateTime.Now - start);
                Console.WriteLine("Time taken: {0}", diff.Milliseconds);
            }
            */
        }
Ejemplo n.º 2
0
        public ScreenManager(ContentManager content, GraphicsDeviceManager graphics)
        {
            // TODO: Construct any child components here
            serverHandler = new ServerHandler();
            weather = new Weather();

            mainScene = new MainScene(content, graphics);
            loadingScreen = new LoadingScreen();

            mainMenu = new MainMenu(content.Load<SpriteFont>("Fonts\\menufont"));
            highScores = new HighScores(serverHandler);
            settingsMenu = new SettingsMenu(weather, this);
            pauseMenu = new PauseMenu();
            deadScreen = new DeadScreen(this);
            weatherMenu = new WeatherMenu(this, weather);

            CurrentWeather = weather.WeatherForecast;
        }
Ejemplo n.º 3
0
        public Task Execute(IJobExecutionContext context)
        {
            // Create a new scope
            var scope = _provider.CreateScope();

            // Resolve the Scoped service
            var _context = scope.ServiceProvider.GetService <ApplicationDbContext>();

            _logger.LogInformation("OpenWeatherJob - Started");

            try
            {
                WebClient webClient = new WebClient();

                const string appid = "49778d403a36e87cf3f7f5b430570a06";
                const string units = "metric";
                const string lon   = "14.86";
                const string lat   = "50.07";

                string url = string.Format("http://api.openweathermap.org/data/2.5/onecall?lat={0}&lon={1}&units={2}&APPID={3}", lat, lon, units, appid);

                var json = webClient.DownloadString(url);

                var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo.Root>(json);
                var dashboard   = _context.Dashboards.Include(t => t.OutdoorCollector.Sensors)
                                  .First();

                if (weatherInfo != null)
                {
                    var weatherForecast = _context.WeatherForecast
                                          .Include(t => t.Current)
                                          .Include(t => t.Current.WeatherList)
                                          .Include(t => t.Hourly)
                                          .Include(t => t.Daily)
                                          .FirstOrDefault();

                    if (weatherForecast != null)
                    {
                        _context.WeatherForecast.Remove(weatherForecast);
                        _context.SaveChanges();
                    }

                    weatherForecast = new WeatherForecast();

                    weatherForecast.DateTime = DateTime.Now;

                    // CurrentState
                    if (weatherForecast.Current == null)
                    {
                        weatherForecast.Current = new WeatherForecast.CurrentState();
                    }
                    weatherForecast.Current.WeatherForecast        = weatherForecast;
                    weatherForecast.Current.WeatherForecastId      = weatherForecast.Id;
                    weatherForecast.Current.DateTime               = DateTimeOffset.FromUnixTimeSeconds(weatherInfo.Current.DateTime).LocalDateTime;
                    weatherForecast.Current.SunriseTime            = DateTimeOffset.FromUnixTimeSeconds(weatherInfo.Current.SunriseTime).LocalDateTime;
                    weatherForecast.Current.SunsetTime             = DateTimeOffset.FromUnixTimeSeconds(weatherInfo.Current.SunsetTime).LocalDateTime;
                    weatherForecast.Current.Temperature            = weatherInfo.Current.Temperature;
                    weatherForecast.Current.FeelsLikeTemperature   = weatherInfo.Current.FeelsLikeTemperature;
                    weatherForecast.Current.Pressure               = weatherInfo.Current.Pressure;
                    weatherForecast.Current.Humidity               = weatherInfo.Current.Humidity;
                    weatherForecast.Current.AtmosphericTemperature = weatherInfo.Current.AtmosphericTemperature;
                    weatherForecast.Current.UVIndex           = weatherInfo.Current.UVIndex;
                    weatherForecast.Current.Cloudiness        = weatherInfo.Current.Cloudiness;
                    weatherForecast.Current.AverageVisibility = weatherInfo.Current.AverageVisibility;
                    weatherForecast.Current.WindSpeed         = weatherInfo.Current.WindSpeed;
                    weatherForecast.Current.WindDirection     = weatherInfo.Current.WindDirection;
                    weatherForecast.Current.Rain = weatherInfo.Current.Rain?.Per1h;
                    weatherForecast.Current.Snow = weatherInfo.Current.Snow?.Per1h;

                    if (weatherInfo.Current.WeatherList != null)
                    {
                        if (weatherForecast.Current.WeatherList == null)
                        {
                            weatherForecast.Current.WeatherList = new List <Weather>();
                        }

                        foreach (var weather in weatherInfo.Current.WeatherList)
                        {
                            var weatherInformation = new Weather();

                            weatherInformation.WeatherConditionId = weather.Id;
                            weatherInformation.Main        = weather.Main;
                            weatherInformation.Description = weather.Description;
                            weatherInformation.Icon        = weather.Icon;

                            weatherForecast.Current.WeatherList.Add(weatherInformation);
                        }
                    }

                    //HourlyState
                    if (weatherForecast.Hourly == null)
                    {
                        weatherForecast.Hourly = new List <WeatherForecast.HourlyState>();
                    }


                    foreach (var hourlyState in weatherInfo.Hourly)
                    {
                        var hourly = new WeatherForecast.HourlyState();

                        hourly.AtmosphericTemperature = hourlyState.AtmosphericTemperature;
                        hourly.Cloudiness             = hourlyState.Cloudiness;
                        hourly.DateTime             = DateTimeOffset.FromUnixTimeSeconds(hourlyState.DateTime).LocalDateTime;
                        hourly.FeelsLikeTemperature = hourlyState.FeelsLikeTemperature;
                        hourly.Humidity             = hourlyState.Humidity;
                        hourly.Pressure             = hourlyState.Pressure;
                        hourly.Temperature          = hourlyState.Temperature;
                        hourly.WindDirection        = hourlyState.WindDirection;
                        hourly.WindSpeed            = hourlyState.WindSpeed;
                        hourly.Rain = hourlyState.Rain == null ? 0 : hourlyState.Rain.Per1h;
                        hourly.Snow = hourlyState.Snow == null ? 0 : hourlyState.Snow.Per1h;

                        if (hourlyState.WeatherList != null)
                        {
                            hourly.WeatherList = new List <Weather>();

                            foreach (var weather in hourlyState.WeatherList)
                            {
                                var weatherInformation = new Weather();

                                weatherInformation.WeatherConditionId = Convert.ToInt32(weather.Id);
                                weatherInformation.Main        = weather.Main;
                                weatherInformation.Description = weather.Description;
                                weatherInformation.Icon        = weather.Icon;

                                hourly.WeatherList.Add(weatherInformation);
                            }
                        }

                        weatherForecast.Hourly.Add(hourly);
                    }

                    //Daily
                    if (weatherForecast.Daily == null)
                    {
                        weatherForecast.Daily = new List <DailyState>();
                    }

                    foreach (var dailyState in weatherInfo.Daily)
                    {
                        var daily = new DailyState();

                        daily.AtmosphericTemperature = dailyState.AtmosphericTemperature;
                        daily.AverageVisibility      = dailyState.AverageVisibility;
                        daily.Cloudiness             = dailyState.Cloudiness;
                        daily.DateTime = DateTimeOffset.FromUnixTimeSeconds(dailyState.DateTime).LocalDateTime;

                        if (dailyState.FeelsLikeTemperature != null)
                        {
                            daily.FeelsLikeTemperature = new WeatherForecast.DailyTemp();
                            daily.FeelsLikeTemperature.DayTemperature      = dailyState.FeelsLikeTemperature.DayTemperature;
                            daily.FeelsLikeTemperature.EveningTemperature  = dailyState.FeelsLikeTemperature.EveningTemperature;
                            daily.FeelsLikeTemperature.MaxDailyTemperature = dailyState.FeelsLikeTemperature.MaxDailyTemperature;
                            daily.FeelsLikeTemperature.MinDailyTemperature = dailyState.FeelsLikeTemperature.MinDailyTemperature;
                            daily.FeelsLikeTemperature.MorningTemperature  = dailyState.FeelsLikeTemperature.MorningTemperature;
                            daily.FeelsLikeTemperature.NightTemperature    = dailyState.FeelsLikeTemperature.NightTemperature;
                        }

                        daily.Humidity    = dailyState.Humidity;
                        daily.Pressure    = dailyState.Pressure;
                        daily.Rain        = dailyState.Rain;
                        daily.Snow        = dailyState.Snow;
                        daily.SunriseTime = DateTimeOffset.FromUnixTimeSeconds(dailyState.SunriseTime).LocalDateTime;
                        daily.SunsetTime  = DateTimeOffset.FromUnixTimeSeconds(dailyState.SunsetTime).LocalDateTime;
                        if (dailyState.Temperature != null)
                        {
                            daily.Temperature = new WeatherForecast.DailyTemp();
                            daily.Temperature.DayTemperature      = dailyState.Temperature.DayTemperature;
                            daily.Temperature.EveningTemperature  = dailyState.Temperature.EveningTemperature;
                            daily.Temperature.MaxDailyTemperature = dailyState.Temperature.MaxDailyTemperature;
                            daily.Temperature.MinDailyTemperature = dailyState.Temperature.MinDailyTemperature;
                            daily.Temperature.MorningTemperature  = dailyState.Temperature.MorningTemperature;
                            daily.Temperature.NightTemperature    = dailyState.Temperature.NightTemperature;
                        }

                        daily.UVIndex = dailyState.UVIndex;
                        if (dailyState.WeatherList != null)
                        {
                            daily.WeatherList = new List <Weather>();

                            foreach (var weather in dailyState.WeatherList)
                            {
                                var weatherInformation = new Weather();

                                weatherInformation.WeatherConditionId = Convert.ToInt32(weather.Id);
                                weatherInformation.Main        = weather.Main;
                                weatherInformation.Description = weather.Description;
                                weatherInformation.Icon        = weather.Icon;

                                daily.WeatherList.Add(weatherInformation);
                            }
                        }
                        daily.WindDirection = dailyState.WindDirection;
                        daily.WindSpeed     = dailyState.WindSpeed;

                        weatherForecast.Daily.Add(daily);
                    }


                    _context.WeatherForecast.Add(weatherForecast);
                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(String.Format("OpenWeatherJob - Error: {0} ", ex.Message));
            }

            _logger.LogInformation("OpenWeatherJob - Finished");

            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
 public void SeedForecast(WeatherForecast forecast)
 {
     _context.Add(forecast);
     _context.SaveChanges();
 }
Ejemplo n.º 5
0
 public void Remove(WeatherForecast weatherForecast) =>
 _weatherForecast.DeleteOne(wo => wo.Id == weatherForecast.Id);
Ejemplo n.º 6
0
        public Result <WeatherForecast> PutWeather([FromBody] WeatherForecast weatherForecast)
        {
            weatherForecast.Summary = "PUT成功,接收后修改的Summary";

            return(Success("0000001", "PUT成功", weatherForecast));
        }
 public IActionResult Post(WeatherForecast x)
 {
     //add here creation logics
     return(Created("api/SampleData/3", x));
 }
Ejemplo n.º 8
0
 public WeatherForecast Create(WeatherForecast weatherForecast)
 {
     _weatherForecast.InsertOne(weatherForecast);
     return(weatherForecast);
 }
Ejemplo n.º 9
0
 public async Task Delete([FromBody] WeatherForecast weatherForecast)
 {
     //insert a new weather record
     await weatherdelete.Delete(weatherForecast);
 }
 public void CreateWeatherForecast()
 {
     newWeatherForecast = new WeatherForecast();
 }
Ejemplo n.º 11
0
 public WeatherForecastController(WeatherForecast weatherForecast)
 {
     _weatherForecast = weatherForecast;
 }
Ejemplo n.º 12
0
 public async Task Post([FromBody] WeatherForecast weatherForecast)
 {
     //insert a new weather record
     await weathercreate.Create(weatherForecast);
 }
 public void Post(WeatherForecast weatherForecast)
 {
     WeatherForecastList.Add(weatherForecast);
 }
Ejemplo n.º 14
0
 void EditForecast(WeatherForecast weatherForecast)
 {
     objWeatherForecast = weatherForecast;
     ShowPopup          = true;
 }
Ejemplo n.º 15
0
 void AddNewForecast()
 {
     objWeatherForecast    = new WeatherForecast();
     objWeatherForecast.Id = 0;
     ShowPopup             = true;
 }
Ejemplo n.º 16
0
 public void Dispose()
 {
     weather = null;
 }
 public void Remove(WeatherForecast itemIn) =>
 _weatherForecast.DeleteOne(item => item.Id == itemIn.Id);
Ejemplo n.º 18
0
 public async Task Put([FromBody] WeatherForecast weatherForecast)
 {
     //update a new record
     await weatherupdate.Update(weatherForecast);
 }
Ejemplo n.º 19
0
 public WeatherData2Controller(ILogger <WeatherDataController> logger)
 {
     _logger = logger;
     _items  = WeatherForecast.GenerateDemo();
 }
Ejemplo n.º 20
0
 public void Post(WeatherForecast cast)
 {
     _weatherService.AddCast(cast);
 }
 public IEnumerable <WeatherForecast> Get()
 {
     return(Enumerable.Range(1, 5)
            .Select(index => WeatherForecast.GetWeatherForectast(index))
            .ToArray());
 }
 public void Cancel()
 {
     newWeatherForecast = null;
 }
Ejemplo n.º 23
0
 public void Post(WeatherForecast weatherForecast)
 {
     _weatherForecasts.Add(weatherForecast);
 }
Ejemplo n.º 24
0
 public void Add(WeatherForecast weather) => weatherData.Add(weather);
Ejemplo n.º 25
0
 public Response Post(int predefinedId, int?oylesine, [FromBody] WeatherForecast wcast)
 {
     return(new Response()
     {
     });
 }
Ejemplo n.º 26
0
 public void Update(string id, WeatherForecast weatherForecast) =>
 _weatherForecast.ReplaceOne(wo => wo.Id == id, weatherForecast);
 public SingleForecastItemViewModel(WeatherForecast forecastItem)
 {
     _forecastItem = forecastItem;
 }
 public async Task AddWeatherForecast(WeatherForecast weather)
 {
     await efCore.AddWeatherForecast(weather);
 }
 public Task <WeatherForecast> CreateForecastAsync(WeatherForecast weatherForecast)
 {
     _context.WeatherForecast.Add(weatherForecast);
     _context.SaveChanges();
     return(Task.FromResult(weatherForecast));
 }
Ejemplo n.º 30
0
 public IActionResult Create([FromQuery] WeatherForecast weatherToDay)
 {
     holder.Values.Add(weatherToDay);
     return(Ok());
 }
Ejemplo n.º 31
0
        private void WriteWeather()
        {
            WeatherForecast weather = WeatherForecast.GetInstance();

            Console.WriteLine(weather.Date);
        }
Ejemplo n.º 32
0
        private void DownloadCompleted(Object sender, DownloadStringCompletedEventArgs e)
        {
            string htmlParse = e.Result;
            string searchString = "<![CDATA[http://www.worldweatheronline.com/images/wsymbols01_png_64/";
            int from = htmlParse.IndexOf(searchString) + searchString.Length;
            string currentWeather = htmlParse.Substring(from, htmlParse.IndexOf("]]></weatherIconUrl>") - from);

            //Different kinds of weather
            switch (currentWeather)
            {
                case "wsymbol_0001_sunny.png":
                    weatherForecast = WeatherForecast.Sunny;
                    isNight = false;
                    break;
                case "wsymbol_0002_sunny_intervals.png":
                    weatherForecast = WeatherForecast.SunnyIntervals;
                    isNight = false;
                    break;
                case "wsymbol_0003_white_cloud.png":
                    weatherForecast = WeatherForecast.WhiteCloud;
                    isNight = false;
                    break;
                case "wsymbol_0004_black_low_cloud.png":
                    weatherForecast = WeatherForecast.BlackLowCloud;
                    isNight = false;
                    break;
                case "wsymbol_0005_hazy_sun.png":
                    weatherForecast = WeatherForecast.HazySun;
                    isNight = false;
                    break;
                case "wsymbol_0006_mist.png":
                    weatherForecast = WeatherForecast.Mist;
                    isNight = false;
                    break;
                case "wsymbol_0007_fog.png":
                    weatherForecast = WeatherForecast.Fog;
                    isNight = false;
                    break;
                case "wsymbol_0008_clear_sky_night.png":
                    weatherForecast = WeatherForecast.ClearSkyNight;
                    isNight = true;
                    break;
                case "wsymbol_0009_light_rain_showers.png":
                    weatherForecast = WeatherForecast.LightRainShowers;
                    isNight = false;
                    break;
                case "wsymbol_0010_heavy_rain_showers.png":
                    weatherForecast = WeatherForecast.HeavyRainShowers;
                    isNight = false;
                    break;
                case "wsymbol_0011_light_snow_showers.png":
                    weatherForecast = WeatherForecast.LightSnowShowers;
                    isNight = false;
                    break;
                case "wsymbol_0012_heavy_snow_showers.png":
                    weatherForecast = WeatherForecast.HeavySnowShowers;
                    isNight = false;
                    break;
                case "wsymbol_0013_sleet_showers.png":
                    weatherForecast = WeatherForecast.SleetShowers;
                    isNight = false;
                    break;
                case "wsymbol_0014_light_hail_showers.png":
                    weatherForecast = WeatherForecast.LightHailShowers;
                    isNight = false;
                    break;
                case "wsymbol_0015_heavy_hail_showers.png":
                    weatherForecast = WeatherForecast.HeavyHailShowers;
                    isNight = false;
                    break;
                case "wsymbol_0016_thundery_showers.png":
                    weatherForecast = WeatherForecast.ThunderyShowers;
                    isNight = false;
                    break;
                case "wsymbol_0017_cloudy_with_light_rain.png":
                    weatherForecast = WeatherForecast.CloudyWithLightRain;
                    isNight = false;
                    break;
                case "wsymbol_0018_cloudy_with_heavy_rain.png":
                    weatherForecast = WeatherForecast.CloudyWithHeavyRain;
                    isNight = false;
                    break;
                case "wsymbol_0019_cloudy_with_light_snow.png":
                    weatherForecast = WeatherForecast.CloudyWithLightSnow;
                    isNight = false;
                    break;
                case "wsymbol_0020_cloudy_with_heavy_snow.png":
                    weatherForecast = WeatherForecast.CloudyWithHeavySnow;
                    isNight = false;
                    break;
                case "wsymbol_0021_cloudy_with_sleet.png":
                    weatherForecast = WeatherForecast.CloudyWithSleet;
                    isNight = false;
                    break;
                case "wsymbol_0022_cloudy_with_light_hail.png":
                    weatherForecast = WeatherForecast.CloudyWithLightHail;
                    isNight = false;
                    break;
                case "wsymbol_0023_cloudy_with_heavy_hail.png":
                    weatherForecast = WeatherForecast.CloudyWithHeavyHail;
                    isNight = false;
                    break;
                case "wsymbol_0024_thunderstorms.png":
                    weatherForecast = WeatherForecast.ThunderStorms;
                    isNight = false;
                    break;
                case "wsymbol_0025_light_rain_showers_night.png":
                    weatherForecast = WeatherForecast.LightRainShowers;
                    isNight = true;
                    break;
                case "wsymbol_0026_heavy_rain_showers_night.png":
                    weatherForecast = WeatherForecast.HeavyRainShowers;
                    isNight = true;
                    break;
                case "wsymbol_0027_light_snow_showers_night.png":
                    weatherForecast = WeatherForecast.LightSnowShowers;
                    isNight = true;
                    break;
                case "wsymbol_0028_heavy_snow_showers_night.png":
                    weatherForecast = WeatherForecast.HeavySnowShowers;
                    isNight = true;
                    break;
                case "wsymbol_0029_sleet_showers_night.png":
                    weatherForecast = WeatherForecast.SleetShowers;
                    isNight = true;
                    break;
                case "wsymbol_0030_light_hail_showers_night.png":
                    weatherForecast = WeatherForecast.LightHailShowers;
                    isNight = true;
                    break;
                case "wsymbol_0031_heavy_hail_showers_night.png":
                    weatherForecast = WeatherForecast.HeavyHailShowers;
                    isNight = true;
                    break;
                case "wsymbol_0032_thundery_showers_night.png":
                    weatherForecast = WeatherForecast.ThunderyShowers;
                    isNight = true;
                    break;
                case "wsymbol_0033_cloudy_with_light_rain_night.png":
                    weatherForecast = WeatherForecast.CloudyWithLightRain;
                    isNight = true;
                    break;
                case "wsymbol_0034_cloudy_with_heavy_rain_night.png":
                    weatherForecast = WeatherForecast.CloudyWithHeavyRain;
                    isNight = true;
                    break;
                case "wsymbol_0035_cloudy_with_light_snow_night.png":
                    weatherForecast = WeatherForecast.CloudyWithLightSnow;
                    isNight = true;
                    break;
                case "wsymbol_0036_cloudy_with_heavy_snow_night.png":
                    weatherForecast = WeatherForecast.CloudyWithHeavySnow;
                    isNight = true;
                    break;
                case "wsymbol_0037_cloudy_with_sleet_night.png":
                    weatherForecast = WeatherForecast.CloudyWithSleet;
                    isNight = true;
                    break;
                case "wsymbol_0038_cloudy_with_light_hail_night.png":
                    weatherForecast = WeatherForecast.CloudyWithLightHail;
                    isNight = true;
                    break;
                case "wsymbol_0039_cloudy_with_heavy_hail_night.png":
                    weatherForecast = WeatherForecast.CloudyWithHeavyHail;
                    isNight = true;
                    break;
                case "wsymbol_0040_thunderstorms_night.png":
                    weatherForecast = WeatherForecast.ThunderStorms;
                    isNight = true;
                    break;
            }
        }
Ejemplo n.º 33
0
        static void Main(string[] args)
        {
            #region Binary Serialization

            UserPrefs userData = new UserPrefs();
            userData.WindowColor = "Yellow";
            userData.FontSize    = 50;

            // The BinaryFormatter persists state data in a binary format.
            BinaryFormatter binFormat = new BinaryFormatter();

            // Store object in a local file
            Stream fStream = new FileStream("user.dat",
                                            FileMode.Create, FileAccess.Write, FileShare.None);
            binFormat.Serialize(fStream, userData);
            fStream.Close();

            //serialization
            MyClass obj = new MyClass();

            obj.N1   = 100;
            obj.N2   = 250;
            obj.Str1 = "This string will be serialized";
            obj.Str2 = "This string will be lost soon";

            IFormatter formatter1 = new BinaryFormatter();

            Stream fStream2 = new FileStream("MyFile.bin",
                                             FileMode.Create, FileAccess.Write, FileShare.None);
            formatter1.Serialize(fStream2, obj);
            fStream2.Close();

            //deserialization
            IFormatter formatter2 = new BinaryFormatter();

            Stream fStream3 = new FileStream("MyFile.bin",
                                             FileMode.Open, FileAccess.Read, FileShare.Read);
            MyClass obj2 = (MyClass)formatter2.Deserialize(fStream3);
            fStream3.Close();

            //deserialization
            IFormatter formatter3 = new BinaryFormatter();

            Stream fStream4 = new FileStream("user.dat",
                                             FileMode.Open, FileAccess.Read, FileShare.Read);
            UserPrefs userData2 = (UserPrefs)formatter3.Deserialize(fStream4);
            fStream4.Close();

            Console.WriteLine(obj2);
            Console.WriteLine(userData2);

            // ----
            // Make a JamesBondCar and set state
            JamesBondCar jbc = new JamesBondCar();
            jbc.CanFly                  = true;
            jbc.CanSubmerge             = false;
            jbc.TheRadio.StationPresets = new double[] { 89.3, 105.1, 97.1 };
            jbc.TheRadio.HasTweeters    = true;

            // Now save the car to a specific file in a binary format
            SaveAsBinaryFormat(jbc, "CarData.dat");
            //Now load the car data from the file
            JamesBondCar jbc2 = LoadFromBinaryFile("CarData.dat");

            Console.WriteLine(jbc2);
            #endregion

            #region SOAP serialization
            SaveAsSoapFormat(jbc, "CarData.soap");
            JamesBondCar jbc3 = LoadFromSoapFile("CarData.soap");
            Console.WriteLine(jbc3);

            #endregion

            #region XMLSerialization
            SaveAsXmlFormat(jbc, "CarData.xml");
            JamesBondCar jbc4 = LoadFromXmlFormat("CarData.xml");
            Console.WriteLine(jbc4);

            #endregion

            #region New JSON serialization
            var options = new JsonSerializerOptions
            {
                IgnoreReadOnlyProperties = false,
                IgnoreNullValues         = true,
                WriteIndented            = true,
            };
            WeatherForecast weatherForecast = new WeatherForecast();
            weatherForecast.Summary            = "Sunny day";
            weatherForecast.TemperatureCelsius = 25;
            weatherForecast.X = 5;
            string jsonString = JsonSerializer.Serialize(weatherForecast);
            Console.WriteLine(jsonString);
            File.WriteAllText("temps.json", jsonString);
            #endregion

            #region CustomSerialization

            StringData myData = new StringData();
            // Save to a local file in Binary format.
            IFormatter customFormat = new BinaryFormatter();
            Stream     fS5          = new FileStream("SData.dat",
                                                     FileMode.Create, FileAccess.Write, FileShare.None);

            customFormat.Serialize(fS5, myData);

            fS5.Close();

            //deserialization
            IFormatter f6 = new BinaryFormatter();

            Stream fS6 = new FileStream("SData.dat",
                                        FileMode.Open, FileAccess.Read, FileShare.Read);
            StringData userData6 = (StringData)f6.Deserialize(fS6);
            fS6.Close();

            #endregion

            #region JSON Old serialization
            HighLowTemps cold = new HighLowTemps();
            cold.High = 15;
            cold.Low  = -10;
            HighLowTemps hot = new HighLowTemps();
            hot.High = 42;
            hot.Low  = 20;
            WeatherForecastWithPocos wfp = new WeatherForecastWithPocos();
            wfp.Date = DateTimeOffset.Now;
            wfp.TemperatureCelsius = 25;
            wfp.Summary            = "Sunny";
            wfp.DatesAvailable     = new List <DateTimeOffset>();
            wfp.DatesAvailable.Add(DateTimeOffset.Parse("2019-08-01T00:00:00-07:00"));
            wfp.DatesAvailable.Add(DateTimeOffset.Parse("2019-08-02T00:00:00-07:00"));
            wfp.TemperatureRanges = new Dictionary <string, HighLowTemps>();
            wfp.TemperatureRanges.Add("Cold", cold);
            wfp.TemperatureRanges.Add("Hot", hot);
            wfp.SummaryWords = new string[] {
                "Cool",
                "Windy",
                "Humid"
            };

            //serialize
            var stream1 = new MemoryStream();
            var ser     = new DataContractJsonSerializer(typeof(WeatherForecastWithPocos));
            ser.WriteObject(stream1, wfp);

            stream1.Position = 0;
            var sr = new StreamReader(stream1);
            Console.Write("JSON form of WeatherForeCastWithPocos object: ");
            Console.WriteLine(sr.ReadToEnd());

            //deserialize
            stream1.Position = 0;
            var p2 = (WeatherForecastWithPocos)ser.ReadObject(stream1);
            Console.WriteLine($"Deserialized back, got summary={wfp.Summary}, temperature={wfp.TemperatureCelsius}");
            Console.WriteLine(wfp);
            #endregion
            Console.ReadLine();
        }