void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { try { StreamReader reader = new StreamReader(e.Result); List <string> slist = new List <string>(); while (!reader.EndOfStream) { slist.Add(reader.ReadLine()); } e.Result.Close(); reader.Close(); List <LabInfo> TempLabInfos = new List <LabInfo>(); foreach (string s in slist) { string[] delim = new string[] { "<TD>" }; if (s.Trim().StartsWith("<TD>")) { List <String> split = new List <String>(s.Trim().Split(delim, StringSplitOptions.RemoveEmptyEntries)); split.RemoveAll(x => x == ""); LabInfo i = new LabInfo(); i.Name = split[0]; i.Available = split[1]; i.Busy = split[2]; i.Total = split[3]; i.Percent = split[4]; i.Time = split[5]; TempLabInfos.Add(i); } } TempLabInfos = TempLabInfos.OrderBy(x => float.Parse(x.Percent)).ToList <LabInfo>(); List <LabDetailControl> LabDetails = new List <LabDetailControl>(); foreach (LabInfo i in TempLabInfos) { LabDetailControl ld = new LabDetailControl(); ld.LabName.Text = i.Name; ld.Detail.Text = "Usage: " + i.Busy + "/" + i.Total + " (" + i.Percent + "%)"; if (float.Parse(i.Percent) > 80) { ld.Background = new SolidColorBrush(Colors.Red); } LabDetails.Add(ld); } LabList.ItemsSource = LabDetails; LastUpdated.Text = "Last update: " + TempLabInfos[0].Time; } catch { UpdateError(); } }
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { try { StreamReader reader = new StreamReader(e.Result); List<string> slist = new List<string>(); while (!reader.EndOfStream) slist.Add(reader.ReadLine()); e.Result.Close(); reader.Close(); List<LabInfo> TempLabInfos = new List<LabInfo>(); foreach (string s in slist) { string[] delim = new string[] { "<TD>" }; if (s.Trim().StartsWith("<TD>")) { List<String> split = new List<String>(s.Trim().Split(delim, StringSplitOptions.RemoveEmptyEntries)); split.RemoveAll(x => x == ""); LabInfo i = new LabInfo(); i.Name = split[0]; i.Available = split[1]; i.Busy = split[2]; i.Total = split[3]; i.Percent = split[4]; i.Time = split[5]; TempLabInfos.Add(i); } } TempLabInfos = TempLabInfos.OrderBy(x => float.Parse(x.Percent)).ToList<LabInfo>(); List<LabDetailControl> LabDetails = new List<LabDetailControl>(); foreach (LabInfo i in TempLabInfos) { LabDetailControl ld = new LabDetailControl(); ld.LabName.Text = i.Name; ld.Detail.Text = "Usage: " + i.Busy + "/" + i.Total + " (" + i.Percent + "%)"; if (float.Parse(i.Percent) > 80) { ld.Background = new SolidColorBrush(Colors.Red); } LabDetails.Add(ld); } LabList.ItemsSource = LabDetails; LastUpdated.Text = "Last update: " + TempLabInfos[0].Time; } catch { UpdateError(); } }