Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("VowelConsCounter has started...");
            RedisHelper redis    = new RedisHelper();
            var         rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("text-rank-tasks", ExchangeType.Direct);
            rabbitMq.ExchangeDeclare("vowel-cons-counter", ExchangeType.Direct);
            rabbitMq.BindQueueToExchange("text-rank-tasks");
            rabbitMq.ConsumeQueue(message =>
            {
                string redisValue = String.Empty;

                redisValue       = redis.Database.StringGet(message);
                var vowelConsNum = TextRankCalc.Calc(redisValue);

                rabbitMq.PublishToExchange("vowel-cons-counter", $"{message}|{vowelConsNum.Consonants}|{vowelConsNum.Vowels}");

                Console.WriteLine(" [x] Received from redis {0} with key: {1} equals {2}", redisValue, message, $"{vowelConsNum.Consonants}|{vowelConsNum.Vowels}");
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("TextRankCalck has started...");
            RedisHelper redis    = RedisHelper.Instance;
            var         rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("processing-limiter", ExchangeType.Fanout);
            rabbitMq.ExchangeDeclare("text-rank-tasks", ExchangeType.Direct);
            rabbitMq.BindQueueToExchange("processing-limiter");
            rabbitMq.ConsumeQueue(message =>
            {
                Console.WriteLine($"Acepted message {message}");

                string[] splittedMessage = message.Split('|');
                string textId            = splittedMessage[0];
                bool doesTextAllowed     = splittedMessage[1] == "True";
                if (!doesTextAllowed)
                {
                    Console.WriteLine($"{message} not allowed");
                    return;
                }
                RedisHelper.Instance.SetDatabase(RedisHelper.Instance.CalculateDatabase(textId));
                if (RedisHelper.Instance.Database.StringGet($"status_{textId}") != Status.Accepted)
                {
                    Console.WriteLine($"'status_{textId}: {Status.Processing}' to redis database({RedisHelper.Instance.Database.Database})");
                    RedisHelper.Instance.Database.StringSet($"status_{textId}", Status.Processing);
                }

                rabbitMq.PublishToExchange("text-rank-tasks", textId);
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("VowelConsRater has started...");
            var    rabbitMq   = new RabbitMq();
            string rankPrefix = "rank_";

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("vowel-cons-counter", ExchangeType.Direct);
            rabbitMq.ExchangeDeclare("text-rank-calc", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("vowel-cons-counter");
            rabbitMq.ConsumeQueue(message =>
            {
                var info      = message.Split('|');
                var contextId = info[0];
                var volwes    = info[1];
                var cons      = info[2];

                var rank       = TextRankCalc.Calc(Decimal.Parse(volwes), Decimal.Parse(cons));
                var databaseId = RedisHelper.Instance.CalculateDatabase(contextId);
                RedisHelper.Instance.SetDatabase(databaseId);
                RedisHelper.Instance.Database.StringSet($"{rankPrefix}{contextId}", $"{rank.ToString()}");
                rabbitMq.PublishToExchange("text-rank-calc", $"{contextId}|{rank}");
                Console.WriteLine(" [x] Received from redis {0} with key: {1} equals {2}", message, rank);
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            string      statusOfText = "status_";
            RedisHelper redishelper  = RedisHelper.Instance;

            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("backend-api");
            rabbitMq.ConsumeQueue(message =>
            {
                Console.WriteLine($"New message from text-rank-calc: \"{message}\"");
                redishelper.SetDatabase(redishelper.CalculateDatabase(message));

                bool status = _succeededTextCount < _limit;

                if (status)
                {
                    ++_succeededTextCount;
                    Console.WriteLine($"'{statusOfText}{message}: {Status.Accepted}', redishelper.Database: {redishelper.Database.Database}");
                    redishelper.Database.StringSet($"{statusOfText}{message}", Status.Accepted);
                }
                else
                {
                    Console.WriteLine($"'{statusOfText}{message}: {Status.Rejected}'redishelper.Database: {redishelper.Database.Database}");
                    redishelper.Database.StringSet($"{statusOfText}{message}", Status.Rejected);
                }
                var stringToPublish = $"{message}|" +
                                      (status ? "True" : "False");
                Console.WriteLine($"{stringToPublish} to 'processing-limiter' exchange");
                rabbitMq.PublishToExchange("processing-limiter", stringToPublish);
            });

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("text-success-marker", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("text-success-marker");
            rabbitMq.ConsumeQueue(message =>
            {
                Console.WriteLine($"New message from 'text-success-marker': \"{message}\"");

                string[] data        = message.Split('|');
                bool isTextSucceeded = data[1] == "True";
                if (!isTextSucceeded)
                {
                    Console.WriteLine("Succeeded text count reset");
                    _succeededTextCount -= 1;
                }

                Console.WriteLine("----------");
            });

            Console.WriteLine("TextProcessingLimiter has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #5
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_textListeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_textListeningExchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Console.WriteLine($"New message from {_textListeningExchangeName}: \"{textId}\"");
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));

                bool status = _succeededTextCount < _limit;
                if (status)
                {
                    ++_succeededTextCount;
                    Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Accepted}' to redis database({Redis.Instance.Database.Database})");
                    Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Accepted);
                }
                else
                {
                    Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Rejected}' to redis database({Redis.Instance.Database.Database})");
                    Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Rejected);
                }
                var stringToPublish = $"{textId}{ConstantLibrary.RabbitMq.Delimiter}" +
                                      (status ? ConstantLibrary.RabbitMq.ProcessingLimiter.Status.True : ConstantLibrary.RabbitMq.ProcessingLimiter.Status.False);
                Console.WriteLine($"{stringToPublish} to {_publishExchangeName} exchange");
                rabbitMq.PublishToExchange(_publishExchangeName, stringToPublish);

                Console.WriteLine("----------");
            });

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_textMarkersListeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_textMarkersListeningExchangeName);
            rabbitMq.ConsumeQueue(textIdMarker =>
            {
                Console.WriteLine($"New message from {_textMarkersListeningExchangeName}: \"{textIdMarker}\"");

                string[] data        = textIdMarker.Split(ConstantLibrary.RabbitMq.Delimiter);
                bool isTextSucceeded = data[1] == ConstantLibrary.RabbitMq.TextSuccessMarker.Status.True;
                if (!isTextSucceeded)
                {
                    Console.WriteLine("Succeeded text count reset");
                    _succeededTextCount = 0;
                }

                Console.WriteLine("----------");
            });

            Console.WriteLine("TextProcessingLimiter has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            string      rankString  = "rank_";
            RedisHelper redishelper = RedisHelper.Instance;
            var         rabbitMq    = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(message =>
            {
                Console.WriteLine($"New message from {_listeningExchangeName}: \"{message}\"");
                var info   = message.Split('|');
                var textId = info[0];
                var rank   = Double.Parse(info[1]);
                redishelper.SetDatabase(redishelper.CalculateDatabase(textId));

                Console.WriteLine($"'{rankString}{textId}: {rank}'");

                var stringToPublish = $"{textId}|" +
                                      (rank > _successLowerBound
                        ? "True"
                        : "False");

                Console.WriteLine($"{stringToPublish} to {_publishExchangeName} exchange");
                rabbitMq.PublishToExchange(_publishExchangeName, stringToPublish);

                Console.WriteLine("----------");
            });

            Console.WriteLine($"TextSuccessMarker has started. Success lower bound is {_successLowerBound}");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare(_queueName);
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Direct);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Console.WriteLine($"New message from {_listeningExchangeName}: \"{textId}\"");
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));

                string text = Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Text}{textId}");
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {text}' from redis database({Redis.Instance.Database.Database})");

                VowelConsonant vowelConsonant = CalculateVowelConsonant(text);

                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}' to redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Count}{textId}", $"{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}");

                Console.WriteLine($"{textId} to {_publishExchangeName} exchange");
                rabbitMq.PublishToExchange(_publishExchangeName, textId);

                Console.WriteLine("----------");
            });

            Console.WriteLine("VowelConsonantCounter has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("TextStatistics has started...");
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("text-success-marker", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("text-success-marker");
            rabbitMq.ConsumeQueue(message =>
            {
                Console.WriteLine($" [x] message: {message}");
                var info      = message.Split('|');
                var contextId = info[0];
                var isSuccess = info[1];
                Console.WriteLine($" [x] contextId: {contextId}, isSuccess: {isSuccess}");

                RedisHelper.Instance.Increment("textNum");

                if (isSuccess == "True")
                {
                    RedisHelper.Instance.Increment("highRankPart");
                }
                var rank = Convert.ToDecimal(RedisHelper.Instance.Database.StringGet($"rank_{contextId}"));

                RedisHelper.Instance.Increment("ranksSum", rank);
                var textNum  = Convert.ToDecimal(RedisHelper.Instance.Database.StringGet("textNum"));
                var ranksSum = Convert.ToDecimal(RedisHelper.Instance.Database.StringGet("ranksSum"));
                RedisHelper.Instance.Database.StringSet("avgRank", $"{ranksSum/textNum}");

                Console.WriteLine($" [x] TextNum: {textNum}, ranksSum: {ranksSum}, rankSum: {ranksSum/textNum}");
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #9
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare(queueName);
            rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Direct);
            rabbitMq.BindQueueToExchange(exchangeName);
            rabbitMq.ConsumeQueue(countId =>
            {
                string[] countData = Redis.Instance.Database.StringGet(countId).ToString().Split('|');
                string text        = Redis.Instance.Database.StringGet(countData[0]);
                int vowelCount;
                int consonantCount;
                if (Int32.TryParse(countData[1], out vowelCount) && Int32.TryParse(countData[2], out consonantCount))
                {
                    string rate = CalculateRate(vowelCount, consonantCount);
                    Console.WriteLine($"'{text}: {rate}' to redis");
                    Redis.Instance.Database.StringSet(text, rate);
                }
            });

            Console.WriteLine("VowelConsonantRater has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            RedisHelper redishelper = new RedisHelper();

            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("backend-api");
            rabbitMq.ConsumeQueue(message =>
            {
                string redisValue = String.Empty;
                redisValue        = redishelper.Database.StringGet(message);
                Console.WriteLine(" [x] Received from redis {0} with key: {1}", redisValue, message);
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();

/*            using(var channel = RabbitMQ.RabbitMq.GetModel())
 *          {
 *              RabbitMQHelper.DeclareExchangeQueue("backend-api", channel);
 *              string queueName = channel.QueueDeclare().QueueName;
 *
 *              RabbitMQHelper.BindQueueToExchange("backend-api", channel, queueName);
 *              var consumer = RabbitMQHelper.GetConsumer(channel);
 *              consumer.Received += (model, ea) =>
 *              {
 *
 *              };
 *
 *              RabbitMQHelper.ConsumeQueue("backend-api", consumer, channel);
 *
 *          }            */
        }
Beispiel #11
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Console.WriteLine($"New message from {_listeningExchangeName}: \"{textId}\"");

                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                double rank = Double.Parse(Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}"));
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' from redis database({Redis.Instance.Database.Database})");

                var stringToPublish = $"{textId}{ConstantLibrary.RabbitMq.Delimiter}" +
                                      (rank > _successLowerBound
                                                ? ConstantLibrary.RabbitMq.TextSuccessMarker.Status.True
                                                : ConstantLibrary.RabbitMq.TextSuccessMarker.Status.False);

                Console.WriteLine($"{stringToPublish} to {_publishExchangeName} exchange");
                rabbitMq.PublishToExchange(_publishExchangeName, stringToPublish);

                Console.WriteLine("----------");
            });

            Console.WriteLine($"TextSuccessMarker has started. Success lower bound is {_successLowerBound}");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #12
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare(queueName);
            rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Direct);
            rabbitMq.BindQueueToExchange(exchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                string countKey        = $"{ConstantLibrary.Redis.Prefix.Count}{textId}";
                string countDataString = Redis.Instance.Database.StringGet(countKey);
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {countDataString}' from redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.KeyDelete(countKey);
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {countDataString}' deleted rfrom redis database({Redis.Instance.Database.Database})");
                string[] countData = countDataString.Split('|');
                int vowelCount;
                int consonantCount;
                if (Int32.TryParse(countData[0], out vowelCount) && Int32.TryParse(countData[1], out consonantCount))
                {
                    string rank = CalculateRank(vowelCount, consonantCount);
                    Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}", rank);
                    Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' to redis database({Redis.Instance.Database.Database})");
                }
            });

            Console.WriteLine("VowelConsonantRater has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("TextStatistics has started...");
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("text-rank-calc", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("text-rank-calc");
            rabbitMq.ConsumeQueue(message =>
            {
                var info      = message.Split('|');
                var contextId = info[0];
                var rank      = Convert.ToDecimal(info[1]);
                RedisHelper.Instance.Increment("textNum");

                if (rank > (decimal)0.5)
                {
                    RedisHelper.Instance.Increment("highRankPart");
                }
                RedisHelper.Instance.Increment("ranksSum", rank);
                var textNum  = Convert.ToDecimal(RedisHelper.Instance.Database.StringGet("textNum"));
                var ranksSum = Convert.ToDecimal(RedisHelper.Instance.Database.StringGet("ranksSum"));
                RedisHelper.Instance.Database.StringSet("avgRank", $"{ranksSum/textNum}");

                Console.WriteLine($" [x] TextNum: {textNum}, ranksSum: {ranksSum}, rankSum: {ranksSum/textNum}");
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("TextRankCalck has started...");
            RedisHelper redis    = new RedisHelper();
            var         rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.ExchangeDeclare("text-rank-tasks", ExchangeType.Direct);
            rabbitMq.BindQueueToExchange("backend-api");
            rabbitMq.ConsumeQueue(message =>
            {
                rabbitMq.PublishToExchange("text-rank-tasks", message);
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
        public string Post([FromBody] DataDto value)
        {
            string id = Guid.NewGuid().ToString();

            Redis.Instance.Database.StringSet(id, value.Data);
            const string exchangeName = "backend-api";

            _rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout);
            _rabbitMq.PublishToExchange(exchangeName, id);
            return(id);
        }
Beispiel #16
0
        public string Post([FromBody] DataDto value)
        {
            string textId = Guid.NewGuid().ToString();

            Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
            Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Text}{textId}", value.Data);
            Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {value.Data}' to redis database({Redis.Instance.Database.Database})");
            const string exchangeName = "backend-api";

            _rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout);
            _rabbitMq.PublishToExchange(exchangeName, textId);
            return(textId);
        }
Beispiel #17
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(exchangeName);
            rabbitMq.ConsumeQueue(message =>
            {
                Console.WriteLine($"{message}: {Redis.Instance.Database.StringGet(message)}");
            });

            Console.WriteLine("TextListener has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #18
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(exchangeName);
            rabbitMq.ConsumeQueue(id =>
            {
                Console.WriteLine($"{id} to text-rank-tasks queue");
                rabbitMq.PublishToExchange("text-rank-tasks", id);
            });

            Console.WriteLine("TextRankCalc has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #19
0
        public string Post([FromBody] DataTransferDto dataTransfer)
        {
            if (dataTransfer == null)
            {
                return(null);
            }

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

            _redisHelper.Database.StringSet(id, dataTransfer.Data);
            var rabbitMq = new RabbitMq();

            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.PublishToExchange("backend-api", id);

            return(id);
        }
Beispiel #20
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(id =>
            {
                Console.WriteLine($"{id} to {_publishExchangeName} exchange");
                rabbitMq.PublishToExchange(_publishExchangeName, id);

                Console.WriteLine("----------");
            });

            Console.WriteLine("TextRankCalc has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #21
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(exchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                string text = Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Text}{textId}");
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {text}' from redis database({Redis.Instance.Database.Database})");
                Console.WriteLine($"{textId}: {text}");
            });

            Console.WriteLine("TextListener has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #22
0
        static void Main()
        {
            LoadStatistics();
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(textIdAndStatus =>
            {
                Console.WriteLine($"New message from {_listeningExchangeName}: \"{textIdAndStatus}\"");

                string[] splittedMessage = textIdAndStatus.Split(ConstantLibrary.RabbitMq.Delimiter);
                string textId            = splittedMessage[0];
                bool isSucceededText     = splittedMessage[1] == ConstantLibrary.RabbitMq.TextSuccessMarker.Status.True;

                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                double rank = Double.Parse(Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}"));
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' from redis database({Redis.Instance.Database.Database})");

                ++_statistics.TotalTextCount;
                if (isSucceededText)
                {
                    ++_statistics.HighRankCount;
                }
                _statistics.TotalRank += rank;

                Redis.Instance.SetDatabase(ConstantLibrary.Redis.Statistics.DatabaseId);
                IncreaseStatisticsVersion();
                Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalTextCount, _statistics.TotalTextCount);
                Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalTextCount}: {_statistics.TotalTextCount}' to redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.HighRankCount, _statistics.HighRankCount);
                Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.HighRankCount}: {_statistics.HighRankCount}' to redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalRank, _statistics.TotalRank);
                Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalRank}: {_statistics.TotalRank}' to redis database({Redis.Instance.Database.Database})");

                Console.WriteLine("----------");
            });

            Console.WriteLine("TextStatistics has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #23
0
        public string Post([FromBody] DataTransferDto dataTransfer)
        {
            if (dataTransfer == null)
            {
                return(null);
            }

            var id         = Guid.NewGuid().ToString();
            var databaseId = _redisHelper.CalculateDatabase(id);

            Console.WriteLine($" [x] For {id} database : {databaseId}");
            _redisHelper.SetDatabase(databaseId);
            _redisHelper.Database.StringSet(id, dataTransfer.Data);

            var rabbitMq = new RabbitMq();

            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.PublishToExchange("backend-api", id);

            return(id);
        }
Beispiel #24
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare(_queueName);
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Direct);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Console.WriteLine($"New message from {_listeningExchangeName}: \"{textId}\"");
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                string countKey        = $"{ConstantLibrary.Redis.Prefix.Count}{textId}";
                string countDataString = Redis.Instance.Database.StringGet(countKey);
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {countDataString}' from redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.KeyDelete(countKey);
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {countDataString}' deleted from redis database({Redis.Instance.Database.Database})");
                string[] countData = countDataString.Split(ConstantLibrary.RabbitMq.Delimiter);
                int vowelCount;
                int consonantCount;
                if (Int32.TryParse(countData[0], out vowelCount) && Int32.TryParse(countData[1], out consonantCount))
                {
                    string rank = CalculateRank(vowelCount, consonantCount);

                    Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' to redis database({Redis.Instance.Database.Database})");
                    Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}", rank);

                    Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Completed}' to redis database({Redis.Instance.Database.Database})");
                    Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Completed);

                    Console.WriteLine($"{textId} to {_publishExchangeName} exchange");
                    rabbitMq.PublishToExchange(_publishExchangeName, textId);
                }

                Console.WriteLine("----------");
            });

            Console.WriteLine("VowelConsonantRater has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            RedisHelper redis    = new RedisHelper();
            var         rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("backend-api");
            rabbitMq.ConsumeQueue(message =>
            {
                string redisValue = String.Empty;

                redisValue  = redis.Database.StringGet(message);
                string rank = TextRankCalc.Calc(redisValue).ToString();

                redis.Database.StringSet(message, rank);
                Console.WriteLine(" [x] Received from redis {0} with key: {1} equals {2}", redisValue, message, rank);
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #26
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare(queueName);
            rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Direct);
            rabbitMq.BindQueueToExchange(exchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                string text = Redis.Instance.Database.StringGet(textId);
                VowelConsonant vowelConsonant = CalculateVowelConsonant(text);
                string countId = Guid.NewGuid().ToString();
                Console.WriteLine($"'{countId}: {textId}|{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}' to redis");
                Redis.Instance.Database.StringSet(countId, $"{textId}|{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}");
                Console.WriteLine($"{countId} to vowel-cons-counter queue");
                rabbitMq.PublishToExchange("vowel-cons-counter", countId);
                Console.WriteLine("----------");
            });

            Console.WriteLine("VowelConsonantCounter has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #27
0
        static void Main()
        {
            LoadStatistics();
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(textId =>
            {
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                double rank = Double.Parse(Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}"));
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' from redis database({Redis.Instance.Database.Database})");

                ++_statistics.TotalTextCount;
                if (rank > 0.5)
                {
                    ++_statistics.HighRankCount;
                }
                _statistics.TotalRank += rank;

                Redis.Instance.SetDatabase(ConstantLibrary.Redis.Statistics.DatabaseId);
                IncreaseStatisticsVersion();
                Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalTextCount, _statistics.TotalTextCount);
                Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalTextCount}: {_statistics.TotalTextCount}' to redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.HighRankCount, _statistics.HighRankCount);
                Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.HighRankCount}: {_statistics.HighRankCount}' to redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalRank, _statistics.TotalRank);
                Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalRank}: {_statistics.TotalRank}' to redis database({Redis.Instance.Database.Database})");

                Console.WriteLine("----------");
            });

            Console.WriteLine("TextStatistics has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Text Listener...");

            RedisHelper redishelper = RedisHelper.Instance;

            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange("backend-api");
            rabbitMq.ConsumeQueue(message =>
            {
                var databaseId = RedisHelper.Instance.CalculateDatabase(message);
                RedisHelper.Instance.SetDatabase(databaseId);
                string redisValue = String.Empty;

                redisValue = redishelper.Database.StringGet(message);
                Console.WriteLine(" [x] Received from redis {0} with key: {1}", redisValue, message);
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadKey();
        }
Beispiel #29
0
        static void Main()
        {
            var rabbitMq = new RabbitMq();

            rabbitMq.QueueDeclare();
            rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout);
            rabbitMq.BindQueueToExchange(_listeningExchangeName);
            rabbitMq.ConsumeQueue(textIdAndStatus =>
            {
                Console.WriteLine($"New message from {_listeningExchangeName}: \"{textIdAndStatus}\"");

                string[] splittedMessage = textIdAndStatus.Split(ConstantLibrary.RabbitMq.Delimiter);
                string textId            = splittedMessage[0];
                bool doesTextAllowed     = splittedMessage[1] == ConstantLibrary.RabbitMq.ProcessingLimiter.Status.True;

                if (!doesTextAllowed)
                {
                    Console.WriteLine($"{textId} not allowed");
                    return;
                }
                Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId));
                Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Processing}' to redis database({Redis.Instance.Database.Database})");
                Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Processing);

                // System.Threading.Thread.Sleep(5000);

                Console.WriteLine($"{textId} to {_publishExchangeName} exchange");
                rabbitMq.PublishToExchange(_publishExchangeName, textId);

                Console.WriteLine("----------");
            });

            Console.WriteLine("TextRankCalc has started");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
 public ValuesController()
 {
     _rabbitMq.ExchangeDeclare(_publishExchangeName, ExchangeType.Fanout);
 }