Example #1
0
        public void Run()
        {
            SysConsole.WriteLine(GREETING_MESSAGE);
            SysConsole.WriteLine();
            SysConsole.WriteLine(_helpMessage);
            SysConsole.WriteLine();

            _socialNetworkService.Authorize(
                Consts.ACCOUNT_LOGIN,
                Consts.ACCOUNT_PASSWORD,
                _inputCaptcha);

            while (true)
            {
                var authorId = SysConsole.ReadLine();
                if (string.IsNullOrEmpty(authorId))
                {
                    break;
                }

                var lastPosts = _socialNetworkService
                                .GetLastPosts(authorId, Consts.ACCOUNT_POSTS_COUNT);

                if (lastPosts == null)
                {
                    SysConsole.WriteLine(ACCOUNT_OR_GROUP_NOT_FOUND_MESSAGE);
                    SysConsole.WriteLine();
                    continue;
                }
                if (lastPosts.Count == 0)
                {
                    SysConsole.WriteLine(NO_POSTS_MESSAGE);
                    SysConsole.WriteLine();
                    continue;
                }
                var joinedPosts = string.Join(string.Empty, lastPosts);

                var letterFrequency = _letterFrequencyService
                                      .GetLetterFrequency(joinedPosts, Consts.FRACTIONAL_DIGITS_COUNT);
                var serializedFrequency = _serializationService
                                          .SerializeData(letterFrequency);
                var authorName = lastPosts.First().AuthorName;
                var postText   = $"{authorName} (id = {authorId})" + STATISTICS_MESSAGE + Environment.NewLine + serializedFrequency;

                _socialNetworkService.SendPost(postText);

                SysConsole.WriteLine(postText);
                SysConsole.WriteLine();
            }

            SysConsole.WriteLine(FAREWELL_MESSAGE);
            SysConsole.ReadKey();
        }