Пример #1
0
        /// <summary>
        /// Remove reservations of a customer
        /// Increase all resources in this reservation by 1.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="c"></param>
        public void UnReserve(Transaction context, Customer c)
        {
            WaitForReady();
            Enlist(context);

            _lockManager.LockForWrite(context, c);
            HashSet <RID> r = _transactionStorage.Read(context, c);

            Console.WriteLine("Unreserve: {0}", r == null ? 0 : r.Count);
            if (r == null)
            {
                // silently discard
            }
            else
            {
                foreach (RID rid in r)
                {
                    _lockManager.LockForWrite(context, rid);
                    Resource resource = _transactionStorage.Read(context, rid);
                    if (resource == null)
                    {
                        // FIXME warn that the rID does not exist!
                    }
                    else
                    {
                        resource.incrCount();
                        _transactionStorage.Write(context, rid, resource);
                    }
                }

                _transactionStorage.Delete(context, c);
            }
        }
Пример #2
0
        public void UnReserve(Transaction context, Customer customer)
        {
            // enlist with TM
            this.Enlist(context);

            Reservation data   = null;
            bool        result = this.dataStore.Read(context, customer, out data);

            if (!result ||
                null == data)
            {
                // silently discard
                return;
            }

            // update the reservations
            foreach (RID rId in data.Resources)
            {
                Resource item = null;

                // read in the resource
                result = this.dataStore.Read(context, rId, out item);
                if (!result)
                {
                    throw new InvalidOperationException(rId + " does not exist!");
                }

                // update the resource
                item.incrCount();

                // write back the resource
                result = this.dataStore.Write(context, rId, item);
                if (!result)
                {
                    throw new InvalidOperationException(rId + " could not be updated!");
                }
            }

            // delete the reservation
            result = this.dataStore.Write(context, customer, null);
            if (!result)
            {
                throw new InvalidOperationException(customer + " could not be un-reserved!");
            }
        }