Advertisement
Guest User

Untitled

a guest
Aug 8th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.41 KB | None | 0 0
  1. namespace AzureTest
  2.  
  3. open System
  4. open System.Runtime
  5. open System.Drawing
  6.  
  7. open MonoTouch.UIKit
  8. open MonoTouch.Foundation
  9.  
  10. open Microsoft.WindowsAzure.MobileServices
  11. open Microsoft.WindowsAzure.MobileServices.Sync
  12. open Microsoft.WindowsAzure.MobileServices.SQLiteStore
  13.  
  14. [<CLIMutable>]
  15. type TodoItem = { Id: string; Text: string; Complete: bool }
  16.  
  17. [<Register ("AzureTestViewController")>]
  18. type AzureTestViewController () =
  19.     inherit UIViewController ()
  20.  
  21.     // Release any cached data, images, etc that aren't in use.
  22.     override this.DidReceiveMemoryWarning () =
  23.         base.DidReceiveMemoryWarning ()
  24.  
  25.     // Perform any additional setup after loading the view, typically from a nib.
  26.     override this.ViewDidLoad () =
  27.         base.ViewDidLoad ()
  28.  
  29.         CurrentPlatform.Init ()
  30.         SQLitePCL.CurrentPlatform.Init () // add this line
  31.  
  32.         // Initialize the Mobile Service client with your URL and key
  33.         let client = new MobileServiceClient ("***", "***")
  34.  
  35.         // Create an MSTable instance to allow us to work with the TodoItem table
  36.         let item = { Id = null; Text = "Awesome item"; Complete = false }
  37.         //let itemTable = client.GetTable<TodoItem>()
  38.         //let itemTable = client.GetTable<Item> ()
  39.  
  40.         match client.SyncContext.IsInitialized with
  41.         | false ->
  42.             use store = new MobileServiceSQLiteStore ("baby.db")
  43.             store.DefineTable<TodoItem> ()
  44.  
  45.             client.SyncContext.InitializeAsync(store, MobileServiceSyncHandler ()).Wait ()
  46.         | _ -> ()
  47. //        protected async override void OnNavigatedTo(NavigationEventArgs e)
  48. //        {
  49. //            if (!App.MobileService.SyncContext.IsInitialized)
  50. //            {
  51. //                var store = new MobileServiceSQLiteStore("localsync12.db");
  52. //                store.DefineTable<TodoItem>();
  53. //                await App.MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
  54. //            }
  55. //            RefreshTodoItems();
  56. //        }
  57.  
  58.         let todoTable = client.GetSyncTable ("TodoItem")
  59.         async {
  60.             do! Async.SwitchToNewThread ()
  61.             todoTable.PurgeAsync().Wait()
  62.             todoTable.PullAsync().Wait()
  63.         } |> Async.StartImmediate
  64.  
  65.         printfn "yolo"
  66.         ()
  67.  
  68.     // Return true for supported orientations
  69.     override this.ShouldAutorotateToInterfaceOrientation (orientation) =
  70.         true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement