Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public virtual Task <SyncTable> LoadTableFromBatchPartInfoAsync(BatchInfo batchInfo, BatchPartInfo batchPartInfo, DataRowState?dataRowState = default)
 => LoadTableFromBatchPartInfoAsync(SyncOptions.DefaultScopeName, batchInfo, batchPartInfo, dataRowState);
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 /// <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);
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 public override Task <SyncContext> SaveTableToBatchPartInfoAsync(string scopeName, BatchInfo batchInfo, BatchPartInfo batchPartInfo, SyncTable syncTable)
 => throw new NotImplementedException();