static void Main(string[] args) { //args int nbArgs = args.Length; string source = "";; string result = @"./result.txt"; if (nbArgs <= 0) { Console.WriteLine("Erreur : fichier d'entrée non spécifié"); } if (nbArgs >= 1) { source = args[0]; Console.WriteLine("sourceok"); } if (nbArgs >= 2) { result = args[1]; Console.WriteLine("result ok"); } Console.WriteLine("Hello World" + nbArgs); AdventureContext a = new AdventureContext(); a.Load(source); a.Compute(); a.Write(result); }
public static void Main(Tweet twitterMessage) { var tweetId = twitterMessage.TweetId_num; var hashtags = twitterMessage.HashTags.Select(h => h.ToLower()).ToList(); if (IsSubmitHashtagMissing(hashtags)) { // Not a submission return; } var day = FindDayFromHashtag(hashtags); if (day == 0) return; using (var adventureContext = new AdventureContext()) { var challenge = GetChallengeForDay(adventureContext, day); if (challenge == null) { TwitterResponder.SendTweetReply(twitterMessage.ScreenName, "Hey! That submission doesn't make any sense to us. Reply @adventiswhat if you think it should.", tweetId); return; } var user = GetUser(adventureContext, twitterMessage.TwitterUserIdentifier) ?? NewUser(twitterMessage); var previouslyComplete = CheckChallengeComplete(adventureContext, challenge, user); if (previouslyComplete == false) { ResponseSaver.SaveNewResponse(adventureContext, twitterMessage, challenge); ContentDeterminier.DetermineContent(twitterMessage, challenge, user, adventureContext); return; } ReplyWithError(twitterMessage, tweetId); } }
public ActionResult Index() { //var db = new AdventureContext(); // Create and save a new Blog //var user = new adventure_users { firstname = "Test", lastname ="FromApp", email ="" }; //db.adventure_users.Add(user); //db.SaveChanges(); //// Display all Blogs from the database //var query = from b in db.adventure_users // orderby b.firstname // select b; //Console.WriteLine("All blogs in the database:"); //foreach (var item in query) //{ // Console.WriteLine(item.firstname); //} //Console.WriteLine("Press any key to exit..."); //Console.ReadKey(); //return View(); var db = new AdventureContext(); return(View(from user in db.adventure_users orderby user.firstname select user)); //return View(query.ToList()); }
public void VerifyBadgeFirstByType(AdventureContext context, int userId, BadgeCodes code) { var result = (from r in context.UserChallenges from c in context.Challenges.Where(x => x.ChallengeId == r.ChallengeId) where r.UserId == userId where c.Type == code.ToString() select r); var badgeCount = (from ub in context.UserBadges from b in context.Badges.Where(x => x.BadgeId == ub.BadgeId) where ub.UserId == userId where b.Code == code.ToString() select b); if (result.Count() == 1 && !badgeCount.Any()) { var badge = context.Badges.First(x => x.Code == code.ToString()); if (badge != null) { context.UserBadges.Add(new UserBadge { BadgeId = badge.BadgeId, UserId = userId }); } } }
public void TestMountainNumberParsing() { AdventureContext context = new AdventureContext(); context.Load(FILENAME); Assert.AreEqual(context.map.Moutains.Count, 2); }
public Dispatcher(ILogger <Dispatcher> log, IControlHandler controlHandler, IExamineHandler examineHandler, IInventoryHandler inventoryHandler, ILockHandler lockHandler, ILookAroundHandler lookHandler, IMagicHandler magicHandler, IMoveDirectionHandler moveDirHandler, IMoveFeatureHandler moveFeatureHandler, IMoveLocationHandler moveLocHandler, IOnOffHandler onOffHandler, IResponseBuilder responseBuilder, AdventureContext context) { _log = log; _controlHandler = controlHandler; _examineHandler = examineHandler; _inventoryHandler = inventoryHandler; _lockHandler = lockHandler; _lookHandler = lookHandler; _magicHandler = magicHandler; _moveDirHandler = moveDirHandler; _moveFeatureHandler = moveFeatureHandler; _moveLocHandler = moveLocHandler; _onOffHandler = onOffHandler; _responseBuilder = responseBuilder; _advContext = context; }
public void TestTreasureNumberParsing() { AdventureContext context = new AdventureContext(); context.Load(FILENAME); Assert.AreEqual(context.map.Treasures.Count, 2); }
public HttpResponseMessage Get() { int userId = 6; var adventureContext = new AdventureContext(); var badgeFinder = new BadgeFinder( adventureContext); badgeFinder.VerifyBadges( userId ); return null; }
public async IAsyncEnumerable <Customer> GetAll() { _AdventureContext = new AdventureContext(); await foreach (var item in _AdventureContext.Customer) { yield return(item); } }
public static AdventureContext CreateContext(DbConnection connection = null) { var builder = new DbContextOptionsBuilder <AdventureContext>(); builder.UseSqlite(connection ?? AdventureContext.CreateInMemoryDatabase()); builder.EnableSensitiveDataLogging(true); return(new AdventureContext(builder.Options)); }
private static bool CheckChallengeComplete(AdventureContext adventureContext, Challenge challenge, User user) { return adventureContext .UserChallenges .Count(u => u.ChallengeId == challenge.ChallengeId && u.UserId == user.UserId && u.IsComplete) >= 1; }
public void TestAdventurerParsing() { AdventureContext context = new AdventureContext(); context.Load(FILENAME); Assert.AreEqual(context.adventurers.Count, 1); Assert.AreEqual(context.adventurers[0].Name, "Lara"); Assert.AreEqual(context.adventurers[0].Orientation, TreasureMap.Model.Orientation.Sud); }
public HttpResponseMessage List() { object result; using (var db = new AdventureContext()) { result = List(db); } return Request.CreateResponse(HttpStatusCode.OK, result, new JsonMediaTypeFormatter()); }
public MoveLocationHandler(ILogger <MoveLocationHandler> log, IResponseBuilder responseBuilder, IMessageProvider messageProvider, ILocationProvider locationProvider, IAdventureContextHelper advHelper, IMapHelper mapHelper, AdventureContext context) : base(log, responseBuilder, messageProvider, locationProvider, advHelper, mapHelper) { }
public void TestFirstTreasureParsing() { AdventureContext context = new AdventureContext(); context.Load(FILENAME); Assert.AreEqual(context.map.Treasures[0].Number, 2); Assert.AreEqual(context.map.Treasures[0].Position.X, 0); Assert.AreEqual(context.map.Treasures[0].Position.Y, 3); }
public FulfillmentController(ILogger <FulfillmentController> log, IActionHandler handler, //ILocationProvider locationProvider, IItemProvider itemProvider, AdventureContext context) { _log = log; _handler = handler; //_itemProvider = itemProvider; //_locationProvider = locationProvider; _advContext = context; }
public RepositoryFixture() { _dbConnection = AdventureContext.CreateInMemoryDatabase(); _services = new ServiceCollection(); _services.AddDbContext <AdventureContext>(builder => builder.UseSqlite(_dbConnection)); _services.AddUnitOfWork <AdventureContext>() .AddRepositories(); }
public void TestMapParsing() { AdventureContext context = new AdventureContext(); context.Load(FILENAME); int height = context.map.Height; int width = context.map.Whidth; Assert.AreEqual(width, 3); Assert.AreEqual(height, 4); }
public static void Main(string[] args) { var loader = new ResourceLoader(); Console.WriteLine("*** MESSAGES *****************************************************\n"); var mp = new MessageProvider(null, loader); foreach (var e in Enum.GetValues(typeof(MsgMnemonic))) { Console.WriteLine($"{e}: {mp.GetMessage((int)e).Speech}"); Console.WriteLine($"{e}: {mp.GetMessage((int)e).Text}"); Console.WriteLine(); } Console.WriteLine("\n\n*** LOCATIONS ****************************************************\n"); var lp = new LocationProvider(null, loader); foreach (var l in lp.Map) { Console.WriteLine($"{l.Value.Id}: {l.Value.ShortDescription}"); } //var l = lp.GetLocation(2); //Console.WriteLine(l.Description); Console.WriteLine("\n\n*** ITEMS ********************************************************"); var ip = new ItemProvider(null, lp, loader); //var i = ip.GetItem(ItemsMoveable.Keys); //Console.WriteLine(i.Description); foreach (var item in ip.Items) { Console.WriteLine($"\n{item}"); if (item.FoundDescriptions != null) { foreach (var desc in item.FoundDescriptions) { Console.WriteLine($"{desc.Item1} - {desc.Item2}"); } } else if (item.ExamineDescriptions != null) { foreach (var desc in item.ExamineDescriptions) { Console.WriteLine($"{desc.Item1} - {desc.Item2}"); } } } var context = new AdventureContext(ip, lp); Console.ReadLine(); }
public static void CompleteChallenge(Challenge challenge, User user, Tweet tweet, AdventureContext adventureContext) { var userChallenge = new UserChallenge { ChallengeId = challenge.ChallengeId, UserId = user.UserId, IsComplete = true }; adventureContext.UserChallenges.Add(userChallenge); adventureContext.SaveChanges(); TwitterResponder.SendMoreInfo( user.ScreenName, challenge, tweet.TweetId_num); new BadgeFinder(adventureContext).VerifyBadges(user.UserId); }
public ActionResult BestProducts() { using (var context = new AdventureContext()) { var products = context.Products.Take(5).ToList(); var totalProducts = context.Products.Count(); return(View(new BestProductsViewModel { Products = products, TotalProductsCount = totalProducts })); } }
public async Task <BestProductsViewModel> BuildViewModelAsync() { using (var context = new AdventureContext()) { var products = await context.Products.Take(5).ToListAsync().ConfigureAwait(false); var totalProducts = await context.Products.CountAsync().ConfigureAwait(false); return(new BestProductsViewModel { Products = products, TotalProductsCount = totalProducts }); } }
public static void SaveNewResponse(AdventureContext adventureContext, Tweet tweet, Challenge challenge) { var user = adventureContext.Users .First(u => u.TwitterId == tweet.TwitterUserIdentifier); var response = new Response { UserId = user.UserId, Tweet = tweet.Text, TweetId = tweet.TweetId, ChallengeId = challenge.ChallengeId }; adventureContext.Responses.Add(response); adventureContext.SaveChanges(); }
public async Task <ActionResult> BestProductsAsync() { using (var context = new AdventureContext()) { var products = await context.Products.Take(5).ToListAsync(); var totalProducts = await context.Products.CountAsync(); return(View("BestProducts", new BestProductsViewModel { Products = products, TotalProductsCount = totalProducts })); } }
private static object List(AdventureContext db) { object result; var users = db.Users .Select(user => new {Name = user.UserName, Id = user.TwitterId, ScreenName = user.ScreenName}) .ToArray(); if (users.Any()) { result = users; } else { result = new {Error = "User not found"}; } return result; }
static void Main(string[] args) { var context = new AdventureContext(); var adv = new Adventure { Weather = new Weather[] { new Weather { Date = DateTime.Now, Temperature = 0u, Unit = "°C" } }, StartDate = DateTime.Now, FinishDate = DateTime.Now.AddDays(5) }; context.Adventures.Add(adv); context.SaveChanges(); }
public async Task <ActionResult> BestProductsConcurrentQueriesAsync() { using (var context = new AdventureContext()) { var productsTask = context.Products.Take(5).ToListAsync(); var totalProductsTask = context.Products.CountAsync(); await Task.WhenAll(productsTask, totalProductsTask); return(View("BestProducts", new BestProductsViewModel { Products = productsTask.Result, TotalProductsCount = totalProductsTask.Result })); } }
static void Main(string[] args) { using (var ctx = new AdventureContext()) { //var orders = ctx.SalesOrderHeader.Include(so => so.SalesOrderDetail).ToList(); var orders = ctx.SalesOrderHeader.AsNoTracking().Include(so => so.SalesOrderDetail).ToList(); foreach (var o in orders) { Console.WriteLine($"{o.SalesOrderDetail.Count}"); } } Console.WriteLine("Press any key."); Console.ReadKey(); }
public static void DetermineContent(Tweet tweet, Challenge challenge, User user, AdventureContext adventureContext) { // Is image? if (tweet.Media.FirstOrDefault() != null && challenge.Type.ToLower() == "image") { TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext); } // Is URL? else if (tweet.Urls.Any()) { var youtubeTest = new Regex("(https?://)?(www\\.)?(yotu\\.be/|youtube\\.com/)?((.+/)?(watch(\\?v=|.+&v=))?(v=)?)([\\w_-]{11})(&.+)?"); var instagramTest = new Regex(@"http://instagr\.?am(?:\.com)?/\S*"); var vineTest = new Regex(@"https://vine.co/v/\w*$@i"); var soundcloudTest = new Regex(@"(https?://)?(www\\.)?( soundcloud.com | snd.sc )(.)"); if (youtubeTest.IsMatch(tweet.Urls.Any().ToString()) && (challenge.Type.ToLower() == "video" | challenge.Type.ToLower() == "audio")) { TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext); } if (instagramTest.IsMatch(tweet.Urls.Any().ToString()) && challenge.Type.ToLower() == "image") { TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext); } if (vineTest.IsMatch(tweet.Urls.Any().ToString()) && challenge.Type.ToLower() == "video") { TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext); } } // Is text response else if (challenge.Type != null && challenge.Type.ToLower() == "text") { tweet.Text = StripContent(tweet); TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext); } }
public HttpResponseMessage Get(int day) { using (var db = new AdventureContext()) { var challenge = db.Challenges.FirstOrDefault(d => d.ChallengeNumber == day); if (challenge == null) { return Request.CreateResponse(HttpStatusCode.NotFound, "Challenge not found", new JsonMediaTypeFormatter()); } var responses = db.Responses.Where(r => r.ChallengeId == challenge.ChallengeId) .ToList(); var userIds = responses.Select(r => r.UserId); var users = db.Users.Where(u => userIds.Contains(u.UserId)).ToList(); var result = responses.Select(r => new { Tweet = r.Tweet, TweetId = r.TweetId, User = users.First(u => u.UserId == r.UserId).ScreenName }) .ToArray(); return Request.CreateResponse(HttpStatusCode.OK, result, new JsonMediaTypeFormatter()); } }
// GET api/days public HttpResponseMessage Get() { IEnumerable<object> challenges; using (var db = new AdventureContext()) { if (!db.Challenges.Any()) { var days = Enumerable .Range(1, 24) .Select(n => new { Day = n, Challenge = new Challenge { Name = "Challenge for December " + n, ChallengeNumber = n } }); foreach (var day in days) { db.Challenges.Add(day.Challenge); } db.SaveChanges(); } challenges = db.Challenges .ToList() .OrderBy(d => d.ChallengeNumber) .Select(c => (object) new { Day = c.ChallengeNumber, Challenge = c }); } return Request.CreateResponse(HttpStatusCode.OK, challenges, new JsonMediaTypeFormatter()); }
public Task <ActionResult> BestProductsManualAsync() { var taskCompletionSource = new TaskCompletionSource <ActionResult>(); var context = new AdventureContext(); context.Products.Take(5).ToListAsync() .ContinueWith(productListTask => { context.Products.CountAsync() .ContinueWith(productsCountTask => { context.Dispose(); taskCompletionSource.SetResult( View("BestProducts", new BestProductsViewModel { Products = productListTask.Result, TotalProductsCount = productsCountTask.Result })); }); }); return(taskCompletionSource.Task); }
public HttpResponseMessage Get(string userName = "") { object result; using (var db = new AdventureContext()) { if (string.IsNullOrEmpty(userName)) { result = List(db); } else { var user = db.Users.FirstOrDefault(u => u.ScreenName == userName); if (user == null) return Request.CreateResponse(HttpStatusCode.OK, (object) null); var responses = db.Responses .Where(c => c.UserId == user.UserId) .ToArray(); var responseChallenges = responses.Select(r => r.ChallengeId); var challenges = db.Challenges .Where(c => responseChallenges .Contains(c.ChallengeId)) .ToArray(); var badges = db.Badges.ToArray(); var userBadges = db.UserBadges.Where(u => u.UserId == user.UserId).ToArray(); result = new { User = user, Responses = responses, Challenges = challenges, Badges = badges, UserBadges = userBadges }; } } return Request.CreateResponse(HttpStatusCode.OK, result, new JsonMediaTypeFormatter()); }
public HttpResponseMessage Get() { var result = new Ranking(); using (var context = new AdventureContext()) { var t = context.Users.First(); result.Positions = (from r in context.UserChallenges.Where( x => x.IsComplete == true) from c in context.Challenges.Where(x => x.ChallengeId == r.ChallengeId) from u in context.Users.Where(x => x.UserId == r.UserId) group c by new { u.UserName } into g select new Position { Points = g.Sum(x => x.Value) ?? 0, UserName = g.Key.UserName }).OrderByDescending(x => x.Points).ToList(); } if (result.Positions.Count() > 1) return Request.CreateResponse(HttpStatusCode.OK, result); return Request.CreateResponse(HttpStatusCode.OK, new Ranking()); }
public CommentsController(AdventureContext context) { _context = context; }
public LikesController(AdventureContext context) { _context = context; }
public ClassVideosController(AdventureContext context) { _context = context; }
public MessagesController(AdventureContext context) { _context = context; }
public PostPhotosController(AdventureContext context) { _context = context; }
public PostVideosController(AdventureContext context) { _context = context; }
private static User NewUser(Tweet twitterMessage) { var newUser = new User { TwitterId = twitterMessage.TwitterUserIdentifier, UserName = twitterMessage.UserName, ScreenName = twitterMessage.ScreenName }; var adventureContext = new AdventureContext(); adventureContext.Users.Add(newUser); adventureContext.SaveChanges(); return newUser; }
private static Challenge GetChallengeForDay(AdventureContext adventureContext, int day) { var challenge = adventureContext.Challenges .FirstOrDefault(c => c.ChallengeNumber == day && !c.Name.Contains("Bonus")); return challenge; }
private static User GetUser(AdventureContext adventureContext, string twitterUser) { var user = adventureContext .Users .FirstOrDefault(r => r.TwitterId == twitterUser); return user; }
public BadgeFinder(AdventureContext adventureContext) { _adventureContext = adventureContext; }
private static void VerifyBadgeFirstParticipation(AdventureContext context, int userId) { var badgeCount = (from b in context.Badges from ub in context.UserBadges.Where(x => x.UserId == userId) where b.Code == BadgeCodes.FirstParticipation.ToString() select b); if (context.UserChallenges.Count(x => x.UserId == userId && x.IsComplete == true) == 1 && !badgeCount.Any()) { var badge = context.Badges.First(x => x.Code == BadgeCodes.FirstParticipation.ToString()); if (badge != null) { context.UserBadges.Add(new UserBadge { BadgeId = badge.BadgeId, UserId = userId }); string twitterUserName = context.Users.FirstOrDefault( x => x.UserId == userId ).UserName; string badgeName = context.Badges.FirstOrDefault( b => b.BadgeId == badge.BadgeId ).Name; string status = string.Format( "@{0} You've just earnt the {1} badge at @AdventHunters. Why not check it out? http://adventure-1.apphb.com/#/badges", twitterUserName, badgeName ); TwitterResponder.SendTweet( twitterUserName, status ); } } }
public FollowingsController(AdventureContext context) { _context = context; }
public UserChatsController(AdventureContext context) { _context = context; }
public ProfesionallsProfilesController(AdventureContext context) { _context = context; }
private void VerifyBadgeStreak(AdventureContext context, int userId) { int[] previousDays = (from uc in context.UserChallenges.Where(x => x.UserId == userId && x.IsComplete == true) from c in context.Challenges select c.ChallengeNumber) .ToArray(); int streak = GetConsecutiveCount(previousDays); for (int i = 0; i <= 24;) { if (streak >= i) { var streakBadge = (from ub in context.UserBadges from b in context.Badges.Where(x => x.BadgeId == ub.BadgeId) where ub.UserId == userId where b.Code == "Streak" + i select b); if (streakBadge.Any()) { var badge = context.Badges.First(x => x.Code == "Streak" + i.ToString()); context.UserBadges.Add(new UserBadge { BadgeId = badge.BadgeId, UserId = userId }); } } else { break; } if (i <= 6) { i += 3; } else { i += 6; } } }