コード例 #1
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();
            FH.SetLogLevel((int)LogService.LogLevels.DEBUG);
            // Perform any additional setup after loading the view, typically from a nib.
            await FHClient.Init();

            ShowMessage("App Ready!");
        }
コード例 #2
0
 public void SetUp()
 {
     FHClient.Init();
     FH.SetLogLevel(1);
 }
コード例 #3
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            FH.SetLogLevel((int)LogService.LogLevels.DEBUG);
            //use ModernHttpClient
            FHHttpClientFactory.Get = (() => new HttpClient(new OkHttpNetworkHandler()));

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            await FHClient.Init();

            ShowMessage("App Ready!");

            Button cloudButton = (Button)FindViewById(Resource.Id.button1);
            Button authButton  = (Button)FindViewById(Resource.Id.button2);
            Button mbaasButton = (Button)FindViewById(Resource.Id.button3);

            cloudButton.Click += async(object sender, EventArgs e) => {
                Dictionary <string, object> data = new Dictionary <string, object>();
                data.Add("hello", "world");
                string     message = null;
                FHResponse res     = await FH.Cloud("hello", "GET", null, data);

                if (res.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    message = (string)res.GetResponseAsDictionary()["msg"];
                }
                else
                {
                    message = "Error";
                }

                ShowMessage(message);
            };

            authButton.Click += async(object sender, EventArgs e) => {
                string     authPolicy = "TestGooglePolicy";
                FHResponse res        = await FH.Auth(authPolicy);

                ShowMessage(res.RawResponse);
            };

            mbaasButton.Click += async(object sender, EventArgs e) => {
                Dictionary <string, object> data = new Dictionary <string, object>();
                data.Add("act", "create");
                data.Add("type", COLLECTION_NAME);
                //create the collection first
                FHResponse createRes = await FH.Mbaas("db", data);

                ShowMessage(createRes.RawResponse);

                //read device id
                string deviceId = GetDeviceId();

                //check if it exists
                data = new Dictionary <string, object>();
                data.Add("type", COLLECTION_NAME);
                data.Add("act", "list");
                Dictionary <string, string> deviceIdField = new Dictionary <string, string>();
                deviceIdField.Add("deviceId", deviceId);
                data.Add("eq", deviceIdField);
                FHResponse listRes = await FH.Mbaas("db", data);

                ShowMessage(listRes.RawResponse);

                IDictionary <string, object> listResDic = listRes.GetResponseAsDictionary();
                if (Convert.ToInt16(listResDic["count"]) == 0)
                {
                    data = new Dictionary <string, object>();
                    data.Add("act", "create");
                    data.Add("type", COLLECTION_NAME);
                    data.Add("fields", GetDeviceInfo());

                    FHResponse dataCreateRes = await FH.Mbaas("db", data);

                    ShowMessage(dataCreateRes.RawResponse);
                }
                else
                {
                    ShowMessage("Device is already created!");
                }
            };
        }