Пример #1
0
        private void SyncSequenceChanges(DataMessage dataMessage, DataServiceTransaction dataServiceTransaction)
        {
            lock (_objLock)
            {
                ArrayList list = new ArrayList(this._sequenceIdToSequenceHash.Values.Count);
                list.AddRange(this._sequenceIdToSequenceHash.Values);
                foreach (Sequence sequence in list)
                {
                    switch (dataMessage.operation)
                    {
                    case 0:
                    case 11:
                        this.RefreshSequence(sequence, dataMessage, dataMessage.body, dataServiceTransaction);
                        break;

                    case 3:
                        this.RefreshSequence(sequence, dataMessage, (dataMessage.body as IList)[2], dataServiceTransaction);
                        break;

                    case 4:
                    {
                        Identity identity = Identity.GetIdentity(dataMessage.body, this._dataDestination);
                        if (sequence.IndexOf(identity) != -1)
                        {
                            this.RemoveIdentityFromSequence(sequence, identity, dataServiceTransaction);
                        }
                        break;
                    }
                    }
                }
            }
        }
Пример #2
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;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Sends a deleteItem method to the clients that are sync'd to sequences that contain this item.
        /// It does not send a delete message to the adapter/assembler but instead assumes that this
        /// item is already have been deleted from the database or is being deleted in this transaction.
        /// If you rollback the transaction, this message is also rolled back.
        ///
        /// This version of the delete method causes clients to generate a conflict if they have a version
        /// of the item that does not match the version of the item specified. You can use the
        /// DeleteItemWithId method to unconditionally delete an item on the client if you do not have
        /// the original version.
        /// </summary>
        /// <param name="destination">Name of the destination containing the item to be deleted.</param>
        /// <param name="item">Version of the item to delete. Clients can detect a conflict if this version of the item does not match the version they are currently managing.</param>
        public void DeleteItem(string destination, object item)
        {
            DataMessage     dataMessage     = new DataMessage();
            DataDestination dataDestination = _dataService.GetDestination(destination) as DataDestination;

            dataMessage.operation   = DataMessage.DeleteOperation;
            dataMessage.body        = item;
            dataMessage.destination = destination;
            if (_clientId != null)
            {
                dataMessage.clientId = _clientId;
            }
            else
            {
                dataMessage.clientId = "srv:" + Guid.NewGuid().ToString("D");
            }
            dataMessage.identity  = Identity.GetIdentity(item, 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);

            AddProcessedMessageBatch(messageBatch);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
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);
        }
Пример #8
0
        public Sequence RefreshSequence(Sequence sequence, DataMessage dataMessage, object item, DataServiceTransaction dataServiceTransaction)
        {
            if (sequence.Parameters != null)
            {
                DotNetAdapter serviceAdapter = this._dataDestination.ServiceAdapter as DotNetAdapter;
                if (serviceAdapter != null)
                {
                    Identity identity;
                    bool     isCreate = (dataMessage.operation == 0) || (dataMessage.operation == 11);
                    switch (serviceAdapter.RefreshFill(sequence.Parameters, item, isCreate))
                    {
                    case 0:
                        return(sequence);

                    case 1:
                    {
                        IList       parameters = sequence.Parameters;
                        DataMessage message    = new DataMessage {
                            clientId  = dataMessage.clientId,
                            operation = 1,
                            body      = (parameters != null) ? ((object)parameters) : ((object)new object[0])
                        };
                        IList result = this._dataDestination.ServiceAdapter.Invoke(message) as IList;
                        return(this.CreateSequence(dataMessage.clientId as string, result, parameters, dataServiceTransaction));
                    }

                    case 2:
                        identity = Identity.GetIdentity(item, this._dataDestination);
                        if (!sequence.Contains(identity))
                        {
                            this.AddIdentityToSequence(sequence, identity, dataServiceTransaction);
                        }
                        this._itemIdToItemHash[identity] = new ItemWrapper(item);
                        return(sequence);

                    case 3:
                        identity = Identity.GetIdentity(item, this._dataDestination);
                        if (sequence.Contains(identity))
                        {
                            this.RemoveIdentityFromSequence(sequence, identity, dataServiceTransaction);
                        }
                        return(sequence);
                    }
                }
            }
            return(sequence);
        }
Пример #9
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);
        }
Пример #10
0
        public Sequence CreateSequence(string clientId, IList result, IList parameters, DataServiceTransaction dataServiceTransaction)
        {
            Sequence sequence = null;

            Identity[] identityArray = new Identity[result.Count];
            lock (_objLock)
            {
                int       num;
                Identity  identity;
                ArrayList list;
                for (num = 0; num < identityArray.Length; num++)
                {
                    if (result[num] != null)
                    {
                        identity           = Identity.GetIdentity(result[num], this._dataDestination);
                        identityArray[num] = identity;
                        if (!this._itemIdToItemHash.ContainsKey(identity))
                        {
                            this._itemIdToItemHash.Add(identity, new ItemWrapper(result[num]));
                        }
                        else
                        {
                            ItemWrapper wrapper = this._itemIdToItemHash[identity] as ItemWrapper;
                            wrapper.Instance = result[num];
                        }
                    }
                }
                if (parameters != null)
                {
                    if (this._parametersToSequenceIdHash.Contains(parameters))
                    {
                        sequence = this._parametersToSequenceIdHash[parameters] as Sequence;
                    }
                }
                else
                {
                    IDictionary dictionary = this._itemIdToSequenceIdMapHash[identityArray[0]] as IDictionary;
                    if (dictionary != null)
                    {
                        foreach (Sequence sequence2 in dictionary.Values)
                        {
                            if (sequence2.Parameters == null)
                            {
                                sequence = sequence2;
                                break;
                            }
                        }
                    }
                }
                if (sequence == null)
                {
                    sequence = new Sequence {
                        Id = sequence.GetHashCode()
                    };
                    object[] array = null;
                    if (parameters != null)
                    {
                        array = new object[parameters.Count];
                        parameters.CopyTo(array, 0);
                        sequence.Parameters = array;
                        this._parametersToSequenceIdHash[parameters] = sequence;
                    }
                    for (num = 0; num < identityArray.Length; num++)
                    {
                        identity = identityArray[num];
                        this.AddIdentityToSequence(sequence, identity, dataServiceTransaction);
                    }
                    this._sequenceIdToSequenceHash[sequence.Id] = sequence;
                    if (log.get_IsDebugEnabled())
                    {
                        log.Debug(__Res.GetString("SequenceManager_CreateSeq", new object[] { sequence.Id, clientId }));
                    }
                }
                else
                {
                    for (num = 0; num < identityArray.Length; num++)
                    {
                        identity = identityArray[num];
                        Identity identity2 = null;
                        if (num < sequence.Count)
                        {
                            identity2 = sequence[num];
                        }
                        if (!identity.Equals(identity2) && !sequence.Contains(identity))
                        {
                            int num2 = this.AddIdentityToSequence(sequence, identity, dataServiceTransaction);
                        }
                    }
                }
                sequence.AddSubscriber(clientId);
                if (this._clientIdToSequenceHash.Contains(clientId))
                {
                    list = this._clientIdToSequenceHash[clientId] as ArrayList;
                }
                else
                {
                    list = new ArrayList();
                    this._clientIdToSequenceHash[clientId] = list;
                }
                if (!list.Contains(sequence))
                {
                    list.Add(sequence);
                }
            }
            return(sequence);
        }