示例#1
0
        private static void GenerateBuildDeltaProcedures(string schema, string tableName, TrackingTable trackingTable, List <SchemaDataSet.ColumnsRow> targetTableColumns, StringBuilder sqlBuilder, AuditUpdateParameters updateParameters)
        {
            CreateUpdateDeltaTableProcedure createUpdateDeltaTableProcedureTemplate = new CreateUpdateDeltaTableProcedure(schema, tableName, trackingTable, targetTableColumns, updateParameters);
            string sql = createUpdateDeltaTableProcedureTemplate.TransformText();

            sqlBuilder.AppendLine(sql);

            SchemaDataSet schemaDataSet = updateParameters.SchemaDataSet;

            if (schemaDataSet.SchemaTables.TableExists(updateParameters.AuditingSchema, "Catalog"))
            {
                EntityConnectionStringBuilder connectionStringBuilder = Generator.GetEntityConnectionStringBuilder(updateParameters);
                AuditFrameworkEntities        context = new AuditFrameworkEntities(connectionStringBuilder.ToString());
                IOrderedQueryable <Catalog>   priorVersionTrackingTableQuery = from catalog in context.Catalogs
                                                                               where catalog.AuditedSchema.Equals(schema, StringComparison.OrdinalIgnoreCase)
                                                                               where catalog.AuditedTableName.Equals(tableName, StringComparison.OrdinalIgnoreCase)
                                                                               where catalog.Version < trackingTable.Version
                                                                               where !catalog.Archived
                                                                               orderby catalog.Version descending
                                                                               select catalog;
                foreach (Catalog catalog in priorVersionTrackingTableQuery)
                {
                    TrackingTable priorTrackingTable = TrackingTable.Parse(catalog.AuditingTableName);
                    CreateUpdateDeltaPriorTableProcedure createUpdateDeltaPriorTableProcedureTemplate = new CreateUpdateDeltaPriorTableProcedure(schema, tableName, trackingTable, priorTrackingTable, targetTableColumns, updateParameters);
                    sql = createUpdateDeltaPriorTableProcedureTemplate.TransformText();
                    sqlBuilder.AppendLine(sql);
                }
            }
        }
        internal static TrackingTable GenerateNewTrackingTable(string schema, string tableName, List <SchemaDataSet.ColumnsRow> targetTableColumns, AuditUpdateParameters updateParameters, StringBuilder sqlBuilder, Action <string, float?> reportProgress)
        {
            int           version;
            SchemaDataSet schemaDataSet = updateParameters.SchemaDataSet;

            if (schemaDataSet.SchemaTables.TableExists(updateParameters.AuditingSchema, "Catalog"))
            {
                EntityConnectionStringBuilder connectionStringBuilder = Generator.GetEntityConnectionStringBuilder(updateParameters);
                AuditFrameworkEntities        context = new AuditFrameworkEntities(connectionStringBuilder.ToString());
                var catalogQuery = from catalog in context.Catalogs
                                   where catalog.AuditedSchema.Equals(schema, StringComparison.OrdinalIgnoreCase) &&
                                   catalog.AuditedTableName.Equals(tableName, StringComparison.OrdinalIgnoreCase)
                                   orderby catalog.Version descending
                                   select catalog;
                var latestCatalog = catalogQuery.FirstOrDefault();
                if (null == latestCatalog)
                {
                    version = 0;
                }
                else
                {
                    version = latestCatalog.Version + 1;
                }
            }
            else
            {
                version = 0;
            }
            TrackingTable trackingTable     = new TrackingTable(schema, tableName, version);
            string        trackingTableName = trackingTable.ToString();

            InsertCatalog insertCatalogTemplate = new InsertCatalog(schema, tableName, version, updateParameters.AuditingSchema, trackingTableName);
            string        sql = insertCatalogTemplate.TransformText();

            sqlBuilder.AppendLine(sql);

            CreateTrackingTable createTrackingTableTemplate = new CreateTrackingTable(schema, tableName, trackingTableName, targetTableColumns, updateParameters);

            sql = createTrackingTableTemplate.TransformText();
            sqlBuilder.AppendLine(sql);

            return(trackingTable);
        }
        internal static TrackingTable GetCurrentTrackingTable(string schema, string tableName, AuditUpdateParameters updateParameters)
        {
            SchemaDataSet schemaDataSet = updateParameters.SchemaDataSet;

            if (schemaDataSet.SchemaTables.TableExists(updateParameters.AuditingSchema, "Catalog"))
            {
                EntityConnectionStringBuilder connectionStringBuilder = Generator.GetEntityConnectionStringBuilder(updateParameters);
                AuditFrameworkEntities        context = new AuditFrameworkEntities(connectionStringBuilder.ToString());
                var catalogQuery = from catalog in context.Catalogs
                                   where catalog.AuditedSchema.Equals(schema, StringComparison.OrdinalIgnoreCase) &&
                                   catalog.AuditedTableName.Equals(tableName, StringComparison.OrdinalIgnoreCase)
                                   orderby catalog.Version descending
                                   select catalog;
                Catalog catalogRow = catalogQuery.FirstOrDefault();
                if (null == catalogRow)
                {
                    return(null);
                }
                TrackingTable trackingTable = TrackingTable.Parse(catalogRow.AuditingTableName);
                return(trackingTable);
            }
            return(null);
        }