public static List<scheduleItem> loadSchedule() { CultureInfo culture = new CultureInfo("en-GB"); List<scheduleItem> schedule = new List<scheduleItem>(); XmlDocument scheduleFile = new XmlDocument(); scheduleFile.Load("schedule.xml"); XmlNodeList programs = scheduleFile.SelectNodes("//program"); for (int i=0; i<programs.Count; i++) { scheduleItem tmpProg = new scheduleItem(); XmlAttribute starttimeAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("starttime"); XmlAttribute endtimeAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("endtime"); XmlAttribute sourceAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("source"); XmlAttribute urlAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("url"); tmpProg.starttime = DateTime.Parse(starttimeAttribute.Value, culture); tmpProg.endtime = DateTime.Parse(endtimeAttribute.Value,culture); switch (sourceAttribute.Value) { case "irn": tmpProg.source = RemoteSources.irn; break; case "ob": tmpProg.source = RemoteSources.ob; break; case "sam": tmpProg.source = RemoteSources.sam; break; case "studio": tmpProg.source = RemoteSources.studio; break; } tmpProg.title = programs[i].InnerText; if (urlAttribute != null) { tmpProg.url = urlAttribute.Value; } schedule.Add(tmpProg); } return schedule; }
public static List <scheduleItem> loadSchedule() { CultureInfo culture = new CultureInfo("en-GB"); List <scheduleItem> schedule = new List <scheduleItem>(); XmlDocument scheduleFile = new XmlDocument(); scheduleFile.Load("schedule.xml"); XmlNodeList programs = scheduleFile.SelectNodes("//program"); for (int i = 0; i < programs.Count; i++) { scheduleItem tmpProg = new scheduleItem(); XmlAttribute starttimeAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("starttime"); XmlAttribute endtimeAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("endtime"); XmlAttribute sourceAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("source"); XmlAttribute urlAttribute = (XmlAttribute)programs[i].Attributes.GetNamedItem("url"); tmpProg.starttime = DateTime.Parse(starttimeAttribute.Value, culture); tmpProg.endtime = DateTime.Parse(endtimeAttribute.Value, culture); switch (sourceAttribute.Value) { case "irn": tmpProg.source = RemoteSources.irn; break; case "ob": tmpProg.source = RemoteSources.ob; break; case "sam": tmpProg.source = RemoteSources.sam; break; case "studio": tmpProg.source = RemoteSources.studio; break; } tmpProg.title = programs[i].InnerText; if (urlAttribute != null) { tmpProg.url = urlAttribute.Value; } schedule.Add(tmpProg); } return(schedule); }
public void Calculate() { if (validate()) { Curr_Amount = _curr_Amount; Curr_Period = _curr_Period; Curr_InterestRate = _curr_InterestRate; Curr_MonthlyPayment = Math.Round(LoanFunctions.Get_PMT(_curr_InterestRate / 12 / 100.0, _curr_Period, _curr_Amount), 3); Curr_Schedule = LoanFunctions.calculate_schedule_Declining(_curr_InterestRate / 12 / 100.0, _curr_Period, _curr_Amount, Curr_MonthlyPayment); Curr_Stat = LoanFunctions.calculate_stat(Curr_Schedule); } else { Curr_Amount = _curr_Amount; Curr_Period = _curr_Period; Curr_InterestRate = _curr_InterestRate; } StateHasChanged(); }
private void checkSchedule(DateTime studioTime) { for (int i = 0; i < schedule.Count; i++) { scheduleItem thisProgramme = schedule[i]; if ((studioTime < thisProgramme.endtime) && (studioTime >= thisProgramme.starttime)) { switchRemote(thisProgramme.source); TimeSpan leaseRemainCalc = studioTime.Subtract(thisProgramme.endtime); if (leaseRemainCalc.TotalSeconds > 0) { // The programme has already finished! leaseRemainCalc = new TimeSpan(0, 0, 0); } int leaseRemaining = Convert.ToInt32(Math.Floor(leaseRemainCalc.TotalSeconds)); int leaseRemainingUnsigned = (leaseRemaining - leaseRemaining - leaseRemaining); lease.Text = leaseRemainCalc.ToString(@"hh\:mm\:ss\.f"); TimeSpan progDuration = thisProgramme.endtime.Subtract(thisProgramme.starttime); // The (leaseRemaining-leaseRemaining-leaseRemaining) ensures the negative number of secs ends up positive int progDurationSecs = Convert.ToInt32(Math.Floor(progDuration.TotalSeconds)); decimal percentRemaining = Convert.ToDecimal(leaseRemainingUnsigned) / Convert.ToDecimal(progDurationSecs); progressBar.Value = Convert.ToInt32(100 - percentRemaining * 100); if (leaseRemaining > -300 && thisProgramme.source == RemoteSources.ob) { lease.ForeColor = Color.DarkRed; } else { lease.ForeColor = Color.SlateGray; } progNow.Text = System.Net.WebUtility.HtmlDecode(thisProgramme.title); untilLabel.Text = thisProgramme.endtime.ToString("HH:mm:ss"); if ((i + 1) < schedule.Count) { progNext.Text = System.Net.WebUtility.HtmlDecode(schedule[(i + 1)].title); progNext.ForeColor = Color.Black; if (leaseRemaining > -120 && schedule[(i + 1)].source == RemoteSources.ob) { lease.ForeColor = Color.ForestGreen; } } else { progNext.Text = "Unknown programme (not in schedule)"; progNext.ForeColor = Color.Red; } if (thisProgramme.url != null && thisProgramme.url.Length > 1 && thisProgramme.urlSent == false) { using (var wb = new WebClient()) { try { wb.DownloadStringAsync(new Uri(thisProgramme.url)); } catch (WebException) { // Do nothing } schedule[i].urlSent = true; } } } } }