Exemple #1
0
        } // GetRecordDuration

        public static RecordDescription GetRecordDescription(EpgProgram epgProgram, RecordChannel channel)
        {
            if (epgProgram == null)
            {
                throw new ArgumentNullException(nameof(epgProgram));
            }

            var description = RecordDescription.CreateWithDefaultValues();

            description.Name = RecordDescription.CreateTaskName(channel, epgProgram.LocalStartTime);

            /* var extended = program as EpgProgramExtended;
             * if (extended != null)
             * {
             *
             * }
             * else */
            {
                var buffer = new StringBuilder();
                buffer.AppendLine(epgProgram.Title);
                buffer.Append(epgProgram.ParentalRating.Description);
                description.Description = buffer.ToString();
            } // if-else

            return(description);
        } // GetRecordDescription
Exemple #2
0
        } // constructor

        public void DisplayData(UiBroadcastService service, EpgProgram epgProgram, DateTime referenceTime, string caption)
        {
            Service    = service;
            EpgProgram = epgProgram;

            labelProgramCaption.Text              = caption;
            labelProgramCaption.Visible           = caption != null;
            labelProgramTime.Visible              = (epgProgram != null);
            labelProgramDetails.Visible           = (epgProgram != null);
            pictureProgramThumbnail.ImageLocation = null;
            buttonProgramProperties.Visible       = (epgProgram != null);
            pictureProgramThumbnail.Cursor        = (epgProgram != null) ? Cursors.Hand : Cursors.Default;

            if (EpgProgram == null)
            {
                labelProgramTitle.Text        = Properties.Texts.EpgNoInformation;
                pictureProgramThumbnail.Image = Properties.Resources.EpgNoProgramImage;
            }
            else
            {
                labelProgramTitle.Text = EpgProgram.Title;
                labelProgramTime.Text  = string.Format("{0} ({1})", FormatString.DateTimeFromToMinutes(EpgProgram.LocalStartTime, EpgProgram.LocalEndTime, referenceTime),
                                                       FormatString.TimeSpanTotalMinutes(EpgProgram.Duration, FormatString.Format.Extended));
                labelProgramDetails.Text = string.Format("{0} / {1}", (EpgProgram.Genre != null) ? EpgProgram.Genre.Description : Properties.Texts.EpgNoGenre,
                                                         (EpgProgram.ParentalRating != null) ? EpgProgram.ParentalRating.Description : Properties.Texts.EpgNoParentalRating);

                pictureProgramThumbnail.Image         = Properties.Resources.EpgLoadingProgramImage;
                pictureProgramThumbnail.ImageLocation = null;
                // TODO: EPG
                // pictureProgramThumbnail.ImageLocation = IpTvProvider.Current.EpgInfo.GetEpgProgramThumbnailUrl(service, EpgProgram, false);
            } // if-else
        }     // DisplayData
Exemple #3
0
        } // CanRecord

        public static RecordTask GetRecordTask(UiBroadcastService service, EpgProgram epgProgram, DateTime localReferenceTime)
        {
            var channel = GetRecordChannel(service);

            if (epgProgram == null)
            {
                return(RecordTask.CreateWithDefaultValues(channel));
            } // if

            var isCurrent   = epgProgram.IsCurrent(localReferenceTime);
            var program     = GetRecordProgram(epgProgram);
            var schedule    = GetRecordSchedule(epgProgram, isCurrent);
            var duration    = GetRecordDuration(epgProgram, isCurrent);
            var description = GetRecordDescription(epgProgram, channel);
            var action      = GetRecordAction(service, epgProgram);
            var advanced    = GetRecordAdvancedSettings();

            var task = new RecordTask()
            {
                Channel          = channel,
                Program          = program,
                Schedule         = schedule,
                Duration         = duration,
                Description      = description,
                Action           = action,
                AdvancedSettings = advanced,
            };

            return(task);
        } // GetRecordTask
Exemple #4
0
        }     // BeginLoadEpgPrograms

        private void LoadEpgPrograms(LoadEpgProgramsData data)
        {
            var programs = Datastore.GetPrograms(data.FullServiceName, LocalReferenceTime, 1, 2);

            // try alternate service if no EPG data
            if ((programs == null) && (data.FullAlternateServiceName != null))
            {
                programs = Datastore.GetPrograms(data.FullAlternateServiceName, LocalReferenceTime, 1, 2);
            } // if

            // populate data
            if (programs != null)
            {
                var epgPrograms = new EpgProgram[4];
                epgPrograms[0] = programs.Requested?.Previous?.Program;
                epgPrograms[1] = programs.Requested?.Program;
                var next = programs.Requested?.Next;
                epgPrograms[2] = next?.Program;
                next           = next?.Next;
                epgPrograms[3] = next?.Program;

                data.EpgPrograms = epgPrograms;
            } // if

            if (InvokeRequired)
            {
                BeginInvoke(new Action <LoadEpgProgramsData>(LoadEpgProgramsEnded), data);
            }
            else
            {
                LoadEpgProgramsEnded(data);
            } // if-else
        }     // LoadEpgPrograms
        private void AddProgramAndApplyTemplates(Channel dbChannel, EpgProgram ep, Program dbProg)
        {
            string title;
            string description;
            string genre;
            int    starRating;
            string classification;
            int    parentRating;

            GetEPGLanguage(ep.Text, out title, out description, out genre, out starRating, out classification,
                           out parentRating);
            NameValueCollection values = new NameValueCollection();

            values.Add("%TITLE%", title);
            values.Add("%DESCRIPTION%", description);
            values.Add("%GENRE%", genre);
            values.Add("%STARRATING%", starRating.ToString());
            values.Add("%STARRATING_STR%", GetStarRatingStr(starRating));
            values.Add("%CLASSIFICATION%", classification);
            values.Add("%PARENTALRATING%", parentRating.ToString());
            values.Add("%NEWLINE%", Environment.NewLine);
            title       = EvalTemplate(_titleTemplate, values);
            description = EvalTemplate(_descriptionTemplate, values);
            if (dbProg == null)
            {
                dbProg = new Program(dbChannel.IdChannel, ep.StartTime, ep.EndTime, title, description, genre,
                                     Program.ProgramState.None,
                                     SqlDateTime.MinValue.Value, string.Empty, string.Empty, string.Empty, string.Empty,
                                     starRating, classification,
                                     parentRating);
            }
            else
            {
                // this prevents a more detailed description getting overriden by a short description from another transponder
                if (dbProg.Title == title)
                {
                    if (dbProg.Description.Length < description.Length)
                    {
                        dbProg.Description = description;
                    }
                }
                else
                {
                    dbProg.Description = description;
                }
                dbProg.Title           = title;
                dbProg.StartTime       = ep.StartTime;
                dbProg.EndTime         = ep.EndTime;
                dbProg.Genre           = genre;
                dbProg.StarRating      = starRating;
                dbProg.Classification  = classification;
                dbProg.ParentalRating  = parentRating;
                dbProg.OriginalAirDate = SqlDateTime.MinValue.Value; // TODO: /!\ add implementation
                dbProg.ClearRecordPendingState();
            }
            dbProg.Persist();
        }
Exemple #6
0
 public void LoadProgramImageAsync(EpgProgram epgProgram, bool portrait)
 {
     if ((epgProgram == null)) // || (!IpTvProvider.Current.EpgInfo.Capabilities.HasFlag(EpgProviderCapabilities.ProgramThumbnail)))
     {
         OnProgramImageLoaded(null, portrait);
     }
     else
     {
         OnProgramImageLoaded(null, portrait);
         // TODO: async load program image
     } // if-else
 }     // LoadProgramImageAsync
Exemple #7
0
        } // GetRecordSchedule

        public static RecordDuration GetRecordDuration(EpgProgram epgProgram, bool isCurrent)
        {
            if (epgProgram == null)
            {
                throw new ArgumentNullException(nameof(epgProgram));
            }

            var duration = RecordDuration.CreateWithDefaultValues();

            duration.EndDateTime = epgProgram.LocalEndTime;

            return(duration);
        } // GetRecordDuration
Exemple #8
0
        } // RefreshEpgPrograms

        public EpgProgram[] GetEpgPrograms()
        {
            if (EpgPrograms == null)
            {
                return(null);
            }

            var result = new EpgProgram[EpgPrograms.Length];

            Array.Copy(EpgPrograms, result, EpgPrograms.Length);

            return(result);
        } // GetEpgPrograms
Exemple #9
0
        } // RecordProgram

        public static bool CanRecord(EpgProgram program, bool allowRecordChannel = true)
        {
            if (allowRecordChannel)
            {
                return(true);
            }

            if ((program == null) || (program.IsBlank))
            {
                return(false);
            }

            return(true);
        } // CanRecord
Exemple #10
0
 public EpgLinkedListPhantomNode(EpgLinkedListWrapper list, EpgProgram program, bool first)
 {
     _linkedList = list;
     Program     = program;
     IsFirst     = first;
     if (first)
     {
         Previous = null;
         Next     = new EpgLinkedListNodeWrapper(list, list.List.First);
     }
     else
     {
         Previous = new EpgLinkedListNodeWrapper(list, list.List.Last);
         Next     = null;
     } // if-else
 }     // constructor
Exemple #11
0
        } // GetRecordChannel

        private static RecordProgram GetRecordProgram(EpgProgram epgProgram)
        {
            if (epgProgram == null)
            {
                throw new ArgumentNullException(nameof(epgProgram));
            }

            var program = new RecordProgram()
            {
                Title        = epgProgram.Title,
                UtcStartTime = epgProgram.UtcStartTime,
                UtcEndTime   = epgProgram.UtcEndTime,
            };

            return(program);
        } // GetRecordProgram
Exemple #12
0
        } // GetRecordDescription

        public static RecordAction GetRecordAction(UiBroadcastService service, EpgProgram epgProgram)
        {
            if (epgProgram == null)
            {
                throw new ArgumentNullException(nameof(epgProgram));
            }

            var action          = RecordAction.CreateWithDefaultValues();
            var defaultLocation = RecordSaveLocation.GetDefaultSaveLocation(AppUiConfiguration.Current.User.Record.SaveLocations);

            action.Filename         = string.Format("{0} - {1}", service.DisplayName, epgProgram.Title);
            action.FileExtension    = RecordChannelDialog.GetFilenameExtensions()[0];
            action.SaveLocationName = defaultLocation.Name;
            action.SaveLocationPath = defaultLocation.Path;
            action.Recorder         = GetDefaultRecorder();

            return(action);
        } // GetRecordAction
Exemple #13
0
        } // GetRecordProgram

        public static RecordSchedule GetRecordSchedule(EpgProgram epgProgram, bool isCurrent)
        {
            RecordSchedule schedule;

            if (epgProgram == null)
            {
                throw new ArgumentNullException(nameof(epgProgram));
            }

            if (isCurrent)
            {
                schedule = RecordSchedule.CreateWithDefaultValues(RecordScheduleKind.RightNow);
            }
            else
            {
                schedule            = RecordSchedule.CreateWithDefaultValues(RecordScheduleKind.OneTime);
                schedule.ExpiryDate = epgProgram.LocalEndTime + epgProgram.Duration + RecordChannelDialog.DefaultExpiryDateTimeSpan;
            } // if-else
            schedule.StartDate = epgProgram.LocalStartTime;

            return(schedule);
        } // GetRecordSchedule
Exemple #14
0
        protected override int Run(string[] args)
        {
            var startTime = DateTime.UtcNow.TruncateToMinutes();

            // create initial programs list

            var list = new List <EpgProgram>();

            var program = new EpgProgram()
            {
                Title        = "Program 1",
                UtcStartTime = startTime,
                Duration     = new TimeSpan(0, 15, 0)
            };

            list.Add(program);

            program = new EpgProgram()
            {
                Title        = "Program 2",
                UtcStartTime = program.UtcEndTime,
                Duration     = new TimeSpan(0, 20, 0)
            };
            list.Add(program);

            program = new EpgProgram()
            {
                Title        = "Program 3",
                UtcStartTime = program.UtcEndTime + new TimeSpan(0, 5, 0),
                Duration     = new TimeSpan(0, 25, 0)
            };
            list.Add(program);

            var service = new EpgService()
            {
                ServiceIdReference = "1.imagenio.es",
                XmlPrograms        = list.ToArray()
            };

            // enumerate programs
            Console.WriteLine("Original programs");
            foreach (var epgProgram in service.Programs)
            {
                DisplayProgram(epgProgram);
            } // foreach
            Console.WriteLine();

            Console.WriteLine("Adding to datastore");
            var datastore = new EpgMemoryDatastore();

            datastore.Add(service);
            Console.WriteLine();

            Console.WriteLine("Original programs after being added");
            foreach (var epgProgram in service.Programs)
            {
                DisplayProgram(epgProgram);
            } // foreach
            Console.WriteLine();

            Console.WriteLine("Programs in 1.imagenio.es (now)");
            var epgPrograms = datastore.GetPrograms("1.imagenio.es", null, 0, 0);

            DisplayEpgPrograms(epgPrograms);
            Console.WriteLine();

            Console.WriteLine("Programs in 1.imagenio.es (in 25 minutes)");
            epgPrograms = datastore.GetPrograms("1.imagenio.es", startTime + new TimeSpan(0, 25, 0), 0, 0);
            DisplayEpgPrograms(epgPrograms);
            Console.WriteLine();

            Console.WriteLine("Programs in 1.imagenio.es (in 2 hours)");
            epgPrograms = datastore.GetPrograms("1.imagenio.es", startTime + new TimeSpan(2, 0, 0), 0, 0);
            DisplayEpgPrograms(epgPrograms);
            Console.WriteLine();

            Console.WriteLine("Programs in 1.imagenio.es (15 minutes ago)");
            epgPrograms = datastore.GetPrograms("1.imagenio.es", startTime - new TimeSpan(0, 15, 0), 0, 0);
            DisplayEpgPrograms(epgPrograms);
            Console.WriteLine();

            return(0);
        } // Run
        private void ImportPrograms(Channel dbChannel, IList <EpgProgram> epgPrograms)
        {
            int  iInserted = 0;
            bool hasGaps   = false;

            _layer.RemoveOldPrograms(dbChannel.IdChannel);

            EpgHoleCollection holes = new EpgHoleCollection();

            if ((dbChannel.EpgHasGaps || _alwaysFillHoles) && !_alwaysReplace)
            {
                Log.Epg("{0}: {1} is marked to have epg gaps. Calculating them...", _grabberName, dbChannel.DisplayName);
                IList <Program> infos = _layer.GetPrograms(dbChannel, DateTime.Now);
                if (infos.Count > 1)
                {
                    for (int i = 1; i < infos.Count; i++)
                    {
                        Program  prev    = infos[i - 1];
                        Program  current = infos[i];
                        TimeSpan diff    = current.StartTime - prev.EndTime;
                        if (diff.TotalMinutes > 5)
                        {
                            holes.Add(new EpgHole(prev.EndTime, current.StartTime));
                        }
                    }
                }
                Log.Epg("{0}: {1} Found {2} epg holes.", _grabberName, dbChannel.DisplayName, holes.Count);
            }
            DateTime   dbLastProgram = _layer.GetNewestProgramForChannel(dbChannel.IdChannel);
            EpgProgram lastProgram   = null;

            for (int i = 0; i < epgPrograms.Count; i++)
            {
                EpgProgram epgProgram = epgPrograms[i];
                // Check for dupes
                if (lastProgram != null)
                {
                    if (epgProgram.StartTime == lastProgram.StartTime && epgProgram.EndTime == lastProgram.EndTime)
                    {
                        continue;
                    }
                    TimeSpan diff = epgProgram.StartTime - lastProgram.EndTime;
                    if (diff.Minutes > 5)
                    {
                        hasGaps = true;
                    }
                }
                if (epgProgram.StartTime <= dbLastProgram && !_alwaysReplace)
                {
                    if (epgProgram.StartTime < DateTime.Now)
                    {
                        continue;
                    }
                    if (!holes.FitsInAnyHole(epgProgram.StartTime, epgProgram.EndTime))
                    {
                        continue;
                    }
                    Log.Epg("{0}: Great we stuffed an epg hole {1}-{2} :-)", _grabberName,
                            epgProgram.StartTime.ToShortDateString() + " " + epgProgram.StartTime.ToShortTimeString(),
                            epgProgram.EndTime.ToShortDateString() + " " + epgProgram.EndTime.ToShortTimeString());
                }
                Program prog = null;
                if (_alwaysReplace)
                {
                    try
                    {
                        IList <Program> epgs = _layer.GetProgramExists(dbChannel, epgProgram.StartTime, epgProgram.EndTime);

                        if (epgs.Count > 0)
                        {
                            prog = epgs[0];
                            if (epgs.Count > 1)
                            {
                                Log.Epg("- {0} entries are obsolete for {1} from {2} to {3}", epgs.Count - 1, dbChannel.DisplayName,
                                        epgProgram.StartTime, epgProgram.EndTime);
                            }
                            for (int idx = 1; idx < epgs.Count; idx++)
                            {
                                try
                                {
                                    epgs[idx].Delete();
                                    Log.Epg("- Deleted the epg entry {0} ({1} - {2})", epgs[idx].Title, epgs[idx].StartTime,
                                            epgs[idx].EndTime);
                                }
                                catch (Exception ex)
                                {
                                    Log.Epg("Error during epg entry deletion: {0}", ex.Message);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Epg("Error the existing epg entry check: {0}", ex.Message);
                    }
                }
                AddProgramAndApplyTemplates(dbChannel, epgProgram, prog);
                iInserted++;
                lastProgram = epgProgram;
            }
            dbChannel.LastGrabTime = DateTime.Now;
            dbChannel.EpgHasGaps   = hasGaps;
            dbChannel.Persist();

            //_layer.StartResetProgramStatesThread(System.Threading.ThreadPriority.Lowest);


            Log.Epg("- Inserted {0} epg entries for channel {1}", iInserted, dbChannel.DisplayName);
        }
Exemple #16
0
        public static void ShowExtendedInfo(IWin32Window owner, UiBroadcastService service, EpgProgram epgProgram)
        {
            using (var dialog = new EpgExtendedInfoDialog())
            {
                // TODO: EPG

                /*
                 * dialog.ProgramInfo = new ProgramEpgInfo()
                 * {
                 *  Service = service,
                 *  Base = epgProgram,
                 * };
                 * dialog.ShowDialog(owner);
                 */
            } // using dialog
        }     // ShowExtendedInfo
Exemple #17
0
        } // RecordService

        public static bool RecordProgram(CommonBaseForm ownerForm, UiBroadcastService service, EpgProgram program, DateTime localReferenceTime, bool allowRecordChannel = true)
        {
            RecordProgramOptions.RecordOption option;

            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (VerifyIsInactive(ownerForm, service))
            {
                return(false);
            }

            // select record options
            using (var dlg = new RecordProgramOptions())
            {
                dlg.SelectedService    = service;
                dlg.SelectedProgram    = program;
                dlg.LocalReferenceTime = localReferenceTime;
                dlg.AllowRecordChannel = allowRecordChannel;
                dlg.ShowDialog(ownerForm);
                option = dlg.SelectedOption;
            } // using

            if (option == RecordProgramOptions.RecordOption.None)
            {
                return(false);
            }
            if (option == RecordProgramOptions.RecordOption.Channel)
            {
                program = null;
            }

            // create record task and allow to edit it
            var task = GetRecordTask(service, program, localReferenceTime);

            if (option != RecordProgramOptions.RecordOption.Default)
            {
                using (var dlg = new RecordChannelDialog())
                {
                    dlg.Task               = task;
                    dlg.IsNewTask          = true;
                    dlg.LocalReferenceTime = localReferenceTime;
                    dlg.ShowDialog(ownerForm);
                    task = dlg.Task;
                    if (dlg.DialogResult != DialogResult.OK)
                    {
                        return(false);
                    }
                } // using dlg
            }     // if

            return(ScheduleTask(ownerForm, task));
        } // RecordProgram
Exemple #18
0
        }         // DisplayEpgPrograms

        private void DisplayProgram(EpgProgram epgProgram, bool current = false)
        {
            Console.WriteLine("{3} {0:dd/MM HH:mm}  {2:hh\\:mm}  {1} ", epgProgram.LocalStartTime, epgProgram.Title, epgProgram.Duration, current? "==>" : "   ");
        } // DisplayProgram