Esempio n. 1
0
        public async Task <GameSession> CreateGameSession(int questionnaireId)
        {
            var questionnaire  = _db.SingleById <Questionnaire>(questionnaireId);
            var newGameSession = new GameSession
            {
                Questionnaire = questionnaire
            };
            var id = _db.Insert(newGameSession);
            await Groups.AddToGroupAsync(Context.ConnectionId, "Server" + newGameSession.JoinCode);

            return(_db.SingleById <GameSession>(id));
        }
Esempio n. 2
0
        public void DeclineEvent(Guid id, string declineMessage)
        {
            var eEvent = _db.SingleById <Event>(id);
            var list   = new List <User>
            {
                eEvent.Author
            };

            _nService.NotifyUsers(new Notification
            {
                Message = declineMessage,
                Subject = _localizer["declineEventSubject", eEvent.Name]
            }, list);
        }
Esempio n. 3
0
        static void TestLitedb()
        {
            var mapper = new BsonMapper();

            mapper.Entity <Note>()
            .Ignore(n => n.Name)
            .Ignore(n => n.IsTransient);
            //.Id(n => n.Id)
            //.Ignore(n => n.Id);

            //https://github.com/mbdavid/LiteDB/wiki/Connection-String
            var connectionString = "Filename=..\\MyLitedb.dat; Password=posvord; Initial Size=5MB; Upgrade=true";

            string id;

            using (var repo = new LiteRepository(connectionString, mapper))
            {
                var note = Note.Create("Blah blah");
                note.Id = ObjectId.NewObjectId().ToString();

                repo.Upsert(note);
                //var bsonDocument = adapter.ToBson(note);
                //repo.Database.Engine.Upsert(nameof(Note), bsonDocument);
                id = note.Id;
            }

            using (var repo = new LiteRepository(connectionString, mapper))
            {
                //var bson = repo.Engine.FindById(nameof(Note), id);
                //var note = adapter.Read(bson);
                var note = repo.SingleById <Note>(id);

                Console.WriteLine($"{note.Name} - {note.CreateTime} - {note.LastUpdateTime}");
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Search for a single instance of T by Id. Shortcut from Query.SingleById
 /// </summary>
 public T SingleById <T>(BsonValue id, string collectionName = null)
 {
     using (var db = new LiteRepository(_configService.ConnectionString))
     {
         return(db.SingleById <T>(id, collectionName));
     }
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // Open database (or create if doesn't exist)
            using (var db = new LiteRepository(@"../../../Customer.litedb"))
            {
                var id = db.Insert(new Customer()
                {
                    Name     = "John Doe",
                    Phones   = new string[] { "8000-0000", "9000-0000" },
                    Age      = 39,
                    IsActive = true
                });

                var customer = db.SingleById <Customer>(99);
                customer.Name = "Very Old";
                customer.Age  = 500;

                var zz = db.Update(customer);



                // query using fluent query
                var result = db.Query <Customer>()
                             .Where(x => x.Age > 499) // used indexes query
                             .ToList();
            }
        }
Esempio n. 6
0
        public void ShouldInsertIntoDatabaseAndRecover()
        {
            var items = CreateCollection();

            using (var repository = new LiteRepository(new MemoryStream(), _mapper))
            {
                var result = repository.Upsert <ItemCollection>(items);
                Assert.IsTrue(result);
                Assert.AreNotEqual(Guid.Empty, items.Id);
                var lst = repository.SingleById <ItemCollection>(items.Id);
                Assert.AreEqual("MyCollection", lst.MyItemCollectionName);
                Assert.AreEqual(lst.Count, 1);
                Assert.IsInstanceOfType(lst[0], typeof(Item));
                Assert.AreEqual(lst[0].MyItemName, "MyItem");
            }
        }
Esempio n. 7
0
        private static async void NextQuestion(int currentSessionId, LiteRepository db, IHubCallerClients clients,
                                               ILogger log)
        {
            log.LogWarning("Showing Question");
            var currentSession = db.SingleById <GameSession>(currentSessionId);
            var qi             = currentSession.CurrentQuestionIndex;
            var question       = currentSession.Questionnaire.Questions[qi];
            var answer         = db.Single <Answer>(ans => ans.Question.Id == question.Id);
            var endTime        = DateTime.Now.Add(question.Time).ToUniversalTime();
            await Task.WhenAll(
                clients.Group("Players" + currentSession.JoinCode).SendAsync("CurrentAnswer", answer, endTime),
                clients.Group("Server" + currentSession.JoinCode).SendAsync("CurrentQuestion", question, endTime),
                Task.Delay(question.Time));

            currentSession.CurrentQuestionIndex++;
            db.Update(currentSession);
            LeaderBoards(currentSessionId, db, clients, log);
        }
Esempio n. 8
0
        private static async void LeaderBoards(int currentSessionId, LiteRepository db, IHubCallerClients clients,
                                               ILogger log)
        {
            log.LogWarning("Showing Leaderboards");
            var currentSession = db.SingleById <GameSession>(currentSessionId);
            var leaderboard    = from player in db.Fetch <Player>()
                                 where player.GameSession.Id.Equals(currentSessionId)
                                 orderby player.Score descending
                                 select player;
            await clients.Groups("Players" + currentSession.JoinCode, "Server" + currentSession.JoinCode)
            .SendAsync("CurrentLeaderboard", leaderboard.ToList());

            await Task.Delay(TimeSpan.FromSeconds(10));

            if (currentSession.CurrentQuestionIndex < currentSession.Questionnaire.Questions.Count)
            {
                NextQuestion(currentSessionId, db, clients, log);
            }
        }
Esempio n. 9
0
        public Result <T> SingleById(BsonValue id, string collectionName = null)
        {
            var result = new Result <T>();

            try
            {
                result.ResultObject = _liteRepository.SingleById <T>(id, collectionName);
            }
            catch (Exception ex)
            {
                result.ResultCode         = (int)ResultStatusCode.InternalServerError;
                result.ResultMessage      = "Hata Oluştu => " + ex;
                result.ResultInnerMessage = "Hata Oluştu => " + ex.InnerException;

                result.ResultStatus = false;
            }

            return(result);
        }
Esempio n. 10
0
 public T RecuperarPorId(int id)
 {
     return(_db.SingleById <T>(id));
 }
Esempio n. 11
0
        // GET: Event/Delete/5
        public ActionResult Delete(Guid id)
        {
            var hggmEvent = _db.SingleById <Event>(id);

            return(View(hggmEvent));
        }
Esempio n. 12
0
 public Task <App> GetApp(string id)
 {
     return(Task.FromResult(_liteRepository.SingleById <App>(id)));
 }
Esempio n. 13
0
        public ActionResult Delete(Guid id)
        {
            var tag = db.SingleById <Tag>(id);

            return(View(tag));
        }
Esempio n. 14
0
 public AuditEntryBase Get(Guid id)
 {
     return(db.SingleById <AuditEntryBase>(id));
 }
Esempio n. 15
0
 public Answer Get(int id)
 {
     return(_db.SingleById <Answer>(id));
 }
 public ISwimNode Get(string hostname)
 {
     return(_repository.SingleById <ISwimNode>(hostname, "nodes"));
 }
Esempio n. 17
0
 public Questionnaire Get(int id)
 {
     return(_db.SingleById <Questionnaire>(id));
 }
Esempio n. 18
0
 public Task <ContentItem> GetContentItem(string id, string appId)
 {
     return(Task.FromResult(_liteRepository.SingleById <ContentItem>(id)));
 }
 public TEntity GetFindById(int id)
 {
     return(_liteRepository.SingleById <TEntity>(id));
 }
        public void SeedDatabase()
        {
            while (_db.Database.GetCollectionNames().Any())
            {
                _db.Database.DropCollection(_db.Database.GetCollectionNames().First());
            }



            var question1 = _db.Insert(new Question
            {
                Content      = "Hvem af disse personer deltog i krigen ved dybbøl?",
                Points       = 700,
                QuestionType = QuestionType.Text,
                Time         = TimeSpan.FromSeconds(30)
            });

            var question2 = _db.Insert(new Question
            {
                Content      = "Hvem af disse personer døde i krigen ved dybbøl?",
                Points       = 500,
                QuestionType = QuestionType.Text,
                Time         = TimeSpan.FromSeconds(30)
            });

            var questionnaire1 = _db.Insert(new Questionnaire
            {
                Title     = "Broager i 1864",
                Questions = new List <Question>()
                {
                    _db.SingleById <Question>(question1), _db.SingleById <Question>(question2)
                }
            });
            var x = _db.Fetch <Questionnaire>();

            var question3 = _db.Insert(new Question
            {
                Content      = "Hvor stor var Broager i Bronzealderen?",
                Points       = 600,
                QuestionType = QuestionType.Text,
                Time         = TimeSpan.FromSeconds(30)
            });
            var question4 = _db.Insert(new Question
            {
                Content      = "Hvor mange boede i broager i Bronzealderen?",
                Points       = 400,
                QuestionType = QuestionType.Text,
                Time         = TimeSpan.FromSeconds(30)
            });

            var questionnaire2 = _db.Insert(new Questionnaire
            {
                Title     = "Broager i Bronzealderen",
                Questions = new List <Question>()
                {
                    _db.SingleById <Question>(question3), _db.SingleById <Question>(question4)
                }
            });

            _db.Insert(new Answer
            {
                Options = new List <string>
                {
                    "Henrik",
                    "Peter",
                    "Lise",
                    "Lars"
                },
                CorrectAnswer = "Henrik",
                AnswerType    = QuestionType.Text,
                Question      = _db.SingleById <Question>(question1)
            });
            _db.Insert(new Answer
            {
                Options = new List <string>
                {
                    "Hansen",
                    "Peter",
                    "Henrik",
                    "Ludvig"
                },
                CorrectAnswer = "Henrik",
                AnswerType    = QuestionType.Text,
                Question      = _db.SingleById <Question>(question2)
            });
            _db.Insert(new Answer
            {
                Options = new List <string>
                {
                    "10 km2",
                    "15 km2",
                    "20 km2",
                    "30 km2"
                },
                CorrectAnswer = "15 km2",
                AnswerType    = QuestionType.Text,
                Question      = _db.SingleById <Question>(question3)
            });
            _db.Insert(new Answer
            {
                Options = new List <string>
                {
                    "100",
                    "200",
                    "500",
                    "350"
                },
                CorrectAnswer = "350",
                AnswerType    = QuestionType.Text,
                Question      = _db.SingleById <Question>(question4)
            });

            _db.Insert(new GameSession
            {
                Questionnaire = _db.SingleById <Questionnaire>(questionnaire1),
                StartTime     = DateTime.Now,
                JoinCode      = "abcde"
            });
            _db.Insert(new GameSession
            {
                Questionnaire = _db.SingleById <Questionnaire>(questionnaire2),
                StartTime     = DateTime.Now,
                JoinCode      = "12345"
            });
        }
 public Question Get(int id)
 {
     return(_db.SingleById <Question>(id));
 }