public ServiceTransactionEventArgs(
     ServiceDataTransactionType serviceOperation,
     int transactionCount,
     int transactionCompletedIndex,
     object entity)
 {
     _serviceOperation          = serviceOperation;
     _transactionCount          = transactionCount;
     _transactionCompletedIndex = transactionCompletedIndex;
     _entity = entity;
 }
Beispiel #2
0
        private void ProcessEntitiesToServer(
            RestWebServiceClient restWebServiceClient,
            ServiceDataTransactionType transactionType,
            Dictionary <K, E> entitiesToProcess)
        {
            List <E> entityQueue      = entitiesToProcess.Values.ToList();
            int      entityQueueCount = entityQueue.Count;
            int      i = 0;

            while (entityQueue.Count > 0) //Process the queue.
            {
                E e = entityQueue[0];
                i++;
                switch (transactionType)
                {
                case ServiceDataTransactionType.Delete:
                    restWebServiceClient.DeleteById <E>(GetSurrogateKeyValue(e));
                    break;

                case ServiceDataTransactionType.Add:
                    restWebServiceClient.PutEntity <E>(e);
                    break;

                case ServiceDataTransactionType.Update:
                    restWebServiceClient.PutEntity <E>(e);
                    break;

                default:
                    throw new ArgumentException(string.Format("Invalid {0} of {1}.", typeof(ServiceDataTransactionType).Name, transactionType.ToString()));
                }
                entityQueue.Remove(e);                             //Remove it from the queue of entities to be processed.
                entitiesToProcess.Remove(GetSurrogateKeyValue(e)); //Remove it from this cache's entities to be processed.
                if (OnServiceTransactionCompleted != null)
                {
                    OnServiceTransactionCompleted(this, new ServiceTransactionEventArgs(transactionType, entityQueueCount, i, e)); //Inform subscribers that the entity has been successfully processed.
                }
            }
            Debug.Assert(entitiesToProcess.Count == 0);
        }