Example #1
0
        private static void LoadSettings(string xml)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            if (SqlServerScript == null)
            {
                SqlServerScript = ReadScripts(doc, "sqlserver");
            }
            else
            {
                UpdateMaintenanceScript(doc, SqlServerScript, "sqlserver");
            }

            if (OracleScript == null)
            {
                OracleScript = ReadScripts(doc, "oracle");
            }
            else
            {
                UpdateMaintenanceScript(doc, OracleScript, "oracle");
            }

            if (MySqlScript == null)
            {
                MySqlScript = ReadScripts(doc, "mysql");
            }
            else
            {
                UpdateMaintenanceScript(doc, MySqlScript, "mysql");
            }

            if (PostgreSqlScript == null)
            {
                PostgreSqlScript = ReadScripts(doc, "postgresql");
            }
            else
            {
                UpdateMaintenanceScript(doc, PostgreSqlScript, "postgresql");
            }

            if (FirebirdScript == null)
            {
                FirebirdScript = ReadScripts(doc, "firebird");
            }
            else
            {
                UpdateMaintenanceScript(doc, FirebirdScript, "firebird");
            }

            if (SQLiteScript == null)
            {
                SQLiteScript = ReadScripts(doc, "sqlite");
            }
            else
            {
                UpdateMaintenanceScript(doc, SQLiteScript, "sqlite");
            }
        }
Example #2
0
        private static string GetClass(string databaseType, MaintenanceScript script)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"
					using System;
					using System.Xml;
					using System.Linq;
					using System.Text;
					using System.Collections.Generic;
					using ArchAngel.Interfaces;
					using ArchAngel.Interfaces.ProjectOptions.TypeMappings;
					using ArchAngel.Interfaces.Scripting.NHibernate.Model;

					namespace Slyce.DBScriptRunner
					{{
						public class {0} : RunnerBase
						{{
							public static string GetHeaderScript(ArchAngel.Interfaces.Scripting.DatabaseChanges.IDatabase database)
							{{
								{1}
							}}

							public static string GetCreateScript(ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable table)
							{{
								{2}
							}}

							public static string GetUpdateScript(ArchAngel.Interfaces.Scripting.DatabaseChanges.IChangedTable table)
							{{
								{3}
							}}

							public static string GetDeleteScript(ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable table)
							{{
								{4}
							}}
						}}
					}}"                    ,
                            databaseType,
                            Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("xx", script.Header, "<%", "%>"),
                            Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("yy", script.Create, "<%", "%>"),
                            Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("zz", script.Update, "<%", "%>"),
                            Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("aa", script.Delete, "<%", "%>"));

            string g = Slyce.Common.Scripter.RemoveDebugSymbols(sb.ToString());

            g = g.Replace("\n          ", "\n");
            return(g);
        }
Example #3
0
        private static void UpdateMaintenanceScript(XmlDocument doc, MaintenanceScript script, string name)
        {
            MaintenanceScript userScript = ReadScripts(doc, name);

            if (userScript == null)
            {
                return;
            }

            script.Header = userScript.Header;
            script.Create = userScript.Create;
            script.Update = userScript.Update;
            script.Delete = userScript.Delete;
        }
Example #4
0
        private static XmlNode CreateScriptNode(XmlDocument doc, MaintenanceScript script, string name)
        {
            XmlNode node = doc.CreateElement(name);

            XmlNode headerNode = doc.CreateElement("header");

            headerNode.InnerText = script.Header;
            node.AppendChild(headerNode);

            //XmlNode createNode = doc.CreateElement("create");
            //createNode.InnerText = script.Create;
            //node.AppendChild(createNode);

            //XmlNode updateNode = doc.CreateElement("update");
            //updateNode.InnerText = script.Update;
            //node.AppendChild(updateNode);

            //XmlNode deleteNode = doc.CreateElement("delete");
            //deleteNode.InnerText = script.Delete;
            //node.AppendChild(deleteNode);

            return(node);
        }
Example #5
0
        private static void UpdateMaintenanceScript(XmlDocument doc, MaintenanceScript script, string name)
        {
            MaintenanceScript userScript = ReadScripts(doc, name);

            if (userScript == null)
                return;

            script.Header = userScript.Header;
            script.Create = userScript.Create;
            script.Update = userScript.Update;
            script.Delete = userScript.Delete;
        }
Example #6
0
        private static void LoadSettings(string xml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            if (SqlServerScript == null)
                SqlServerScript = ReadScripts(doc, "sqlserver");
            else
                UpdateMaintenanceScript(doc, SqlServerScript, "sqlserver");

            if (OracleScript == null)
                OracleScript = ReadScripts(doc, "oracle");
            else
                UpdateMaintenanceScript(doc, OracleScript, "oracle");

            if (MySqlScript == null)
                MySqlScript = ReadScripts(doc, "mysql");
            else
                UpdateMaintenanceScript(doc, MySqlScript, "mysql");

            if (PostgreSqlScript == null)
                PostgreSqlScript = ReadScripts(doc, "postgresql");
            else
                UpdateMaintenanceScript(doc, PostgreSqlScript, "postgresql");

            if (FirebirdScript == null)
                FirebirdScript = ReadScripts(doc, "firebird");
            else
                UpdateMaintenanceScript(doc, FirebirdScript, "firebird");

            if (SQLiteScript == null)
                SQLiteScript = ReadScripts(doc, "sqlite");
            else
                UpdateMaintenanceScript(doc, SQLiteScript, "sqlite");
        }
Example #7
0
        private static XmlNode CreateScriptNode(XmlDocument doc, MaintenanceScript script, string name)
        {
            XmlNode node = doc.CreateElement(name);

            XmlNode headerNode = doc.CreateElement("header");
            headerNode.InnerText = script.Header;
            node.AppendChild(headerNode);

            //XmlNode createNode = doc.CreateElement("create");
            //createNode.InnerText = script.Create;
            //node.AppendChild(createNode);

            //XmlNode updateNode = doc.CreateElement("update");
            //updateNode.InnerText = script.Update;
            //node.AppendChild(updateNode);

            //XmlNode deleteNode = doc.CreateElement("delete");
            //deleteNode.InnerText = script.Delete;
            //node.AppendChild(deleteNode);

            return node;
        }
Example #8
0
        private static string GetClass(string databaseType, MaintenanceScript script)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"
                    using System;
                    using System.Xml;
                    using System.Linq;
                    using System.Text;
                    using System.Collections.Generic;
                    using ArchAngel.Interfaces;
                    using ArchAngel.Interfaces.ProjectOptions.TypeMappings;
                    using ArchAngel.Interfaces.Scripting.NHibernate.Model;

                    namespace Slyce.DBScriptRunner
                    {{
                        public class {0} : RunnerBase
                        {{
                            public static string GetHeaderScript(ArchAngel.Interfaces.Scripting.DatabaseChanges.IDatabase database)
                            {{
                                {1}
                            }}

                            public static string GetCreateScript(ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable table)
                            {{
                                {2}
                            }}

                            public static string GetUpdateScript(ArchAngel.Interfaces.Scripting.DatabaseChanges.IChangedTable table)
                            {{
                                {3}
                            }}

                            public static string GetDeleteScript(ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable table)
                            {{
                                {4}
                            }}
                        }}
                    }}",
                    databaseType,
                    Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("xx", script.Header, "<%", "%>"),
                    Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("yy", script.Create, "<%", "%>"),
                    Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("zz", script.Update, "<%", "%>"),
                    Slyce.Common.Scripter.FormatFunctionBodyAsTemplate("aa", script.Delete, "<%", "%>"));

            string g = Slyce.Common.Scripter.RemoveDebugSymbols(sb.ToString());
            g = g.Replace("\n          ", "\n");
            return g;
        }