/// <summary> /// Reserve a list of resources for a customer /// Decrease all reserved resources by 1. /// </summary> /// <param name="context"></param> /// <param name="c"></param> /// <param name="i"></param> /// <returns>true if reservation is successful</returns> public bool Reserve(Transaction context, Customer c, RID i) { WaitForReady(); Enlist(context); _lockManager.LockForWrite(context, c); _lockManager.LockForWrite(context, i); Resource resource = _transactionStorage.Read(context, i); if (resource == null) { throw new InvalidOperationException(i + " does not exist!"); } if (resource.getCount() == 0) { return(false); } HashSet <RID> r = _transactionStorage.Read(context, c) ?? new HashSet <RID>(); r.Add(resource.getID()); Console.WriteLine("Reserving flight: Stops={0}", r.Count); _transactionStorage.Write(context, c, r); resource.decrCount(); _transactionStorage.Write(context, i, resource); return(true); }
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); }