internal async Task <SyncContext> InternalSaveTableToBatchPartInfoAsync(SyncContext context, BatchInfo batchInfo, BatchPartInfo batchPartInfo, SyncTable syncTable) { var localSerializer = new LocalJsonSerializer(); // Get full path of my batchpartinfo var fullPath = batchInfo.GetBatchPartInfoPath(batchPartInfo).FullPath; if (File.Exists(fullPath)) { File.Delete(fullPath); } var interceptorsWriting = this.interceptors.GetInterceptors <SerializingRowArgs>(); if (interceptorsWriting.Count > 0) { localSerializer.OnWritingRow(async(schemaTable, rowArray) => { var args = new SerializingRowArgs(context, schemaTable, rowArray); await this.InterceptAsync(args).ConfigureAwait(false); return(args.Result); }); } // open the file and write table header await localSerializer.OpenFileAsync(fullPath, syncTable).ConfigureAwait(false); foreach (var row in syncTable.Rows) { await localSerializer.WriteRowToFileAsync(row, syncTable).ConfigureAwait(false); } // Close file await localSerializer.CloseFileAsync(fullPath, syncTable).ConfigureAwait(false); return(context); }
public virtual Task <SyncTable> LoadTableFromBatchPartInfoAsync(BatchInfo batchInfo, BatchPartInfo batchPartInfo, DataRowState?dataRowState = default) => LoadTableFromBatchPartInfoAsync(SyncOptions.DefaultScopeName, batchInfo, batchPartInfo, dataRowState);
public virtual Task <SyncContext> SaveTableToBatchPartInfoAsync(string scopeName, BatchInfo batchInfo, BatchPartInfo batchPartInfo, SyncTable syncTable) { var context = new SyncContext(Guid.NewGuid(), scopeName); try { return(InternalSaveTableToBatchPartInfoAsync(context, batchInfo, batchPartInfo, syncTable)); } catch (Exception ex) { throw GetSyncError(context, ex); } }
/// <summary> /// Save a batch part info containing all rows from a sync table /// </summary> /// <param name="batchInfo">Represents the directory containing all batch parts and the schema associated</param> /// <param name="batchPartInfo">Represents the table to serialize in a batch part</param> /// <param name="syncTable">The table to serialize</param> public virtual Task <SyncContext> SaveTableToBatchPartInfoAsync(BatchInfo batchInfo, BatchPartInfo batchPartInfo, SyncTable syncTable) => SaveTableToBatchPartInfoAsync(SyncOptions.DefaultScopeName, batchInfo, batchPartInfo, syncTable);
/// <summary> /// Load the Batch part info in memory, in a SyncTable /// </summary> internal Task <SyncTable> InternalLoadTableFromBatchPartInfoAsync(SyncContext context, BatchInfo batchInfo, BatchPartInfo batchPartInfo, DataRowState?dataRowState = default) { if (batchInfo == null || batchInfo.SanitizedSchema == null) { return(Task.FromResult <SyncTable>(null)); } var localSerializer = new LocalJsonSerializer(); // Get full path of my batchpartinfo var fullPath = batchInfo.GetBatchPartInfoPath(batchPartInfo).FullPath; if (!File.Exists(fullPath)) { return(Task.FromResult <SyncTable>(null)); } if (batchPartInfo.Tables == null || batchPartInfo.Tables.Count() < 1) { return(Task.FromResult <SyncTable>(null)); } var schemaTable = batchInfo.SanitizedSchema.Tables[batchPartInfo.Tables[0].TableName, batchPartInfo.Tables[0].SchemaName]; var table = schemaTable.Clone(); var interceptorsReading = this.interceptors.GetInterceptors <DeserializingRowArgs>(); if (interceptorsReading.Count > 0) { localSerializer.OnReadingRow(async(schemaTable, rowString) => { var args = new DeserializingRowArgs(context, schemaTable, rowString); await this.InterceptAsync(args).ConfigureAwait(false); return(args.Result); }); } foreach (var syncRow in localSerializer.ReadRowsFromFile(fullPath, schemaTable)) { if (!dataRowState.HasValue || dataRowState == default || syncRow.RowState == dataRowState) { table.Rows.Add(syncRow); } } return(Task.FromResult(table)); }
public virtual Task <SyncTable> LoadTableFromBatchPartInfoAsync(string scopeName, BatchInfo batchInfo, BatchPartInfo batchPartInfo, DataRowState?dataRowState = default) { var context = new SyncContext(Guid.NewGuid(), scopeName); try { return(InternalLoadTableFromBatchPartInfoAsync(context, batchInfo, batchPartInfo, dataRowState)); } catch (Exception ex) { throw GetSyncError(context, ex); } }
public override Task <SyncContext> SaveTableToBatchPartInfoAsync(string scopeName, BatchInfo batchInfo, BatchPartInfo batchPartInfo, SyncTable syncTable) => throw new NotImplementedException();