예제 #1
0
        private void vCreateDb()
        {
            if (!DataEx.db_ServerExists)
            {
                log.Warn("Database doesn't exist!");
                if (!Directory.Exists(DataEx.dir_Database)) Directory.CreateDirectory(DataEx.dir_Database);

                log.Info("Creating database.");
                ISessionFactory sessionFactory = SessionManager.createDatabase();

                log.Info("Setting minimum pkPersonaId to 100.");
                using (var sqliteConnection = new SQLiteConnection("Data Source=\"" + DataEx.db_Server + "\";Version=3;"))
                {
                    sqliteConnection.Open();
                    SQLiteCommand insertSQL = new SQLiteCommand("INSERT INTO sqlite_sequence (name, seq) VALUES ('Personas', 99)", sqliteConnection);
                    insertSQL.ExecuteNonQuery();
                    sqliteConnection.Close();
                }


                log.Info("Inserting filler entries.");
                using (var session = sessionFactory.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    UserEntity userEntity = new UserEntity();
                    userEntity.defaultPersonaIdx = 0;

                    for (int i = 0; i < 20; i++)
                    {
                        PersonaEntity personaEntity = new PersonaEntity();
                        personaEntity.boost = 7331;
                        personaEntity.cash = 1337;
                        personaEntity.currentCarIndex = 0;
                        personaEntity.iconIndex = 27;
                        personaEntity.level = 60;
                        personaEntity.motto = "test";
                        personaEntity.name = "DEBUG Id" + (i + 100);
                        personaEntity.percentageOfLevelCompletion = 100;
                        personaEntity.rating = 8752;
                        personaEntity.reputationInLevel = 0;
                        personaEntity.reputationInTotal = 99999999;
                        personaEntity.score = 2578;

                        CarEntity carEntity = new CarEntity();
                        carEntity.baseCarId = 1816139026L;
                        carEntity.durability = 100;
                        carEntity.heatLevel = 6;
                        carEntity.carId = 1;
                        carEntity.paints = "<Paints/>";
                        carEntity.performanceParts = "<PerformanceParts/>";
                        carEntity.physicsProfileHash = 4123572107L;
                        carEntity.raceClass = CarClass.A;
                        carEntity.rating = 750;
                        carEntity.resalePrice = 123456789;
                        carEntity.skillModParts = "<SkillModParts/>";
                        carEntity.vinyls = "<Vinyls/>";
                        carEntity.visualParts = "<VisualParts/>";

                        personaEntity.addCar(carEntity);
                        session.Save(personaEntity);
                    }
                    session.Save(userEntity);
                    transaction.Commit();
                    log.Info("Database actions finalized.");
                }
            }
            else { log.Info("Database already exists, skipping creation."); }
        }
예제 #2
0
        /// <summary>
        /// Initializes the Persona class with the given persona entity.
        /// </summary>
        public Persona(PersonaEntity persona)
        {
            Id = persona.id;
            IconIndex = persona.iconIndex;
            Name = persona.name;
            Motto = persona.motto;
            Level = persona.level;
            Cash = persona.cash;
            Boost = persona.boost;
            PercentageOfLevelCompletion = persona.percentageOfLevelCompletion;
            ReputationInLevel = persona.reputationInLevel;
            ReputationInTotal = persona.reputationInTotal;
            CurrentCarIndex = persona.currentCarIndex;

            foreach (CarEntity car in persona.garage)
            {
                Cars.Add(new Car(car));
            }
            SelectedCar = cars[currentCarIndex];
        }