Example #1
0
        void IEpgDataSink.EndChannelPrograms(string id, string name)
        {
            if (_currentChannels == null)
            {
                return;
            }
            if (_channelPrograms.Count == 0)
            {
                return;
            }

            // Sort programs
            _channelPrograms.SortIfNeeded();
            _channelPrograms.AlreadySorted = true;

            // Fix end times
            _channelPrograms.FixEndTimes();
            ClipProgramsToWindow();

            // Remove overlapping programs
            _channelPrograms.RemoveOverlappingPrograms();

            if (!_deleteExisting)
            {
                // Remove programs overlapping ones in DB:
                // First retrieve all programs for current channels
                SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Program));
                sb.AddConstraint(Operator.In, "idChannel", _currentChannels, "IdChannel");
                //sb.AddConstraint(Operator.Equals, "idChannel", _currentChannels.IdChannel);
                //sb.AddOrderByField(false, "starttime");
                SqlStatement stmt       = sb.GetStatement(true);
                ProgramList  dbPrograms = new ProgramList(ObjectFactory.GetCollection <Program>(stmt.Execute()));

                _channelPrograms.RemoveOverlappingPrograms(dbPrograms);
            }
            foreach (Channel chan in _currentChannels)
            {
                layer.RemoveOldPrograms(chan.IdChannel);
            }

            DeleteBeforeImportOption programsToDelete = _deleteExisting
                                                    ? DeleteBeforeImportOption.OverlappingPrograms
                                                    : DeleteBeforeImportOption.None;

            layer.InsertPrograms(_channelPrograms, programsToDelete, ThreadPriority.BelowNormal);

            //_channelPrograms.Clear();
            _channelPrograms = null;
            _currentChannels = null;
        }