protected async override void OnCreate (Bundle bundle) { base.OnCreate (bundle); String beaconID = Intent.GetStringExtra("BeaconID"); if (!String.IsNullOrWhiteSpace(beaconID)) { beacon = await BeaconManager.GetBeaconAsync(beaconID); } else { currentGenerateGuid = Guid.NewGuid (); beacon.ID = currentGenerateGuid.ToString (); } // set our layout to be the home screen SetContentView(Resource.Layout.BeaconDetails); nameTextEdit = FindViewById<EditText>(Resource.Id.NameText); notesTextEdit = FindViewById<EditText>(Resource.Id.NotesText); saveButton = FindViewById<Button>(Resource.Id.SaveButton); // find all our controls cancelDeleteButton = FindViewById<Button>(Resource.Id.CancelDeleteButton); // set the cancel delete based on whether or not it's an existing task cancelDeleteButton.Text = (currentGenerateGuid != null ? "Cancel" : "Delete"); nameTextEdit.Text = beacon.Name; notesTextEdit.Text = beacon.Notes; // button clicks cancelDeleteButton.Click += async (sender, e) => { await CancelDelete(); }; saveButton.Click += async (sender, e) => { await Save(); }; }
public static void SaveBeaconAsync(Beacon item) { var httpReq = (HttpWebRequest)HttpWebRequest.Create (new Uri (BeaconRepositoryADO.URL)); if(item.IsNew) { httpReq.Method = "POST"; } else { httpReq.Method = "PUT"; } httpReq.ContentType = "application/json"; string postData = JsonConvert.SerializeObject (new { @_id = item.ID, title = item.Name, description = item.Notes }); byte[] byteArray = Encoding.UTF8.GetBytes (postData); httpReq.ContentLength = byteArray.Length; Stream dataStream = httpReq.GetRequestStream (); dataStream.Write (byteArray, 0, byteArray.Length); dataStream.Close (); var response = httpReq.GetResponse(); var resultString = "0"; using (StreamReader stream = new StreamReader (response.GetResponseStream ())) { resultString = stream.ReadToEnd (); } }
public static Beacon GetBeaconAsync(String id) { var httpReq = (HttpWebRequest)HttpWebRequest.Create (new Uri (BeaconRepositoryADO.URL + "/" + id)); Beacon beacon; try { var response = httpReq.GetResponse(); using(StreamReader stream = new StreamReader(response.GetResponseStream())) { var resultString = stream.ReadToEnd(); var serverFormat = new { @_id = "", title = "", description = "" }; var serverObject = JsonConvert.DeserializeAnonymousType(resultString, serverFormat); beacon = new Beacon(false); beacon.ID = serverObject._id; beacon.Name = serverObject.title; beacon.Notes = serverObject.description; } } catch(WebException webException) { return null; } return beacon; }
public static void SaveBeaconAsync (Beacon item) { BeaconRepositoryADO.SaveBeaconAsync(item); }
public async static Task SaveBeaconAsync (Beacon item) { await BeaconRepositoryADO.SaveBeaconAsync(item); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); _textBeaconId = FindViewById<EditText>(Resource.Id.textViewBeaconId); _textBeaconName = FindViewById<EditText>(Resource.Id.textViewBeaconName); _textBeaconDescription = FindViewById<EditText>(Resource.Id.textViewBeaconDescription); _iBeaconManager.Bind(this); _monitorNotifier.EnterRegionComplete += EnteredRegion; _monitorNotifier.ExitRegionComplete += ExitedRegion; _rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion; _saveButton = FindViewById<Button> (Resource.Id.buttonSave); // wire up add beacon button handler if(_saveButton != null) { _saveButton.Click += (sender, e) => { if(_newBeaconDetected && _iBeacon == null) { Beacon beacon = new Beacon(_newBeaconDetected); beacon.Name = _textBeaconName.Text; beacon.Notes = _textBeaconDescription.Text; beacon.ID = Guid.NewGuid().ToString(); BeaconManager.SaveBeaconAsync(beacon); } else { Beacon beacon = new Beacon(_newBeaconDetected); beacon.Name = _textBeaconName.Text; beacon.Notes = _textBeaconDescription.Text; beacon.ID = _iBeacon.ProximityUuid; BeaconManager.SaveBeaconAsync(beacon); } }; } }