Ejemplo n.º 1
0
        public static TriggerTemplate Create(EnumTriggerType iTriggerType)
        {
            TriggerTemplate trigTemplate = new TriggerTemplate(iTriggerType);

            string configOption = GetTriggerConfiguration(iTriggerType);

            var trigTemplateFile = ConfigurationManager.AppSettings["TriggerTemplateXML"];

            var doc = XDocument.Load(trigTemplateFile);

            trigTemplate.TriggerScriptDirective = (string)doc.Descendants("TriggerScriptDirective")
                                                  .Descendants("TriggerScript")
                                                  .First()
                                                  .Attribute("directive");

            var listOfConfiguration = doc.Descendants(configOption);



            trigTemplate.TriggerCreateSyntax = (string)listOfConfiguration.Descendants("TriggerCreateSyntax")
                                               .First()
                                               .Attribute("syntax");


            trigTemplate.TriggerBodySyntax = (string)listOfConfiguration.Descendants("TriggerBodySyntax")
                                             .First()
                                             .Attribute("syntax");


            trigTemplate.TriggerBodyCondition = (string)listOfConfiguration.Descendants("TriggerBodyCondition")
                                                .First()
                                                .Attribute("syntax");

            trigTemplate.InsertHistorytable = (string)listOfConfiguration.Descendants("Historytable")
                                              .First()
                                              .Attribute("flag")
            ;

            trigTemplate.HistoryTableInsert = (string)listOfConfiguration.Descendants("Historytable")
                                              .First()
                                              .Attribute("syntax")
            ;

            trigTemplate.HistoryTablequalifier = (string)listOfConfiguration.Descendants("Historytable")
                                                 .First()
                                                 .Attribute("qualifier")
            ;

            return(trigTemplate);
        }
Ejemplo n.º 2
0
        private static string BuildHistTableClause(DBTable tab, TriggerTemplate trig)
        {
            // Generally column list in history is replica of main table + few additions
            // Concatinate the columns list with "," sperator
            var hist_column_list = tab.ColumnList.Aggregate((a, c) => string.Join(",\n\t\t", a, c));

            // Create value list with "," sperator. Depending upon the trigger type
            // The main table values are accessed via OLD or NEW qualifier
            var value_column_list = trig.HistoryTablequalifier + "." + tab.ColumnList.Aggregate((a, c) => string.Join(",\n\t\t", a, trig.HistoryTablequalifier + "." + c));

            //Replace the history table insert for actual history table, column list and value list
            var trihistory = trig.HistoryTableInsert.Replace("{hist_table}", tab.HistoryTableName);

            trihistory = trihistory.Replace("{column_list}", hist_column_list);
            trihistory = trihistory.Replace("{value_list}", value_column_list);

            return(trihistory);
        }