Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
        public Sequence CreateSequence(string clientId, IList result, IList parameters, DataServiceTransaction dataServiceTransaction)
        {
            Sequence sequence = null;

            Identity[] identities = new Identity[result.Count];

            lock (_objLock)
            {
                for (int i = 0; i < identities.Length; i++)
                {
                    if (result[i] != null)
                    {
                        Identity identity = Identity.GetIdentity(result[i], _dataDestination);
                        identities[i] = identity;
                        if (!_itemIdToItemHash.ContainsKey(identity))
                        {
                            _itemIdToItemHash.Add(identity, new ItemWrapper(result[i]));
                        }
                        else
                        {
                            ItemWrapper itemWrapper = _itemIdToItemHash[identity] as ItemWrapper;
                            itemWrapper.Instance = result[i];
                        }
                    }
                }
                //Lookup existing sequence
                if (parameters != null)
                {
                    if (_parametersToSequenceIdHash.Contains(parameters))
                    {
                        sequence = _parametersToSequenceIdHash[parameters] as Sequence;
                    }
                }
                else
                {
                    IDictionary sequenceIdMap = _itemIdToSequenceIdMapHash[identities[0]] as IDictionary;
                    if (sequenceIdMap != null)
                    {
                        foreach (Sequence sequenceTmp in sequenceIdMap.Values)
                        {
                            if (sequenceTmp.Parameters == null)
                            {
                                sequence = sequenceTmp;
                                break;
                            }
                        }
                    }
                }
                //if (parameters == null)
                //    parameters = new ArrayList();

                if (sequence == null)
                {
                    sequence    = new Sequence();
                    sequence.Id = sequence.GetHashCode();

                    object[] parametersArray = null;
                    if (parameters != null)
                    {
                        parametersArray = new object[parameters.Count];
                        parameters.CopyTo(parametersArray, 0);
                        sequence.Parameters = parametersArray;
                        _parametersToSequenceIdHash[parameters] = sequence;
                    }

                    for (int i = 0; i < identities.Length; i++)
                    {
                        Identity identity = identities[i];
                        AddIdentityToSequence(sequence, identity, dataServiceTransaction);
                    }

                    _sequenceIdToSequenceHash[sequence.Id] = sequence;

                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.SequenceManager_CreateSeq, sequence.Id, clientId));
                    }
                }
                else
                {
                    for (int i = 0; i < identities.Length; i++)
                    {
                        Identity identity         = identities[i];
                        Identity existingIdentity = null;
                        if (i < sequence.Count)
                        {
                            existingIdentity = sequence[i];
                        }
                        if (!identity.Equals(existingIdentity))
                        {
                            //Identity not found in sequence
                            if (!sequence.Contains(identity))
                            {
                                int position = AddIdentityToSequence(sequence, identity, dataServiceTransaction);
                            }
                        }
                    }
                }
                sequence.AddSubscriber(clientId);
                ArrayList sequences;
                if (_clientIdToSequenceHash.Contains(clientId))
                {
                    sequences = _clientIdToSequenceHash[clientId] as ArrayList;
                }
                else
                {
                    sequences = new ArrayList();
                    _clientIdToSequenceHash[clientId] = sequences;
                }
                if (!sequences.Contains(sequence))
                {
                    sequences.Add(sequence);
                }
            }
            return(sequence);
        }
Esempio n. 4
0
		public Sequence RefreshSequence(Sequence sequence, DataMessage dataMessage, object item, DataServiceTransaction dataServiceTransaction)
		{
            if (sequence.Parameters == null)
                return sequence;
			DotNetAdapter dotNetAdapter = _dataDestination.ServiceAdapter as DotNetAdapter;
			if( dotNetAdapter != null )
			{
				bool isCreate = (dataMessage.operation == DataMessage.CreateOperation || dataMessage.operation == DataMessage.CreateAndSequenceOperation);
				int fill = dotNetAdapter.RefreshFill( sequence.Parameters, item, isCreate );
				switch(fill)
				{
					case Assembler.ExecuteFill:
					{
						IList parameters = sequence.Parameters;
                        //if (parameters == null)
                        //    parameters = new object[0];
						DataMessage fillDataMessage = new DataMessage();
						fillDataMessage.clientId = dataMessage.clientId;
						fillDataMessage.operation = DataMessage.FillOperation;
                        fillDataMessage.body = parameters != null ? parameters : new object[0];
						IList result = _dataDestination.ServiceAdapter.Invoke(fillDataMessage) as IList;
                        return CreateSequence(dataMessage.clientId as string, result, parameters, dataServiceTransaction);
					} 
					case Assembler.AppendToFill:
					{
						Identity identity = Identity.GetIdentity(item, _dataDestination);
						if( !sequence.Contains(identity) )
							AddIdentityToSequence(sequence, identity, dataServiceTransaction);
                        _itemIdToItemHash[identity] = new ItemWrapper(item);
					}
						break;
					case Assembler.RemoveFromFill:
					{
						Identity identity = Identity.GetIdentity(item, _dataDestination);
						if( sequence.Contains(identity) )
							RemoveIdentityFromSequence(sequence, identity, dataServiceTransaction);
					}
						break;
					case Assembler.DoNotExecuteFill:
						break;
				}
			}
			return sequence;
		}