public async Task <bool> TryRemoveStateAsync(string stateName, CancellationToken cancellationToken)
        {
            ArgumentVerifier.ThrowIfNull(stateName, nameof(stateName));

            EnsureStateProviderInitialized();

            if (this.stateChangeTracker.ContainsKey(stateName))
            {
                var stateMetadata = this.stateChangeTracker[stateName];

                switch (stateMetadata.ChangeKind)
                {
                case StateChangeKind.Remove:
                    return(false);

                case StateChangeKind.Add:
                    this.stateChangeTracker.Remove(stateName);
                    return(true);
                }

                stateMetadata.ChangeKind = StateChangeKind.Remove;
                return(true);
            }

            if (await this.actor.Host.StateProvider.ContainsStateAsync(this.actorTypeName, this.actor.Id.ToString(), stateName, cancellationToken))
            {
                this.stateChangeTracker.Add(stateName, StateMetadata.CreateForRemove());
                return(true);
            }

            return(false);
        }
示例#2
0
        public async Task <bool> TryRemoveStateAsync(string stateName, CancellationToken cancellationToken)
        {
            Requires.Argument("stateName", stateName).NotNull();

            if (this.stateChangeTracker.ContainsKey(stateName))
            {
                var stateMetadata = this.stateChangeTracker[stateName];

                switch (stateMetadata.ChangeKind)
                {
                case StateChangeKind.Remove:
                    return(false);

                case StateChangeKind.Add:
                    this.stateChangeTracker.Remove(stateName);
                    return(true);
                }

                stateMetadata.ChangeKind = StateChangeKind.Remove;
                return(true);
            }

            if (await this.stateProvider.ContainsStateAsync(this.actor.Id, stateName, cancellationToken))
            {
                this.stateChangeTracker.Add(stateName, StateMetadata.CreateForRemove());
                return(true);
            }

            return(false);
        }