/// <summary> /// Create a new BPI, and serialize the changeset if not in memory /// </summary> internal static BatchPartInfo CreateBatchPartInfo(int batchIndex, DmSet changesSet, string fileName, Boolean isLastBatch, Boolean inMemory) { BatchPartInfo bpi = null; // Create a batch part // The batch part creation process will serialize the changesSet to the disk if (!inMemory) { // Serialize the file ! BatchPart.Serialize(new DmSetSurrogate(changesSet), fileName); bpi = new BatchPartInfo { FileName = fileName }; } else { bpi = new BatchPartInfo { Set = changesSet }; } bpi.Index = batchIndex; bpi.IsLastBatch = isLastBatch; // Even if the set is empty (serialized on disk), we should retain the tables names bpi.Tables = changesSet.Tables.Select(t => t.TableName).ToArray(); return(bpi); }
/// <summary> /// Deserialize the BPI WITHOUT the DmSet /// </summary> public static BatchPartInfo DeserializeFromDmSet(DmSet set) { if (set == null) { return(null); } if (!set.Tables.Contains("DotmimSync__BatchPartsInfo")) { return(null); } var dmRow = set.Tables["DotmimSync__BatchPartsInfo"].Rows[0]; var bpi = new BatchPartInfo(); bpi.Index = (int)dmRow["Index"]; bpi.FileName = dmRow["FileName"] as string; bpi.IsLastBatch = (Boolean)dmRow["IsLastBatch"]; if (dmRow["Tables"] != null) { var stringTables = dmRow["Tables"] as string; var tables = stringTables.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); bpi.Tables = tables; } return(bpi); }
/// <summary> /// Create a new BPI, and serialize the changeset if not in memory /// </summary> internal static BatchPartInfo CreateBatchPartInfo(int batchIndex, SyncSet set, string fileName, string directoryFullPath, bool isLastBatch) { BatchPartInfo bpi = null; // Create a batch part // The batch part creation process will serialize the changesSet to the disk // Serialize the file ! Serialize(set.GetContainerSet(), fileName, directoryFullPath); bpi = new BatchPartInfo { FileName = fileName }; bpi.Index = batchIndex; bpi.IsLastBatch = isLastBatch; // Even if the set is empty (serialized on disk), we should retain the tables names if (set != null) { bpi.Tables = set.Tables.Select(t => new BatchPartTableInfo(t.TableName, t.SchemaName)).ToArray(); } return(bpi); }
/// <summary> /// Create a new BPI, and serialize the changeset if not in memory /// </summary> internal static async Task <BatchPartInfo> CreateBatchPartInfoAsync(int batchIndex, SyncSet set, string fileName, string directoryFullPath, bool isLastBatch, BaseOrchestrator orchestrator = null) { BatchPartInfo bpi = null; // Create a batch part // The batch part creation process will serialize the changesSet to the disk // Serialize the file ! await SerializeAsync(set.GetContainerSet(), fileName, directoryFullPath, orchestrator); bpi = new BatchPartInfo { FileName = fileName }; bpi.Index = batchIndex; bpi.IsLastBatch = isLastBatch; // Even if the set is empty (serialized on disk), we should retain the tables names if (set != null) { bpi.Tables = set.Tables.Select(t => new BatchPartTableInfo(t.TableName, t.SchemaName, t.Rows.Count)).ToArray(); bpi.RowsCount = set.Tables.Sum(t => t.Rows.Count); } return(bpi); }
/// <summary> /// Add changes to batch info. /// </summary> public async Task AddChangesAsync(SyncSet changes, int batchIndex = 0, bool isLastBatch = true, BaseOrchestrator orchestrator = null) { if (this.InMemory) { this.InMemoryData = changes; } else { var bpId = this.GenerateNewFileName(batchIndex.ToString()); //var fileName = Path.Combine(this.GetDirectoryFullPath(), bpId); var bpi = await BatchPartInfo.CreateBatchPartInfoAsync(batchIndex, changes, bpId, GetDirectoryFullPath(), isLastBatch, orchestrator).ConfigureAwait(false); // add the batchpartinfo tp the current batchinfo this.BatchPartsInfo.Add(bpi); } }
/// <summary> /// Add changes to batch info. /// </summary> public void AddChanges(SyncSet changes, int batchIndex = 0, bool isLastBatch = true) { if (this.InMemory) { this.InMemoryData = changes; } else { var bpId = this.GenerateNewFileName(batchIndex.ToString()); //var fileName = Path.Combine(this.GetDirectoryFullPath(), bpId); var bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changes, bpId, GetDirectoryFullPath(), isLastBatch); // add the batchpartinfo tp the current batchinfo this.BatchPartsInfo.Add(bpi); } }
/// <summary> /// Add changes to batch info. /// </summary> public async Task AddChangesAsync(SyncSet changes, int batchIndex = 0, bool isLastBatch = true, ISerializerFactory serializerFactory = default, BaseOrchestrator orchestrator = null) { if (this.InMemory) { this.SerializerFactoryKey = null; this.InMemoryData = changes; } else { this.SerializerFactoryKey = serializerFactory.Key; var bpId = GenerateNewFileName(batchIndex.ToString()); var bpi = await BatchPartInfo.CreateBatchPartInfoAsync(batchIndex, changes, bpId, GetDirectoryFullPath(), isLastBatch, serializerFactory, orchestrator).ConfigureAwait(false); // add the batchpartinfo tp the current batchinfo this.BatchPartsInfo.Add(bpi); } }
public static BatchPartInfo NewBatchPartInfo(string batchPartFileName, string tableName, string schemaName, int rowsCount, int batchIndex) { var bpi = new BatchPartInfo { FileName = batchPartFileName }; // Create the info on the batch part BatchPartTableInfo tableInfo = new BatchPartTableInfo { TableName = tableName, SchemaName = schemaName, RowsCount = rowsCount }; bpi.Tables = new BatchPartTableInfo[] { tableInfo }; bpi.RowsCount = rowsCount; bpi.IsLastBatch = false; bpi.Index = batchIndex; return(bpi); }
/// <summary> /// Generate a new BatchPartInfo and add it to the current batchInfo /// </summary> internal BatchPartInfo GenerateBatchInfo(int batchIndex, DmSet changesSet, string batchDirectory) { var hasData = true; if (changesSet == null || changesSet.Tables.Count == 0) { hasData = false; } else { hasData = changesSet.Tables.Any(t => t.Rows.Count > 0); } if (!hasData) { return(null); } BatchPartInfo bpi = null; // Create a batch part // The batch part creation process will serialize the changesSet to the disk if (!InMemory) { var bpId = GenerateNewFileName(batchIndex.ToString()); var fileName = Path.Combine(batchDirectory, this.Directory, bpId); bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changesSet, fileName, false, false); } else { bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changesSet, null, true, true); } // add the batchpartinfo tp the current batchinfo this.BatchPartsInfo.Add(bpi); return(bpi); }
/// <summary> /// Generate a new BatchPartInfo and add it to the current batchInfo /// </summary> internal BatchPartInfo GenerateBatchInfo(int batchIndex, DmSet changesSet, string batchDirectory) { var hasData = true; if (changesSet == null || changesSet.Tables.Count == 0) { hasData = false; } else { hasData = changesSet.Tables.Any(t => t.Rows.Count > 0); } // Sometimes we can have a last BPI without any data, but we need to generate it to be able to have the IsLast batch property //if (!hasData) // return null; BatchPartInfo bpi = null; // Create a batch part // The batch part creation process will serialize the changesSet to the disk if (!InMemory) { var bpId = GenerateNewFileName(batchIndex.ToString()); var fileName = Path.Combine(batchDirectory, this.Directory, bpId); bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changesSet, fileName, false, false); } else { bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changesSet, null, true, true); } // add the batchpartinfo tp the current batchinfo this.BatchPartsInfo.Add(bpi); return(bpi); }
public (string FullPath, string FileName) GetBatchPartInfoPath(BatchPartInfo batchPartInfo) { if (BatchPartsInfo == null) { return(default, default);