示例#1
0
        /// <summary>
        /// Lädt die Einstellungen im JSON-Format
        /// </summary>
        public static async void LoadSettings()
        {
            try
            {
                // Load Zip
                var streams = await ZipFileHelper.LoadZipFile(_ZipFileName);

                DataContractJsonSerializer ser;

                // States
                try
                {
                    streams[_StatesFileName].Position = 0;
                    ser    = new DataContractJsonSerializer(typeof(StateCollection));
                    States = (StateCollection)ser.ReadObject(streams[_StatesFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read States");
                    SimpleLog.Log(e);
                }

                // Stadiums
                try
                {
                    streams[_StadiumsFileName].Position = 0;
                    ser      = new DataContractJsonSerializer(typeof(StadiumCollection));
                    Stadiums = (StadiumCollection)ser.ReadObject(streams[_StadiumsFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read Stadiums");
                    SimpleLog.Log(e);
                }

                // FootballTeams
                try
                {
                    streams[_FootballTeamsFileName].Position = 0;
                    ser           = new DataContractJsonSerializer(typeof(FootballTeamCollection));
                    FootballTeams = (FootballTeamCollection)ser.ReadObject(streams[_FootballTeamsFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read FootballTeams");
                    SimpleLog.Log(e);
                }

                // LeagueWikiTemplates
                try
                {
                    streams[_LeagueWikiTemplatesFileName].Position = 0;
                    ser = new DataContractJsonSerializer(typeof(LeagueWikiTemplateCollection));
                    LeageWikiTemplates = (LeagueWikiTemplateCollection)ser.ReadObject(streams[_LeagueWikiTemplatesFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read LeagueWikiTemplates");
                    SimpleLog.Log(e);
                }

                // RacingDrivers
                try
                {
                    streams[_RacingDriversFileName].Position = 0;
                    ser           = new DataContractJsonSerializer(typeof(RacingDriverCollection));
                    RacingDrivers = (RacingDriverCollection)ser.ReadObject(streams[_RacingDriversFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read RacingDrivers");
                    SimpleLog.Log(e);
                }

                // RacingTeams
                try
                {
                    streams[_RacingTeamsFileName].Position = 0;
                    ser         = new DataContractJsonSerializer(typeof(RacingTeamCollection));
                    RacingTeams = (RacingTeamCollection)ser.ReadObject(streams[_RacingTeamsFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read RacingDrivers");
                    SimpleLog.Log(e);
                }

                // WikiStrings
                try
                {
                    streams[_WikiStringsFileName].Position = 0;
                    ser         = new DataContractJsonSerializer(typeof(WikiStrings));
                    WikiStrings = (WikiStrings)ser.ReadObject(streams[_WikiStringsFileName]);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not read WikiStrings");
                    SimpleLog.Log(e);
                }
            }
            catch (Exception e)
            {
                SimpleLog.Error(String.Format("{0} {1}", "Could not read database", _ZipFileName));
                SimpleLog.Log(e);
            }
        }
示例#2
0
        /// <summary>
        /// Speichert die aktuellen Einstellungen im JSON-Format
        /// </summary>
        public static void SaveSettings()
        {
            try
            {
                var streams = new Dictionary <string, MemoryStream>();
                DataContractJsonSerializer ser;

                // States
                try
                {
                    var statesStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(StateCollection));
                    ser.WriteObject(statesStream, States);
                    streams.Add(_StatesFileName, statesStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize State List");
                    SimpleLog.Log(e);
                }

                // Stadiums
                try
                {
                    var stadiumsStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(StadiumCollection));
                    ser.WriteObject(stadiumsStream, Stadiums);
                    streams.Add(_StadiumsFileName, stadiumsStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize Stadium List");
                    SimpleLog.Log(e);
                }

                // FootballTeams
                try
                {
                    var footbalTeamStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(FootballTeamCollection));
                    ser.WriteObject(footbalTeamStream, FootballTeams);
                    streams.Add(_FootballTeamsFileName, footbalTeamStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize FootballTeam List");
                    SimpleLog.Log(e);
                }

                // LeagueWikiTemplates
                try
                {
                    var leagueWikiTemplateStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(LeagueWikiTemplateCollection));
                    ser.WriteObject(leagueWikiTemplateStream, LeageWikiTemplates);
                    streams.Add(_LeagueWikiTemplatesFileName, leagueWikiTemplateStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize LeagueWikiTemplate List");
                    SimpleLog.Log(e);
                }

                // RacingDrivers
                try
                {
                    var racingDriversStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(RacingDriverCollection));
                    ser.WriteObject(racingDriversStream, RacingDrivers);
                    streams.Add(_RacingDriversFileName, racingDriversStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize RacingDriver List");
                    SimpleLog.Log(e);
                }

                // RacingTeams
                try
                {
                    var racingTeamsStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(RacingTeamCollection));
                    ser.WriteObject(racingTeamsStream, RacingTeams);
                    streams.Add(_RacingTeamsFileName, racingTeamsStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize RacingDriver List");
                    SimpleLog.Log(e);
                }

                // WikiStrings
                try
                {
                    var wikiStringsStream = new MemoryStream();
                    ser = new DataContractJsonSerializer(typeof(WikiStrings));
                    ser.WriteObject(wikiStringsStream, WikiStrings);
                    streams.Add(_WikiStringsFileName, wikiStringsStream);
                }
                catch (Exception e)
                {
                    SimpleLog.Error("Could not serialize WikiStrings");
                    SimpleLog.Log(e);
                }


                // Save as Zip
                ZipFileHelper.SaveZipFile(_ZipFileName, streams);
            }
            catch (Exception e)
            {
                SimpleLog.Error(String.Format("{0} {1}", "Error saving Settings to", _ZipFileName));
                SimpleLog.Log(e);
            }
        }