public List <WordBank> AddWordsToQueue(List <WordBank> words, WikiSession aSession) { for (var i = 0; i < words.Count(); i++) { var wbId = words[i].WordBankId; var cached = _dbContext.WikiPages.FirstOrDefault(x => x.WordBankId == wbId); if (cached != null) { continue; } var wordBank = _dbContext.WordBanks.FirstOrDefault(x => x.WordBankId == wbId); var wbq = new WordBankQueue { CreatedDate = DateTime.Now, IsProcessed = false, WordBankId = wbId, WordBank = wordBank }; _dbContext.WordBankQueues.Add(wbq); _dbContext.SaveChanges(); _dbContext.Entry(wbq).Reload(); wbq = RabbitHelper.Send(wbq, aSession); //Send items to RabbitMQ for processing words[i] = wbq.WordBank; words[i].WordBankQueues.Add(wbq); } return(words); }
public void AddWordToQueue(WordBank word, WikiSession aWikiSession) { this.AddWordsToQueue(new List <WordBank>() { word }, aWikiSession); }
public ActionResult UserClicked(string word, Guid wikiLinkId, WikiSession aSessionId) { var res = _wikiSurfRepository.GetWikiPage(wikiLinkId, word, aSessionId); return(Json(new { currentPage = res.HtlmFormatted, title = res.Title }, JsonRequestBehavior.AllowGet)); }
public WikiSession IncreaseClick(WikiSession session) { var dbEntry = _dbContext.WikiSessions.First(s => s.WikiSessionId == session.WikiSessionId); dbEntry.TotalClicks += 1; _dbContext.Entry(dbEntry).State = EntityState.Modified; _dbContext.SaveChanges(); return(dbEntry); }
public List <WordBank> GetRandomWords(WikiSession aWikiSession, int count = 2) { var test = GetNewWords(aWikiSession); //var test = _dbContext.WordBanks // //.Where(x => x.WordIndex == firstIndex || x.WordIndex == lastIndex) // //.ToList() // .Where(x => x.Word == "Endotherium" || x.Word == "Academy of Allied Health & Science") // .ToList(); _dbContext.Entry(aWikiSession).State = EntityState.Modified; _dbContext.SaveChanges(); return(AddWordsToQueue(test.ToList(), aWikiSession)); }
public WikiSession GetNewSession() { var newSession = new WikiSession { PlayerName = "Test", CreatedDate = DateTime.Now, UpdateDateTime = DateTime.Now, IsActive = true }; _dbContext.WikiSessions.Add(newSession); _dbContext.SaveChanges(); return(newSession); }
public List <WordBank> GetNewWords(WikiSession session) { var sessionIdParamter = new SqlParameter("@WikiSessionId", session.WikiSessionId); var result = _dbContext .Database .SqlQuery <S_New_Game_Words>("EXEC S_NEW_GAME_WORDS @WikiSessionId", sessionIdParamter) .ToList(); var res = new List <WordBank>(); foreach (var a in result) { res.Add(a.WordBank()); } return(res); }
public WikiSession GetSession() { if (Request != null) { if (_session == null && Request.Headers.Contains(SessionAuthenticateMiddleware.SessionHeader)) { var list = Request.Headers.FirstOrDefault(x => x.Key == SessionAuthenticateMiddleware.SessionHeader).Value; var sessionId = Guid.Parse(list.First()); if (_repository != null) { _session = _repository.GetExistingSession(sessionId); Session = _session; } } } return(_session); }
public WikiPage GetWikiPage(Guid aWikiLinkId, string aWord, WikiSession aWikiSession) { var wikiLink = _dbContext.WikiLinks.FirstOrDefault((x => x.WikiLinksId == aWikiLinkId && x.Additional == aWord)); if (wikiLink == null) { return(null); } var wordBank = _dbContext.WordBanks.FirstOrDefault(x => x.Word == aWord); AddWordToQueue(wordBank, aWikiSession); var wikiPage = _dbContext.WikiPages.FirstOrDefault(x => x.WordBankId == wordBank.WordBankId); aWikiSession.CurrentWordBankId = wordBank.WordBankId; _dbContext.Entry(aWikiSession).State = EntityState.Modified; _dbContext.SaveChanges(); return(wikiPage); }
public static WordBankQueue Send(WordBankQueue queueItem, WikiSession aSession) { WordBankQueue aQueueItem = null; bool processed = false; var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "wiki_surf_dev", durable: false, exclusive: false, autoDelete: false, arguments: null); var consumer = new EventingBasicConsumer(channel); var props = channel.CreateBasicProperties(); var correlationId = Guid.NewGuid().ToString(); var replyQueue = channel.QueueDeclare().QueueName; props.CorrelationId = correlationId; props.ReplyTo = replyQueue; consumer.Received += (model, ea) => { var body = ea.Body.ToArray(); var response = Encoding.UTF8.GetString(body); if (ea.BasicProperties.CorrelationId == correlationId) { using (StreamReader sr = new StreamReader(new MemoryStream(body))) { aQueueItem = JsonConvert.DeserializeObject <WordBankQueue>(sr.ReadToEnd()); } Console.WriteLine(response); processed = true; } }; var json = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new { queueItem.WordBankId, queueItem.WordBankQueueId, queueItem.CreatedDate, queueItem.IsProcessed, queueItem.ProcessedDate, queueItem.WordBank.Word, aSession.WikiSessionId })); channel.BasicPublish(exchange: "", routingKey: "wiki_surf_dev", basicProperties: props, body: json); Console.WriteLine(" [x] Sent WordBankQueueId: {0} Word: {1}", queueItem.WordBankQueueId, queueItem.WordBank.Word); while (!processed) { Thread.Sleep(1000); var reply = channel.BasicConsume(replyQueue, true, consumer); } return(aQueueItem); } }