Esempio n. 1
0
		public SequenceManager(DataDestination dataDestination)
		{
			_dataDestination = dataDestination;
            _sequenceIdToSequenceHash = new CopyOnWriteDictionary();
#if (NET_1_1)
			_parametersToSequenceIdHash = new Hashtable(new ListHashCodeProvider(), new ListComparer());
#else
            _parametersToSequenceIdHash = new Hashtable(new ListHashCodeProvider());
#endif
            _itemIdToSequenceIdMapHash = new Hashtable();
			_clientIdToSequenceHash = new Hashtable();
			_itemIdToItemHash = new Hashtable();
		}
Esempio n. 2
0
		public static Identity GetIdentity(object item, DataDestination destination)
		{
            IdentityConfiguration[] keys = destination.GetIdentityKeys();
			Identity identity = new Identity(item);
			foreach(IdentityConfiguration ic in keys)
			{
                string key = ic.Property;
				PropertyInfo pi = item.GetType().GetProperty(key);
				if( pi != null )
				{
					try
					{
						identity[key] = pi.GetValue( item, new object[0] );
					}
					catch(Exception ex)
					{
						throw new FluorineException(__Res.GetString(__Res.Identity_Failed, key), ex);
					}
				}
				else
				{				
					try
					{
						FieldInfo fi = item.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance);
						if( fi != null )
						{
							identity[key] = fi.GetValue( item );
						}
					}
					catch(Exception ex)
					{
						throw new FluorineException(__Res.GetString(__Res.Identity_Failed, key), ex);
					}
				}
			}
			return identity;
		}
		private UpdateCollectionMessage CreateUpdateCollectionMessage(DataDestination dataDestination, Sequence sequence)
		{
			UpdateCollectionMessage updateCollectionMessage = new UpdateCollectionMessage();
			updateCollectionMessage.clientId = this.ClientId;
			updateCollectionMessage.updateMode = UpdateCollectionMessage.ServerUpdate;
			// The unique identifier for the collection that was updated. For a collection filled with the 
			// DataService.fill() method this contains an Array of the parameters specified.
			updateCollectionMessage.collectionId = sequence.Parameters;
			updateCollectionMessage.destination = dataDestination.Id;
			updateCollectionMessage.correlationId = this.CorrelationId;
			updateCollectionMessage.messageId = "srv:" + Guid.NewGuid().ToString("D") + ":" + _idCounter.ToString();
			System.Threading.Interlocked.Increment(ref _idCounter);

			return updateCollectionMessage;
		}
		internal void GenerateUpdateCollectionMessage(int updateType, DataDestination dataDestination, Sequence sequence, int position, Identity identity)
		{
			UpdateCollectionMessage updateCollectionMessage = CreateUpdateCollectionMessage(dataDestination, sequence);
			updateCollectionMessage.AddItemIdentityChange(updateType, position, identity);
            if (updateCollectionMessage.collectionId != null)
                _updateCollectionMessages[updateCollectionMessage.collectionId] = updateCollectionMessage;
            else
            {
                //without fill parameters
                _updateCollectionMessages[new object[0]] = updateCollectionMessage;
            }
		}
Esempio n. 5
0
        /// <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;
            }
        }
Esempio n. 6
0
        public override object ServiceMessage(IMessage message)
        {
            CommandMessage commandMessage = message as CommandMessage;

            if (commandMessage != null)
            {
                //Sub/unsub handled by base class
                return(base.ServiceMessage(commandMessage));
            }
            else
            {
                AsyncMessage responseMessage = null;
                DataMessage  dataMessage     = message as DataMessage;

                DataDestination dataDestination = this.GetDestination(dataMessage) as DataDestination;
                if (dataDestination.SubscriptionManager.GetSubscriber(dataMessage.clientId as string) == null)
                {
                    //Subscribe here as DS doesn't send a separate subscribe command
                    CommandMessage commandMessageSubscribe = new CommandMessage();
                    commandMessageSubscribe.destination = dataDestination.Id;
                    commandMessageSubscribe.operation   = CommandMessage.SubscribeOperation;
                    commandMessageSubscribe.clientId    = dataMessage.clientId as string;
                    string endpointId = dataMessage.GetHeader(MessageBase.EndpointHeader) as string;
                    commandMessageSubscribe.headers[MessageBase.EndpointHeader] = endpointId;
                    string flexClientIdHeader = dataMessage.GetHeader(MessageBase.FlexClientIdHeader) as string;
                    if (flexClientIdHeader != null)
                    {
                        commandMessageSubscribe.headers[MessageBase.FlexClientIdHeader] = flexClientIdHeader;
                    }
                    IEndpoint endpoint = GetMessageBroker().GetEndpoint(endpointId);
                    endpoint.ServiceMessage(commandMessageSubscribe);//route through the endpoint again
                    //base.ServiceMessage(commandMessageSubscribe);
                }

                switch (dataMessage.operation)
                {
                case DataMessage.FillOperation:
                    responseMessage = ExecuteFillOperation(message);
                    break;

                case DataMessage.GetOperation:
                    responseMessage = ExecuteGetOperation(message);
                    break;

                case DataMessage.BatchedOperation:
                case DataMessage.MultiBatchOperation:
                case DataMessage.TransactedOperation:
                    responseMessage = ExecuteMultiBatchOperation(message);
                    break;

                case DataMessage.PageItemsOperation:
                    responseMessage = ExecutePageItemsOperation(message);
                    break;

                case DataMessage.PageOperation:
                    responseMessage = ExecutePageOperation(message);
                    break;

                case DataMessage.ReleaseCollectionOperation:
                    responseMessage = ExecuteReleaseCollectionOperation(message);
                    break;

                case DataMessage.GetSequenceIdOperation:
                    responseMessage = ExecuteGetSequenceIdOperation(message);
                    break;

                case DataMessage.ReleaseItemOperation:
                    responseMessage = ExecuteReleaseItemOperation(message);
                    break;

                default:
                    if (log.IsErrorEnabled)
                    {
                        log.Error(__Res.GetString(__Res.DataService_Unknown, dataMessage.operation));
                    }

                    responseMessage = new AcknowledgeMessage();
                    break;
                }
                responseMessage.clientId      = message.clientId;
                responseMessage.correlationId = message.messageId;
                //Dump();
                return(responseMessage);
            }
        }