Beispiel #1
0
        public void CastVote(int number)
        {
            string connectionId = Context.ConnectionId;

            try
            {
                string userAgent = Context.Headers["User-Agent"];
                string ip = Context.Request.GetRemoteIpAddress();

                //Read the value from the cookie that we paced when the visitor joined us
                string voterId = Context.RequestCookies["Voter"].Value;

                Vote vote = new Vote()
                {
                    ConnectionId = connectionId,
                    IpAddress = ip,
                    UserAgent = userAgent,
                    VoteDateTime = DateTime.Now,
                    VoterId = voterId,
                    VoteValue = number
                };

                //Publish the message to the Message Bus
                BusHost.Publish<Vote>(vote, BusTopic.NewVote);
            }
            catch (Exception ex)
            {
                _Log.Error("Failed to make vote " + number + " for connection " + connectionId + ". " + ex.Message, ex);
            }
        }
Beispiel #2
0
 public static Task ProcessVote(Vote vote)
 {
     return Task.Factory.StartNew(() =>
     {
         //Save the vote to the database
         using (DevConfVoteContext db = new DevConfVoteContext())
         {
             db.Votes.Add(vote);
             db.SaveChanges();
         }
     });
 }
Beispiel #3
0
 public void Add(Vote pVote)
 {
     _arrayInternal.Add(pVote);
 }
Beispiel #4
0
        public void Vote()
        {
            //给景点投票

            Vote vote = new Vote();
            vote.IdCard = "1234";
            vote.Num = 15;
            vote.Scenic = scenic;
            vote.Time = DateTime.Now;
            vote.TourMembershipId = memberId;
            vote.Type = "网站投票";

            //拥有的总票数
            long usertotalvotes = dalUserVoteAmount.GetTotalAmount(memberId);
            Console.WriteLine("用户拥有的总票数"+usertotalvotes);

            long usertotalvotes_used = dalVote.GetVotedAmount(memberId);
            Console.WriteLine("用户已经投掉的票数" + usertotalvotes_used);

            dalVote.SaveVote(vote);
            Console.WriteLine("投票");
            long usertotalvotes_used2 = dalVote.GetVotedAmount(memberId);
            Console.WriteLine("用户已经投掉的票数" + usertotalvotes_used2);
        }
Beispiel #5
0
        //Process good votes as quickly as we can and return the current average.
        public Task ProcessGoodVote(Vote vote)
        {
            return Task.Factory.StartNew(() =>
            {
                if (vote.VoteValue < 0)
                {
                    //Add the vote to the local store of all votes
                    _Votes.Add(vote);

                    var avg = GetAverageResult();

                    VoteProcessed processed = new VoteProcessed()
                    {
                        VoterId = vote.VoterId,
                        ConnectionId = vote.ConnectionId,
                        ProcessedDateTime = DateTime.Now,
                        OriginalVoteValue = vote.VoteValue,
                        CurrentAverage = avg.Average
                    };

                    //Publish the latest average vote value to the bus
                    BusHost.Publish(avg, BusTopic.NewAverageResult);

                    //publish a message saying that the message was processed
                    BusHost.Publish(processed, BusTopic.VoteProcessed);
                }
            });
        }
Beispiel #6
0
        //Process bad votes in out own time..
        public Task ProcessBadVote(Vote vote)
        {
            return Task.Factory.StartNew(() =>
            {
                if (vote.VoteValue >= 0)
                {
                    //Bad votes take longer to count.
                    Thread.Sleep(3000);

                    //One in every 4 bad votes get lost.
                    if ((_Votes.Count +1) % 4 == 0)
                    {
                        //Add the vote to the local store of all votes
                        vote.VoteLost = true;
                    }
                    _Votes.Add(vote);

                    var avg = GetAverageResult();

                    VoteProcessed processed = new VoteProcessed()
                    {
                        VoterId = vote.VoterId,
                        ConnectionId = vote.ConnectionId,
                        ProcessedDateTime = DateTime.Now,
                        OriginalVoteValue = vote.VoteValue,
                        CurrentAverage = avg.Average
                    };

                    //Publish the latest average vote value to the bus
                    BusHost.Publish(avg, BusTopic.NewAverageResult);

                    //publish a message saying
                    BusHost.Publish(processed, BusTopic.VoteProcessed);
                }
            });
        }