Esempio n. 1
0
        private async void importSetButton_ClickedAsync(object sender, EventArgs e)
        {
            var thepacketset = packetSetJSONListView.SelectedItem as PacketSetJSON;

            if (thepacketset != null)
            {
                if (!String.IsNullOrWhiteSpace(thepacketset.name) &&
                    !String.IsNullOrWhiteSpace(thepacketset.packetjson)
                    )
                {
                    var _packetsjson = JsonConvert.DeserializeObject <List <PacketJSON> >(thepacketset.packetjson);

                    if (_packetsjson != null)
                    {
                        if (_packetsjson.Count > 0)
                        {
                            MessagingCenter.Send(this, Events.NEW_PACKET_LIST, PacketJSON.ToPacketList(_packetsjson));

                            await DisplayAlert("Success", "Imported " + _packetsjson.Count() + " packets", "OK");

                            await Navigation.PopModalAsync();
                        }
                    }
                }
            }
        }
        private async void OnLoginButtonClicked(object sender, EventArgs e)
        {
            var http = new HttpClient();
            var un   = usernameEntry.Text;
            var pw   = passwordEntry.Text;

            un = "boom";
            pw = "pass";

            string json = "";

            try {
                //Xamarin cannot read cloudflare cert. This works with Let's Encrypt cert.
                json = await http.GetStringAsync(new Uri("https://cloud.packetsender.com/?un=" + un + "&pw=" + pw));
            } catch (HttpRequestException eHttp) {
                Debug.WriteLine("Exception : " + eHttp.Message);
                Debug.WriteLine("Exception : " + eHttp.InnerException.Message);
            }

            if (json.Length > 0)
            {
                //JsonConvert.DeserializeObject<List<CustomerJson>>(json);

                try
                {
                    _packetsjson = JsonConvert.DeserializeObject <List <PacketJSON> >(json);
                }
                catch (Exception eJson)
                {
                    Debug.WriteLine("Exception : " + eJson.Message);
                    Debug.WriteLine("Exception : " + eJson.InnerException.Message);
                }

                MessagingCenter.Send(this, Events.NEW_PACKET_LIST, PacketJSON.ToPacketList(_packetsjson));

                SettingsPage.UserEmail = un;
                SettingsPage.UserPass  = pw;


                Device.BeginInvokeOnMainThread(async() =>
                {
                    await DisplayAlert("Success", "Found " + _packetsjson.Count() + " packets", "OK");
                });

                await Navigation.PopModalAsync();
            }
            else
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await DisplayAlert("Error", "Could not connect to packet sender.", "OK");
                });
            }
        }