Exemplo n.º 1
0
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            powerpollContext context = new powerpollContext();

            DomainManager = new EntityDomainManager <Result>(context, Request, Services);
        }
        public void PollResults()
        {
            var           context    = new powerpollContext();
            var           polls      = context.Polls;
            string        result1_Id = Guid.NewGuid().ToString();
            string        result2_Id = Guid.NewGuid().ToString();
            string        hashtag    = Guid.NewGuid().ToString();
            List <Result> results    = new List <Result>
            {
                new Result {
                    Id = result1_Id, Count = 2, PollId = hashtag
                },
                new Result {
                    Id = result2_Id, Count = 3, PollId = hashtag
                }
            };

            Poll poll = new Poll {
                Id = hashtag, End_Time = DateTime.Now, Results = results
            };

            foreach (Poll p in context.Polls)
            {
                Console.WriteLine(p.Id);
            }
            //context.Polls.Add(poll);
            //context.Set<Poll>().Add(poll);

            /*
             * context.SaveChanges();
             * polls = context.Polls;
             * foreach (Poll i in polls)
             * {
             *  foreach (Result result in i.Results)
             *  {
             *      if (result.Id.Equals(result1_Id))
             *      {
             *          Assert.AreEqual<int>(2, result.Count);
             *      }
             *      else if (result.Id.Equals(result2_Id))
             *      {
             *          Assert.AreEqual<int>(3, result.Count);
             *      }
             *  }
             * }
             * */
        }
Exemplo n.º 3
0
        public static void monitor()
        {
            var stream = Stream.CreateUserStream();

            stream.TweetCreatedByAnyone += (s, t) =>
            {
                powerpollContext context = new powerpollContext();
                var hashtags             = t.Tweet.Hashtags.ToArray()
                                           .Select(x => x.Text.ToLowerInvariant());
                foreach (Poll poll in context.Polls.ToArray()) //go through all the polls
                {
                    foreach (String hashtag in hashtags)       //if the tweet contains the poll Id as a hashtag
                    {
                        if (hashtag.ToLowerInvariant().Equals(poll.Id.ToLowerInvariant()) && poll.End_Time >= DateTime.UtcNow)
                        {
                            String test = t.Tweet.Text.Replace("#" + poll.Id, "").ToLowerInvariant();//string of tweet to be tested against
                            test = test.Replace("@twitpollpp", "");
                            Regex rgx = new Regex("[^a-zA-Z0-9 ]");
                            test = rgx.Replace(test, "").Trim() + ".";
                            foreach (Result result in poll.Results.ToArray())//go through the results of that poll
                            {
                                if (test.Contains(result.Id.ToLowerInvariant() + "."))
                                {
                                    result.Count++;
                                    context.SaveChangesAsync();
                                }
                            }
                        }
                    }
                }
                context.SaveChanges();
            };
            while (true)
            {
                stream.StartStream();
            }
        }
Exemplo n.º 4
0
        protected override void Initialize(ScheduledJobDescriptor scheduledJobDescriptor, CancellationToken cancellationToken)
        {
            base.Initialize(scheduledJobDescriptor, cancellationToken);

            context = new powerpollContext();
        }