コード例 #1
0
        public AcknowledgeMessage ManageSequence(DataMessage dataMessage, IList items, DataServiceTransaction dataServiceTransaction)
        {
            AcknowledgeMessage acknowledgeMessage = null;

            switch (dataMessage.operation)
            {
            case DataMessage.FillOperation:
            {
                Sequence sequence = CreateSequence(dataMessage.clientId as string, items, dataMessage.body as IList, dataServiceTransaction);
                acknowledgeMessage = GetSequencedMessage(dataMessage, sequence);
            }
            break;

            case DataMessage.GetOperation:
            case DataMessage.GetSequenceIdOperation:
            {
                Sequence sequence = CreateSequence(dataMessage.clientId as string, items, null, dataServiceTransaction);
                acknowledgeMessage = GetSequencedMessage(dataMessage, sequence);
            }
            break;

            default:
            {
                if (log != null && log.IsErrorEnabled)
                {
                    log.Error(__Res.GetString(__Res.SequenceManager_Unknown, dataMessage.operation));
                }
            }
            break;
            }
            return(acknowledgeMessage);
        }
コード例 #2
0
        public void RemoveIdentityFromSequence(Sequence sequence, Identity identity, int position, DataServiceTransaction dataServiceTransaction)
        {
            if (position == -1)
            {
                return;
            }
            lock (_objLock)
            {
                IDictionary sequenceIdMap = _itemIdToSequenceIdMapHash[identity] as IDictionary;
                if (sequenceIdMap != null)
                {
                    sequenceIdMap.Remove(sequence.Id);
                    //Release the item if it does'n occur in any sequence
                    if (sequenceIdMap.Count == 0)
                    {
                        _itemIdToItemHash.Remove(identity);
                        _itemIdToSequenceIdMapHash.Remove(identity);
                    }
                    if (sequence[position].Equals(identity))
                    {
                        sequence.RemoveAt(position);
                    }
                    else
                    {
                        sequence.Remove(identity);
                    }

                    if (dataServiceTransaction != null)
                    {
                        dataServiceTransaction.GenerateUpdateCollectionMessage(UpdateCollectionRange.DeleteFromCollection, _dataDestination, sequence, position, identity);
                    }
                }
                else
                {
                    _itemIdToItemHash.Remove(identity);
                    sequence.Remove(identity);
                }
            }
        }
コード例 #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);
        }
コード例 #4
0
 public int AddIdentityToSequence(Sequence sequence, Identity identity, DataServiceTransaction dataServiceTransaction)
 {
     return(AddIdentityToSequence(sequence, -1, identity, dataServiceTransaction));
 }
コード例 #5
0
 public void RemoveIdentityFromSequence(Sequence sequence, Identity identity, DataServiceTransaction dataServiceTransaction)
 {
     RemoveIdentityFromSequence(sequence, identity, sequence.IndexOf(identity), dataServiceTransaction);
 }
コード例 #6
0
		public int AddIdentityToSequence(Sequence sequence, int position, Identity identity, DataServiceTransaction dataServiceTransaction)
		{
			lock(_objLock)
			{
				if(position == -1 || position > sequence.Size)
					position = sequence.Add(identity);
				else
					sequence.Insert(position, identity);

                IDictionary sequenceIdMap = _itemIdToSequenceIdMapHash[identity] as IDictionary;
				if( sequenceIdMap == null )
				{
					sequenceIdMap = new Hashtable();
					_itemIdToSequenceIdMapHash[identity] = sequenceIdMap;
				}
				sequenceIdMap[sequence.Id] = sequence;

				if(dataServiceTransaction != null)
					dataServiceTransaction.GenerateUpdateCollectionMessage(UpdateCollectionRange.InsertIntoCollection, _dataDestination, sequence, position, identity);

				return position;
			}
		}
コード例 #7
0
        public int AddIdentityToSequence(Sequence sequence, int position, Identity identity, DataServiceTransaction dataServiceTransaction)
        {
            lock (_objLock)
            {
                if (position == -1 || position > sequence.Size)
                {
                    position = sequence.Add(identity);
                }
                else
                {
                    sequence.Insert(position, identity);
                }

                IDictionary sequenceIdMap = _itemIdToSequenceIdMapHash[identity] as IDictionary;
                if (sequenceIdMap == null)
                {
                    sequenceIdMap = new Hashtable();
                    _itemIdToSequenceIdMapHash[identity] = sequenceIdMap;
                }
                sequenceIdMap[sequence.Id] = sequence;

                if (dataServiceTransaction != null)
                {
                    dataServiceTransaction.GenerateUpdateCollectionMessage(UpdateCollectionRange.InsertIntoCollection, _dataDestination, sequence, position, identity);
                }

                return(position);
            }
        }
コード例 #8
0
        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);
                }
            }
		}
コード例 #9
0
		void SyncSequenceChanges(DataMessage dataMessage, DataServiceTransaction dataServiceTransaction)
		{
			lock(_objLock)
			{
                ArrayList sequenceList = new ArrayList(_sequenceIdToSequenceHash.Values.Count);
                sequenceList.AddRange(_sequenceIdToSequenceHash.Values);//Hashtable may be changed here
                foreach (Sequence sequence in sequenceList)
				{
					switch(dataMessage.operation)
					{
						case DataMessage.CreateOperation:
						case DataMessage.CreateAndSequenceOperation:
							RefreshSequence(sequence, dataMessage, dataMessage.body, dataServiceTransaction);
							break;
						case DataMessage.DeleteOperation:
						{
							//RefreshSequence(sequence, dataMessage, dataMessage.body, dataServiceTransaction);
							Identity identity = Identity.GetIdentity(dataMessage.body, _dataDestination);
							int index = sequence.IndexOf(identity);
							if( index != -1 )
								RemoveIdentityFromSequence(sequence, identity, dataServiceTransaction);
						}
							break;
						case DataMessage.UpdateOperation:
							RefreshSequence(sequence, dataMessage, (dataMessage.body as IList)[2], dataServiceTransaction);
							break;
					}
				}
			}
		}
コード例 #10
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;
		}
コード例 #11
0
		public AcknowledgeMessage ManageSequence(DataMessage dataMessage, IList items, DataServiceTransaction dataServiceTransaction)
		{
			AcknowledgeMessage acknowledgeMessage = null;
			switch(dataMessage.operation)
			{
				case DataMessage.FillOperation:
				{
					Sequence sequence = CreateSequence(dataMessage.clientId as string, items, dataMessage.body as IList, dataServiceTransaction);
					acknowledgeMessage = GetSequencedMessage(dataMessage, sequence);
				}
					break;
				case DataMessage.GetOperation:
				case DataMessage.GetSequenceIdOperation:
				{
					Sequence sequence = CreateSequence(dataMessage.clientId as string, items, null, dataServiceTransaction);
					acknowledgeMessage = GetSequencedMessage(dataMessage, sequence);
				}
					break;
				default:
				{
					if( log != null && log.IsErrorEnabled )
						log.Error(__Res.GetString(__Res.SequenceManager_Unknown, dataMessage.operation));
				}
					break;
			}
			return acknowledgeMessage;
		}
コード例 #12
0
		public void RemoveIdentityFromSequence(Sequence sequence, Identity identity, int position, DataServiceTransaction dataServiceTransaction)
		{
			if( position == -1 )
				return;
			lock(_objLock)
			{
                IDictionary sequenceIdMap = _itemIdToSequenceIdMapHash[identity] as IDictionary;
                if (sequenceIdMap != null)
                {
                    sequenceIdMap.Remove(sequence.Id);
                    //Release the item if it does'n occur in any sequence
                    if (sequenceIdMap.Count == 0)
                    {
                        _itemIdToItemHash.Remove(identity);
                        _itemIdToSequenceIdMapHash.Remove(identity);
                    }
                    if (sequence[position].Equals(identity))
                        sequence.RemoveAt(position);
                    else
                        sequence.Remove(identity);

                    if (dataServiceTransaction != null)
                        dataServiceTransaction.GenerateUpdateCollectionMessage(UpdateCollectionRange.DeleteFromCollection, _dataDestination, sequence, position, identity);
                }
                else
                {
                    _itemIdToItemHash.Remove(identity);
                    sequence.Remove(identity);
                }
			}
		}
コード例 #13
0
		public void RemoveIdentityFromSequence(Sequence sequence, Identity identity, DataServiceTransaction dataServiceTransaction)
		{
			RemoveIdentityFromSequence(sequence, identity, sequence.IndexOf(identity), dataServiceTransaction);
		}
コード例 #14
0
		public int AddIdentityToSequence(Sequence sequence, Identity identity, DataServiceTransaction dataServiceTransaction)
		{
			return AddIdentityToSequence(sequence, -1, identity, dataServiceTransaction);
		}
コード例 #15
0
 private static void SetCurrentDataServiceTransaction(DataServiceTransaction dataServiceTransaction)
 {
     FluorineWebSafeCallContext.SetData(FluorineContext.FluorineDataServiceTransaction, dataServiceTransaction);
 }
コード例 #16
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;
		}
コード例 #17
0
		internal static DataServiceTransaction Begin(DataService dataService)
		{
			DataServiceTransaction dataServiceTransaction = new DataServiceTransaction(dataService);
			SetCurrentDataServiceTransaction(dataServiceTransaction);
			return dataServiceTransaction;
		}
コード例 #18
0
 private static void SetCurrentDataServiceTransaction(DataServiceTransaction dataServiceTransaction)
 {
     FluorineWebSafeCallContext.SetData(FluorineContext.FluorineDataServiceTransaction, dataServiceTransaction);
 }