private void Enable_Changed(object sender, RoutedEventArgs e) { for (int i = 0; i < m_models.Length; i++) { BossModel model = m_models[i]; if (model.enableCheck == sender) { model.enable = model.enableCheck.IsChecked.Value; } } }
private void Window_Closed(object sender, EventArgs e) { for (int i = 0; i < m_models.Length; i++) { BossModel model = m_models[i]; model.running = false; if (model.thread != null) { model.thread.Join(); } model.thread = null; } }
private void UpdateModel(BossModel model) { HttpWebRequest request; String text; BossJson json; DateTime now; double max; try { request = (HttpWebRequest)WebRequest.Create(model.url); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { text = reader.ReadToEnd(); } } } catch (WebException) { return; } json = JsonConvert.DeserializeObject <BossJson>(text); // name model.name = json.boss_name; // guess year now = DateTime.Now; max = double.MaxValue; for (int i = 0; i < 3; i++) { DateTime t = DateTime.Parse(string.Format("{0}-{1} {2}", now.Year + i - 1, json.pre_day, json.pre_hm)); double d = Math.Abs((t - now).TotalSeconds); if (d < max) { max = d; model.time1 = t; } } model.time2 = model.time1 + model.span1; model.time3 = model.time1 + model.span2; }
private void UpdateUI(BossModel model) { if (model.enable) { model.timeText1.Text = model.time1.ToString(@"HH\:mm"); model.timeText2.Text = model.time2.ToString(@"HH\:mm") + " - " + model.time3.ToString(@"HH\:mm"); model.remText.Text = model.rem.ToString(@"mm\:ss"); } else { model.timeText1.Text = string.Empty; model.timeText2.Text = string.Empty; model.remText.Text = string.Empty; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { m_models = new BossModel[] { new BossModel { url = "http://bd.youxidudu.com/tools/clock/clock_boss_time.php?cid=200", group = GroupA, timeText1 = TimeA1, timeText2 = TimeA2, remText = RemA, enableCheck = EnableA, span1 = TimeSpan.FromHours(8), span2 = TimeSpan.FromHours(12), enable = EnableA.IsChecked.Value, }, new BossModel { url = "http://bd.youxidudu.com/tools/clock/clock_boss_time.php?cid=250", group = GroupB, timeText1 = TimeB1, timeText2 = TimeB2, remText = RemB, enableCheck = EnableB, span1 = TimeSpan.FromHours(9), span2 = TimeSpan.FromHours(13), enable = EnableB.IsChecked.Value, }, new BossModel { url = "http://bd.youxidudu.com/tools/clock/clock_boss_time.php?cid=251", group = GroupC, timeText1 = TimeC1, timeText2 = TimeC2, remText = RemC, enableCheck = EnableC, span1 = TimeSpan.FromHours(14), span2 = TimeSpan.FromHours(18), enable = EnableC.IsChecked.Value, }, new BossModel { url = "http://bd.youxidudu.com/tools/clock/clock_boss_time.php?cid=252", group = GroupD, timeText1 = TimeD1, timeText2 = TimeD2, remText = RemD, enableCheck = EnableD, span1 = TimeSpan.FromHours(8), span2 = TimeSpan.FromHours(12), enable = EnableD.IsChecked.Value, } }; m_hwnd = new WindowInteropHelper(this).Handle; m_title = Title; for (int i = 0; i < m_models.Length; i++) { BossModel model = m_models[i]; model.running = true; model.thread = new Thread(new ParameterizedThreadStart(Worker)); model.thread.Start(model); } }