Ejemplo n.º 1
0
        private Dictionary <int, ImportGuideChannel> BuildImportGuideChannelDictionary(xtvdResponse response, string channelNameFormat)
        {
            // StationLCNs
            Dictionary <int, int> guideChannelsLcn = BuildGuideChannelLcnDictionary(response);

            Dictionary <int, ImportGuideChannel> guideChannels = new Dictionary <int, ImportGuideChannel>();

            foreach (stationsStation station in response.xtvd.stations)
            {
                if (!guideChannels.ContainsKey(station.id))
                {
                    ImportGuideChannel importGuideChannel = new ImportGuideChannel();
                    importGuideChannel.ExternalId = station.id.ToString();

                    string channelName = channelNameFormat.ToLowerInvariant();

                    channelName = channelName.Replace("{callsign}", station.callSign);
                    channelName = channelName.Replace("{name}", station.name);
                    channelName = channelName.Replace("{affiliate}", station.affiliate);
                    if (guideChannelsLcn.ContainsKey(station.id))
                    {
                        importGuideChannel.LogicalChannelNumber = guideChannelsLcn[station.id];
                        //string lcn3Digits = String.Format("{0:D3}", guideChannelsLcn[station.id]);
                        channelName = channelName.Replace("{logicalchannelnumber}", guideChannelsLcn[station.id].ToString());
                    }
                    else
                    {
                        channelName = channelName.Replace("{logicalchannelnumber}", String.Empty);
                    }
                    importGuideChannel.ChannelName = channelName;

                    guideChannels.Add(station.id, importGuideChannel);
                }
            }
            return(guideChannels);
        }
Ejemplo n.º 2
0
        private void Import(List <ImportGuideChannel> skipChannels,
                            ImportDataCallback importDataCallback,
                            ProgressCallback progressCallback,
                            FeedbackCallback feedbackCallback,
                            KeepImportServiceAliveCallback keepImportServiceAliveCallback,
                            string startDate, string endDate)
        {
            GiveFeedback(feedbackCallback, "Calling SchedulesDirect WebService ...");

            if (progressCallback != null)
            {
                progressCallback(0);
            }

            keepImportServiceAliveCallback();

            xtvdResponse response = CallSchedulesDirectWebService(startDate, endDate);

            if (response != null)
            {
                GiveFeedback(feedbackCallback, "Processing SchedulesDirect data ...");

                //DataDumper.DumpResponse(response, @"d:\steph\temp\response.txt");
                keepImportServiceAliveCallback();

                // Process results, create dictionaries for easier access

                // Stations
                Dictionary <int, ImportGuideChannel> guideChannels = BuildImportGuideChannelDictionary(response, ConfigInstance.Current.ChannelNameFormat);
                GuideChannelStore.Save(AvailableChannelsConfigFile, new List <ImportGuideChannel>(guideChannels.Values));

                // Programs
                Dictionary <string, Program> programs = BuildProgramsDictionary(response);

                // Add genres to programs
                AddGenresToPrograms(response, programs);

                // Add actors and directors to programs
                AddActorsAndDirectorsToPrograms(response, programs);

                // Start the real import :
                List <GuideProgram> guideData           = new List <GuideProgram>();
                ImportGuideChannel  currentGuideChannel = new ImportGuideChannel(String.Empty, String.Empty);
                int importedCount = 0;
                int procentDone   = 0;

                foreach (schedulesSchedule schedule in response.xtvd.schedules)
                {
                    if (guideChannels.ContainsKey(schedule.station) && !skipChannels.Contains(guideChannels[schedule.station]))
                    {
                        if (!currentGuideChannel.ExternalId.Equals(schedule.station.ToString()))
                        {
                            if (guideData.Count > 0)
                            {
                                GiveFeedback(feedbackCallback, String.Format("Importing channel {0}, {1} schedule(s).", currentGuideChannel.ChannelName, guideData.Count));

                                importDataCallback(currentGuideChannel, ChannelType.Television, guideData.ToArray(), ConfigInstance.Current.UpdateChannelNames);
                                guideData = new List <GuideProgram>();
                            }
                            currentGuideChannel = guideChannels[schedule.station];
                        }
                        if (programs.ContainsKey(schedule.program))
                        {
                            GuideProgram guideProgram = FillGuideProgram(schedule, programs[schedule.program]);
                            if (guideProgram != null)
                            {
                                guideData.Add(guideProgram);
                            }
                            else
                            {
                                Logger.Write(FormatForLogger("FillGuideProgram returned null for schedule program : " + schedule.program));
                            }
                        }
                        else
                        {
                            Logger.Write(FormatForLogger("FillGuideProgram : unknown schedule program : " + schedule.program));
                        }
                    }
                    importedCount++;

                    int currentProcentDone = ((100 * importedCount) / response.xtvd.schedules.Length);
                    if (currentProcentDone != procentDone)
                    {
                        procentDone = currentProcentDone;
                        if (progressCallback != null)
                        {
                            progressCallback(procentDone);
                        }
                        else if ((procentDone % 5) == 0)
                        {
                            Logger.Write(FormatForLogger(String.Format("Progress : {0} % done.", procentDone)));
                        }
                    }
                }
                if (guideData.Count > 0)
                {
                    importDataCallback(currentGuideChannel, ChannelType.Television, guideData.ToArray(), ConfigInstance.Current.UpdateChannelNames);
                }
            }
        }
        /// <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;
            }
        }
Ejemplo n.º 4
0
        public List<GuideProgram> GetGuideDataByClickFinderChannel(ImportGuideChannel clickFinderChannel)
        {            
            string sqlStatement = @"SELECT  Bezeichnung as Channel,
                                     Sendungen.Beginn as StartTime, 
                                     Sendungen.Ende as EndTime, 
                                     Sendungen.Titel as Title, 
                                     Sendungen.Originaltitel as SubTitle, 
                                     Sendungen.KurzBeschreibung as ShortDescription, 
                                     SendungenDetails.Beschreibung as Description, 
                                     Sendungen.Kategorietext, 
                                     Sendungen.Genre as Category, 
                                     Sendungen.KzWiederholung as IsRepeat, 
                                     Sendungen.Kz16zu9 as ImageFormat16to9,
                                     Sendungen.Kurzkritik as ShortCritic,
                                     Sendungen.Bewertungen as Rating,  
                                     Sendungen.Bewertung as StarRating, 
                                     Sendungen.Regie as Director, 
                                     SendungenDetails.Darsteller as Actors
                                    FROM Sender, Sendungen, SendungenDetails
                                    WHERE Sender.SenderKennung=Sendungen.SenderKennung AND Sendungen.Pos=SendungenDetails.Pos AND Sender.Bezeichnung ='{0}'  
                                     AND Sendungen.Ende>=Now() AND Sender.GueltigAb < Now() AND Sender.GueltigBis > Now() 
                                    ORDER BY Sender.Bezeichnung, Sendungen.Beginn, Sendungen.Ende";

            #region SQL without time filter
            /*
            string sqlStatement = @"SELECT  Bezeichnung as Channel,
                                     Sendungen.Beginn as StartTime, 
                                     Sendungen.Ende as EndTime, 
                                     Sendungen.Titel as Title, 
                                     Sendungen.Originaltitel as SubTitle, 
                                     Sendungen.KurzBeschreibung as ShortDescription, 
                                     SendungenDetails.Beschreibung as Description, 
                                     Sendungen.Kategorietext as Category, 
                                     Sendungen.Genre, 
                                     Sendungen.KzWiederholung as IsRepeat, 
                                     Sendungen.Kz16zu9 as ImageFormat16to9, 
                                     Sendungen.Kurzkritik as ShortCritic, 
                                     Sendungen.Bewertungen as Rating,  
                                     Sendungen.Bewertung as StarRating, 
                                     Sendungen.Regie as Director, 
                                     SendungenDetails.Darsteller as Actors
                                    FROM Sender, Sendungen, SendungenDetails
                                    WHERE Sender.SenderKennung=Sendungen.SenderKennung AND Sendungen.Pos=SendungenDetails.Pos AND Sender.Bezeichnung ='{0}'  
                                    ORDER BY Sender.Bezeichnung, Sendungen.Beginn, Sendungen.Ende";
            */
            #endregion

            sqlStatement = string.Format(sqlStatement, clickFinderChannel.ChannelName);
            
            List<GuideProgram> guideProgramList = new List<GuideProgram>();
            //try
            //{
                using (OleDbConnection dbConnection = new OleDbConnection(ConfigInstance.Current.ClickFinderConnectionString))
                {
                    dbConnection.Open();
                    using (OleDbCommand dbCommand = new OleDbCommand(sqlStatement, dbConnection))
                    {
                        using (OleDbDataReader dbReader = dbCommand.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                GuideProgram guideProgram = FillGuideProgram(dbReader);
                                if (guideProgram != null)
                                {
                                    guideProgramList.Add(guideProgram);
                                }
                            }
                        }
                    }
                }
            //}
            //catch { }

            return guideProgramList;
        }
Ejemplo n.º 5
0
        public List<ImportGuideChannel> GetAllImportChannels()
        {
            List<ImportGuideChannel> channelList = new List<ImportGuideChannel>();

            string sqlSelect = "SELECT Sender.Bezeichnung as channelName, Sender.ID as externalId FROM Sender ORDER BY Sender.Bezeichnung;";

            //try
            //{
                using (OleDbConnection dbConnection = new OleDbConnection(ConfigInstance.Current.ClickFinderConnectionString))
                {
                    dbConnection.Open();
                    using (OleDbCommand dbCommand = new OleDbCommand(sqlSelect, dbConnection))
                    {
                        OleDbDataReader dbReader = dbCommand.ExecuteReader();
                        while (dbReader.Read())
                        {
                            string channelName = dbReader["channelName"].ToString();
                            string externalId = dbReader["externalId"].ToString();
                            if(String.IsNullOrEmpty(externalId))
                            {
                                externalId = channelName;
                            }
                            ImportGuideChannel channel = new ImportGuideChannel(channelName, externalId);
                            channelList.Add(channel);
                        }
                    }
                }
            //}
            //catch {}

            return channelList;
        }
Ejemplo n.º 6
0
        private Guid EnsureDefaultChannel(ImportGuideChannel channel, ChannelType channelType, bool updateChannelName)
        {
            using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent())
            {
                using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent())
                {
                    Guid guideChannelId = guideServiceAgent.EnsureChannel(channel.ExternalId, channel.ChannelName, channelType);

                    // If we have exactly one channel, check LCN and DisplayName :
                    Channel[] channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                    if (channels.Length == 1 && updateChannelName)
                    {
                        bool needsToBeSaved = false;
                        if (channels[0].LogicalChannelNumber == null && channel.LogicalChannelNumber.HasValue)
                        {
                            channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                            needsToBeSaved = true;
                        }
                        if (channels[0].DisplayName != channel.ChannelName)
                        {
                            channels[0].DisplayName = channel.ChannelName;
                            needsToBeSaved = true;
                        }

                        if (needsToBeSaved)
                        {
                            schedulerServiceAgent.SaveChannel(channels[0]);
                        }
                    }
                    else if(channels.Length == 0)
                    {
                        // No channels linked to the GuideChannel. If we have an existing channel with the same name, then link it.
                        Channel existingChannel = schedulerServiceAgent.GetChannelByDisplayName(channelType, channel.ChannelName);
                        if (existingChannel != null)
                        {
                            existingChannel.LogicalChannelNumber = channel.LogicalChannelNumber;
                            schedulerServiceAgent.SaveChannel(existingChannel);
                        }
                        else
                        {
                            schedulerServiceAgent.EnsureDefaultChannel(guideChannelId, channelType, channel.ChannelName, null);
                            channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                            if (channels.Length == 1)
                            {
                                channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                                schedulerServiceAgent.SaveChannel(channels[0]);
                            }
                        }
                    }
                    return guideChannelId;
                }
            }
        }
Ejemplo n.º 7
0
 public void SaveGuideDataInArgusTV(ImportGuideChannel channel, ChannelType channelType, GuideProgram[] guideProgramData, bool updateChannelName )
 {
     if (guideProgramData.Length > 0)
     {
         using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent())
         {
             using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent())
             {
                 Guid guideChannelId = EnsureDefaultChannel(channel, channelType, updateChannelName);
                 foreach (GuideProgram guideProgram in guideProgramData)
                 {
                     guideProgram.GuideChannelId = guideChannelId;
                     try
                     {
                         guideServiceAgent.ImportProgram(guideProgram, GuideSource.XmlTv);
                     }
                     catch { }
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
        private void Import(List<ImportGuideChannel> skipChannels, 
                           ImportDataCallback importDataCallback, 
                           ProgressCallback progressCallback, 
                           FeedbackCallback feedbackCallback, 
                           KeepImportServiceAliveCallback keepImportServiceAliveCallback,
                           string startDate, string endDate )
        {
            GiveFeedback(feedbackCallback, "Calling SchedulesDirect WebService ...");

            if (progressCallback != null)
            {
                progressCallback(0);
            }

            keepImportServiceAliveCallback();

            xtvdResponse response = CallSchedulesDirectWebService(startDate, endDate);
            if (response != null)
            {
                GiveFeedback(feedbackCallback, "Processing SchedulesDirect data ...");

                //DataDumper.DumpResponse(response, @"d:\steph\temp\response.txt");
                keepImportServiceAliveCallback();

                // Process results, create dictionaries for easier access

                // Stations
                Dictionary<int, ImportGuideChannel> guideChannels = BuildImportGuideChannelDictionary(response, ConfigInstance.Current.ChannelNameFormat);
                GuideChannelStore.Save(AvailableChannelsConfigFile, new List<ImportGuideChannel>(guideChannels.Values));

                // Programs
                Dictionary<string, Program> programs = BuildProgramsDictionary(response);

                // Add genres to programs
                AddGenresToPrograms(response, programs);

                // Add actors and directors to programs
                AddActorsAndDirectorsToPrograms(response, programs);

                // Start the real import :
                List<GuideProgram> guideData = new List<GuideProgram>();
                ImportGuideChannel currentGuideChannel = new ImportGuideChannel(String.Empty, String.Empty);
                int importedCount = 0;
                int procentDone = 0;

                foreach (schedulesSchedule schedule in response.xtvd.schedules)
                {
                    if (guideChannels.ContainsKey(schedule.station) && !skipChannels.Contains(guideChannels[schedule.station]))
                    {
                        if (!currentGuideChannel.ExternalId.Equals(schedule.station.ToString()))
                        {
                            if (guideData.Count > 0)
                            {
                                GiveFeedback(feedbackCallback, String.Format("Importing channel {0}, {1} schedule(s).", currentGuideChannel.ChannelName, guideData.Count));

                                importDataCallback(currentGuideChannel, ChannelType.Television, guideData.ToArray(), ConfigInstance.Current.UpdateChannelNames);
                                guideData = new List<GuideProgram>();
                            }
                            currentGuideChannel = guideChannels[schedule.station];
                        }
                        if (programs.ContainsKey(schedule.program))
                        {
                            GuideProgram guideProgram = FillGuideProgram(schedule, programs[schedule.program]);
                            if (guideProgram != null)
                            {
                                guideData.Add(guideProgram);
                            }
                            else
                            {
                                Logger.Write(FormatForLogger("FillGuideProgram returned null for schedule program : " + schedule.program));
                            }
                        }
                        else
                        {
                            Logger.Write(FormatForLogger("FillGuideProgram : unknown schedule program : " + schedule.program));
                        }
                    }
                    importedCount++;

                    int currentProcentDone = ((100 * importedCount) / response.xtvd.schedules.Length);
                    if (currentProcentDone != procentDone)
                    {
                        procentDone = currentProcentDone;
                        if (progressCallback != null)
                        {
                            progressCallback(procentDone);
                        }
                        else if ((procentDone % 5) == 0)
                        {
                            Logger.Write(FormatForLogger(String.Format("Progress : {0} % done.", procentDone)));
                        }
                    }
                }
                if (guideData.Count > 0)
                {
                    importDataCallback(currentGuideChannel, ChannelType.Television, guideData.ToArray(), ConfigInstance.Current.UpdateChannelNames);
                }
            }
        }
Ejemplo n.º 9
0
        private Dictionary<int, ImportGuideChannel> BuildImportGuideChannelDictionary(xtvdResponse response, string channelNameFormat)
        {
            // StationLCNs
            Dictionary<int, int> guideChannelsLcn = BuildGuideChannelLcnDictionary(response);

            Dictionary<int, ImportGuideChannel> guideChannels = new Dictionary<int, ImportGuideChannel>();
            foreach (stationsStation station in response.xtvd.stations)
            {
                if (!guideChannels.ContainsKey(station.id))
                {
                    ImportGuideChannel importGuideChannel = new ImportGuideChannel();
                    importGuideChannel.ExternalId = station.id.ToString();

                    string channelName = channelNameFormat.ToLowerInvariant();

                    channelName = channelName.Replace("{callsign}", station.callSign);
                    channelName = channelName.Replace("{name}", station.name);
                    channelName = channelName.Replace("{affiliate}", station.affiliate);
                    if (guideChannelsLcn.ContainsKey(station.id))
                    {
                        importGuideChannel.LogicalChannelNumber = guideChannelsLcn[station.id];
                        //string lcn3Digits = String.Format("{0:D3}", guideChannelsLcn[station.id]);
                        channelName = channelName.Replace("{logicalchannelnumber}", guideChannelsLcn[station.id].ToString());
                    }
                    else
                    {
                        channelName = channelName.Replace("{logicalchannelnumber}", String.Empty);
                    }
                    importGuideChannel.ChannelName = channelName;

                    guideChannels.Add(station.id, importGuideChannel);
                }
            }
            return guideChannels;
        }
Ejemplo n.º 10
0
        public static List<ImportGuideChannel> makeImportChannels(LineupInfoResponse lir, string channelNameFormat)
        {
            List<ImportGuideChannel> ligc = new List<ImportGuideChannel>();
            Dictionary<string, ImportGuideChannel> migc = new Dictionary<string, ImportGuideChannel>();

            // make a real map from the map "array"
            //			Dictionary<string,string> channelMap = new Dictionary<string, string>();
            //			foreach (LineupInfoResponse.ChannelMap cm in lir.map) {
            //				if (!channelMap.ContainsKey(cm.stationID)) {
            //					if (lir.metadata.transport != null && lir.metadata.transport.ToLower().Equals("antenna")) {
            //						// Over the air channels have a uhfVhf channel and/or atscMajor/atsc minor
            //						//
            //						// example:
            //						// sometimes, uvfVhf is only present, sometimes just atsc stuff is present
            //						//{
            //						//		"stationID": "24504",
            //            			//		"uhfVhf": 9,
            //            			// 		"atscMajor": 9,
            //            			//		"atscMinor": 9
            //        				//},
            //
            //
            //        				if (cm.atscMinor != null && cm.atscMajor != null && cm.uhfVhf != null) {
            //        					// all three options are there
            //        					if (ConfigInstance.Current.AntennaUseUhfVhfChannel) {
            //        						channelMap.Add(cm.stationID, cm.uhfVhf);
            //	        				} else {
            //	        					channelMap.Add(cm.stationID, cm.atscMajor + "." + cm.atscMinor);
            //	        				}
            //        				} else if (cm.uhfVhf != null) {
            //    						channelMap.Add(cm.stationID, cm.uhfVhf);
            //        				} else if (cm.atscMinor != null && cm.atscMajor != null) {
            //        					channelMap.Add(cm.stationID, cm.atscMajor + "." + cm.atscMinor);
            //        				} else {
            //        					Logger.Info("There was a problem picking a Logical Channel Number for station ID: {0}", cm.stationID);
            //
            //        				}
            //					} else {
            //						channelMap.Add(cm.stationID, cm.channel);
            //					}
            //				}
            //			}

            Dictionary<string,string> channelMap = makeChannelMap(lir);

            foreach (LineupInfoResponse.Station station in lir.stations) {
                ImportGuideChannel igc = new ImportGuideChannel();
                igc.ExternalId = station.stationID;
                igc.ChannelName = makeChannelName(station, channelMap, channelNameFormat);
                if (!migc.ContainsKey(station.stationID)) {
                    migc.Add(station.stationID, igc);
                }
                string lcn = channelMap[station.stationID];
                if (lcn != null && lcn.Contains(".")) {
                    string[] lcnArray = lcn.Split('.');
                    igc.LogicalChannelNumber = Int32.Parse(lcnArray[0]);
                } else {
                    igc.LogicalChannelNumber = Int32.Parse(lcn);
                }
            }
            ligc.AddRange(migc.Values);
            return ligc;
        }
Ejemplo n.º 11
0
        public List <GuideProgram> GetGuideDataByClickFinderChannel(ImportGuideChannel clickFinderChannel)
        {
            string sqlStatement = @"SELECT  Bezeichnung as Channel,
                                     Sendungen.Beginn as StartTime, 
                                     Sendungen.Ende as EndTime, 
                                     Sendungen.Titel as Title, 
                                     Sendungen.Originaltitel as SubTitle, 
                                     Sendungen.KurzBeschreibung as ShortDescription, 
                                     SendungenDetails.Beschreibung as Description, 
                                     Sendungen.Kategorietext, 
                                     Sendungen.Genre as Category, 
                                     Sendungen.KzWiederholung as IsRepeat, 
                                     Sendungen.Kz16zu9 as ImageFormat16to9,
                                     Sendungen.Kurzkritik as ShortCritic,
                                     Sendungen.Bewertungen as Rating,  
                                     Sendungen.Bewertung as StarRating, 
                                     Sendungen.Regie as Director, 
                                     SendungenDetails.Darsteller as Actors
                                    FROM Sender, Sendungen, SendungenDetails
                                    WHERE Sender.SenderKennung=Sendungen.SenderKennung AND Sendungen.Pos=SendungenDetails.Pos AND Sender.Bezeichnung ='{0}'  
                                     AND Sendungen.Ende>=Now() AND Sender.GueltigAb < Now() AND Sender.GueltigBis > Now() 
                                    ORDER BY Sender.Bezeichnung, Sendungen.Beginn, Sendungen.Ende";

            #region SQL without time filter

            /*
             * string sqlStatement = @"SELECT  Bezeichnung as Channel,
             *                       Sendungen.Beginn as StartTime,
             *                       Sendungen.Ende as EndTime,
             *                       Sendungen.Titel as Title,
             *                       Sendungen.Originaltitel as SubTitle,
             *                       Sendungen.KurzBeschreibung as ShortDescription,
             *                       SendungenDetails.Beschreibung as Description,
             *                       Sendungen.Kategorietext as Category,
             *                       Sendungen.Genre,
             *                       Sendungen.KzWiederholung as IsRepeat,
             *                       Sendungen.Kz16zu9 as ImageFormat16to9,
             *                       Sendungen.Kurzkritik as ShortCritic,
             *                       Sendungen.Bewertungen as Rating,
             *                       Sendungen.Bewertung as StarRating,
             *                       Sendungen.Regie as Director,
             *                       SendungenDetails.Darsteller as Actors
             *                      FROM Sender, Sendungen, SendungenDetails
             *                      WHERE Sender.SenderKennung=Sendungen.SenderKennung AND Sendungen.Pos=SendungenDetails.Pos AND Sender.Bezeichnung ='{0}'
             *                      ORDER BY Sender.Bezeichnung, Sendungen.Beginn, Sendungen.Ende";
             */
            #endregion

            sqlStatement = string.Format(sqlStatement, clickFinderChannel.ChannelName);

            List <GuideProgram> guideProgramList = new List <GuideProgram>();
            //try
            //{
            using (OleDbConnection dbConnection = new OleDbConnection(ConfigInstance.Current.ClickFinderConnectionString))
            {
                dbConnection.Open();
                using (OleDbCommand dbCommand = new OleDbCommand(sqlStatement, dbConnection))
                {
                    using (OleDbDataReader dbReader = dbCommand.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            GuideProgram guideProgram = FillGuideProgram(dbReader);
                            if (guideProgram != null)
                            {
                                guideProgramList.Add(guideProgram);
                            }
                        }
                    }
                }
            }
            //}
            //catch { }

            return(guideProgramList);
        }
Ejemplo n.º 12
0
        private Guid EnsureDefaultChannel(ImportGuideChannel channel, ChannelType channelType, bool updateChannelName)
        {
            Guid guideChannelId = Proxies.GuideService.EnsureChannelExists(channel.ExternalId, channel.ChannelName, channelType).Result;

            // If we have exactly one channel, check LCN and DisplayName :
            var channels = Proxies.SchedulerService.GetChannelsForGuideChannel(guideChannelId).Result;
            if (channels.Count == 1 && updateChannelName)
            {
                bool needsToBeSaved = false;
                if (channels[0].LogicalChannelNumber == null && channel.LogicalChannelNumber.HasValue)
                {
                    channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                    needsToBeSaved = true;
                }
                if (channels[0].DisplayName != channel.ChannelName)
                {
                    channels[0].DisplayName = channel.ChannelName;
                    needsToBeSaved = true;
                }

                if (needsToBeSaved)
                {
                    Proxies.SchedulerService.SaveChannel(channels[0]).Wait();
                }
            }
            else if(channels.Count == 0)
            {
                // No channels linked to the GuideChannel. If we have an existing channel with the same name, then link it.   
                Channel existingChannel = Proxies.SchedulerService.GetChannelByDisplayName(channelType, channel.ChannelName).Result;
                if (existingChannel != null)
                {
                    existingChannel.LogicalChannelNumber = channel.LogicalChannelNumber;
                    Proxies.SchedulerService.SaveChannel(existingChannel).Wait();
                }
                else
                {
                    Proxies.SchedulerService.EnsureDefaultChannel(guideChannelId, channelType, channel.ChannelName, null).Wait();
                    channels = Proxies.SchedulerService.GetChannelsForGuideChannel(guideChannelId).Result;
                    if (channels.Count == 1)
                    {
                        channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                        Proxies.SchedulerService.SaveChannel(channels[0]).Wait();
                    }
                }
            }
            return guideChannelId;
        }
Ejemplo n.º 13
0
 public void SaveGuideDataInArgusTV(ImportGuideChannel channel, ChannelType channelType, GuideProgram[] guideProgramData, bool updateChannelName )
 {
     if (guideProgramData.Length > 0)
     {
         Guid guideChannelId = EnsureDefaultChannel(channel, channelType, updateChannelName);
         foreach (GuideProgram guideProgram in guideProgramData)
         {
             guideProgram.GuideChannelId = guideChannelId;
             try
             {
                 Proxies.GuideService.ImportProgram(guideProgram, GuideSource.XmlTv).Wait();
             }
             catch { }
         }
     }
 }
Ejemplo n.º 14
0
        public static List <ImportGuideChannel> makeImportChannels(LineupInfoResponse lir, string channelNameFormat)
        {
            List <ImportGuideChannel> ligc = new List <ImportGuideChannel>();
            Dictionary <string, ImportGuideChannel> migc = new Dictionary <string, ImportGuideChannel>();

            // make a real map from the map "array"
//			Dictionary<string,string> channelMap = new Dictionary<string, string>();
//			foreach (LineupInfoResponse.ChannelMap cm in lir.map) {
//				if (!channelMap.ContainsKey(cm.stationID)) {
//					if (lir.metadata.transport != null && lir.metadata.transport.ToLower().Equals("antenna")) {
//						// Over the air channels have a uhfVhf channel and/or atscMajor/atsc minor
//						//
//						// example:
//						// sometimes, uvfVhf is only present, sometimes just atsc stuff is present
//						//{
//						//		"stationID": "24504",
//                      //		"uhfVhf": 9,
//                      //      "atscMajor": 9,
//                      //		"atscMinor": 9
//                      //},
//
//
//                      if (cm.atscMinor != null && cm.atscMajor != null && cm.uhfVhf != null) {
//                          // all three options are there
//                          if (ConfigInstance.Current.AntennaUseUhfVhfChannel) {
//                              channelMap.Add(cm.stationID, cm.uhfVhf);
//	                        } else {
//	                            channelMap.Add(cm.stationID, cm.atscMajor + "." + cm.atscMinor);
//	                        }
//                      } else if (cm.uhfVhf != null) {
//                          channelMap.Add(cm.stationID, cm.uhfVhf);
//                      } else if (cm.atscMinor != null && cm.atscMajor != null) {
//                          channelMap.Add(cm.stationID, cm.atscMajor + "." + cm.atscMinor);
//                      } else {
//                          Logger.Info("There was a problem picking a Logical Channel Number for station ID: {0}", cm.stationID);
//
//                      }
//					} else {
//						channelMap.Add(cm.stationID, cm.channel);
//					}
//				}
//			}

            Dictionary <string, string> channelMap = makeChannelMap(lir);

            foreach (LineupInfoResponse.Station station in lir.stations)
            {
                ImportGuideChannel igc = new ImportGuideChannel();
                igc.ExternalId  = station.stationID;
                igc.ChannelName = makeChannelName(station, channelMap, channelNameFormat);
                if (!migc.ContainsKey(station.stationID))
                {
                    migc.Add(station.stationID, igc);
                }
                string lcn = channelMap[station.stationID];
                if (lcn != null && lcn.Contains("."))
                {
                    string[] lcnArray = lcn.Split('.');
                    igc.LogicalChannelNumber = Int32.Parse(lcnArray[0]);
                }
                else
                {
                    igc.LogicalChannelNumber = Int32.Parse(lcn);
                }
            }
            ligc.AddRange(migc.Values);
            return(ligc);
        }