コード例 #1
0
        private void Handle(UserKeysMessage message)
        {
            var keys = new string(message.Keys).ToLower();

            this.logger.LogAsync($"Received message from {message.Name}: {keys}")
            .PipeTo(this.Self);

            var foundBadWords = new List <string>();

            foreach (var word in UserActor.BadWords)
            {
                if (keys.Contains(word))
                {
                    foundBadWords.Add(word);
                }
            }

            if (foundBadWords.Count > 0)
            {
                var notification = Context.ActorOf(
                    Context.DI().Props <EmailActor>());
                notification.Tell(new UserBadWordsMessage(
                                      message.Name, foundBadWords.ToArray()));
            }
        }
コード例 #2
0
        public async Task ProcessAsync(UserKeysMessage message)
        {
            var keys = new string(message.Keys.ToArray()).ToLower();

            await this.logger.LogAsync($"Received message from {message.Name}: {keys}");

            var foundBadWords = new List <string>();

            foreach (var word in UserGrain.BadWords)
            {
                if (keys.Contains(word))
                {
                    foundBadWords.Add(word);
                }
            }

            await this.logger.LogAsync($"Bad word count for {message.Name}: {this.State.BadWords.Count}");

            if (foundBadWords.Count > 0)
            {
                this.State.BadWords.AddRange(foundBadWords);
                await this.WriteStateAsync();

                var badWords = string.Join(", ", foundBadWords);
                await this.notification.Value.SendAsync("*****@*****.**", "BAD WORDS SAID",
                                                        $"The user {message.Name} typed the following bad words: {badWords}");

                var streamProvider = this.GetStreamProvider("NotificationStream");
                var stream         = streamProvider.GetStream <string>(this.streamId, "NotificationData");
                await stream.OnNextAsync(badWords);
            }
        }
コード例 #3
0
        public async Task ProcessAsync(UserKeysMessage message)
        {
            var keys = new string(message.Keys).ToLower();

            await this.logger.LogAsync($"Received message from {message.Name}: {keys}");

            if (keys.Contains("die"))
            {
                throw new NotSupportedException("I will never die!");
            }

            var foundBadWords = new List <string>();

            foreach (var word in UserGrain.BadWords)
            {
                if (keys.Contains(word))
                {
                    foundBadWords.Add(word);
                }
            }

            if (foundBadWords.Count > 0)
            {
                this.State.BadWords.AddRange(foundBadWords);
                await this.WriteStateAsync();

                var badWords = string.Join(", ", foundBadWords);
                await this.notification.Value.SendAsync("*****@*****.**", "BAD WORDS SAID",
                                                        $"The user {message.Name} typed the following bad words: {badWords}");
            }

            await this.logger.LogAsync($"Bad word count for {message.Name}: {this.State.BadWords.Count}");
        }
コード例 #4
0
 private void Handle(UserKeysMessage message)
 {
     if (this.users.ContainsKey(message.Name))
     {
         this.users[message.Name].Tell(message);
     }
     else
     {
         var user = ActorBase.Context.ActorOf(
             ActorBase.Context.DI().Props <UserActor>(), message.Name);
         this.users.Add(message.Name, user);
         Console.Out.WriteLine($"New user at {user.Path.ToStringWithAddress()}");
         user.Tell(message);
     }
 }
コード例 #5
0
 public void Post([FromBody] UserKeysMessage value)
 {
     this.holder.UsersActor.Tell(value);
 }