Ejemplo n.º 1
0
        /// <summary>
        /// If there is any table updates that need to be applied, calling this method will apply
        /// each update until the specifed update version
        /// </summary>
        public void MigrateTables(Version ToVersion)
        {
            // If we dont need updated, what are we doing here?
            if (ToVersion.CompareTo(LatestVersion) < 0)
            {
                return;
            }

            // Make sure version is valid
            if (!VersionList.Contains(ToVersion))
            {
                throw new ArgumentException("Supplied version does not exist as one of the migratable versions", "ToVersion");
            }

            // Get our start and stop indexies
            int start = Array.IndexOf(VersionList, Version);
            int end   = Array.IndexOf(VersionList, ToVersion);

            // Loop until we are at the specifed version
            for (int i = start; i <= end; i++)
            {
                // Apply updates till we reach the version we want
                using (DbTransaction Transaction = base.BeginTransaction())
                {
                    try
                    {
                        // Get our version string
                        Version nextVersion = VersionList[i];

                        // Gets Table Queries
                        string        resource = $"BF2Statistics.SQL.Stats.{DatabaseEngine}_{nextVersion}_update.sql";
                        List <string> Queries  = SqlFile.ExtractQueries(Program.GetResourceFileLines(resource));

                        // Delete old version data
                        base.Execute("DELETE FROM _version");

                        // Insert rows
                        foreach (string Query in Queries)
                        {
                            base.Execute(Query);
                        }

                        // Insert New Data
                        base.Execute("INSERT INTO _version(dbver, dbdate) VALUES (@P0, @P1)", nextVersion, DateTime.UtcNow.ToUnixTimestamp());
                        Transaction.Commit();
                    }
                    catch
                    {
                        Transaction.Rollback();
                        throw;
                    }
                }

                // Set new version
                GetTablesVersion();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// On a new Mysql database, this method will create the default tables
        /// </summary>
        private void CreateMysqlTables(IProgress <TaskProgressUpdate> TaskProgress)
        {
            // Show Progress Form
            if (TaskProgress != null)
            {
                TaskProgress.Report(new TaskProgressUpdate("Creating Stats Tables", "Creating Bf2Stats Mysql Tables..."));
            }

            // Gets Table Queries
            string[]      SQL     = Program.GetResourceFileLines("BF2Statistics.SQL.MySQL.Stats.sql");
            List <string> Queries = SqlFile.ExtractQueries(SQL);

            // Start Transaction
            using (DbTransaction Transaction = BeginTransaction())
            {
                // Attempt to do the transaction
                try
                {
                    // Create Tables
                    foreach (string Query in Queries)
                    {
                        base.Execute(Query);
                    }

                    // Commit
                    Transaction.Commit();
                }
                catch
                {
                    Transaction.Rollback();
                    throw;
                }
            }

            // Update status
            if (TaskProgress != null)
            {
                TaskProgress.Report(new TaskProgressUpdate("Inserting Ip2Nation Data"));
            }

            // WE STILL INSTALL ip2Nation DATA to stay compatible with the web ASP
            SQL     = Program.GetResourceFileLines("BF2Statistics.SQL.Ip2nation.sql");
            Queries = SqlFile.ExtractQueries(SQL);

            // Insert Ip2Nation data
            using (DbTransaction Transaction = BeginTransaction())
            {
                // Attempt to do the transaction
                try
                {
                    // Insert rows
                    foreach (string Query in Queries)
                    {
                        base.Execute(Query);
                    }

                    // Commit
                    Transaction.Commit();
                }
                catch
                {
                    Transaction.Rollback();
                    throw;
                }
            }
        }