/// <summary> /// Clients can call this method to commit the transaction. You should only use this method if /// you used the begin method to create the DataServiceTransaction. /// Otherwise, the gateway will commit or rollback the transaction as necessary. /// </summary> public void Commit() { if( _rollbackOnly ) { Rollback(); return; } try { ProcessRefreshFills(); _pushMessages = new ArrayList(); for(int i = 0; i < _processedMessageBatches.Count; i++) { MessageBatch messageBatch = _processedMessageBatches[i] as MessageBatch; if( messageBatch.Messages != null && messageBatch.Messages.Count > 0 ) { DataDestination dataDestination = _dataService.GetDestination(messageBatch.IncomingMessage) as DataDestination; try { dataDestination.SequenceManager.ManageMessageBatch(messageBatch, this); } catch(Exception ex) { MessageException messageException = new MessageException(ex); ErrorMessage errorMessage = messageException.GetErrorMessage(); errorMessage.correlationId = messageBatch.IncomingMessage.messageId; errorMessage.destination = messageBatch.IncomingMessage.destination; messageBatch.Messages.Clear(); messageBatch.Messages.Add(errorMessage); } for(int j = 0; j < messageBatch.Messages.Count; j++) { IMessage message = messageBatch.Messages[j] as IMessage; if( !(message is ErrorMessage) ) _pushMessages.Add(message); } } _outgoingMessages.AddRange(messageBatch.Messages); } for(int i = 0; i < _pushMessages.Count; i++) { IMessage message = _pushMessages[i] as IMessage; DataMessage dataMessage = message as DataMessage; if( dataMessage != null ) PushMessage(GetSubscribers(message), message); } foreach(DictionaryEntry entry in _clientUpdateCollectionMessages) { UpdateCollectionMessage updateCollectionMessage = entry.Value as UpdateCollectionMessage; _outgoingMessages.Add(updateCollectionMessage); PushMessage(GetSubscribers(updateCollectionMessage), updateCollectionMessage); } foreach(DictionaryEntry entry in _updateCollectionMessages) { UpdateCollectionMessage updateCollectionMessage = entry.Value as UpdateCollectionMessage; _outgoingMessages.Add(updateCollectionMessage); PushMessage(GetSubscribers(updateCollectionMessage), updateCollectionMessage); } } finally { _transactionState = TransactionState.Committed; } }
private IList Batch(DataMessage dataMessage) { ArrayList result = new ArrayList(); IList messageBatch = dataMessage.body as IList; for(int i = 0; i < messageBatch.Count; i++) { IMessage message = messageBatch[i] as IMessage; try { if( message is UpdateCollectionMessage ) { result.Add(UpdateCollection(message as UpdateCollectionMessage, messageBatch)); } else { object obj = Invoke(message); result.Add(obj); } } catch(DataSyncException dataSyncException) { DataErrorMessage dataErrorMessage = dataSyncException.GetErrorMessage() as DataErrorMessage; dataErrorMessage.cause = message as DataMessage; dataErrorMessage.correlationId = message.messageId; dataErrorMessage.destination = message.destination; result.Add(dataErrorMessage); } catch(Exception exception) { MessageException messageException = new MessageException(exception); ErrorMessage errorMessage = messageException.GetErrorMessage(); errorMessage.correlationId = message.messageId; errorMessage.destination = message.destination; result.Add(errorMessage); } } return result; }