void IBurritoDayView.SetState(BurritoDayState state, string description) { var name = "Images/" + state.ToString().ToLower() + ".png"; var image = UIImage.FromFile(name) ?? UIImage.FromFile("Images/no.png"); this.image.Image = image; this.label.Text = description; }
void IBurritoDayView.SetState(BurritoDayState state, string description) { if (this.si == null) { return; } var name = state.ToString().ToLower(); var path = NSBundle.MainBundle.PathForResource(name, "png") ?? NSBundle.MainBundle.PathForResource("no", "png"); this.si.Image = new NSImage(path); this.si.ToolTip = description; }
private void PollLocation() { if (this.state == BurritoDayState.Arrived) { return; } var new_state = BurritoDayState.Yes; var data = this.client.Download(this.latitude_uri); double latitude, longitude; if (BurritoDayModel.TryParseLocation(data, out latitude, out longitude)) { var uri = new Uri(this.distance_api + latitude + "," + longitude); data = this.client.Download(uri); bool success; lock (this.sync) { success = BurritoDayModel.TryParseDistance(data, out this.location, out this.duration, out this.meters); } if (success) { if (meters >= this.destination_threshold && meters <= this.origin_threshold) { new_state = BurritoDayState.Transit; this.StartLocationPolling(TimeSpan.FromMinutes(2)); } else if (this.state == BurritoDayState.Transit && meters <= this.destination_threshold) { new_state = BurritoDayState.Arrived; this.StopLocationPolling(); // force a transition out of the Arrived state // around midnight in case of back to back // burrito days. a delicious special case. this.fiber.Schedule(() => { this.state = BurritoDayState.Unknown; this.PollState(); }, (long)TimeSpan.FromHours(12).TotalMilliseconds); } } } this.State = new_state; }
private void PollState() { var data = this.client.Download(this.burrito_day_uri); BurritoDayState new_state; if (!BurritoDayModel.TryParseState(data, out new_state)) { this.State = BurritoDayState.Unknown; } else if (new_state != BurritoDayState.Yes) { this.StopLocationPolling(); this.State = new_state; } else { this.StartLocationPolling(TimeSpan.FromMinutes(10)); } }
private static bool TryParseState(string data, out BurritoDayState state) { var doc = new HtmlDocument(); doc.LoadHtml(data ?? String.Empty); var node = doc.DocumentNode.SelectSingleNode("//div[@id='hooray']") ?? doc.DocumentNode.SelectSingleNode("//div[@id='answer']"); if (node != null && !String.IsNullOrEmpty(node.InnerText)) { var text = node.InnerText.ToLower(); foreach (var pair in BurritoDayModel.StateKeywords) { if (text.Contains(pair.Key)) { state = pair.Value; return true; } } } state = default(BurritoDayState); return false; }