Пример #1
0
        public void Run()
        {
            _subscription = _connection.SubscribeAsync(Const.RankProcess, "rank_calculator", (sender, args) =>
            {
                var id      = Encoding.UTF8.GetString(args.Message.Data);
                var textKey = Const.TextTitleKey + id;

                if (!_redisStorage.IsKeyExist(textKey))
                {
                    _logger.LogWarning("Text key {textKey} doesn't exists", textKey);
                    return;
                }

                var text    = _redisStorage.Load(textKey);
                var rankKey = Const.RankTitleKey + id;
                var rank    = CalculateRank(text).ToString();

                _redisStorage.Store(rankKey, rank);

                string message = $"Event: RankCalculated, context id: {id}, rank: {rank}";
                _connection.Publish(Const.BrokerRank, Encoding.UTF8.GetBytes(message));
            });

            _subscription.Start();

            Console.WriteLine("Press Enter to exit (RankCalculator)");
            Console.ReadLine();

            _subscription.Unsubscribe();

            _connection.Drain();
            _connection.Close();
        }
Пример #2
0
        public void Run()
        {
            var subscription = _connection.SubscribeAsync(Const.BrokerRank, "rank_calculator", (sender, args) =>
            {
                var id      = Encoding.UTF8.GetString(args.Message.Data);
                var textKey = Const.TextTitleKey + id;

                if (!_redisStorage.IsKeyExist(textKey))
                {
                    _logger.LogWarning("Text key {textKey} doesn't exists", textKey);
                    return;
                }

                var text    = _redisStorage.Load(textKey);
                var rankKey = Const.RankTitleKey + id;
                var rank    = CalculateRank(text).ToString();

                _logger.LogDebug("Rank {rank} with key {rankKey} by text id {id}", rank, rankKey, id);

                _redisStorage.Store(rankKey, rank);
            });

            subscription.Start();

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();

            subscription.Unsubscribe();

            _connection.Drain();
            _connection.Close();
        }
Пример #3
0
        public async Task <IActionResult> OnPost(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                Redirect("/");
            }

            var id = Guid.NewGuid().ToString();

            _redisStorage.Store(Const.SimilarityTitleKey + id, GetSimilarity(text, id).ToString());

            _redisStorage.Store(Const.TextTitleKey + id, text);

            await CreateRankCalculator(id);

            return(Redirect($"summary?id={id}"));
        }
Пример #4
0
        public IActionResult OnPost(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                Redirect("/");
            }

            var id = Guid.NewGuid().ToString();

            var similarityKey = "SIMILARITY-" + id;

            _redisStorage.Store(similarityKey, GetSimilarity(text, id).ToString());

            var textKey = "TEXT-" + id;

            _redisStorage.Store(textKey, text);

            var rankKey = "RANK-" + id;

            _redisStorage.Store(rankKey, GetRank(text).ToString());
            return(Redirect($"summary?id={id}"));
        }
Пример #5
0
        public async Task <IActionResult> OnPost(string text, string segment)
        {
            _logger.LogDebug(text);
            if (string.IsNullOrEmpty(text))
            {
                Redirect("/");
            }

            var id = Guid.NewGuid().ToString();

            _logger.LogInformation($"{segment} : {id} - OnPost");
            var similarity = GetSimilarity(text, id);

            _redisStorage.StoreShard(id, segment);
            _redisStorage.Store(Const.SimilarityTitleKey + id, similarity.ToString(), segment);
            _redisStorage.Store(Const.TextTitleKey + id, text, segment);

            await CreateEventForSimilarity(id, similarity);
            await CreateRankCalculator(id);

            return(Redirect($"summary?id={id}"));
        }