public static void RunDataModelSample() { Console.WriteLine("Creating the context object"); DynamoDBContext context = new DynamoDBContext(client); Console.WriteLine("Creating actors"); Actor christianBale = new Actor { Name = "Christian Bale", Bio = "Christian Charles Philip Bale is an excellent horseman and an avid reader.", BirthDate = new DateTime(1974, 1, 30), Address = new Address { City = "Los Angeles", Country = "USA" }, HeightInMeters = 1.83f }; Actor michaelCaine = new Actor { Name = "Michael Caine", Bio = "Maurice Joseph Micklewhite is an English actor, better known as Michael Caine", BirthDate = new DateTime(1933, 3, 14), Address = new Address { City = "London", Country = "England" }, HeightInMeters = 1.88f }; Console.WriteLine("Creating movie"); Movie darkKnight = new Movie { Title = "The Dark Knight", ReleaseDate = new DateTime(2008, 7, 18), Genres = new List<string> { "Action", "Crime", "Drama" }, ActorNames = new List<string> { christianBale.Name, michaelCaine.Name } }; Console.WriteLine("Saving actors and movie"); context.Save<Actor>(michaelCaine); context.Save<Actor>(christianBale); context.Save<Movie>(darkKnight); Console.WriteLine("Creating and saving new actor"); Actor maggieGyllenhaal = new Actor { Name = "Maggie Gyllenhaal", BirthDate = new DateTime(1977, 11, 16), Bio = "Maggie Gyllenhaal studied briefly at the Royal Academy of Dramatic Arts in London.", Address = new Address { City = "New York City", Country = "USA" }, HeightInMeters = 1.75f }; context.Save<Actor>(maggieGyllenhaal); Console.WriteLine(); Console.WriteLine("Loading existing movie"); Movie existingMovie = context.Load<Movie>("The Dark Knight", new DateTime(2008, 7, 18)); Console.WriteLine(existingMovie.ToString()); Console.WriteLine(); Console.WriteLine("Loading nonexistent movie"); Movie nonexistentMovie = context.Load<Movie>("The Dark Knight", new DateTime(2008, 7, 19)); Console.WriteLine("Movie is null : " + (nonexistentMovie == null)); Console.WriteLine("Updating movie and saving"); existingMovie.ActorNames.Add(maggieGyllenhaal.Name); existingMovie.Genres.Add("Thriller"); context.Save<Movie>(existingMovie); Console.WriteLine("Adding movie with same hash key but different range key"); Movie darkKnight89 = new Movie { Title = "The Dark Knight", Genres = new List<string> { "Drama" }, ReleaseDate = new DateTime(1989, 2, 23), ActorNames = new List<string> { "Juan Diego", "Fernando Guillén", "Manuel de Blas" } }; context.Save<Movie>(darkKnight89); IEnumerable<Movie> movieQueryResults; Console.WriteLine(); Console.WriteLine("Running query 1, expecting 1 result"); movieQueryResults = context.Query<Movie>("The Dark Knight", QueryOperator.GreaterThan, new DateTime(1995, 1, 1)); foreach (var result in movieQueryResults) Console.WriteLine(result.ToString()); Console.WriteLine(); Console.WriteLine("Running query 2, expecting 2 results"); movieQueryResults = context.Query<Movie>("The Dark Knight", QueryOperator.Between, new DateTime(1970, 1, 1), new DateTime(2011, 1, 1)); foreach (var result in movieQueryResults) Console.WriteLine(result.ToString()); IEnumerable<Actor> actorScanResults; Console.WriteLine(); Console.WriteLine("Running scan 1, expecting 2 results"); actorScanResults = context.Scan<Actor>( new ScanCondition("HeightInMeters", ScanOperator.LessThan, 1.85f)); foreach (var result in actorScanResults) Console.WriteLine(result.ToString()); Console.WriteLine(); Console.WriteLine("Running scan 2, expecting 1 result"); Address scanAddress = new Address { City = "New York City", Country = "USA" }; actorScanResults = context.Scan<Actor>( new ScanCondition("Address", ScanOperator.Equal, scanAddress)); foreach (var result in actorScanResults) Console.WriteLine(result.ToString()); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } User user = context.Load <User>(model.Username); //List<ScanCondition> conditions = new List<ScanCondition>(); //conditions.Add(new ScanCondition("UserID", ScanOperator.Equal, model.Username)); //conditions.Add(new ScanCondition("Password", ScanOperator.Equal, model.Password)); //User user = context.Scan<User>(conditions.ToArray()).FirstOrDefault(); if (user != null && user.Password == model.Password) { FormsAuthentication.SetAuthCookie(user.UserID, false); Session["User"] = user.Info; var authTicket = new FormsAuthenticationTicket(1, user.UserID, DateTime.Now, DateTime.Now.AddMinutes(20), false, user.Info.FullName); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("", "Wrong user or password"); return(View(model)); } }
private void addBtn_Click(object sender, RoutedEventArgs e) { Book selected = (Book)newbookLst.SelectedItem; List <Book> userbook = new List <Book>(); userbook.Add(selected); User retrieved = context.Load <User>(user.Username); if (retrieved.Books == null) { retrieved.Books = userbook; } else { retrieved.Books.Add(selected); } context.Save <User>(retrieved); string userdownloadpath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), selected.PDFFile.Key); selected.PDFFile.DownloadTo(userdownloadpath); //userbookshelfwindow.loadBooks(); MessageBox.Show("Book has successfully added to your bookshelf!"); }
static void Main() { var regionEndpoint = RegionEndpoint.GetBySystemName("us-west-1"); using (var context = new DynamoDBContext(regionEndpoint)) { var rca = context.Load <Label>("895"); Console.WriteLine(rca.Name); Console.WriteLine(); Console.WriteLine(rca.contact_info); Console.WriteLine(); Console.WriteLine(); var rickAstley = context.Load <Artist>("72872"); Console.WriteLine(rickAstley.Name); Console.WriteLine(rickAstley.Profile); Console.WriteLine(); Console.WriteLine(); var song = context.Load <Release>("249504"); Console.WriteLine(song.Title); Console.WriteLine(song.Country); Console.WriteLine(song.Year); Console.WriteLine(); } Console.ReadLine(); }
public void Delete(string id) { Type original = _context.Load <Type>(id); if (original != null) { _context.Delete <Type>(original); } }
public void Delete(string id) { Widget original = _context.Load <Widget>(id); if (original != null) { _context.Delete <Widget>(original); } }
public bool Add(T record) { T savedItem = _DbContext.Load(record); if (savedItem != null) { return(false); } _DbContext.Save <T>(record); return(true); }
public ActionResult MatchWeek(string id) { MatchWeekIndex model = new MatchWeekIndex(); model.League = context.Load <League>(id); //var model = db.MatchWeeks.Include(m => m.League).Where(m => m.LeagueID == id).OrderBy(m => m.StarDate).AsEnumerable(); List <ScanCondition> condition = new List <ScanCondition>(); condition.Add(new ScanCondition("LeagueID", ScanOperator.Equal, id)); model.Index = context.Scan <MatchWeek>(condition.ToArray()).OrderBy(m => m.StarDate).AsEnumerable(); ViewBag.LeagueID = id; return(View(model)); }
public IHttpActionResult GetContribution(string id) { DynamoDBContext context = new DynamoDBContext(dynamoClient); User dbUser = context.Load <User>(id); if (dbUser == null) { return(NotFound()); } Team dbTeam = context.Load <Team>(dbUser.teamId); if (dbTeam == null) { return(NotFound()); } Battle dbBattle = context.Load <Battle>(dbTeam.currentBattle); if (dbBattle == null) { return(NotFound()); } int index = 0; for (; index < dbBattle.participants.Count; index++) { if (dbBattle.participants[index].Equals(dbUser.teamId)) { break; } } dbBattle.scores[index] += dbBattle.offsets[index]; // dbBattle.participants[dbUser.teamId] += 1; context.Save <Battle>(dbBattle); Guid contribGuid = new Guid(); Contribution newContrib = new Contribution() { contributionId = contribGuid.ToString(), username = dbUser.username, teamId = dbUser.teamId, battleId = dbBattle.battleId }; //RestRequest requ = new RestRequest("contributions/user/" + dbUser.username + "/battle/" + dbBattle.battleId, Method.GET); RestRequest contribPost = new RestRequest("contributions", Method.POST); contribPost.AddJsonBody(newContrib); Contribution userContrib = RestDispatcher.ExecuteRequest <Contribution>(contribPost); return(Ok(userContrib)); }
protected override TValue DbGet <TKey, TValue>(RedisStoreKey <TKey> key) { using (var dynamoCtx = new DynamoDBContext(DynamoDBClient.Instance)) { return(dynamoCtx.Load <TValue>(key.Data)); } }
public T Get <T>(string key) where T : class { using (DynamoDBContext context = new DynamoDBContext(_client, _conf)) { return(context.Load <T>(key)); } }
public HttpResponseMessage Post(Battle battle) { Guid guid = Guid.NewGuid(); if (ModelState.IsValid) { battle.battleId = guid.ToString(); DynamoDBContext context = new DynamoDBContext(dynamoClient); context.Save <Battle>(battle); for (var i = 0; i < battle.participants.Count; i++) { Team team = context.Load <Team>(battle.participants.ElementAt(i)); team.currentBattle = battle.battleId; context.Save <Team>(team); } return(new HttpResponseMessage(HttpStatusCode.Created)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public override ErrorLogEntry GetError(string id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } AssertTableExists(); Guid key; if (!Guid.TryParse(id, out key)) { throw new ArgumentException($"Invalid id '{id}'", nameof(id)); } using (var context = new DynamoDBContext(_client)) { var entity = context.Load <ErrorEntity>(key, new DynamoDBOperationConfig { OverrideTableName = TableName }); var error = ErrorXml.DecodeString(entity.AllXml); return(new ErrorLogEntry(this, id, error)); } }
private void loginBtn_Click(object sender, RoutedEventArgs e) { if (usernameTxt.Text != null && passPbx.Password != null) { string username = usernameTxt.Text; //string password = passTxt.Text; string password = passPbx.Password; context = new DynamoDBContext(client); //Table UserTable = Table.LoadTable(client, "Users"); User getUser = context.Load <User>(username); if (username == "ADMIN" && password == "password") { AdminWindow adw = new AdminWindow(); adw.Show(); } else if (getUser != null && getUser.Password == password) { errorMsgLbl.Content = ""; UserBookshelfWindow usbsw = new UserBookshelfWindow(getUser); usbsw.Show(); } else { errorMsgLbl.Content = "**Wrong username/password."; } } else { errorMsgLbl.Content = "**Please put username/password"; } }
private static void GetBook(DynamoDBContext context, int productId) { Book bookItem = context.Load <Book>(productId); Console.WriteLine("\nGetBook: Printing result....."); Console.WriteLine("Title: {0} \n No.Of threads:{1} \n No. of messages: {2}", bookItem.Title, bookItem.ISBN, bookItem.PageCount); }
public string GetUser(DynamoDBContext context, int UserID) { Users user = context.Load<Users>(UserID); if (user != null) return user.UserName; else return "User doesn't exist"; }
public T Get <T>(string key, long range) where T : class { using (DynamoDBContext context = new DynamoDBContext(_client, _conf)) { T t = context.Load <T>(key, range); return(t); } }
private static void TestCRUDOperations(DynamoDBContext context) { int bookID = 1001; // Some unique value. Book myBook = new Book { Id = bookID, Title = "object persistence-AWS SDK for.NET SDK-Book 1001", ISBN = "111-1111111001", BookAuthors = new List <string> { "Author 1", "Author 2" }, }; // Save the book. context.Save(myBook); // Retrieve the book. Book bookRetrieved = context.Load <Book>(bookID); // Update few properties. bookRetrieved.ISBN = "222-2222221001"; bookRetrieved.BookAuthors = new List <string> { " Author 1", "Author x" }; // Replace existing authors list with this. context.Save(bookRetrieved); // Retrieve the updated book. This time add the optional ConsistentRead parameter using DynamoDBContextConfig object. Book updatedBook = context.Load <Book>(bookID, new DynamoDBContextConfig { ConsistentRead = true }); // Delete the book. context.Delete <Book>(bookID); // Try to retrieve deleted book. It should return null. Book deletedBook = context.Load <Book>(bookID, new DynamoDBContextConfig { ConsistentRead = true }); if (deletedBook == null) { Console.WriteLine("Book is deleted"); } }
public T GetItem <T>(string hashKey) where T : class { if (string.IsNullOrEmpty(hashKey)) { return(null); } dbContext = CreateDynamoDBContext(); return(dbContext.Load <T>(hashKey)); }
public Review GetReview(Category category, Guid id) { Review review; using (var context = new DynamoDBContext(_dbClient, _dbOperationConfig)) { review = context.Load <Review>(category, id); } return(review); }
public void loadBooks() { context = new DynamoDBContext(client); User retrieved = context.Load <User>(user.Username); if (retrieved.Books != null) { userBooksLst.ItemsSource = retrieved.Books; } }
public IHttpActionResult GetBattle(string id) { DynamoDBContext context = new DynamoDBContext(dynamoClient); Battle battle = context.Load <Battle>(id); if (battle == null) { return(NotFound()); } return(Ok(battle)); }
public IHttpActionResult GetTeam(string id) { DynamoDBContext context = new DynamoDBContext(dynamoClient); Team team = context.Load <Team>(id); if (team == null) { return(NotFound()); } return(Ok(team)); }
public void bookmark(int pagenumber) { AWSConnectionService instance = AWSConnectionService.getInstance(); AmazonDynamoDBClient client = new AmazonDynamoDBClient(instance.credentials, AWSConnectionService.dynamoDbRegion); DynamoDBContext context = new DynamoDBContext(client); FileModel pdfRecordRetrived = context.Load <FileModel>(emailId, key); Trace.WriteLine(pdfRecordRetrived.ToString()); pdfRecordRetrived.CurrentPageNumber = pagenumber; context.Save <FileModel>(pdfRecordRetrived); }
public IHttpActionResult GetSubscription(string team) { DynamoDBContext context = new DynamoDBContext(); Subscription sub = context.Load <Subscription>(team); if (sub == null) { return(NotFound()); } return(Ok(sub)); }
public IHttpActionResult GetUser(string id) { DynamoDBContext context = new DynamoDBContext(dynamoClient); User user = context.Load <User>(id); if (user == null) { return(NotFound()); } return(Ok(user)); }
public void DeleteItem <T>(T item) { dbContext = CreateDynamoDBContext(); T savedItem = dbContext.Load(item); if (savedItem == null) { throw new AmazonDynamoDBException("Item does not exist in the Table"); } dbContext.Delete(savedItem); }
public void UpdateItem <T>(T item) where T : class { T savedItem = dbContext.Load(item); if (savedItem == null) { throw new AmazonDynamoDBException("Item does not exist in the Table"); } dbContext = CreateDynamoDBContext(); dbContext.Save(item); }
public static void UpdateBookPriceConditionally(this DynamoDBContext context, int sampleBookId) { Console.WriteLine("\n*** Executing UpdateBookPriceConditionally() ***"); var partitionKey = sampleBookId; var book = context.Load <Book>(partitionKey); book.Price = 29.99; context.Save(book); Console.WriteLine("UpdateBookPriceConditionally: Printing item whose price was conditionally updated"); }
public void Delete <T>(string key, string range) { using (DynamoDBContext context = new DynamoDBContext(_client, _conf)) { var savedItem = context.Load <T>(key, range); if (savedItem == null) { throw new IdentityException("The item does not exist in the Table"); } context.Delete(savedItem); } }
//???? public void Update <T>(T item) where T : class { using (DynamoDBContext context = new DynamoDBContext(_client, _conf)) { T savedItem = context.Load(item); if (savedItem == null) { throw new EntityNotExistsException("The item does not exist in the Table"); } context.Save(item); } }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { currentpage = viewer.CurrentPageNumber; context = new DynamoDBContext(client); User retrieved = context.Load <User>(user.Username); retrieved.Books.Where(b => b.ISBN == book.ISBN) .Select(b => b) .First().CurrentPage = currentpage; context.Save <User>(retrieved); UserBookshelfWindow ubsw = new UserBookshelfWindow(retrieved); ubsw.Show(); base.OnClosing(e); }
public override void ViewDidLoad () { base.ViewDidLoad (); var client = new AmazonDynamoDBClient(ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1); var context = new DynamoDBContext(client); var actor = new Actor("John Doe"); context.Save(actor); actor = context.Load<Actor>("John Doe"); actor.Biography = "Current email: [email protected]"; context.Save(actor); context.Delete(actor); var movie = new Movie("Casablanca", new DateTime(1943, 1, 23)); context.Save(movie); movie = context.Load<Movie>("Casablanca", new DateTime(1943, 1, 23)); movie.Genres = new List<string> { "Drama", "Romance", "War" }; context.Save(movie); DateTime date = new DateTime(1960, 1, 1); var queryResults = context.Query<Movie>("Casablanca", QueryOperator.LessThan, date).ToList (); foreach (var result in queryResults) Console.WriteLine(result.Title); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button> (Resource.Id.myButton); button.Click += delegate { var client = new AmazonDynamoDBClient(ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1); var context = new DynamoDBContext(client); var actor = new Actor("John Doe"); context.Save(actor); actor = context.Load<Actor>("John Doe"); actor.Biography = "Current email: [email protected]"; context.Save(actor); context.Delete(actor); var movie = new Movie("Casablanca", new DateTime(1943, 1, 23)); context.Save(movie); movie = context.Load<Movie>("Casablanca", new DateTime(1943, 1, 23)); movie.Genres = new List<string> { "Drama", "Romance", "War" }; context.Save(movie); DateTime date = new DateTime(1960, 1, 1); var queryResults = context.Query<Movie>("Casablanca", QueryOperator.LessThan, date).ToList (); foreach (var result in queryResults) Console.WriteLine(result.Title); }; }
public static void PopulateMovies() { Console.WriteLine("Creating the context object"); DynamoDBContext context = new DynamoDBContext(Database.Client); Console.WriteLine("Creating actors"); Actor christianBale = new Actor { Name = "Christian Bale", Bio = "Christian Charles Philip Bale is an excellent horseman and an avid reader.", BirthDate = new DateTime(1974, 1, 30), Address = new Address { City = "Los Angeles", Country = "USA" }, HeightInMeters = 1.83f }; Actor michaelCaine = new Actor { Name = "Michael Caine", Bio = "Maurice Joseph Micklewhite is an English actor, better known as Michael Caine", BirthDate = new DateTime(1933, 3, 14), Address = new Address { City = "London", Country = "England" }, HeightInMeters = 1.88f }; Console.WriteLine("Creating movie"); Movie darkKnight = new Movie { Title = "The Dark Knight", ReleaseDate = new DateTime(2008, 7, 18), Genres = new List<string> { "Action", "Crime", "Drama" }, ActorNames = new List<string> { christianBale.Name, michaelCaine.Name } }; Console.WriteLine("Saving actors and movie"); context.Save<Actor>(michaelCaine); context.Save<Actor>(christianBale); context.Save<Movie>(darkKnight); Console.WriteLine("Creating and saving new actor"); Actor maggieGyllenhaal = new Actor { Name = "Maggie Gyllenhaal", BirthDate = new DateTime(1977, 11, 16), Bio = "Maggie Gyllenhaal studied briefly at the Royal Academy of Dramatic Arts in London.", Address = new Address { City = "New York City", Country = "USA" }, HeightInMeters = 1.75f }; context.Save<Actor>(maggieGyllenhaal); Console.WriteLine(); Console.WriteLine("Loading existing movie"); Movie existingMovie = context.Load<Movie>("The Dark Knight", new DateTime(2008, 7, 18)); Console.WriteLine(existingMovie.ToString()); Console.WriteLine(); Console.WriteLine("Loading nonexistent movie"); Movie nonexistentMovie = context.Load<Movie>("The Dark Knight", new DateTime(2008, 7, 19)); Console.WriteLine("Movie is null : " + (nonexistentMovie == null)); Console.WriteLine("Updating movie and saving"); existingMovie.ActorNames.Add(maggieGyllenhaal.Name); existingMovie.Genres.Add("Thriller"); context.Save<Movie>(existingMovie); Console.WriteLine("Adding movie with same hash key but different range key"); Movie darkKnight89 = new Movie { Title = "The Dark Knight", Genres = new List<string> { "Drama" }, ReleaseDate = new DateTime(1989, 2, 23), ActorNames = new List<string> { "Juan Diego", "Fernando Guillén", "Manuel de Blas" } }; context.Save<Movie>(darkKnight89); }