public int QueryReservedPrice(Transaction context, Customer customer) { int bill = 0; // enlist with TM this.Enlist(context); // read the reservation data Reservation data = null; bool result = this.dataStore.Read(context, customer, out data); if (!result) { return(bill); } // tally up the resource prices foreach (RID rId in data.Resources) { Resource resource = null; // read the resource result = this.dataStore.Read(context, rId, out resource); if (!result) { throw new InvalidOperationException(rId + " does not exist in RM"); } bill += resource.getPrice(); } return(bill); }
/// <summary> /// Gets the total price of reserved resources for the customer /// </summary> /// <param name="context"></param> /// <param name="customer"></param> /// <returns>the total price of reserved resources for the customer</returns> public int QueryReservedPrice(Transaction context, Customer customer) { WaitForReady(); Enlist(context); int bill = 0; _lockManager.LockForRead(context, customer); HashSet <RID> reserved = _transactionStorage.Read(context, customer); if (reserved != null) { foreach (RID rid in reserved) { Resource r = _transactionStorage.Read(context, rid); if (r == null) { throw new InvalidOperationException(rid + " does not exist in RM"); } bill += r.getPrice(); } } return(bill); }
public static Row ConvertResourceToRow(Resource resource) { var encoder = new UTF8Encoding(); var rowString = resource.getType() + "," + resource.getID().getName() + "," + resource.getCount().ToString(CultureInfo.InvariantCulture) + "," + resource.getPrice(); //TODO: FIX THE SIZE var row = new Row(96) { Data = encoder.GetBytes(rowString) }; return(row); }
/// <summary> /// Need to add code here /// returns the price for the specified item type /// </summary> /// <param name="context"></param> /// <param name="rId"></param> /// <returns></returns> public int QueryPrice(Transaction context, RID rId) { // enlist with TM this.Enlist(context); Resource data = null; bool result = this.dataStore.Read(context, rId, out data); if (!result) { throw new ArgumentException(rId + " does not exist"); } return(data.getPrice()); }
/// <summary> /// Queries the price of given resource /// </summary> /// <param name="context"></param> /// <param name="rid"></param> /// <returns>returns the price for the specified item type</returns> public int QueryPrice(Transaction context, RID rid) { WaitForReady(); Enlist(context); _lockManager.LockForRead(context, rid); Resource resource = _transactionStorage.Read(context, rid); if (resource == null) { throw new ArgumentException(rid + " does not exist"); } return(resource.getPrice()); }