Beispiel #1
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);
        }
Beispiel #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);
                }
            }
        }