Пример #1
0
        private TableSchema(
            string tableName,
            Column[] columns,
            TableVersion sourceVersion,
            TableVersion targetVersion,
            string targetStatePath,
            int? batchSize
            )
        {
            var buffername = tableName.Replace("[", "").Replace("]", "");

            TableName = tableName;
            SyncNewOrUpdatedTableName = $"sync.[{buffername}_{Guid.NewGuid()}]";
            SyncDeletedTableName = $"sync.[{buffername}_{Guid.NewGuid()}]";
            Columns = columns;
            SourceVersion = sourceVersion;
            TargetVersion = targetVersion;

            CreateNewOrUpdatedSyncTableStatement = this.GetCreateNewOrUpdatedSyncTableStatement();
            CreateDeletedSyncTableStatement = this.GetCreateDeletedSyncTableStatement();

            SourceNewOrUpdatedSelectStatment = this.GetNewOrUpdatedAtSourceSelectStatment();
            SourceDeletedSelectStatement = this.GetDeletedAtSourceSelectStatement();
            MergeNewOrUpdateStatement = this.GetNewOrUpdatedMergeStatement();
            DeleteStatement = this.GetDeleteStatement();
            DropNewOrUpdatedTableStatment = SyncNewOrUpdatedTableName.GetDropStatment();
            DropDeletedTableStatment = SyncDeletedTableName.GetDropStatment();
            TargetStatePath = targetStatePath;
            BatchSize = batchSize ?? 1000;
        }
Пример #2
0
        private TableSchema(
            string tableName,
            Column[] columns,
            TableVersion sourceVersion,
            TableVersion targetVersion,
            string targetStatePath,
            int? batchSize
            )
        {
            TableName = tableName;
            SyncTableName = string.Format(
                "sync.[{0}_{1}]",
                tableName,
                Guid.NewGuid()
                );
            Columns = columns;
            SourceVersion = sourceVersion;
            TargetVersion = targetVersion;

            CreateSyncTableStatement = this.GetCreateSyncTableStatement();
            SourceSelectStatment = this.GetSourceSelectStatment();
            MergeStatement = this.GetMergeStatement();
            DropStatment = this.GetDropStatment();
            TargetStatePath = targetStatePath;
            BatchSize = batchSize ?? 1000;
        }
Пример #3
0
        public static TableVersion GetTargetVersion(
            this SqlConnection conn,
            string tableName,
            out string targetStatePath
            )
        {
            if (!SyncStateDirectory.Exists)
                SyncStateDirectory.Create();

            targetStatePath = Path.Combine(
                SyncStateDirectory.FullName,
                Uri.EscapeDataString(
                    String.Concat(
                        conn.DataSource,
                        "_",
                        conn.Database,
                        "_",
                        tableName,
                        ".hron"
                        )
                    )
                );


            TableVersion targetVersion;
            HRONObjectParseError[] errors;
            if (
                File.Exists(targetStatePath) &&
                HRONSerializer.TryParseObject(
                    0,
                    File.ReadAllText(targetStatePath, Encoding.UTF8).ReadLines(),
                    out targetVersion,
                    out errors
                    ))
                return targetVersion;

            var tableVersion = new TableVersion
            {
                CurrentVersion = -1,
                MinValidVersion = -1
            };
            File.WriteAllText(
                targetStatePath,
                HRONSerializer.ObjectAsString(
                    tableVersion
                    ),
                Encoding.UTF8
                );
            return tableVersion;
        }
Пример #4
0
 protected bool Equals(TableVersion other)
 {
     return StringComparer.OrdinalIgnoreCase.Equals(TableName, other.TableName) &&
            CurrentVersion == other.CurrentVersion &&
            MinValidVersion == other.MinValidVersion;
 }
Пример #5
0
 protected bool Equals(TableVersion other)
 {
     return(StringComparer.OrdinalIgnoreCase.Equals(TableName, other.TableName) &&
            CurrentVersion == other.CurrentVersion &&
            MinValidVersion == other.MinValidVersion);
 }