public async Task <bool> NoControlAsync(Profile p, Profile a) { List <string> s = await NetWorkTable.Where(item => item.FPID == p.ID).Select(item => item.SPID).ToListAsync(); ObservableCollection <Profile> items2 = new ObservableCollection <Profile>(); ObservableCollection <Profile> items3 = new ObservableCollection <Profile>(); foreach (var x in s) { items2.Add(await profileTable.LookupAsync(x)); } for (var i = 0; i < items2.Count; i++) { if (items2.ElementAt(i).TelNo == a.TelNo) { items3.Add(await profileTable.LookupAsync(items2.ElementAt(i).ID)); } } if (items3.Count == 0) { return(true); } else { return(false); } }
public async Task LookupAsync() { string appUrl = "http://www.test.com"; string appKey = "secret..."; TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient service = new MobileServiceClient(appUrl, appKey) .WithFilter(hijack); hijack.Response.Content = new JsonObject() .Set("id", 12) .Set("Name", "Bob") .Stringify(); IMobileServiceTable <Person> table = service.GetTable <Person>(); Person bob = await table.LookupAsync(12); Assert.AreEqual(12L, bob.Id); Assert.AreEqual("Bob", bob.Name); hijack.Response.StatusCode = 404; bool thrown = false; try { bob = await table.LookupAsync(12); } catch (InvalidOperationException) { thrown = true; } Assert.IsTrue(thrown, "Exception should be thrown on a 404!"); }
private async Task RegisterUser() { User user = new User { Id = this.user.UserId }; if (users == null || curr != null) { return; } try { curr = await usersTable.LookupAsync(user.Id); } catch (Exception) { //User does not exist } if (curr != null) { return; } try { await usersTable.InsertAsync(user); } catch (Exception) { // } curr = await usersTable.LookupAsync(this.user.UserId); }
//METHODS public async Task <User> ValidateSignIn(string email, string password) { if (email == null || email.Equals("") || password == null || password.Equals("")) { return(null); } else { User user = await userTable.LookupAsync(email); if (user == null) { throw new ArgumentException("Aanmeldgegevens incorrect"); } else { SHA256Managed crypt = new SHA256Managed(); StringBuilder hash = new StringBuilder(); byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password)); foreach (byte theByte in crypto) { hash.Append(theByte.ToString("x2")); } string hashedPassword = hash.ToString(); if (!user.Password.Equals(hashedPassword)) { throw new ArgumentException("Aanmeldgegevens incorrect"); } else { return(user); } } } }
public async Task TestInsertWithNoId() { var order = new Order { OrderDate = DateTime.UtcNow, Client = "John Doe", Items = new OrderItem[] { new OrderItem { Name = "Bread", Quantity = 1, Price = 1.99 } } }; await Table.InsertAsync(order); Assert.IsNotNull(order.Id); var inserted = await Table.LookupAsync(order.Id); Assert.AreEqual(order.OrderDate.ToUniversalTime(), inserted.OrderDate.ToUniversalTime()); Assert.AreEqual(order.Id, inserted.Id); Assert.AreEqual(order.Client, inserted.Client); CollectionAssert.AreEqual(order.Items, inserted.Items); // Cleanup await Table.DeleteAsync(order); }
public async Task ChangeCulture() { IMobileServiceTable <DateExample> table = GetClient().GetTable <DateExample>(); //win7 is different setting default thread current culture //CultureInfo threadCulture = CultureInfo.DefaultThreadCurrentCulture; //CultureInfo threadUICulture = CultureInfo.DefaultThreadCurrentUICulture; CultureInfo threadCulture = System.Threading.Thread.CurrentThread.CurrentCulture; CultureInfo threadUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture; DateTime original = new DateTime(2009, 10, 21, 14, 22, 59, 860, DateTimeKind.Local); DateExample instance = new DateExample { Date = original }; await table.InsertAsync(instance); Log("Change culture to ar-EG"); CultureInfo arabic = new CultureInfo("ar-EG"); //CultureInfo.DefaultThreadCurrentCulture = arabic; //CultureInfo.DefaultThreadCurrentUICulture = arabic; System.Threading.Thread.CurrentThread.CurrentCulture = arabic; System.Threading.Thread.CurrentThread.CurrentUICulture = arabic; DateExample arInstance = await table.LookupAsync(instance.Id); Assert.AreEqual(original, arInstance.Date); Log("Change culture to zh-CHS"); CultureInfo chinese = new CultureInfo("zh-CHS"); //CultureInfo.DefaultThreadCurrentCulture = chinese; //CultureInfo.DefaultThreadCurrentUICulture = chinese; System.Threading.Thread.CurrentThread.CurrentCulture = chinese; System.Threading.Thread.CurrentThread.CurrentUICulture = chinese; DateExample zhInstance = await table.LookupAsync(instance.Id); Assert.AreEqual(original, zhInstance.Date); Log("Change culture to ru-RU"); CultureInfo russian = new CultureInfo("ru-RU"); //CultureInfo.DefaultThreadCurrentCulture = russian; //CultureInfo.DefaultThreadCurrentUICulture = russian; System.Threading.Thread.CurrentThread.CurrentCulture = russian; System.Threading.Thread.CurrentThread.CurrentUICulture = russian; DateExample ruInstance = await table.LookupAsync(instance.Id); Assert.AreEqual(original, ruInstance.Date); //CultureInfo.DefaultThreadCurrentCulture = threadCulture; //CultureInfo.DefaultThreadCurrentUICulture = threadUICulture; System.Threading.Thread.CurrentThread.CurrentCulture = threadCulture; System.Threading.Thread.CurrentThread.CurrentUICulture = threadCulture; }
public async override Task <Auction> GetItemAsync(string Id) { IMobileServiceTable <Auction> auctionTable = StoreManager.MobileService.GetTable <Auction>(); var auction = await auctionTable.LookupAsync(Id); return(auction); }
public async Task DeleteAsyncWithNosuchItemAgainstStringIdTable() { await EnsureEmptyTableAsync <ToDoWithStringId>(); string[] testIdData = IdTestData.ValidStringIds; IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); foreach (string testId in testIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = testId, Name = "Hey" }; await table.InsertAsync(item); } foreach (string testId in testIdData) { ToDoWithStringId item = await table.LookupAsync(testId); await table.DeleteAsync(item); item.Id = testId; var exception = await Assert.ThrowsAnyAsync <MobileServiceInvalidOperationException>(() => table.DeleteAsync(item)); Assert.Equal(HttpStatusCode.NotFound, exception.Response.StatusCode); Assert.True(exception.Message == "The item does not exist" || exception.Message == "The request could not be completed. (Not Found)"); } }
public async Task InsertAsyncWithExistingItemAgainstStringIdTable() { await EnsureEmptyTableAsync <ToDoWithStringId>(); string[] testIdData = IdTestData.ValidStringIds; IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); foreach (string testId in testIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = testId, Name = "Hey" }; await table.InsertAsync(item); } foreach (string testId in testIdData) { ToDoWithStringId item = await table.LookupAsync(testId); item.Name = "No we're talking!"; var exception = await Assert.ThrowsAnyAsync <MobileServiceInvalidOperationException>(() => table.InsertAsync(item)); Assert.Equal(HttpStatusCode.Conflict, exception.Response.StatusCode); Assert.True(exception.Message.Contains("Could not insert the item because an item with that id already exists.") || exception.Message == "The request could not be completed. (Conflict)"); } }
async Task <T> lookupItemAsync <T> (IMobileServiceTable <T> table, string itemId) #endif where T : AzureEntity, new() { #if DEBUG var sw = new System.Diagnostics.Stopwatch(); sw.Start(); #endif try { return(await table?.LookupAsync(itemId)); #if !DEBUG } catch (Exception) { throw; #else } catch (Exception e) { logDebug <T> (e); throw; } finally { sw.Stop(); logDebug <T> (sw.ElapsedMilliseconds); #endif } }
public async Task Version() { // Create the untyped collection MobileServiceClient client = GetClient(); IMobileServiceTable <ToDo> table = client.GetTable <ToDo>(); IMobileServiceTable <ToDoV2> tableV2 = client.GetTable <ToDoV2>(); // Get some V1 data ToDo first = new ToDo { Title = "Foo" }; await table.InsertAsync(first); // Get the data in V2 format ToDoV2 second = await tableV2.LookupAsync(first.Id); Assert.AreEqual(first.Title, second.Title); // Add a tag second.Tag = "Bar"; await tableV2.UpdateAsync(second); await table.RefreshAsync(first); Assert.AreEqual("Bar: Foo", first.Title); // Chagne the tag first.Title = "Baz: Quux"; await table.UpdateAsync(first); await tableV2.RefreshAsync(second); Assert.AreEqual("Baz", second.Tag); Assert.AreEqual("Quux", second.Title); }
private async void ButtonLogin_Click(object sender, RoutedEventArgs e) { // Login the user and then load data from the mobile app. if (await AuthenticateAsync()) { // Switch the buttons and load items from the mobile app. // ButtonLogin.Visibility = Visibility.Collapsed; //await InitLocalStoreAsync(); //offline sync support. // await RefreshTodoItems(); User currentUser = null; try { currentUser = await UsersTable.LookupAsync(user.UserId.Substring(4)); var parameters = new MainDashboardParams(currentUser); Frame.Navigate(typeof(MainDashboard), parameters); } catch (Exception) { Frame.Navigate(typeof(UserDeatailsPage), user.UserId.Substring(4)); } } }
public async Task Basics() { // Insert a few records IMobileServiceTable <ToDo> table = GetClient().GetTable <ToDo>(); ToDo first = new ToDo { Title = "ABC", Complete = false }; await table.InsertAsync(first); await table.InsertAsync(new ToDo { Title = "DEF", Complete = true }); await table.InsertAsync(new ToDo { Title = "GHI", Complete = false }); // Run a simple query and verify we get all 3 items List <ToDo> items = await table.Where(t => t.Id >= first.Id).ToListAsync(); Assert.AreEqual(3, items.Count); // Query and sort ascending items = await table.Where(t => t.Id >= first.Id).OrderBy(t => t.Title).ToListAsync(); Assert.AreEqual(3, items.Count); Assert.AreEqual("ABC", items[0].Title); Assert.AreEqual("DEF", items[1].Title); Assert.AreEqual("GHI", items[2].Title); // Query and sort descending items = await table.Where(t => t.Id >= first.Id).OrderByDescending(t => t.Title).ToListAsync(); Assert.AreEqual(3, items.Count); Assert.AreEqual("ABC", items[2].Title); Assert.AreEqual("DEF", items[1].Title); Assert.AreEqual("GHI", items[0].Title); // Filter to completed items = await table.Where(t => t.Id >= first.Id).Where(t => t.Complete == true).ToListAsync(); Assert.AreEqual(1, items.Count); Assert.AreEqual("DEF", items[0].Title); // Verify that inserting into a non-existant collection // also throws an error try { await GetClient().GetTable("notreal").ReadAsync(null); } catch (InvalidOperationException ex) { Assert.Contains(ex.Message, "notreal"); } // Verify we can insert non-latin characters as a TODO item string title = "ÃÇßÑᾆΏ"; ToDo item = new ToDo { Title = title }; await table.InsertAsync(item); Assert.AreEqual(title, (await table.LookupAsync(item.Id)).Title); }
private async Task <RunningGameItem> GetgameItem(string id) { // This code inserts a new TodoItem into the database. After the operation completes // and the mobile app backend has assigned an id, the item is added to the CollectionView. RunningGameItem result = new RunningGameItem(); try { result = await gameTable.LookupAsync(id); } catch (System.Net.Http.HttpRequestException ex) { ContentDialog deleteFileDialog = new ContentDialog { FontSize = 10, Title = "Network Error", PrimaryButtonText = "Home" }; ContentDialogResult result2 = await deleteFileDialog.ShowAsync(); this.Frame.Navigate(typeof(ServerMenuPage)); } return(result); //gameItems.Add(gameItem); #if OFFLINE_SYNC_ENABLED await App.MobileService.SyncContext.PushAsync(); // offline sync #endif }
public async Task <object> GetValueAsync() { object item = null; if (typeof(T) == typeof(JObject)) { IMobileServiceTable table = _context.Client.GetTable(_context.ResolvedAttribute.TableName); await IgnoreNotFoundExceptionAsync(async() => { item = await table.LookupAsync(_context.ResolvedAttribute.Id); _originalItem = CloneItem(item); }); } else { // If TableName is specified, add it to the internal table cache. Now items of this type // will operate on the specified TableName. if (!string.IsNullOrEmpty(_context.ResolvedAttribute.TableName)) { _context.Client.AddToTableNameCache(typeof(T), _context.ResolvedAttribute.TableName); } IMobileServiceTable <T> table = _context.Client.GetTable <T>(); await IgnoreNotFoundExceptionAsync(async() => { item = await table.LookupAsync(_context.ResolvedAttribute.Id); _originalItem = CloneItem(item); }); } return(item); }
public static Task GetTask(int taskID) { var asyncTask = table.LookupAsync(taskID); asyncTask.Wait(); return(asyncTask.Result); }
/// <summary> /// get a all mission details form a mission id /// </summary> /// <returns>The mission details async.</returns> /// <param name="ID">Identifier.</param> public async Task <MissionDataModel> GetMissionDetailsAsync(string ID) { Initialize(); MissionDataModel item = await missionsTable.LookupAsync(ID); return(item); }
public async Task RefreshAsyncWithNoSuchItemAgainstStringIdTable() { await EnsureEmptyTableAsync <ToDoWithStringId>(); string[] testIdData = IdTestData.ValidStringIds; IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); foreach (string testId in testIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = testId, Name = "Hey" }; await table.InsertAsync(item); } foreach (string testId in testIdData) { ToDoWithStringId item = await table.LookupAsync(testId); await table.DeleteAsync(item); item.Id = testId; await Assert.ThrowsAsync <InvalidOperationException>(() => table.RefreshAsync(item)); } }
public async Task <Member> GetItemAsync(string id) { if (id != null && CrossConnectivity.Current.IsConnected) { return(await MemberTable.LookupAsync(id)); } return(null); }
public void LookupAsync() { string appUrl = "http://www.test.com"; string appKey = "secret..."; var userDefinedParameters = new Dictionary <string, string>() { { "state", "CA" } }; TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient service = new MobileServiceClient(appUrl, appKey) .WithFilter(hijack); hijack.Response.Content = new JsonObject() .Set("id", 12) .Set("Name", "Bob") .Stringify(); IMobileServiceTable <Person> table = service.GetTable <Person>(); table.LookupAsync(12, userDefinedParameters).ContinueWith(t => { var bob = t.Result; Assert.That(hijack.Request.Uri.Query, Contains.Substring("state=CA")); Assert.AreEqual(12L, bob.Id); Assert.AreEqual("Bob", bob.Name); hijack.Response.StatusCode = 404; bool thrown = false; try { Task <Person> lookup = table.LookupAsync(12); lookup.WaitOrFail(Timeout); bob = lookup.Result; } catch (AggregateException aex) { aex.AssertCaught <InvalidOperationException>(); thrown = true; } Assert.IsTrue(thrown, "Exception should be thrown on a 404!"); }).WaitOrFail(Timeout); }
public async Task <Food> GetItemAsync(string id) { if (id != null) { IMobileServiceTable <Food> todoTable = _client.GetTable <Food>(); return(await todoTable.LookupAsync(id)); } return(null); }
public async Task ChangeCulture() { IMobileServiceTable <Dates> table = GetClient().GetTable <Dates>(); CultureInfo threadCulture = CultureInfo.DefaultThreadCurrentCulture; CultureInfo threadUICulture = CultureInfo.DefaultThreadCurrentUICulture; DateTime original = new DateTime(2009, 10, 21, 14, 22, 59, 860, DateTimeKind.Local); Dates instance = new Dates { Date = original }; await table.InsertAsync(instance); Log("Change culture to ar-EG"); CultureInfo arabic = new CultureInfo("ar-EG"); CultureInfo.DefaultThreadCurrentCulture = arabic; CultureInfo.DefaultThreadCurrentUICulture = arabic; Dates arInstance = await table.LookupAsync(instance.Id); Assert.AreEqual(original, arInstance.Date); Log("Change culture to zh-CN"); CultureInfo chinese = new CultureInfo("zh-CN"); CultureInfo.DefaultThreadCurrentCulture = chinese; CultureInfo.DefaultThreadCurrentUICulture = chinese; Dates zhInstance = await table.LookupAsync(instance.Id); Assert.AreEqual(original, zhInstance.Date); Log("Change culture to ru-RU"); CultureInfo russian = new CultureInfo("ru-RU"); CultureInfo.DefaultThreadCurrentCulture = russian; CultureInfo.DefaultThreadCurrentUICulture = russian; Dates ruInstance = await table.LookupAsync(instance.Id); Assert.AreEqual(original, ruInstance.Date); CultureInfo.DefaultThreadCurrentCulture = threadCulture; CultureInfo.DefaultThreadCurrentUICulture = threadUICulture; }
// public ToDoItem GetTaskFromList(string id) // { // return todoTable.FirstOrDefault(o => o.ID == id); // } public async Task <TodoItem> GetTaskAsync(string id) { try { return(await todoTable.LookupAsync(id)); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"INVALID {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"ERROR {0}", e.Message); } return(null); }
public async Task <T> ReadItemAsync(string id) { T val = null; try { val = await table.LookupAsync(id); } catch (Exception e) { Debug.WriteLine(e.StackTrace); } return(val); }
public async Task PostComments() { IMobileServiceClient client = GetClient(); IMobileServiceTable <BlogPost> postTable = client.GetTable <BlogPost>(); IMobileServiceTable <BlogComment> commentTable = client.GetTable <BlogComment>(); var userDefinedParameters = new Dictionary <string, string>() { { "state", "NY" }, { "tags", "#pizza #beer" } }; // Add a few posts and a comment Log("Adding posts"); BlogPost post = new BlogPost { Title = "Windows 8" }; await postTable.InsertAsync(post, userDefinedParameters); BlogPost highlight = new BlogPost { Title = "ZUMO" }; await postTable.InsertAsync(highlight); await commentTable.InsertAsync(new BlogComment { BlogPostId = post.Id, UserName = "******", Text = "Beta runs great" }); await commentTable.InsertAsync(new BlogComment { BlogPostId = highlight.Id, UserName = "******", Text = "Whooooo" }); Assert.AreEqual(2, (await postTable.Where(p => p.Id >= post.Id) .WithParameters(userDefinedParameters) .ToListAsync()).Count); // Navigate to the first post and add a comment Log("Adding comment to first post"); BlogPost first = await postTable.LookupAsync(post.Id); Assert.AreEqual("Windows 8", first.Title); BlogComment opinion = new BlogComment { BlogPostId = first.Id, Text = "Can't wait" }; await commentTable.InsertAsync(opinion); Assert.AreNotEqual(0, opinion.Id); }
public async Task <int> GetReport(string id) { try { Place place = await table.LookupAsync(id); return(place.report); } catch { return(-1); } }
public async static Task <User> Get(this User user) { IMobileServiceTable <User> users = AzureContext.Client.GetTable <User>(); try { return(await users.LookupAsync(user.Id)); } catch { return(null); } }
public static Task <Hub> Get(this Hub hub) { IMobileServiceTable <Hub> hubs = AzureContext.Client.GetTable <Hub>(); try { return(hubs.LookupAsync(hub.Id)); } catch { return(null); } }
public async Task LookupAsync() { TestHttpHandler hijack = new TestHttpHandler(); IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack); IMobileServiceTable table = service.GetTable("tests"); hijack.SetResponseContent("{\"id\":12,\"String\":\"Hello\"}"); JToken expected = await table.LookupAsync(12); Assert.AreEqual(12, (int)expected["id"]); Assert.AreEqual("Hello", (string)expected["String"]); }
public async Task LookupAsyncWithNosuchItemAgainstStringIdTable() { await EnsureEmptyTableAsync <ToDoWithStringId>(); string[] testIdData = IdTestData.ValidStringIds; IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); foreach (string testId in testIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = testId, Name = "Hey" }; await table.InsertAsync(item); } foreach (string testId in testIdData) { ToDoWithStringId item = await table.LookupAsync(testId); await table.DeleteAsync(item); MobileServiceInvalidOperationException exception = null; try { await table.LookupAsync(testId); } catch (MobileServiceInvalidOperationException e) { exception = e; } Assert.IsNotNull(exception); Assert.AreEqual(exception.Response.StatusCode, HttpStatusCode.NotFound); Assert.IsTrue(exception.Message.Contains(string.Format("Error: An item with id '{0}' does not exist.", testId)) || exception.Message == "The request could not be completed. (Not Found)"); } }