Esempio n. 1
0
        public static string ExecuteInserts(QueryResult querys, RadProgressBar progressBarResult)
        {
            StringBuilder results = new StringBuilder();

            // Obtenemos la configuracion
            SettingsModel model = SettingsManager.GetXml(true);
            if (model == null)
            {
                results.AppendLine(GetTime() + " - Settings are not setted");
                return results.ToString();
            }

            // Inicializamos el manager
            DatabaseManage manager = new DatabaseManage(model);

            int currentNumberRow = 0;
            int rowsAffected = 0;

            results.AppendLine(string.Format("{0} - Starting migration", GetTime()));

            foreach (string query in querys.Querys.ToString().Split('\n'))
            {
                if (string.IsNullOrWhiteSpace(query)) continue;

                try
                {
                    manager.ExecuteCommand(query);
                    rowsAffected++;
                }
                catch (Exception ex)
                {
                    results.AppendLine(string.Format("{0} - Migrating error - Current query: {1} - Error: {2}", GetTime(), query, ex.Message));
                }

                currentNumberRow++;

                progressBarResult.BeginInvoke(new Action(() =>
                {
                    int newValue = (int)(((float)currentNumberRow / querys.NumberOfItems) * 100);
                    if (newValue > 100)
                    {
                        newValue = 100;
                    }
                    progressBarResult.Value1 = newValue;
                }));
            }
            results.AppendLine(results.Length == 0
                ? string.Format("{0} - Migrated OK - Rows inserted: {1}", GetTime(), rowsAffected)
                : string.Format("{0} - Migrated with Errors - Rows inserted: {1}", GetTime(), rowsAffected));

            return results.ToString();
        }
Esempio n. 2
0
        public static string ExecuteQuerys(QueryResult result, RadProgressBar progressBarResult)
        {
            StringBuilder results = new StringBuilder();

            // Obtenemos la configuracion
            SettingsModel model = SettingsManager.GetXml(true);
            if (model == null)
            {
                results.AppendLine(GetTime() + " - Settings are not setted");
                return results.ToString();
            }

            // Inicializamos el manager
            DatabaseManage manager = new DatabaseManage(model);

            // Si tenemos que deshabilitar constraints
            if (result.DisableConstraints)
            {
                foreach (string query in result.QuerysDisableConstraints.ToString().Split('\n'))
                {
                    if (string.IsNullOrWhiteSpace(query)) continue;

                    int startCut = query.IndexOf("EXISTS", StringComparison.Ordinal) + 7;
                    int lengthCut = query.IndexOf("DISABLE", StringComparison.Ordinal) - startCut - 1;

                    string tableName = query.Substring(startCut, lengthCut);

                    try
                    {
                        manager.ExecuteCommand(query);
                        results.AppendLine(string.Format("{0} - Disabling constraints for table {1} - Disabled", GetTime(), tableName));
                    }
                    catch (Exception ex)
                    {
                        results.AppendLine(string.Format("{0} - Disabling constraints for table {1} - Cannot be disabled - Error: {2}", GetTime(), tableName, ex.Message));
                    }
                }
            }

            int currentNumberTable = 0;

            foreach (string query in result.Querys.ToString().Split('\n'))
            {
                if (string.IsNullOrWhiteSpace(query)) continue;

                int startCut = query.IndexOf("INTO", StringComparison.Ordinal) + 5;
                int lengthCut = query.IndexOf("(", StringComparison.Ordinal) - startCut - 1;

                string tableName = query.Substring(startCut, lengthCut);
                int rowsAffected = 0;

                try
                {
                    rowsAffected = manager.ExecuteCommand(query);
                    results.AppendLine(string.Format("{0} - {1} - Migrated OK - Rows inserted: {2}", GetTime(), tableName, rowsAffected));
                }
                catch (Exception ex)
                {
                    results.AppendLine(string.Format("{0} - {1} - Migrated Error - Rows inserted: {2} - Error: {3}", GetTime(), tableName, rowsAffected, ex.Message));
                }

                currentNumberTable++;

                int table = currentNumberTable;
                progressBarResult.BeginInvoke(new Action(() =>
                {
                    int newValue = (int)(((float)table / result.NumberOfItems) * 100);
                    if (newValue > 100)
                    {
                        newValue = 100;
                    }
                    progressBarResult.Value1 = newValue;
                }));
            }

            // Si tenemos que habilitar constraints
            if (result.DisableConstraints)
            {
                foreach (string query in result.QuerysEnableConstraints.ToString().Split('\n'))
                {
                    if (string.IsNullOrWhiteSpace(query)) continue;

                    int startCut = query.IndexOf("EXISTS", StringComparison.Ordinal) + 7;
                    int lengthCut = query.IndexOf("ENABLE", StringComparison.Ordinal) - startCut - 1;

                    string tableName = query.Substring(startCut, lengthCut);

                    try
                    {
                        manager.ExecuteCommand(query);
                        results.AppendLine(string.Format("{0} - Enabling constraints for table {1} - Enabled", GetTime(), tableName));
                    }
                    catch (Exception ex)
                    {
                        results.AppendLine(string.Format("{0} - Enabling constraints for table {1} - Cannot be enabled - Error: {2}", GetTime(), tableName, ex.Message));
                    }
                }
            }

            return results.ToString();
        }
Esempio n. 3
0
        public static string ToggleContraints(IEnumerable<string> tableList, bool enable = false)
        {
            StringBuilder results = new StringBuilder();

            // Obtenemos la configuracion
            SettingsModel model = SettingsManager.GetXml(true);
            if (model == null)
            {
                results.AppendLine(GetTime() + "Settings are not setted");
                return results.ToString();
            }

            // Inicializamos el manager
            DatabaseManage manager = new DatabaseManage(model);

            foreach (string table in tableList)
            {
                string query = string.Format(enable ?
                    "ALTER TABLE IF EXISTS {0} ENABLE TRIGGER ALL" :
                    "ALTER TABLE IF EXISTS {0} DISABLE TRIGGER ALL", table);

                string mode = enable ? "Enabling" : "Disabling";
                string action = enable ? "Enabled" : "Disabled";

                if (string.IsNullOrWhiteSpace(query)) continue;

                try
                {
                    manager.ExecuteCommand(query);
                    results.AppendLine(string.Format("{0} - {1} constraints for table {2} - {3}", GetTime(), mode, table, action));
                }
                catch (Exception ex)
                {
                    results.AppendLine(string.Format("{0} - {1} constraints for table {2} - Cannot be {3} - Error: {4}", GetTime(), mode, table, action, ex.Message));
                }
            }

            return results.ToString();
        }
Esempio n. 4
0
        public static void ExecuteSequences(List<string> querys, RadProgressBar progressBarResult)
        {
            // Obtenemos la configuracion
            SettingsModel model = SettingsManager.GetXml(true);
            if (model == null)
            {
                return;
            }

            // Inicializamos el manager
            DatabaseManage manager = new DatabaseManage(model);

            int currentNumberSeq = 0;
            int numSequences = querys.Count();

            foreach (string query in querys)
            {
                if (string.IsNullOrWhiteSpace(query)) continue;

                manager.ExecuteCommand(query);

                currentNumberSeq++;
                progressBarResult.BeginInvoke(new Action(() =>
                {
                    int newValue = (int)(((float)currentNumberSeq / numSequences) * 100);
                    if (newValue > 100)
                    {
                        newValue = 100;
                    }
                    progressBarResult.Value1 = newValue;
                }));
            }
        }