/// <summary> /// Send an update event to clients subscribed to this message. Note that this method does not send /// the change to the adapter/assembler - it assumes that the changes have already been applied /// or are being applied. It only updates the clients with the new version of this data. /// /// You must supply a destination parameter and a new version of the object. If you supply a /// non-null previous version, this object is used to detect conflicts on the client in case /// the client's version of the data does not match the previous version. You may also supply /// a list of property names that have changed as a hint to the client to indicate which properties /// should be checked for conflicts and updated. If you supply null for the changes, all /// properties on the client are updated. These property names do not accept any kind of dot /// notation to specify that a property of a property has changed. Only top level property /// names are allowed. /// </summary> /// <param name="destination">Name of the Data Management Services destination that is managing the item you want to update.</param> /// <param name="newVersion">New version of the item to update. The identity of the item is used to determine which item to update.</param> /// <param name="previousVersion">If not null, this contains a version of the item you intend to update. The client can detect a conflict if its version does not match the previousVersion. If you specify the value as null, a conflict is only detected if the client has pending changes for the item being updated.</param> /// <param name="changes">Array of property names which are to be updated. You can provide a null value to indicate that all property values may have changed.</param> public void UpdateItem(string destination, object newVersion, object previousVersion, string[] changes) { DataMessage dataMessage = new DataMessage(); DataDestination dataDestination = _dataService.GetDestination(destination) as DataDestination; object[] body = new object[3]; body[0] = changes; body[2] = newVersion; body[1] = previousVersion; dataMessage.operation = DataMessage.UpdateOperation; dataMessage.body = body; dataMessage.destination = destination; if (_clientId != null) { dataMessage.clientId = _clientId; } else { dataMessage.clientId = "srv:" + Guid.NewGuid().ToString("D"); } dataMessage.identity = Identity.GetIdentity(newVersion, dataDestination); dataMessage.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString(); System.Threading.Interlocked.Increment(ref _idCounter); ArrayList messages = new ArrayList(1); messages.Add(dataMessage); MessageBatch messageBatch = new MessageBatch(dataMessage, messages); _processedMessageBatches.Add(messageBatch); }
private MessageBatch ServiceBatch(IMessage message, ArrayList messages) { //Send a DataMessage.BatchedOperation to the specific adapter DataMessage dataMessage = messages[0] as DataMessage; DataMessage adapterDataMessage = null; if (messages.Count == 1 && dataMessage.operation == DataMessage.BatchedOperation) { adapterDataMessage = dataMessage; } else { adapterDataMessage = new DataMessage(); adapterDataMessage.destination = dataMessage.destination; adapterDataMessage.operation = DataMessage.BatchedOperation; adapterDataMessage.body = messages; adapterDataMessage.headers = message.headers; adapterDataMessage.clientId = message.clientId; } DataDestination dataDestination = GetDestination(dataMessage) as DataDestination; IList result = dataDestination.ServiceAdapter.Invoke(adapterDataMessage) as IList; MessageBatch messageBatch = new MessageBatch(adapterDataMessage, result); return(messageBatch); }
/// <summary> /// This version of the deleteItem method does not provide for conflict detection if the item has been modified before the delete occurs; it is deleted. /// </summary> /// <param name="destination">Name of the destination containing the item to be deleted.</param> /// <param name="identity">A Hashtable containing entries for each of the id properties for this item (the key is the id property name, the value is its value).</param> public void DeleteItemWithId(string destination, Hashtable identity) { DataMessage dataMessage = new DataMessage(); DataDestination dataDestination = _dataService.GetDestination(destination) as DataDestination; dataMessage.operation = DataMessage.DeleteOperation; dataMessage.body = null; dataMessage.destination = destination; if (_clientId != null) { dataMessage.clientId = _clientId; } else { dataMessage.clientId = "srv:" + Guid.NewGuid().ToString("D"); } dataMessage.identity = identity; dataMessage.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString(); System.Threading.Interlocked.Increment(ref _idCounter); ArrayList messages = new ArrayList(1); messages.Add(dataMessage); MessageBatch messageBatch = new MessageBatch(dataMessage, messages); AddProcessedMessageBatch(messageBatch); }
public void UpdateItem(string destination, object newVersion, object previousVersion, string[] changes) { DataMessage message = new DataMessage(); DataDestination destination2 = this._dataService.GetDestination(destination) as DataDestination; object[] objArray = new object[3]; objArray[0] = changes; objArray[2] = newVersion; objArray[1] = previousVersion; message.operation = 3; message.body = objArray; message.destination = destination; if (this._clientId != null) { message.clientId = this._clientId; } else { message.clientId = "srv:" + Guid.NewGuid().ToString("D"); } message.identity = Identity.GetIdentity(newVersion, destination2); message.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString(); Interlocked.Increment(ref _idCounter); ArrayList messages = new ArrayList(1); messages.Add(message); MessageBatch batch = new MessageBatch(message, messages); this._processedMessageBatches.Add(batch); }
public void DeleteItem(string destination, object item) { DataMessage message = new DataMessage(); DataDestination destination2 = this._dataService.GetDestination(destination) as DataDestination; message.operation = 4; message.body = item; message.destination = destination; if (this._clientId != null) { message.clientId = this._clientId; } else { message.clientId = "srv:" + Guid.NewGuid().ToString("D"); } message.identity = Identity.GetIdentity(item, destination2); message.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString(); Interlocked.Increment(ref _idCounter); ArrayList messages = new ArrayList(1); messages.Add(message); MessageBatch messageBatch = new MessageBatch(message, messages); this.AddProcessedMessageBatch(messageBatch); }
public void ManageMessageBatch(MessageBatch messageBatch, DataServiceTransaction dataServiceTransaction) { DataMessage dataMessage = messageBatch.IncomingMessage; //Manage existing sequences for (int j = 0; j < messageBatch.Messages.Count; j++) { IMessage message = messageBatch.Messages[j] as IMessage; if (message is UpdateCollectionMessage) { UpdateCollectionMessage updateCollectionMessage = message as UpdateCollectionMessage; //update collections, fix sequences IList fillParameters = updateCollectionMessage.collectionId as IList; Sequence sequence = _dataDestination.SequenceManager.GetSequence(fillParameters); if (sequence != null) { ApplyUpdateCollectionMessage(sequence, updateCollectionMessage); } } } for (int j = 0; j < messageBatch.Messages.Count; j++) { DataMessage dataMessageTmp = messageBatch.Messages[j] as DataMessage; if (dataMessageTmp != null) { switch (dataMessageTmp.operation) { case DataMessage.CreateAndSequenceOperation: { //dataMessage.identity contains identity //dataMessage.body contains the object IList result = new ArrayList(); result.Add(dataMessageTmp.body); //Will generate an UpdateCollectionMessage too (server adding item to collection) Sequence sequence = this.CreateSequence(dataMessageTmp.clientId as string, result, null, dataServiceTransaction); SequencedMessage sequencedMessage = this.GetSequencedMessage(dataMessageTmp, sequence); messageBatch.Messages[j] = sequencedMessage; } break; } } } for (int j = 0; j < messageBatch.Messages.Count; j++) { if (messageBatch.Messages[j] is DataMessage) { DataMessage dataMessageTmp = messageBatch.Messages[j] as DataMessage; SyncSequenceChanges(dataMessageTmp, dataServiceTransaction); } if (messageBatch.Messages[j] is SequencedMessage) { SequencedMessage sequencedMessage = messageBatch.Messages[j] as SequencedMessage; DataMessage dataMessageTmp = sequencedMessage.dataMessage; SyncSequenceChanges(dataMessageTmp, dataServiceTransaction); } } }
private AcknowledgeMessage ExecuteMultiBatchOperation(IMessage message) { //May contain multiple batched, create, update or delete operations that involve //more than one destination, that is, more than one remote adapter AcknowledgeMessage responseMessage = null; DataMessage dataMessage = message as DataMessage; IList messages = dataMessage.body as IList; DataServiceTransaction dataServiceTransaction = DataServiceTransaction.Begin(this); dataServiceTransaction.ClientId = message.clientId as string; //correlate al generated messages dataServiceTransaction.CorrelationId = message.messageId; string currentDestination = null; ArrayList currentMessageBatch = new ArrayList(); for (int i = 0; i < messages.Count; i++) { DataMessage batchMessage = messages[i] as DataMessage; string destination = batchMessage.destination; DataDestination dataDestination = GetDestination(batchMessage) as DataDestination; if (currentDestination != null && destination != currentDestination && currentMessageBatch.Count > 0) { MessageBatch messageBatch = ServiceBatch(message, currentMessageBatch); dataServiceTransaction.AddProcessedMessageBatch(messageBatch); currentMessageBatch = new ArrayList(); } currentMessageBatch.Add(batchMessage); currentDestination = destination; if (batchMessage is UpdateCollectionMessage) { dataServiceTransaction.AddClientUpdateCollection(batchMessage as UpdateCollectionMessage); } } if (currentMessageBatch.Count > 0) { MessageBatch messageBatch = ServiceBatch(message, currentMessageBatch); dataServiceTransaction.AddProcessedMessageBatch(messageBatch); } dataServiceTransaction.Commit(); IList outgoingMessages = dataServiceTransaction.GetOutgoingMessages(); responseMessage = new AcknowledgeMessage(); object[] result = new object[outgoingMessages.Count]; outgoingMessages.CopyTo(result, 0); responseMessage.body = result; //outgoingMessages.ToArray(typeof(object)); return(responseMessage); }
public void ManageMessageBatch(MessageBatch messageBatch, DataServiceTransaction dataServiceTransaction) { int num; Sequence sequence; DataMessage dataMessage; SequencedMessage sequencedMessage; DataMessage incomingMessage = messageBatch.IncomingMessage; for (num = 0; num < messageBatch.Messages.Count; num++) { IMessage message2 = messageBatch.Messages[num] as IMessage; if (message2 is UpdateCollectionMessage) { UpdateCollectionMessage updateCollectionMessage = message2 as UpdateCollectionMessage; IList collectionId = updateCollectionMessage.collectionId; sequence = this._dataDestination.SequenceManager.GetSequence(collectionId); if (sequence != null) { this.ApplyUpdateCollectionMessage(sequence, updateCollectionMessage); } } } for (num = 0; num < messageBatch.Messages.Count; num++) { dataMessage = messageBatch.Messages[num] as DataMessage; if ((dataMessage != null) && (dataMessage.operation == 11)) { IList result = new ArrayList(); result.Add(dataMessage.body); sequence = this.CreateSequence(dataMessage.clientId as string, result, null, dataServiceTransaction); sequencedMessage = this.GetSequencedMessage(dataMessage, sequence); messageBatch.Messages[num] = sequencedMessage; } } for (num = 0; num < messageBatch.Messages.Count; num++) { if (messageBatch.Messages[num] is DataMessage) { dataMessage = messageBatch.Messages[num] as DataMessage; this.SyncSequenceChanges(dataMessage, dataServiceTransaction); } if (messageBatch.Messages[num] is SequencedMessage) { sequencedMessage = messageBatch.Messages[num] as SequencedMessage; dataMessage = sequencedMessage.dataMessage; this.SyncSequenceChanges(dataMessage, dataServiceTransaction); } } }
private MessageBatch ServiceBatch(IMessage message, ArrayList messages) { //Send a DataMessage.BatchedOperation to the specific adapter DataMessage dataMessage = messages[0] as DataMessage; DataMessage adapterDataMessage = null; if( messages.Count == 1 && dataMessage.operation == DataMessage.BatchedOperation ) adapterDataMessage = dataMessage; else { adapterDataMessage = new DataMessage(); adapterDataMessage.destination = dataMessage.destination; adapterDataMessage.operation = DataMessage.BatchedOperation; adapterDataMessage.body = messages; adapterDataMessage.headers = message.headers; adapterDataMessage.clientId = message.clientId; } DataDestination dataDestination = GetDestination(dataMessage) as DataDestination; IList result = dataDestination.ServiceAdapter.Invoke(adapterDataMessage) as IList; MessageBatch messageBatch = new MessageBatch(adapterDataMessage, result); return messageBatch; }
internal void AddProcessedMessageBatch(MessageBatch messageBatch) { _processedMessageBatches.Add(messageBatch); }
/// <summary> /// This version of the deleteItem method does not provide for conflict detection if the item has been modified before the delete occurs; it is deleted. /// </summary> /// <param name="destination">Name of the destination containing the item to be deleted.</param> /// <param name="identity">A Hashtable containing entries for each of the id properties for this item (the key is the id property name, the value is its value).</param> public void DeleteItemWithId(string destination, Hashtable identity) { DataMessage dataMessage = new DataMessage(); DataDestination dataDestination = _dataService.GetDestination(destination) as DataDestination; dataMessage.operation = DataMessage.DeleteOperation; dataMessage.body = null; dataMessage.destination = destination; if (_clientId != null) dataMessage.clientId = _clientId; else dataMessage.clientId = "srv:" + Guid.NewGuid().ToString("D"); dataMessage.identity = identity; dataMessage.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString(); System.Threading.Interlocked.Increment(ref _idCounter); ArrayList messages = new ArrayList(1); messages.Add(dataMessage); MessageBatch messageBatch = new MessageBatch(dataMessage, messages); AddProcessedMessageBatch(messageBatch); }
/// <summary> /// Send an update event to clients subscribed to this message. Note that this method does not send /// the change to the adapter/assembler - it assumes that the changes have already been applied /// or are being applied. It only updates the clients with the new version of this data. /// /// You must supply a destination parameter and a new version of the object. If you supply a /// non-null previous version, this object is used to detect conflicts on the client in case /// the client's version of the data does not match the previous version. You may also supply /// a list of property names that have changed as a hint to the client to indicate which properties /// should be checked for conflicts and updated. If you supply null for the changes, all /// properties on the client are updated. These property names do not accept any kind of dot /// notation to specify that a property of a property has changed. Only top level property /// names are allowed. /// </summary> /// <param name="destination">Name of the Data Management Services destination that is managing the item you want to update.</param> /// <param name="newVersion">New version of the item to update. The identity of the item is used to determine which item to update.</param> /// <param name="previousVersion">If not null, this contains a version of the item you intend to update. The client can detect a conflict if its version does not match the previousVersion. If you specify the value as null, a conflict is only detected if the client has pending changes for the item being updated.</param> /// <param name="changes">Array of property names which are to be updated. You can provide a null value to indicate that all property values may have changed.</param> public void UpdateItem(string destination, object newVersion, object previousVersion, string[] changes) { DataMessage dataMessage = new DataMessage(); DataDestination dataDestination = _dataService.GetDestination(destination) as DataDestination; object[] body = new object[3]; body[0] = changes; body[2] = newVersion; body[1] = previousVersion; dataMessage.operation = DataMessage.UpdateOperation; dataMessage.body = body; dataMessage.destination = destination; if (_clientId != null) dataMessage.clientId = _clientId; else dataMessage.clientId = "srv:" + Guid.NewGuid().ToString("D"); dataMessage.identity = Identity.GetIdentity(newVersion, dataDestination); dataMessage.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString(); System.Threading.Interlocked.Increment(ref _idCounter); ArrayList messages = new ArrayList(1); messages.Add(dataMessage); MessageBatch messageBatch = new MessageBatch(dataMessage, messages); _processedMessageBatches.Add(messageBatch); }
/// <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; } }
public void ManageMessageBatch(MessageBatch messageBatch, DataServiceTransaction dataServiceTransaction) { DataMessage dataMessage = messageBatch.IncomingMessage; //Manage existing sequences for(int j = 0; j < messageBatch.Messages.Count; j++) { IMessage message = messageBatch.Messages[j] as IMessage; if( message is UpdateCollectionMessage ) { UpdateCollectionMessage updateCollectionMessage = message as UpdateCollectionMessage; //update collections, fix sequences IList fillParameters = updateCollectionMessage.collectionId as IList; Sequence sequence = _dataDestination.SequenceManager.GetSequence(fillParameters); if( sequence != null ) { ApplyUpdateCollectionMessage(sequence, updateCollectionMessage); } } } for (int j = 0; j < messageBatch.Messages.Count; j++) { DataMessage dataMessageTmp = messageBatch.Messages[j] as DataMessage; if (dataMessageTmp != null) { switch (dataMessageTmp.operation) { case DataMessage.CreateAndSequenceOperation: { //dataMessage.identity contains identity //dataMessage.body contains the object IList result = new ArrayList(); result.Add(dataMessageTmp.body); //Will generate an UpdateCollectionMessage too (server adding item to collection) Sequence sequence = this.CreateSequence(dataMessageTmp.clientId as string, result, null, dataServiceTransaction); SequencedMessage sequencedMessage = this.GetSequencedMessage(dataMessageTmp, sequence); messageBatch.Messages[j] = sequencedMessage; } break; } } } for (int j = 0; j < messageBatch.Messages.Count; j++) { if (messageBatch.Messages[j] is DataMessage) { DataMessage dataMessageTmp = messageBatch.Messages[j] as DataMessage; SyncSequenceChanges(dataMessageTmp, dataServiceTransaction); } if (messageBatch.Messages[j] is SequencedMessage) { SequencedMessage sequencedMessage = messageBatch.Messages[j] as SequencedMessage; DataMessage dataMessageTmp = sequencedMessage.dataMessage; SyncSequenceChanges(dataMessageTmp, dataServiceTransaction); } } }
public void Commit() { if (this._rollbackOnly) { this.Rollback(); } else { try { int num; IMessage message2; UpdateCollectionMessage message4; this.ProcessRefreshFills(); this._pushMessages = new ArrayList(); for (num = 0; num < this._processedMessageBatches.Count; num++) { MessageBatch messageBatch = this._processedMessageBatches[num] as MessageBatch; if ((messageBatch.Messages != null) && (messageBatch.Messages.Count > 0)) { DataDestination destination = this._dataService.GetDestination(messageBatch.IncomingMessage) as DataDestination; try { destination.SequenceManager.ManageMessageBatch(messageBatch, this); } catch (Exception exception) { ErrorMessage errorMessage = new MessageException(exception).GetErrorMessage(); errorMessage.correlationId = messageBatch.IncomingMessage.messageId; errorMessage.destination = messageBatch.IncomingMessage.destination; messageBatch.Messages.Clear(); messageBatch.Messages.Add(errorMessage); } for (int i = 0; i < messageBatch.Messages.Count; i++) { message2 = messageBatch.Messages[i] as IMessage; if (!(message2 is ErrorMessage)) { this._pushMessages.Add(message2); } } } this._outgoingMessages.AddRange(messageBatch.Messages); } for (num = 0; num < this._pushMessages.Count; num++) { message2 = this._pushMessages[num] as IMessage; DataMessage message3 = message2 as DataMessage; if (message3 != null) { this.PushMessage(this.GetSubscribers(message2), message2); } } foreach (DictionaryEntry entry in this._clientUpdateCollectionMessages) { message4 = entry.Value as UpdateCollectionMessage; this._outgoingMessages.Add(message4); this.PushMessage(this.GetSubscribers(message4), message4); } foreach (DictionaryEntry entry in this._updateCollectionMessages) { message4 = entry.Value as UpdateCollectionMessage; this._outgoingMessages.Add(message4); this.PushMessage(this.GetSubscribers(message4), message4); } } finally { this._transactionState = FluorineFx.Data.TransactionState.Committed; } } }