예제 #1
0
        public static bool ResetDatabase(string AZippedNewDatabaseData)
        {
            List <string>tables = TTableList.GetDBNames();

            TProgressTracker.InitProgressTracker(DomainManager.GClientID.ToString(),
                Catalog.GetString("Importing database"),
                tables.Count + 3);

            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                tables.Reverse();

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("deleting current data"),
                    0);

                foreach (string table in tables)
                {
                    DBAccess.GDBAccessObj.ExecuteNonQuery("DELETE FROM pub_" + table, Transaction);
                }

                if (TProgressTracker.GetCurrentState(DomainManager.GClientID.ToString()).CancelJob == true)
                {
                    TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
                    DBAccess.GDBAccessObj.RollbackTransaction();
                    return false;
                }

                TSimpleYmlParser ymlParser = new TSimpleYmlParser(PackTools.UnzipString(AZippedNewDatabaseData));

                ymlParser.ParseCaptions();

                tables.Reverse();

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("loading initial tables"),
                    1);

                // one transaction to import the user table and user permissions. otherwise logging in will not be possible if other import fails?
                bool success = true;
                success = success && LoadTable("s_user", ymlParser, Transaction);
                success = success && LoadTable("s_module", ymlParser, Transaction);
                success = success && LoadTable("s_user_module_access_permission", ymlParser, Transaction);
                success = success && LoadTable("s_system_defaults", ymlParser, Transaction);
                success = success && LoadTable("s_system_status", ymlParser, Transaction);

                // make sure we have the correct database version
                TFileVersionInfo serverExeInfo = new TFileVersionInfo(TSrvSetting.ApplicationVersion);
                DBAccess.GDBAccessObj.ExecuteNonQuery(String.Format(
                        "UPDATE PUB_s_system_defaults SET s_default_value_c = '{0}' WHERE s_default_code_c = 'CurrentDatabaseVersion'",
                        serverExeInfo.ToString()), Transaction);

                if (!success)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                    return false;
                }

                if (TProgressTracker.GetCurrentState(DomainManager.GClientID.ToString()).CancelJob == true)
                {
                    TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
                    DBAccess.GDBAccessObj.RollbackTransaction();
                    return false;
                }

                DBAccess.GDBAccessObj.CommitTransaction();

                tables.Remove("s_user");
                tables.Remove("s_module");
                tables.Remove("s_user_module_access_permission");
                tables.Remove("s_system_defaults");
                tables.Remove("s_system_status");

                FCurrencyPerLedger = new SortedList <int, string>();

                Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

                int tableCounter = 2;

                foreach (string table in tables)
                {
                    TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                        String.Format(Catalog.GetString("loading table {0}"), table),
                        tableCounter);

                    tableCounter++;

                    if (TProgressTracker.GetCurrentState(DomainManager.GClientID.ToString()).CancelJob == true)
                    {
                        TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
                        DBAccess.GDBAccessObj.RollbackTransaction();
                        return false;
                    }

                    LoadTable(table, ymlParser, Transaction);
                }

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("loading sequences"),
                    tables.Count + 5 + 3);

                // set sequences appropriately, not lagging behind the imported data
                foreach (string seq in TTableList.GetDBSequenceNames())
                {
                    LoadSequence(seq, ymlParser, Transaction);
                }

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("finish import"),
                    tables.Count + 5 + 4);

                DBAccess.GDBAccessObj.CommitTransaction();

                // reset all cached tables
                TCacheableTablesManager.GCacheableTablesManager.MarkAllCachedTableNeedsRefreshing();

                TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
            }
            catch (Exception e)
            {
                TLogging.Log("Problem in ResetDatabase: " + e.Message);
                TLogging.Log(e.StackTrace);
                DBAccess.GDBAccessObj.RollbackTransaction();
                return false;
            }

            return true;
        }
예제 #2
0
        public static bool ResetDatabase(string AZippedNewDatabaseData)
        {
            List <string>tables = TTableList.GetDBNames();
            bool SubmissionResult = false;
            TDBTransaction Transaction = null;

            string ClientID = "ClientID";

            try
            {
                ClientID = DomainManager.GClientID.ToString();
            }
            catch (Exception)
            {
            }

            TProgressTracker.InitProgressTracker(ClientID,
                Catalog.GetString("Restoring Database..."),
                tables.Count + 3);

            DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref Transaction,
                ref SubmissionResult,
                delegate
                {
                    try
                    {
                        tables.Reverse();

                        TProgressTracker.SetCurrentState(ClientID,
                            Catalog.GetString("Deleting current data..."),
                            0);

                        foreach (string table in tables)
                        {
                            DBAccess.GDBAccessObj.ExecuteNonQuery("DELETE FROM pub_" + table, Transaction);
                        }

                        if (TProgressTracker.GetCurrentState(ClientID).CancelJob == true)
                        {
                            TProgressTracker.FinishJob(ClientID);

                            // As SubmissionResult is still false, a DB Transaction Rollback will get
                            // executed automatically and the Method will be exited with return value 'false'!
                            return;
                        }

                        TSimpleYmlParser ymlParser = new TSimpleYmlParser(PackTools.UnzipString(AZippedNewDatabaseData));

                        ymlParser.ParseCaptions();

                        tables.Reverse();

                        TProgressTracker.SetCurrentState(ClientID,
                            Catalog.GetString("Loading initial tables..."),
                            1);

                        // one transaction to import the user table and user permissions. otherwise logging in will not be possible if other import fails?
                        bool success = true;
                        success = success && LoadTable("s_user", ymlParser, Transaction);
                        success = success && LoadTable("s_module", ymlParser, Transaction);
                        success = success && LoadTable("s_user_module_access_permission", ymlParser, Transaction);
                        success = success && LoadTable("s_system_defaults", ymlParser, Transaction);
                        success = success && LoadTable("s_system_status", ymlParser, Transaction);

                        // make sure we have the correct database version
                        TFileVersionInfo serverExeInfo = new TFileVersionInfo(TSrvSetting.ApplicationVersion);
                        DBAccess.GDBAccessObj.ExecuteNonQuery(String.Format(
                                "UPDATE PUB_s_system_defaults SET s_default_value_c = '{0}' WHERE s_default_code_c = 'CurrentDatabaseVersion'",
                                serverExeInfo.ToString()), Transaction);

                        if (!success)
                        {
                            // As SubmissionResult is still TSubmitChangesResult.scrError, a DB Transaction Rollback will get
                            // executed automatically and the Method will be exited with return value 'false'!
                            return;
                        }

                        if (TProgressTracker.GetCurrentState(ClientID).CancelJob == true)
                        {
                            TProgressTracker.FinishJob(ClientID);

                            // As SubmissionResult is still false, a DB Transaction Rollback will get
                            // executed automatically and the Method will be exited with return value 'false'!
                            return;
                        }

                        tables.Remove("s_user");
                        tables.Remove("s_module");
                        tables.Remove("s_user_module_access_permission");
                        tables.Remove("s_system_defaults");
                        tables.Remove("s_system_status");

                        FCurrencyPerLedger = new SortedList <int, string>();

                        int tableCounter = 2;

                        foreach (string table in tables)
                        {
                            TProgressTracker.SetCurrentState(ClientID,
                                String.Format(Catalog.GetString("Loading Table {0}..."), table),
                                tableCounter);

                            tableCounter++;

                            if (TProgressTracker.GetCurrentState(ClientID).CancelJob == true)
                            {
                                TProgressTracker.FinishJob(ClientID);

                                // As SubmissionResult is still false, a DB Transaction Rollback will get
                                // executed automatically and the Method will be exited with return value 'false'!
                                return;
                            }

                            LoadTable(table, ymlParser, Transaction);
                        }

                        TProgressTracker.SetCurrentState(ClientID,
                            Catalog.GetString("Loading Sequences..."),
                            tables.Count + 5 + 3);

                        // set sequences appropriately, not lagging behind the imported data
                        foreach (string seq in TTableList.GetDBSequenceNames())
                        {
                            LoadSequence(seq, ymlParser, Transaction);
                        }

                        TProgressTracker.SetCurrentState(ClientID,
                            Catalog.GetString("Finishing Restore..."),
                            tables.Count + 5 + 4);

                        SubmissionResult = true;

                        // reset all cached tables
                        TCacheableTablesManager.GCacheableTablesManager.MarkAllCachedTableNeedsRefreshing();

                        TProgressTracker.FinishJob(ClientID);
                    }
                    catch (Exception e)
                    {
                        TLogging.Log("Problem in ResetDatabase: " + e.ToString());
                        TLogging.LogStackTrace(TLoggingType.ToLogfile);

                        throw;
                    }
                });

            return SubmissionResult;
        }