public SequencedMessage GetSequencedMessage(DataMessage dataMessage, Sequence sequence) { if( dataMessage.headers != null && dataMessage.headers.ContainsKey(DataMessage.PageSizeHeader) ) { return GetPagedMessage(dataMessage, sequence); } else { SequencedMessage sequencedMessage = new SequencedMessage(); sequencedMessage.destination = dataMessage.destination; sequencedMessage.sequenceId = sequence.Id; sequencedMessage.sequenceSize = sequence.Size; //object[] body = new object[result.Count]; //result.CopyTo(body, 0); object[] body = new object[sequence.Count]; lock(_objLock) { for(int i = 0; i < sequence.Count; i++) { ItemWrapper itemWrapper = GetItem(sequence[i]) as ItemWrapper; if( itemWrapper != null ) body[i] = itemWrapper.Instance; } } sequencedMessage.body = body; sequencedMessage.sequenceProxies = null; sequencedMessage.dataMessage = dataMessage; sequencedMessage.messageId = dataMessage.messageId; sequencedMessage.clientId = dataMessage.clientId; sequencedMessage.correlationId = dataMessage.messageId; //dataMessage.identity = new Hashtable(0); return sequencedMessage; } }
public SequencedMessage GetPageItems(DataMessage dataMessage) { int sequenceId = (int)dataMessage.headers[DataMessage.SequenceIdHeader]; Sequence sequence = GetSequence(sequenceId); if (sequence != null) { IList DSids = dataMessage.headers["DSids"] as IList; //ArrayList items = new ArrayList(DSids.Count); SequencedMessage sequencedMessage = new SequencedMessage(); object[] items = new object[DSids.Count]; lock (_objLock) { for (int i = 0; i < DSids.Count; i++) { Identity identity = new Identity(DSids[i] as IDictionary); ItemWrapper itemWrapper = GetItem(identity); //items.Add(item); items[i] = itemWrapper.Instance; } sequencedMessage.destination = dataMessage.destination; sequencedMessage.sequenceId = sequence.Id; sequencedMessage.sequenceSize = sequence.Size; sequencedMessage.sequenceProxies = null; sequencedMessage.body = items; } return sequencedMessage; } else { DataServiceException dse = new DataServiceException(string.Format("Sequence {0} in destination {1} was not found", sequenceId, dataMessage.destination)); throw dse; } }
private AcknowledgeMessage ExecuteGetSequenceIdOperation(IMessage message) { DataMessage dataMessage = message as DataMessage; AcknowledgeMessage responseMessage = null; DataDestination dataDestination = this.GetDestination(dataMessage) as DataDestination; //2 cases: body set or identity set if (dataMessage.body != null && dataMessage.body is IList) { dataMessage.operation = DataMessage.FillOperation; IList result = dataDestination.ServiceAdapter.Invoke(message) as IList;//Fill returns an IList responseMessage = dataDestination.SequenceManager.ManageSequence(dataMessage, result); dataMessage.operation = DataMessage.GetSequenceIdOperation; } else { dataMessage.operation = DataMessage.GetOperation; object result = dataDestination.ServiceAdapter.Invoke(message); if (result != null) { ArrayList collection = new ArrayList(1); collection.Add(result); responseMessage = dataDestination.SequenceManager.ManageSequence(dataMessage, collection); } else { SequencedMessage sequencedMessage = new SequencedMessage(); sequencedMessage.sequenceId = -1;//no sequence responseMessage = sequencedMessage; } dataMessage.operation = DataMessage.GetSequenceIdOperation; } return responseMessage; }