public bool SyncSlave(Dictionary <string, string> lastTxn, SyncContext context, Func <SyncContext, Message, bool> messageSink) { bool syncOk = true; // Push existing transactions down the pipe foreach (var storeId in _stores) { IEnumerable <ITransactionInfo> transactionsToSend; if (lastTxn.ContainsKey(storeId)) { Guid lastJobId = Guid.Parse(lastTxn[storeId]); transactionsToSend = _serverCore.GetTransactions(storeId).SkipWhile(t => !t.JobId.Equals(lastJobId)).Skip(1); syncOk &= SendTransactions(context, messageSink, transactionsToSend, storeId, lastJobId); } else { // For all stores that aren't listed in the lastTxn dictionary // Send a create store message followed byt all transactions var createMessage = new Message("+store", storeId); if (messageSink(context, createMessage)) { syncOk &= SendTransactions(context, messageSink, _serverCore.GetTransactions(storeId), storeId, Guid.Empty); } else { syncOk = false; } } } // For all stores that are listed in lastTxn dictionary and not in our store list // send a delete store message foreach (var storeId in lastTxn.Keys.Where(s => !_stores.Contains(s))) { var deleteMessage = new Message("-store", storeId); messageSink(context, deleteMessage); } return(syncOk); }
/// <summary> /// Gets a list of transations /// </summary> /// <param name="storeName">Name of store</param> /// <param name="skip">Number of transactions to skip</param> /// <param name="take">Number of transaction to return</param> /// <returns></returns> public IEnumerable <ITransactionInfo> GetTransactions(string storeName, int skip, int take) { try { return(_serverCore.GetTransactions(storeName).Skip(skip).Take(take) .Select(t => new TransactionInfoWrapper( new TransactionInfo { Id = t.DataStartPosition, JobId = t.JobId, StartTime = t.TransactionStartTime, StoreName = storeName, #if SILVERLIGHT Status = (BrightstarTransactionStatus)((int)t.TransactionStatus), TransactionType = (BrightstarTransactionType)((int)t.TransactionType) #else Status = (TransactionStatus)((int)t.TransactionStatus), TransactionType = (TransactionType)((int)t.TransactionType) #endif // ReSharper disable RedundantEnumerableCastCall // Cast is not redundant for SILVERLIGHT builds })).Cast <ITransactionInfo>()); // ReSharper restore RedundantEnumerableCastCall }