Exemple #1
0
 private static void WriteGenres(xtvdResponse response, string filename)
 {
     Debug.WriteLine(String.Format("Writing genres to : {0}", filename));
     File.Delete(filename);
     using (StreamWriter sw = new StreamWriter(filename))
     {
         sw.WriteLine("Program;GenreClass;GenreRelevance");
         try
         {
             foreach (genresProgramGenre genresProgramGenre in response.xtvd.genres)
             {
                 genresProgramGenreGenre[] genreGenres = genresProgramGenre.genre;
                 foreach (genresProgramGenreGenre genresProgramGenreGenre in genreGenres)
                 {
                     sw.WriteLine(String.Format("{0};{1};{2}",
                                                String.IsNullOrEmpty(genresProgramGenre.program) ? "-" : genresProgramGenre.program,
                                                String.IsNullOrEmpty(genresProgramGenreGenre.@class) ? "-" : genresProgramGenreGenre.@class,
                                                genresProgramGenreGenre.relevance));
                 }
             }
         }
         catch (Exception ex)
         {
             Debug.WriteLine(String.Format("An exception occured : {0}", ex.Message));
         }
     }
     Debug.WriteLine("Done writing genres");
 }
Exemple #2
0
        private void AddActorsAndDirectorsToPrograms(xtvdResponse response, Dictionary <string, Program> programs)
        {
            foreach (productionCrewCrew productionCrew in response.xtvd.productionCrew)
            {
                if (programs.ContainsKey(productionCrew.program))
                {
                    try
                    {
                        foreach (crewMember crewMember in productionCrew.member)
                        {
                            if (String.IsNullOrEmpty(crewMember.role))
                            {
                                continue;
                            }

                            if (crewMember.role.Equals("Actor", StringComparison.InvariantCultureIgnoreCase))
                            {
                                string actorName = String.Format("{0} {1}", crewMember.givenname, crewMember.surname);
                                programs[productionCrew.program].AddActor(actorName.Trim());
                            }
                            else if (crewMember.role.Equals("Director", StringComparison.InvariantCultureIgnoreCase))
                            {
                                string directorName = String.Format("{0} {1}", crewMember.givenname, crewMember.surname);
                                programs[productionCrew.program].AddDirector(directorName.Trim());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Write(FormatForLogger(String.Format("Exception in AddActorsAndDirectorsToPrograms, message : {0} .", ex.Message)));
                    }
                }
            }
        }
Exemple #3
0
 private static void WriteStations(xtvdResponse response, string filename)
 {
     Debug.WriteLine(String.Format("Writing stations to : {0}", filename));
     File.Delete(filename);
     using (StreamWriter sw = new StreamWriter(filename))
     {
         sw.WriteLine("Id;Name;FccChanNbr;CallSign;Affiliate");
         try
         {
             foreach (stationsStation station in response.xtvd.stations)
             {
                 sw.WriteLine(String.Format("{0};{1};{2};{3};{4}",
                                            station.id,
                                            String.IsNullOrEmpty(station.name) ? "-" : station.name,
                                            String.IsNullOrEmpty(station.fccChannelNumber) ? "-" : station.fccChannelNumber,
                                            String.IsNullOrEmpty(station.callSign) ? "-" : station.callSign,
                                            String.IsNullOrEmpty(station.affiliate) ? "-" : station.affiliate));
             }
         }
         catch (Exception ex)
         {
             Debug.WriteLine(String.Format("An exception occured : {0}", ex.Message));
         }
     }
     Debug.WriteLine("Done writing stations");
 }
Exemple #4
0
        public static void DumpResponse(xtvdResponse response, string fileName)
        {
            string fileNamePrefix = fileName.Substring(0, fileName.LastIndexOf('.'));
            string fileExtension  = Path.GetExtension(fileName);

            WritePrograms(response, String.Format("{0}{1}.{2}", fileNamePrefix, "_programs", fileExtension));
            WriteSchedules(response, String.Format("{0}{1}.{2}", fileNamePrefix, "_schedules", fileExtension));
            WriteStations(response, String.Format("{0}{1}.{2}", fileNamePrefix, "_stations", fileExtension));
            WriteGenres(response, String.Format("{0}{1}.{2}", fileNamePrefix, "_genres", fileExtension));
            WriteLineUps(response, String.Format("{0}{1}.{2}", fileNamePrefix, "_lineups", fileExtension));
        }
Exemple #5
0
        private Dictionary <string, Program> BuildProgramsDictionary(xtvdResponse response)
        {
            Dictionary <string, Program> programs = new Dictionary <string, Program>();

            foreach (programsProgram program in response.xtvd.programs)
            {
                if (!programs.ContainsKey(program.id))
                {
                    programs.Add(program.id, new Program(program));
                }
            }
            return(programs);
        }
Exemple #6
0
 private static void WriteSchedules(xtvdResponse response, string filename)
 {
     Debug.WriteLine(String.Format("Writing schedules to : {0}", filename));
     File.Delete(filename);
     using (StreamWriter sw = new StreamWriter(filename))
     {
         sw.WriteLine("Program;Station;CloseCaptionedSpecified;CloseCaptioned;DolbySpecified;Dolby;Duration;EiSpecified;Ei;HDTVSpecified;HDTV;NewSpecified;New;Part;RepeatSpecified;Repeat;StereoSpecified;Stereo;SubtitledSpecified;Subtitled;TvRatingSpecified;TvRating;Time");
         try
         {
             foreach (schedulesSchedule schedulesSchedule in response.xtvd.schedules)
             {
                 sw.WriteLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12};{13};{14};{15};{16};{17};{18};{19};{20};{21};{22}",
                                            String.IsNullOrEmpty(schedulesSchedule.program) ? "-" : schedulesSchedule.program,
                                            schedulesSchedule.station,
                                            schedulesSchedule.closeCaptionedSpecified.ToString(),
                                            schedulesSchedule.closeCaptioned.ToString(),
                                            schedulesSchedule.dolbySpecified.ToString(),
                                            schedulesSchedule.dolby.ToString(),
                                            String.IsNullOrEmpty(schedulesSchedule.duration) ? "-" : schedulesSchedule.duration,
                                            schedulesSchedule.eiSpecified.ToString(),
                                            schedulesSchedule.ei.ToString(),
                                            schedulesSchedule.hdtvSpecified.ToString(),
                                            schedulesSchedule.hdtv.ToString(),
                                            schedulesSchedule.newSpecified.ToString(),
                                            [email protected](),
                                            schedulesSchedule.part != null ? schedulesSchedule.part.number.ToString() + "/" + schedulesSchedule.part.total.ToString() : "-",
                                            schedulesSchedule.repeatSpecified.ToString(),
                                            schedulesSchedule.repeat.ToString(),
                                            schedulesSchedule.stereoSpecified.ToString(),
                                            schedulesSchedule.stereo.ToString(),
                                            schedulesSchedule.subtitledSpecified.ToString(),
                                            schedulesSchedule.subtitled.ToString(),
                                            schedulesSchedule.tvRatingSpecified.ToString(),
                                            schedulesSchedule.tvRating.ToString(),
                                            schedulesSchedule.time.ToLocalTime()));
             }
         }
         catch (Exception ex)
         {
             Debug.WriteLine(String.Format("An exception occured : {0}", ex.Message));
         }
     }
     Debug.WriteLine("Done writing schedules");
 }
Exemple #7
0
        public List <ImportGuideChannel> GetAllImportChannels(bool reload, ProgressCallback progressCallback, FeedbackCallback feedbackCallback)
        {
            if (reload)
            {
                GiveFeedback(feedbackCallback, "Calling SchedulesDirect WebService ...");
                xtvdResponse response = CallSchedulesDirectWebService(ConvertStartDateTimeToString(DateTime.Now), ConvertEndDateTimeToString(DateTime.Now));
                if (response != null)
                {
                    GiveFeedback(feedbackCallback, "Processing retrieved SchedulesDirect channels ...");

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

            List <ImportGuideChannel> availableGuideChannels = GuideChannelStore.Load(AvailableChannelsConfigFile);

            return(availableGuideChannels);
        }
Exemple #8
0
        private void AddGenresToPrograms(xtvdResponse response, Dictionary <string, Program> programs)
        {
            foreach (genresProgramGenre genresProgramGenre in response.xtvd.genres)
            {
                if (programs.ContainsKey(genresProgramGenre.program))
                {
                    genresProgramGenreGenre[] programGenres = genresProgramGenre.genre;
                    int highestRelevance = -1;

                    for (int i = programGenres.Length - 1; i >= 0; i--)
                    {
                        if (programGenres[i].relevance > highestRelevance && !String.IsNullOrEmpty(programGenres[i].@class))
                        {
                            highestRelevance = programGenres[i].relevance;
                            programs[genresProgramGenre.program].Genre = programGenres[i].@class;
                        }
                    }
                }
            }
        }
Exemple #9
0
        private Dictionary <int, int> BuildGuideChannelLcnDictionary(xtvdResponse response)
        {
            Dictionary <int, int> guideChannelLcns = new Dictionary <int, int>();

            foreach (lineupsLineup lineUps in response.xtvd.lineups)
            {
                foreach (lineupsLineupMap lineUpMap in lineUps.map)
                {
                    if (!guideChannelLcns.ContainsKey(lineUpMap.station))
                    {
                        int lcn;
                        if (int.TryParse(lineUpMap.channel, out lcn))
                        {
                            guideChannelLcns.Add(lineUpMap.station, lcn);
                        }
                    }
                }
            }
            return(guideChannelLcns);
        }
Exemple #10
0
        private static void WriteLineUps(xtvdResponse response, string filename)
        {
            Debug.WriteLine("LineUps :");
            File.Delete(filename);
            using (StreamWriter sw = new StreamWriter(filename))
            {
                sw.WriteLine("Id;Name;UserLineupName;Location;Type;Device;PostalCode");
                try
                {
                    foreach (lineupsLineup lineupsLineup in response.xtvd.lineups)
                    {
                        sw.WriteLine(String.Format("{0};{1}",
                                                   String.IsNullOrEmpty(lineupsLineup.id) ? "-" : lineupsLineup.id,
                                                   String.IsNullOrEmpty(lineupsLineup.name) ? "-" : lineupsLineup.name,
                                                   String.IsNullOrEmpty(lineupsLineup.userLineupName) ? "-" : lineupsLineup.userLineupName,
                                                   String.IsNullOrEmpty(lineupsLineup.location) ? "-" : lineupsLineup.location,
                                                   String.IsNullOrEmpty(lineupsLineup.type.ToString()) ? "-" : lineupsLineup.type.ToString(),
                                                   String.IsNullOrEmpty(lineupsLineup.device) ? "-" : lineupsLineup.device,
                                                   String.IsNullOrEmpty(lineupsLineup.postalCode) ? "-" : lineupsLineup.postalCode));

                        sw.WriteLine("LineUpMaps :");
                        sw.WriteLine("Station;Channel;ChannelMinor");

                        foreach (lineupsLineupMap lineupsLineupMap in lineupsLineup.map)
                        {
                            sw.WriteLine(String.Format("{0};{1};{2}",
                                                       lineupsLineupMap.station,
                                                       String.IsNullOrEmpty(lineupsLineupMap.channel) ? "-" : lineupsLineupMap.channel,
                                                       String.IsNullOrEmpty(lineupsLineupMap.channelMinor) ? "-" : lineupsLineupMap.channelMinor));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(String.Format("An exception occured : {0}", ex.Message));
                }
            }
            Debug.WriteLine("Done writing LineUps");
        }
Exemple #11
0
        private static void WritePrograms(xtvdResponse response, string filename)
        {
            Debug.WriteLine(String.Format("Writing programs to : {0}", filename));
            File.Delete(filename);

            using (StreamWriter sw = new StreamWriter(filename))
            {
                sw.WriteLine("Id;Title;SubTitle;StarRating;ShowType;Series;ColorCodeSpecified;ColorCode;MpaaRatingSpecified;MpaaRating;OriginalAirDateSpecified;OriginalAirDate;SyndicatedEpisodeNumber;Year;Description");
                try
                {
                    foreach (programsProgram programsProgram in response.xtvd.programs)
                    {
                        sw.WriteLine(String.Format("'{0}';'{1}';'{2}';'{3}';'{4}';'{5}';'{6}';'{7}';'{8}';'{9}';'{10}';'{11}';'{12}';'{13}';'{14}';",
                                                   programsProgram.id,
                                                   String.IsNullOrEmpty(programsProgram.title) ? "-" : CleanContent(programsProgram.title),
                                                   String.IsNullOrEmpty(programsProgram.subtitle) ? "-" : CleanContent(programsProgram.subtitle),
                                                   String.IsNullOrEmpty(programsProgram.starRating.ToString()) ? "-" : programsProgram.starRating.ToString(),
                                                   String.IsNullOrEmpty(programsProgram.showType) ? "-" : programsProgram.showType,
                                                   String.IsNullOrEmpty(programsProgram.series) ? "-" : programsProgram.series,
                                                   programsProgram.colorCodeSpecified.ToString(),
                                                   programsProgram.colorCode.ToString(),
                                                   programsProgram.mpaaRatingSpecified.ToString(),
                                                   programsProgram.mpaaRating.ToString(),
                                                   programsProgram.originalAirDateSpecified.ToString(),
                                                   programsProgram.originalAirDate.ToString(),
                                                   String.IsNullOrEmpty(programsProgram.syndicatedEpisodeNumber) ? "-" : programsProgram.syndicatedEpisodeNumber,
                                                   String.IsNullOrEmpty(programsProgram.year) ? "-" : programsProgram.year,
                                                   String.IsNullOrEmpty(programsProgram.description) ? "-" : CleanContent(programsProgram.description)));
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(String.Format("An exception occured : {0}", ex.Message));
                }
            }
            Debug.WriteLine("Done writing programs");
        }
Exemple #12
0
        private xtvdResponse CallSchedulesDirectWebService(string startTime, string endTime)
        {
            try
            {
                xtvdWebService xtvdWebService = new xtvdWebService();
                xtvdWebService.EnableDecompression = true;
                xtvdWebService.UserAgent           = String.Format("ARGUS TV Version {0}", Constants.ProductVersion);
                xtvdWebService.Credentials         = new NetworkCredential(ConfigInstance.Current.SDUserName, ConfigInstance.Current.SDPassword);
                //xtvdWebService.Timeout = 2000;
                //#if DEBUG
                // xtvdWebService.Credentials = new NetworkCredential("argustv", "password");
                //#endif
                Logger.Write(TraceEventType.Verbose, FormatForLogger("Begin call to WS"));
                xtvdResponse response = xtvdWebService.download(startTime, endTime);
                Logger.Write(TraceEventType.Verbose, FormatForLogger("End call to WS"));

                return(response);
            }
            catch (Exception ex)
            {
                Logger.Write(FormatForLogger(String.Format("Exception calling scheduleDirect webservice: {0} .", ex.ToString())));
            }
            return(null);
        }
Exemple #13
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);
        }
Exemple #14
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);
                }
            }
        }