public void TestAAGetAssignedLineups() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; List<AssignedLineupsResponse.Lineup> alr = wc.getAssignedLineups(tr); Assert.NotNull(alr); Assert.AreEqual(0, alr.Count); }
void getLogosClick(object sender, EventArgs e) { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(ConfigInstance.Current.SDUserName, ConfigInstance.Current.SDPassword); List<LineupInfoResponse> llir = wc.getAssignedLineupInfoList(tr); Dictionary<string, string> logoUrls = new Dictionary<string, string>(); foreach (LineupInfoResponse lir in llir) { // make a real map from the map "array" Dictionary<string,string> channelMap = ChannelFactory.makeChannelMap(lir); foreach (LineupInfoResponse.Station station in lir.stations) { if (station.logo != null && station.logo.URL != null) { string channelName = ChannelFactory.makeChannelName(station, channelMap, ConfigInstance.Current.ChannelNameFormat); if (!logoUrls.ContainsKey(channelName)) { logoUrls.Add(channelName,station.logo.URL); } } } } foreach (string channelName in logoUrls.Keys) { System.Net.WebClient httpWebClient = new System.Net.WebClient(); try { httpWebClient.DownloadFile( logoUrls[channelName], Path.Combine(this.logoPath.Text, channelName + ".png")); } catch (Exception ex) { Logger.Error("Could not download logo for channel {0}: {1}", channelName, ex.StackTrace); } } }
public void TestAddLineupDeleteLineup() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; AlterLineupsResponse alr = wc.addLineup(tr, "/20141201/lineups/CAN-0005410-X"); Assert.NotNull(alr); Assert.AreEqual(0, alr.code); List<AssignedLineupsResponse.Lineup> alrl = wc.getAssignedLineups(tr); Assert.NotNull(alrl); Assert.AreEqual(1, alrl.Count); // alr = wc.deleteLineup(tr, "/20141201/lineups/CAN-0005410-X"); // Assert.NotNull(alr); // // Assert.AreEqual(0, alr.code); }
public void TestAAAGetToken() { /// <summary> /// Called AAAGetToken so it gets run first. /// </summary> WebClient wc = WebClient.getInstance(); Assert.IsNull(wc.Token); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; string tok = wc.getToken(tr); Assert.IsNotNull(tok); string tok2 = wc.getToken(tr); Assert.AreEqual(tok, tok2); Logger.Info("Token worked"); }
public void TestGetHeadends() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; List<HeadendResponseInstance> headends = wc.getHeadends(tr, "CAN", "K1Z6R6"); Assert.NotNull(headends); foreach(var he in headends) { foreach(var lu in he.lineups) { // Logger.Info("This is a lineup: {0} - {1}", lu.name, lu.uri); System.Console.WriteLine("This is a lineup: {0} - {1}", lu.name, lu.uri); } } }
public void TestLineups() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; List<HeadendResponseInstance.Lineup> lus = wc.getLineupsFromHeadends(tr, "CAN", "K1Z6R6"); Assert.NotNull(lus); foreach(var lu in lus) { System.Console.WriteLine("This is a lineup: {0} - {1}", lu.name, lu.uri); } }
public void TestGetStatus() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; string tok = wc.getToken(tr); StatusResponse sr = wc.getStatus(tr); Assert.NotNull(sr); Assert.NotNull(sr.systemStatus[0]); Assert.AreEqual("Online", sr.systemStatus[0].status); }
public void TestGetSchedules() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; List<string> sil = new List<string>(); sil.Add("10116"); sil.Add("10127"); List<SchedulesResponse> sr = wc.getSchedules(tr,sil, 2); Assert.NotNull(sr); }
public void TestGetPrograms() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; List<string> programIds = new List<string>(); programIds.Add("EP011581290125"); programIds.Add("EP015084700066"); List<ProgramResponseInstance> lpri = wc.getPrograms(tr,programIds); Assert.NotNull(lpri); Assert.AreEqual(2, lpri.Count); }
public void TestGetLineupInfo() { WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(); tr.username = username; tr.password = password; LineupInfoResponse lir = wc.getLineupInfo(tr, "/20141201/lineups/CAN-0005410-X"); Assert.NotNull(lir); }
void SaveLineupsButtonClick(object sender, EventArgs e) { // this.saveButton.Enabled = false; // get currently assigned lineups WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(ConfigInstance.Current.SDUserName, ConfigInstance.Current.SDPassword); List<AssignedLineupsResponse.Lineup> assignedLineups = wc.getAssignedLineups(tr); List<string> lineupsToAssign = new List<string>(); List<string> lineupsToDelete = new List<string>(); // find lineups that were added foreach (object i in this.allLineupsList.SelectedItems) { LineupFactory.GuiLineup lu = (LineupFactory.GuiLineup)i; bool skipAdd = false; foreach (AssignedLineupsResponse.Lineup alu in assignedLineups) { if (alu.uri.Equals(lu.uri)) { skipAdd = true; break; } } if (!skipAdd) { lineupsToAssign.Add(lu.uri); } } // find lineups that were deleted foreach (AssignedLineupsResponse.Lineup alu in assignedLineups) { bool skipDelete = false; foreach (object i in this.allLineupsList.SelectedItems) { LineupFactory.GuiLineup lu = (LineupFactory.GuiLineup)i; if (lu.uri.Equals(alu.uri)) { // assigned lineup is still selected skipDelete = true; break; } } if (!skipDelete) { lineupsToDelete.Add(alu.uri); } } // add the lineups that need adding foreach (string uriToAdd in lineupsToAssign) { AlterLineupsResponse alr = wc.addLineup(tr, uriToAdd); this.addsLeftValueLabel.Text = alr.changesRemaining.ToString(); this.addsLeftValueLabel.Refresh(); } // delete the lineups that need deleting foreach (string uriToAdd in lineupsToDelete) { AlterLineupsResponse alr = wc.deleteLineup(tr, uriToAdd); this.addsLeftValueLabel.Text = alr.changesRemaining.ToString(); this.addsLeftValueLabel.Refresh(); } this.saveButton.Enabled = true; }
private void reloadLineupsButton_Click(Object sender, EventArgs e) { this.reloadLineupsButton.Enabled = false; saveButton_Click(sender, e); WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(ConfigInstance.Current.SDUserName, ConfigInstance.Current.SDPassword); // get all available lineups List<HeadendResponseInstance.Lineup> allLineups = wc.getLineupsFromHeadends(tr, ConfigInstance.Current.SDCountry, ConfigInstance.Current.SDPostalCode); this.allLineupsList.DataSource = new List<LineupFactory.GuiLineup>(); // get the assigned headends List<AssignedLineupsResponse.Lineup> assignedLineups = wc.getAssignedLineups(tr); List<LineupFactory.GuiLineup> allGuiLineups = LineupFactory.makeGuiLineupList(allLineups); List<LineupFactory.GuiLineup> assignedGuiLineups = LineupFactory.makeGuiLineupList(assignedLineups); this.allLineupsList.DataSource = allGuiLineups; this.allLineupsList.DisplayMember = "displayName"; this.allLineupsList.ValueMember = "uri"; // clear the default selected item allLineupsList.ClearSelected(); for (int i = 0; i < allLineupsList.Items.Count; i++) { foreach (LineupFactory.GuiLineup lu in assignedGuiLineups) { if (lu.uri.Equals(((LineupFactory.GuiLineup)allLineupsList.Items[i]).uri)) { this.allLineupsList.SetSelected(i,true); } } } this.reloadLineupsButton.Enabled = true; }
/// <summary> /// Do the actual guide update /// </summary> /// <param name="skipChannels"></param> /// <param name="importDataCallback"></param> /// <param name="progressCallback"></param> /// <param name="feedbackCallback"></param> /// <param name="keepImportServiceAliveCallback"></param> public void Import( List<ImportGuideChannel> skipChannels, ImportDataCallback importDataCallback, ProgressCallback progressCallback, FeedbackCallback feedbackCallback, KeepImportServiceAliveCallback keepImportServiceAliveCallback) { try { GiveFeedback(feedbackCallback,"Staring SD JSON guide data import..."); DateTime importStart = DateTime.Now; if (progressCallback != null) { progressCallback(0); } keepImportServiceAliveCallback(); // get station list List<string> stationIdList = getStationIdList(skipChannels); Logger.Info("Getting guide data for {0} channels", stationIdList.Count); WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(ConfigInstance.Current.SDUserName, ConfigInstance.Current.SDPassword); // make sure SD site is online StatusResponse status = wc.getStatus(tr); if (status != null && status.systemStatus != null) { string st = status.systemStatus[0].status.ToLower(); if (!"online".Equals(st)) { Logger.Error("The SD server is not online: {0} - {1) - {2}", status.serverID, status.systemStatus[0].status, status.systemStatus[0].details); throw new SystemException("The SD Server is not online. See log for details"); } } // get lineup info GiveFeedback(feedbackCallback, "Getting channel information..."); List<LineupInfoResponse> llir = wc.getAssignedLineupInfoList(tr); // map is keyed by stationId or externalId... the number that SD uses to identify the channel Dictionary<string,ImportGuideChannel> digc = ChannelFactory.makeImportChannelMap(llir, ConfigInstance.Current.ChannelNameFormat); // SD asks that no more than 5000 stations be queried at once // ignore this for now as not many will have 5000+ channels GiveFeedback(feedbackCallback, "Getting schedules..."); Logger.Info("Get schedules for {0} days", ConfigInstance.Current.NrOfDaysToImport); // lsr contains the schedules for a station for a single day List<SchedulesResponse> lsr = wc.getSchedules(tr, stationIdList, ConfigInstance.Current.NrOfDaysToImport); // combine all days' schedules into one entry for each station Dictionary<string, SchedulesResponse> srMap = new Dictionary<string, SchedulesResponse>(); // 1) Get all programs at once // make a global HashSet of program IDs and populate ScheduleResponse map HashSet<string> globalProgramSet = new HashSet<string>(); foreach (SchedulesResponse sr in lsr) { if (sr.programs != null) { // make list of program IDs to get foreach (SchedulesResponse.Program pg in sr.programs) { // we only get a programID once, even if it's on multiple schedules globalProgramSet.Add(pg.programID); } // populate map of schedule responses if (srMap.ContainsKey(sr.stationID)) { srMap[sr.stationID].programs.AddRange(sr.programs); } else { srMap.Add(sr.stationID, sr); } } } Logger.Info("There are {0} programs in this timeframe", globalProgramSet.Count); // take the programs in chunks of _programBlockSize... value below 5000 // SD won't allow a query of more than 5000 programs at once int progLoops = globalProgramSet.Count / _programBlockSize; int progsInFinalLoop = globalProgramSet.Count % _programBlockSize; if (progsInFinalLoop > 0) { progLoops++; } // this map will contain *all* program responses across all stations Dictionary<string,ProgramResponseInstance> globalProgramResponseMap = new Dictionary<string, ProgramResponseInstance>(); // keep a list for navigating in for loop List<string> globalProgramList = new List<string>(); globalProgramList.AddRange(globalProgramSet); GiveFeedback(feedbackCallback,"About to get program information for all programs..."); for (int i = 0; i < progLoops; i++) { // is this the last loop? int blockSize = _programBlockSize; if (i == progLoops - 1) { blockSize = progsInFinalLoop; } string message = string.Format("Getting program information for items {0} to {1}", i * _programBlockSize + 1, (i * _programBlockSize) + blockSize); GiveFeedback(feedbackCallback, message); List<string> programSubset = globalProgramList.GetRange(i * _programBlockSize, blockSize); List<ProgramResponseInstance> lpri = wc.getPrograms(tr, programSubset); if (lpri != null) { foreach (ProgramResponseInstance pri in lpri) { globalProgramResponseMap.Add(pri.programID, pri); } } } // tackle each station at a time... int count = 1; foreach (SchedulesResponse sr in srMap.Values) { keepImportServiceAliveCallback(); List<GuideProgram> lgp = new List<GuideProgram>(); try { // take the schedules and programs and create the guide programs to put into Argus // in a try block to catch issues with programfactory lgp = ProgramFactory.makeGuidePrograms(globalProgramResponseMap, sr); } catch (Exception ex) { Logger.Error("Could not extract program information: {0}", ex.StackTrace); throw; } ImportGuideChannel currentGuideChannel = digc[sr.stationID]; double percentDone = 100 * ((double)count/srMap.Values.Count); int percentInt = Convert.ToInt32(percentDone); if (progressCallback != null) { progressCallback(percentInt); } string programMessage = string.Format("Processing station: {0}, ID: {1}, Program Count: {2}, {3} done", digc[sr.stationID].ChannelName, sr.stationID, sr.programs.Count, string.Format("{0}%",percentInt)); GiveFeedback(feedbackCallback, programMessage); // save the programs in the Argus db importDataCallback( currentGuideChannel, ChannelType.Television, lgp.ToArray(), ConfigInstance.Current.UpdateChannelNames); count++; } DateTime endTime = DateTime.Now; TimeSpan ts = endTime.Subtract(importStart); int seconds = ts.Seconds; int minutes = ts.Minutes; int hours = ts.Hours; Logger.Info("Import complete. Took {0} hours, {1} minutes and {2} seconds", hours, minutes, seconds); Logger.Info("Channels processed: {0}", srMap.Values.Count); GiveFeedback(feedbackCallback,"Completed SD JSON guide data import."); } catch (Exception ex) { Logger.Error("There was an error importing the guide data: {0}/n{1}", ex.Message, ex.StackTrace); throw; } }
/// <summary> /// Return a list of channels for the GUI to display /// </summary> /// <param name="reload"></param> /// <param name="progressCallback"></param> /// <param name="feedbackCallback"></param> /// <returns></returns> public List<ImportGuideChannel> GetAllImportChannels( bool reload, ProgressCallback progressCallback, FeedbackCallback feedbackCallback) { List<ImportGuideChannel> ligc = new List<ImportGuideChannel>(); if (reload) { try { GiveFeedback(feedbackCallback, "Calling SchedulesDirect JSON WebService ..."); WebClient wc = WebClient.getInstance(); TokenRequest tr = new TokenRequest(ConfigInstance.Current.SDUserName, ConfigInstance.Current.SDPassword); List<AssignedLineupsResponse.Lineup> lineups = wc.getAssignedLineups(tr); GiveFeedback(feedbackCallback, "Got the lineups.... " + lineups.Count + " lineup assigned"); foreach (AssignedLineupsResponse.Lineup lu in lineups) { GiveFeedback(feedbackCallback, "Get channels for " + lu.name); LineupInfoResponse liur = wc.getLineupInfo(tr, lu.uri); GiveFeedback(feedbackCallback, "Got a bunch of channels: " + liur.stations.Count); List<ImportGuideChannel> localLigc = ChannelFactory.makeImportChannels(liur, ConfigInstance.Current.ChannelNameFormat); ligc.AddRange(localLigc); } GuideChannelStore.Save(AvailableChannelsConfigFile, ligc); } catch (Exception ex) { Logger.Error("Had a problem importing channels: {0}\n{1}", ex.Message, ex.StackTrace); throw; } } else { // read from file List<ImportGuideChannel> availableGuideChannels = GuideChannelStore.Load(AvailableChannelsConfigFile); ligc.AddRange(availableGuideChannels); } return ligc; }