public override void RemoveContributor(ParticipantId participant) { if (_contributors.Contains(participant)) { _contributors.Remove(participant); } }
/// <summary> /// Creates an empty snapshot. /// </summary> public EmptyWaveletSnapshot(WaveId waveId, WaveletId waveletId, ParticipantId creator, HashedVersion version, DateTime creationTime) { WaveId = waveId; WaveletId = waveletId; Creator = creator; HashedVersion = version; CreationTime = creationTime; }
public Confirmation(ParticipantId paricipant, Guid transactionId, DateTime timestamp, Func <Task> call, ILogger logger) { this.paricipant = paricipant; this.transactionId = transactionId; this.timestamp = timestamp; this.call = call; this.logger = logger; this.pending = null; this.complete = false; }
protected AbstractBlipData(string id, AbstractWaveletData<IBlipData> wavelet, ParticipantId author, IDocumentOperationSink content, DateTime lastModifiedTime, long lastModifiedVersion) { Content = content; Id = id; Author = author; _wavelet = wavelet; LastModifiedTime = lastModifiedTime; LastModifiedVersion = lastModifiedVersion; }
public async Task <IActionResult> FindParticipantAsync(ParticipantId participantId) { var participant = await _participantQuery.FindParticipantAsync(participantId); if (participant == null) { return(this.NotFound("Participant not found.")); } return(this.Ok(_mapper.Map <ChallengeParticipantDto>(participant))); }
public async Task <IActionResult> FetchParticipantMatchesAsync(ParticipantId participantId) { var matches = await _matchQuery.FetchParticipantMatchesAsync(participantId); if (!matches.Any()) { return(this.NoContent()); } return(this.Ok(_mapper.Map <IReadOnlyCollection <ChallengeMatchDto> >(matches))); }
public override int GetHashCode() { unchecked { int hashCode = (ParticipantId != null ? ParticipantId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Deduction; hashCode = (hashCode * 397) ^ (Time != null ? Time.GetHashCode() : 0); return(hashCode); } }
public async Task Ping(Guid transactionId, DateTime timeStamp, ParticipantId participant) { this.logger.Info($"Grain {this.context.GrainInstance} started Ping transaction {transactionId}"); await this.tm.Ping(transactionId, timeStamp, participant); if (this.deactivationPhaseReference.DeactivationPhase == TransactionDeactivationPhase.AfterPing) { this.grainRuntime.DeactivateOnIdle((context.GrainInstance)); this.deactivationPhaseReference.DeactivationPhase = TransactionDeactivationPhase.None; this.logger.Info($"Grain {this.context.GrainInstance} deactivating after transaction {transactionId} Ping"); } }
public override byte[] ToBytes() { return(TLUtils.Combine( TLUtils.SignatureToBytes(Signature), Id.ToBytes(), AccessHash.ToBytes(), Date.ToBytes(), AdminId.ToBytes(), ParticipantId.ToBytes(), GB.ToBytes(), Protocol.ToBytes())); }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); Id.ToStream(output); AccessHash.ToStream(output); Date.ToStream(output); AdminId.ToStream(output); ParticipantId.ToStream(output); GB.ToStream(output); Protocol.ToStream(output); }
public async Task Ping(Guid transactionId, DateTime timeStamp, ParticipantId participant) { this.logger.Info($"Grain {this.context.GrainInstance} started Ping transaction {transactionId}"); await this.tm.Ping(transactionId, timeStamp, participant); if (this.faultInjectionControl?.FaultInjectionPhase == TransactionFaultInjectPhase.AfterPing && this.faultInjectionControl.FaultInjectionType == FaultInjectionType.Deactivation) { this.grainRuntime.DeactivateOnIdle((context.GrainInstance)); this.faultInjectionControl.FaultInjectionPhase = TransactionFaultInjectPhase.None; this.logger.Info($"Grain {this.context.GrainInstance} deactivating after transaction {transactionId} Ping"); } }
public async Task Prepared(Guid transactionId, DateTime timeStamp, ParticipantId participant, TransactionalStatus status) { this.logger.Info($"Grain {this.context.GrainInstance} started Prepared transaction {transactionId}"); await this.tm.Prepared(transactionId, timeStamp, participant, status); if (this.faultInjectionControl.FaultInjectionPhase == TransactionFaultInjectPhase.AfterPrepared && this.faultInjectionControl?.FaultInjectionType == FaultInjectionType.Deactivation) { this.grainRuntime.DeactivateOnIdle((context.GrainInstance)); this.logger.Info($"Grain {this.context.GrainInstance} deactivating after transaction {transactionId} Prepared"); } this.faultInjectionControl.Reset(); }
public override byte[] ToBytes() { return(TLUtils.Combine( TLUtils.SignatureToBytes(Signature), Flags.ToBytes(), Id.ToBytes(), AccessHash.ToBytes(), Date.ToBytes(), AdminId.ToBytes(), ParticipantId.ToBytes(), Protocol.ToBytes(), ToBytes(ReceiveDate, Flags, (int)PhoneCallWaitingFlags.ReceiveDate))); }
/// <inheritdoc /> public override int GetHashCode() { unchecked { int hashCode = ParticipantId.GetHashCode(); hashCode = (hashCode * 397) ^ GX1.GetHashCode(); hashCode = (hashCode * 397) ^ X1V.GetHashCode(); hashCode = (hashCode * 397) ^ X1R.GetHashCode(); hashCode = (hashCode * 397) ^ GX2.GetHashCode(); hashCode = (hashCode * 397) ^ X2V.GetHashCode(); hashCode = (hashCode * 397) ^ X2R.GetHashCode(); return(hashCode); } }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); Flags.ToStream(output); Id.ToStream(output); AccessHash.ToStream(output); Date.ToStream(output); AdminId.ToStream(output); ParticipantId.ToStream(output); Protocol.ToStream(output); ToStream(output, ReceiveDate, Flags, (int)PhoneCallWaitingFlags.ReceiveDate); }
public TocTransactionQueue( TService service, IOptions <TransactionalStateOptions> options, ParticipantId resource, Action deactivate, ITransactionalStateStorage <TransactionCommitter <TService> .OperationState> storage, JsonSerializerSettings serializerSettings, IClock clock, ILogger logger) : base(options, resource, deactivate, storage, serializerSettings, clock, logger) { this.service = service; }
public TocTransactionQueue( TService service, IOptions <TransactionalStateOptions> options, ParticipantId resource, Action deactivate, ITransactionalStateStorage <TransactionCommitter <TService> .OperationState> storage, IClock clock, ILogger logger, ITimerManager timerManager, IActivationLifetime activationLifetime) : base(options, resource, deactivate, storage, clock, logger, timerManager, activationLifetime) { this.service = service; }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); Id.ToStream(output); AccessHash.ToStream(output); Date.ToStream(output); AdminId.ToStream(output); ParticipantId.ToStream(output); GAorB.ToStream(output); KeyFingerprint.ToStream(output); Protocol.ToStream(output); Connection.ToStream(output); AlternativeConnections.ToStream(output); StartDate.ToStream(output); }
public override byte[] ToBytes() { return(TLUtils.Combine( TLUtils.SignatureToBytes(Signature), Id.ToBytes(), AccessHash.ToBytes(), Date.ToBytes(), AdminId.ToBytes(), ParticipantId.ToBytes(), GAorB.ToBytes(), KeyFingerprint.ToBytes(), Protocol.ToBytes(), Connection.ToBytes(), AlternativeConnections.ToBytes(), StartDate.ToBytes())); }
public async Task Ping(Guid transactionId, DateTime timeStamp, ParticipantId participant) { this.logger.LogInformation("Grain {GrainInstance} started Ping transaction {TransactionId}", context.GrainInstance, transactionId); await this.tm.Ping(transactionId, timeStamp, participant); if (this.faultInjectionControl?.FaultInjectionPhase == TransactionFaultInjectPhase.AfterPing && this.faultInjectionControl.FaultInjectionType == FaultInjectionType.Deactivation) { this.grainRuntime.DeactivateOnIdle(context); this.logger.LogInformation( "Grain {GrainInstance} deactivating after transaction {TransactionId} Ping", context.GrainInstance, transactionId); } this.faultInjectionControl.Reset(); }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); output.Write(Id.ToBytes()); output.Write(AccessHash.ToBytes()); output.Write(Date.ToBytes()); output.Write(AdminId.ToBytes()); output.Write(ParticipantId.ToBytes()); Key.NullableToStream(output); KeyFingerprint.NullableToStream(output); P.NullableToStream(output); G.NullableToStream(output); A.NullableToStream(output); MessageTTL.NullableToStream(output); FileName.NullableToStream(output); }
public static Participant ToEntity(this ParticipantModel model) { var participant = new Participant( ParticipantId.FromGuid(model.Id), UserId.FromGuid(model.UserId), PlayerId.Parse(model.PlayerId), new DateTimeProvider(model.RegisteredAt)); if (model.SynchronizedAt.HasValue && model.Matches != null) { participant.Snapshot(model.Matches.Select(match => match.ToEntity()), new DateTimeProvider(model.SynchronizedAt.Value)); } participant.ClearDomainEvents(); return(participant); }
public async Task HandleAsync_WhenChallengeParticipantRegisteredIntegrationEventIsValid_ShouldBeCompletedTask() { // Arrange var participantId = new ParticipantId(); TestMock.UserService.Setup(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>())) .Returns(Task.CompletedTask) .Verifiable(); var handler = new ChallengeParticipantRegisteredIntegrationEventHandler(TestMock.UserService.Object, TestMock.SendgridOptions.Object); var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent { Participant = new ChallengeParticipantDto { ChallengeId = new ChallengeId(), GamePlayerId = "testId", Id = participantId, Score = new DecimalValue(50.0m), SynchronizedAt = DateTime.UtcNow.ToTimestamp(), UserId = new UserId(), Matches = { new ChallengeMatchDto { Id = new MatchId(), ParticipantId = participantId, Score = DecimalValue.FromDecimal(10) }, new ChallengeMatchDto { Id = new MatchId(), ParticipantId = participantId, Score = DecimalValue.FromDecimal(10) } } } }; // Act await handler.HandleAsync(integrationEvent); // Assert TestMock.UserService.Verify(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>()), Times.Once); }
public ConfirmationWorker( IOptions <TransactionalStateOptions> options, ParticipantId me, BatchWorker storageWorker, Func <StorageBatch <TState> > getStorageBatch, ILogger logger, ITimerManager timerManager, IActivationLifetime activationLifetime) { this.options = options.Value; this.me = me; this.storageWorker = storageWorker; this.getStorageBatch = getStorageBatch; this.logger = logger; this.timerManager = timerManager; this.activationLifetime = activationLifetime; this.pending = new HashSet <Guid>(); }
public override int GetHashCode() { int hash = 1; if (ParticipantId != 0L) { hash ^= ParticipantId.GetHashCode(); } if (StageId != 0L) { hash ^= StageId.GetHashCode(); } if (Score != 0D) { hash ^= Score.GetHashCode(); } return(hash); }
public async Task <DomainValidationResult <Participant> > RegisterChallengeParticipantAsync( IChallenge challenge, UserId userId, ParticipantId participantId, PlayerId playerId, IDateTimeProvider registeredAt, CancellationToken cancellationToken = default ) { var result = new DomainValidationResult <Participant>(); if (challenge.SoldOut) { result.AddFailedPreconditionError("The challenge was sold out."); } if (challenge.ParticipantExists(userId)) { result.AddFailedPreconditionError("The user already is registered."); } if (result.IsValid) { var participant = new Participant( participantId, userId, playerId, registeredAt); challenge.Register(participant); if (challenge.SoldOut) { challenge.Start(registeredAt); } await _challengeRepository.CommitAsync(true, cancellationToken); return(participant); } return(result); }
public static async Task PublishChallengeParticipantRegisteredIntegrationEventAsync( this IServiceBusPublisher publisher, ChallengeId challengeId, UserId userId, ParticipantId participantId ) { var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent { Participant = new ChallengeParticipantDto { Id = participantId, ChallengeId = challengeId, UserId = userId } }; await publisher.PublishAsync(integrationEvent); }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); output.Write(Id.ToBytes()); output.Write(AccessHash.ToBytes()); output.Write(Date.ToBytes()); output.Write(AdminId.ToBytes()); output.Write(ParticipantId.ToBytes()); Key.NullableToStream(output); KeyFingerprint.NullableToStream(output); P.NullableToStream(output); G.NullableToStream(output); A.NullableToStream(output); MessageTTL.NullableToStream(output); CustomFlags.NullableToStream(output); ToStream(output, OriginalKey, CustomFlags, (int)EncryptedChatCustomFlags.OriginalKey); ToStream(output, ExtendedKey, CustomFlags, (int)EncryptedChatCustomFlags.ExtendedKey); }
public TransactionQueue( IOptions <TransactionalStateOptions> options, ParticipantId resource, Action deactivate, ITransactionalStateStorage <TState> storage, JsonSerializerSettings serializerSettings, IClock clock, ILogger logger) { this.options = options.Value; this.resource = resource; this.deactivate = deactivate; this.storage = storage; this.serializerSettings = serializerSettings; this.Clock = new CausalClock(clock); this.logger = logger; this.confirmationTasks = new Dictionary <Guid, TransactionRecord <TState> >(); this.storageWorker = new BatchWorkerFromDelegate(StorageWork); this.confirmationWorker = new BatchWorkerFromDelegate(ConfirmationWork); this.RWLock = new ReadWriteLock <TState>(options, this, this.storageWorker, logger); }
public void NotifyOfPing(Guid transactionId, DateTime timeStamp, ParticipantId resource) { if (this.commitQueue.Find(transactionId, timeStamp) != -1) { // no need to take special action now - the transaction is still // in the commit queue and its status is not yet determined. // confirmation or cancellation will be sent after committing or aborting. if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("received ping for {TransactionId}, irrelevant (still processing)", transactionId); } this.storageWorker.Notify(); // just in case the worker fell asleep or something } else { if (this.confirmationTasks.TryGetValue(transactionId, out var record)) { if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("received ping for {TransactionId}, irrelevant (still notifying)", transactionId); } // re-send now this.confirmationWorker.Notify(); } else { if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("received ping for {TransactionId}, unknown - presumed abort", transactionId); } // we never heard of this transaction - so it must have aborted resource.Reference.AsReference <ITransactionalResourceExtension>() .Cancel(resource.Name, transactionId, timeStamp, TransactionalStatus.PresumedAbort).Ignore(); } } }
public TransactionQueue( IOptions <TransactionalStateOptions> options, ParticipantId resource, Action deactivate, ITransactionalStateStorage <TState> storage, JsonSerializerSettings serializerSettings, IClock clock, ILogger logger) { this.options = options.Value; this.resource = resource; this.deactivate = deactivate; this.storage = storage; this.Clock = new CausalClock(clock); this.logger = logger; this.storageWorker = new BatchWorkerFromDelegate(StorageWork); this.RWLock = new ReadWriteLock <TState>(options, this, this.storageWorker, logger); this.confirmationWorker = new ConfirmationWorker <TState>(options, this.resource, this.storageWorker, () => this.storageBatch, this.logger); this.unprocessedPreparedMessages = new Dictionary <DateTime, PreparedMessages>(); this.commitQueue = new CommitQueue <TState>(); this.readyTask = Task.CompletedTask; }
/// <summary> /// Called when the dialog is started and pushed onto the dialog stack. /// </summary> /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param> /// <param name="options">Optional, initial information to pass to the dialog.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken)) { if (options is CancellationToken) { throw new ArgumentException($"{nameof(options)} cannot be a cancellation token"); } if (this.Disabled != null && this.Disabled.GetValue(dc.State)) { return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false)); } if (dc.Context.Activity.ChannelId != Channels.Msteams) { throw new InvalidOperationException($"{Kind} works only on the Teams channel."); } string meetingId = MeetingId.GetValueOrNull(dc.State); string participantId = ParticipantId.GetValueOrNull(dc.State); string tenantId = TenantId.GetValueOrNull(dc.State); if (participantId == null) { // TeamsInfo.GetMeetingParticipantAsync will default to retrieving the current meeting's participant // if none is provided. This could lead to unexpected results. Therefore, GetMeetingParticipant action // throws an exception if the expression provided somehow maps to an invalid result. throw new InvalidOperationException($"{Kind} could not determine the participant id by expression value provided. {nameof(participantId)} is required."); } var result = await TeamsInfo.GetMeetingParticipantAsync(dc.Context, meetingId, participantId, tenantId, cancellationToken : cancellationToken).ConfigureAwait(false); if (this.Property != null) { dc.State.SetValue(this.Property.GetValue(dc.State), result); } return(await dc.EndDialogAsync(result, cancellationToken : cancellationToken).ConfigureAwait(false)); }
public async Task HandleAsync_ChallengeParticipantRegisteredIntegrationEventIsValid_ShouldBeCompletedTask() { // Arrange var userId = new UserId(); var account = new Account(userId); var participantId = new ParticipantId(); var mockLogger = new MockLogger <ChallengeParticipantRegisteredIntegrationEventHandler>(); TestMock.AccountService.Setup(accountService => accountService.AccountExistsAsync(It.IsAny <UserId>())).ReturnsAsync(true).Verifiable(); TestMock.AccountService.Setup(accountService => accountService.FindAccountAsync(It.IsAny <UserId>())).ReturnsAsync(account).Verifiable(); TestMock.AccountService .Setup( accountService => accountService.MarkAccountTransactionAsSucceededAsync( It.IsAny <IAccount>(), It.IsAny <TransactionMetadata>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new DomainValidationResult <ITransaction>()) .Verifiable(); var handler = new ChallengeParticipantRegisteredIntegrationEventHandler(TestMock.AccountService.Object, mockLogger.Object); var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent { Participant = new ChallengeParticipantDto { ChallengeId = new ChallengeId(), GamePlayerId = new PlayerId(), UserId = userId, Score = DecimalValue.FromDecimal(20), SynchronizedAt = DateTime.UtcNow.ToTimestamp(), Id = participantId, Matches = { new ChallengeMatchDto { Id = new MatchId(), ParticipantId = participantId, Score = DecimalValue.FromDecimal(10) }, new ChallengeMatchDto { Id = new MatchId(), ParticipantId = participantId, Score = DecimalValue.FromDecimal(10) } } } }; // Act await handler.HandleAsync(integrationEvent); // Assert TestMock.AccountService.Verify(accountService => accountService.AccountExistsAsync(It.IsAny <UserId>()), Times.Once); TestMock.AccountService.Verify(accountService => accountService.FindAccountAsync(It.IsAny <UserId>()), Times.Once); TestMock.AccountService.Verify( accountService => accountService.MarkAccountTransactionAsSucceededAsync( It.IsAny <IAccount>(), It.IsAny <TransactionMetadata>(), It.IsAny <CancellationToken>()), Times.Once); mockLogger.Verify(Times.Once()); }
public override void AddContributor(ParticipantId participant) { _contributors.Add(participant); }
public BlipData(string docId, WaveletData waveletData, ParticipantId author, IList<ParticipantId> contributors, IDocumentOperationSink contentSink, DateTime lastModifiedTime, long lastModifiedVersion) : base(docId, waveletData, author, contentSink, lastModifiedTime, lastModifiedVersion) { _contributors = contributors; }
public abstract void RemoveContributor(ParticipantId participant);
public abstract void AddContributor(ParticipantId participant);