public bool Equals(Reservation other) { if (null == other) { return false; } // compare ids if (!this.Id.Equals(other.Id)) { return false; } // compare lists if (this.resourceList.Count() != other.resourceList.Count()) { return false; } // compare each resource foreach (var resource in this.resourceList) { if (!other.resourceList.Contains(resource)) { return false; } } return true; }
private static void ReadReservations(Transaction context, StorageManager storage, Reservation[] data) { bool createTransaction = (null == context); if (createTransaction) { context = new Transaction(); } foreach (var item in data) { Reservation output = null; if (!storage.Read(context, item.Id, out output)) { Assert.Fail("{0}: Read of [{1}] was un-successful.", context.Id.ToString(), item.Id.ToString()); } Assert.AreEqual<Reservation>(item, output, "{0}: Read was un-successful.", context.Id.ToString()); } if (createTransaction) { storage.Prepare(context); storage.Commit(context); } }
private static void WriteReservations(Transaction context, StorageManager storage, Reservation[] data, bool abort) { bool createTransaction = (null == context); if (createTransaction) { context = new Transaction(); } // write the data foreach (var item in data) { storage.Write(context, item.Id, item); } // read the data in the same transaction ReadReservations(context, storage, data); if (createTransaction && !abort) { storage.Prepare(context); storage.Commit(context); } else if (createTransaction && abort) { storage.Abort(context); } }
public bool Reserve(Transaction context, Customer customer, RID resource) { // enlist with TM this.Enlist(context); // get the resource info Resource item = null; bool result = this.dataStore.Read(context, resource, out item); if (!result) { throw new InvalidOperationException(resource + " does not exist!"); } if (item.getCount() <= 0) { return false; } // get the reservation record Reservation data = null; result = this.dataStore.Read(context, customer, out data); if (!result) { data = new Reservation(customer); } // only allow one reservation per item if (data.Resources.Contains(resource)) { return false; } // update the data data.Resources.Add(resource); item.decrCount(); // write back the records result = this.dataStore.Write(context, customer, data); if (!result) { return result; } result = this.dataStore.Write(context, resource, item); if (!result) { return result; } return true; }