public async Task <bool> PublishUpdate(PollSummary summary)
        {
            var pollId = summary.Poll?.Id;

            if (pollId == null || pollId == "")
            {
                return(false);
            }


            var memoryStream = new MemoryStream();

            using (var outputStream = new Google.Protobuf.CodedOutputStream(memoryStream))
            {
                summary.WriteTo(outputStream);
            }



            var summaryData = System.Convert.ToBase64String(memoryStream.ToArray());

            var receivers = await _subscriber.PublishAsync(GetRedisChannel(pollId), summaryData);

            _logger.LogDebug($"Publishing update to {receivers} receivers");
            return(true);
        }
        public async Task <bool> UpsertPollSummary(PollSummary summary)
        {
            try
            {
                var memoryStream = new MemoryStream();
                using (var outputStream = new Google.Protobuf.CodedOutputStream(memoryStream))
                {
                    summary.WriteTo(outputStream);
                }


                var summaryData = memoryStream.ToArray();

                var pollId = summary.Poll?.Id;
                if (pollId == null || pollId == "")
                {
                    return(false);
                }

                var response = await _database.HashSetAsync(PollSummaryHashKey, pollId, summaryData, When.Always);

                var didPublish = await _pubSub.PublishUpdate(summary);

                return(didPublish);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while poll summary to database");
                return(false);
            }
        }
        public PollSummary DefaultPollSummary(Poll poll)
        {
            var summary = new PollSummary();

            summary.TotalVotes = 0;
            summary.Poll       = poll;

            for (var i = 0; i < poll.Options.Count; i++)
            {
                var optionSummary = new PollOptionSummary {
                    Option     = poll.Options[i],
                    Rank       = i,
                    Ratio      = 0,
                    VoteCounts = 0,
                };
                summary.Options.Add(optionSummary);
            }

            return(summary);
        }