public IEnumerable <Inmate> GetInmates() { lock (Lock) { return(Inmates.Select(x => x.Value).ToList()); } }
public (int noted, int banned) CountInmates() { lock (Lock) { return(Inmates.Count(x => x.Value.Punishment == Punishment.Noted), Inmates.Count(x => x.Value.Punishment == Punishment.Banned)); } }
public bool TryGet(OutPoint utxo, [NotNullWhen(returnValue: true)] out Inmate?inmate) { lock (Lock) { return(Inmates.TryGetValue(utxo, out inmate)); } }
public static void SortInmates() { var inmates = Inmates.ToList(); inmates.Sort(new InmateComparer()); Inmates.Clear(); foreach (var inmate in inmates) { Inmates.Add(inmate); } }
public static void MapInmateToViewModel(Inmate inmate) { // shop obj needed to get the shop index for the drop down menu var shop = Shops.SingleOrDefault(s => s.Id == inmate.ShopId); Inmates.Add(new InmateViewModel { Id = inmate.Id, FirstName = inmate.FirstName, LastName = inmate.LastName, GDCNumber = inmate.GDCNumber, ShopId = inmate.ShopId, ShopIndex = Shops.IndexOf(shop) }); }
public bool TryRelease(OutPoint utxo, [NotNullWhen(returnValue: true)] out Inmate?inmate) { lock (Lock) { if (Inmates.TryGetValue(utxo, out inmate)) { Inmates.Remove(utxo); ChangeId = Guid.NewGuid(); return(true); } else { return(false); } } }
public void Punish(Inmate inmate) { lock (Lock) { var utxo = inmate.Utxo; // If successfully removed, then it contained it previously, so make the punishment banned and restart its time. Inmate inmateToPunish = inmate; if (Inmates.Remove(utxo)) { // If it was noted before, then no matter the specified punishment, it must be banned. // Both the started and the last disrupted round parameters must be updated. inmateToPunish = new Inmate(utxo, Punishment.Banned, inmate.Started, inmate.LastDisruptedRoundId); } Inmates.Add(utxo, inmateToPunish); ChangeId = Guid.NewGuid(); } }
public IEnumerable <Inmate> ReleaseEligibleInmates(TimeSpan time) { lock (Lock) { var released = new List <Inmate>(); foreach (var inmate in Inmates.Values.ToList()) { if (inmate.TimeSpent > time) { Inmates.Remove(inmate.Utxo); released.Add(inmate); } } if (released.Any()) { ChangeId = Guid.NewGuid(); } return(released); } }
public IEnumerable <Inmate> ReleaseEligibleInmates(TimeSpan normalBanPeriod, TimeSpan longBanPeriod) { lock (Lock) { var released = new List <Inmate>(); foreach (var inmate in Inmates.Values.ToList()) { var banPeriod = inmate.Punishment is Punishment.LongBanned ? longBanPeriod : normalBanPeriod; if (inmate.TimeSpent > banPeriod) { Inmates.Remove(inmate.Utxo); released.Add(inmate); } } if (released.Any()) { ChangeId = Guid.NewGuid(); } return(released); } }