/// <summary> /// Full state of the <see cref="AtLeastOnceDeliverySemantic"/>. It can be saved with /// <see cref="Eventsourced.SaveSnapshot" />. During recovery the snapshot received in /// <see cref="SnapshotOffer"/> should be set with <see cref="SetDeliverySnapshot"/>. /// /// The <see cref="AtLeastOnceDeliverySnapshot"/> contains the full delivery state, /// including unconfirmed messages. If you need a custom snapshot for other parts of the /// actor state you must also include the <see cref="AtLeastOnceDeliverySnapshot"/>. /// It is serialized using protobuf with the ordinary Akka serialization mechanism. /// It is easiest to include the bytes of the <see cref="AtLeastOnceDeliverySnapshot"/> /// as a blob in your custom snapshot. /// </summary> /// <returns>TBD</returns> public AtLeastOnceDeliverySnapshot GetDeliverySnapshot() { UnconfirmedDelivery[] unconfirmedDeliveries = _unconfirmed .Select(e => new UnconfirmedDelivery(e.Key, e.Value.Destination, e.Value.Message)) .ToArray(); return(new AtLeastOnceDeliverySnapshot(_deliverySequenceNr, unconfirmedDeliveries)); }
private Map( int gid = 0, ImmutableSortedDictionary <int, Group <N, V> > groups = null, ImmutableSortedDictionary <N, ImmutableHashSet <int> > index = null ) { _nextGid = gid; _groups = groups ?? ImmutableSortedDictionary <int, Group <N, V> > .Empty; _index = index ?? ImmutableSortedDictionary <N, ImmutableHashSet <int> > .Empty; _hash = _groups .Select(kv => kv.Value) .Aggregate(17, (ac, g) => (ac + g.GetHashCode() * 3) + 5); }
public async Task <CommandResult> Badges(CommandContext context) { (Optional <PkmnSpecies> optionalSpecies, Optional <User> optionalUser) = await context.ParseArgs <Optional <PkmnSpecies>, Optional <User> >(); Console.WriteLine($"species present: {optionalSpecies.IsPresent}"); Console.WriteLine($"user present: {optionalUser.IsPresent}"); bool isSelf = !optionalUser.IsPresent; User user = isSelf ? context.Message.User : optionalUser.Value; if (optionalSpecies.IsPresent) { PkmnSpecies species = optionalSpecies.Value; long numBadges = await _badgeRepo.CountByUserAndSpecies(user.Id, species); return(new CommandResult { Response = numBadges == 0 ? isSelf ? $"You have no {species} badges." : $"{user.Name} has no {species} badges." : isSelf ? $"You have {numBadges}x {species} badges." : $"{user.Name} has {numBadges}x {species} badges." }); } else { ImmutableSortedDictionary <PkmnSpecies, int> numBadgesPerSpecies = await _badgeRepo.CountByUserPerSpecies(user.Id); if (!numBadgesPerSpecies.Any()) { return(new CommandResult { Response = isSelf ? "You have no badges." : $"{user.Name} has no badges." }); } IEnumerable <string> badgesFormatted = numBadgesPerSpecies.Select(kvp => $"{kvp.Value}x {kvp.Key}"); return(new CommandResult { Response = isSelf ? $"Your badges: {string.Join(", ", badgesFormatted)}" : $"{user.Name}'s badges: {string.Join(", ", badgesFormatted)}", ResponseTarget = ResponseTarget.WhisperIfLong }); } }
/// <inheritdoc/> public override string ToString() { var versions = _versions.Select(p => p.Key + "->" + p.Value); return($"VectorClock({string.Join(", ", versions)})"); }
public override string ToString() { return(String.Format("VectorClock({0})", _versions.Select(p => p.Key + "->" + p.Value).Aggregate((n, t) => n + ", " + t))); }
public ImmutableSortedDictionary <TKey2, TValue2> Convert(ImmutableSortedDictionary <TKey1, TValue1> source, ImmutableSortedDictionary <TKey2, TValue2> destination, ResolutionContext context) { return(source.Select(p => new KeyValuePair <TKey2, TValue2>(context.Mapper.Map <TKey1, TKey2>(p.Key), context.Mapper.Map <TValue1, TValue2>(p.Value))).ToImmutableSortedDictionary()); }
private List <PlayTimeInfo> ConvertToPlayTimeList(ImmutableSortedDictionary <string, int?> playTimes) { return(playTimes .Select(pair => new PlayTimeInfo(pair.Key, Convert.ToInt32(pair.Value))) .ToList()); }
protected List <int> FindUniqueCandidates(ImmutableSortedDictionary <Position, SudokuElement> elements) => elements .Select(n => n.Value) .Where(n => n.Number == Data.Empty) .SelectMany(n => n.Candidates) .GroupBy(n => n) .Select(num => new { num.Key, Total = num.Count() }) .Where(n => n.Total <= 1) .Select(n => n.Key) .ToList();