Пример #1
0
 private bool SendTransactions(SyncContext context, Func <SyncContext, Message, bool> messageSink, IEnumerable <ITransactionInfo> transactionsToSend, string storeId,
                               Guid prevId)
 {
     foreach (var txn in transactionsToSend.Where(t => t.TransactionStatus == TransactionStatus.CompletedOk))
     {
         if (txn.TransactionType == TransactionType.UpdateTransaction)
         {
             var job = _serverCore.LoadTransaction(storeId, txn);
             if (job is UpdateTransaction)
             {
                 var updateJob       = job as UpdateTransaction;
                 var syncTransaction = new ClusterUpdateTransaction
                 {
                     StoreId       = storeId,
                     PrevTxnId     = prevId,
                     JobId         = txn.JobId,
                     Preconditions = updateJob.Preconditions,
                     Deletes       = updateJob.DeletePatterns,
                     Inserts       = updateJob.InsertData
                 };
                 if (!messageSink(context, syncTransaction.AsMessage()))
                 {
                     // If message sink stops accepting messages, fail the entire sync process immediately
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         else if (txn.TransactionType == TransactionType.SparqlUpdateTransaction)
         {
             var job = _serverCore.LoadTransaction(storeId, txn);
             if (job is SparqlUpdateJob)
             {
                 var sparqlJob       = job as SparqlUpdateJob;
                 var syncTransaction = new ClusterSparqlTransaction
                 {
                     StoreId    = storeId,
                     PrevTxnId  = prevId,
                     JobId      = txn.JobId,
                     Expression = sparqlJob.Expression
                 };
                 if (!messageSink(context, syncTransaction.AsMessage()))
                 {
                     // If message sink stops accepting messages, fail the entire sync process immediately
                     return(false);
                 }
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }