예제 #1
0
        private void UpdatePlaylist(MyWebRequest req)
        {

            if (_lastUpdate + _maxAge < DateTime.Now)
            {
                
                DateTime date = req.Parameters.ContainsKey("date") ? ParseDateTime(req.Parameters["date"]) : DateTime.Today;
                _channels = new ArcList().Run(_device.Proxy.SessionState.session);
                _channels.channels.RemoveAll(c => _device.Filter.Check("ttv").Find("ch" + c.id).Check());
                if (req.Parameters.ContainsKey("channel_id"))
                {
                    int channel_id = int.Parse(req.Parameters["channel_id"]);
                    var ch = _channels.channels.FirstOrDefault(c => c.epg_id == channel_id);
                    if (ch != null)
                        _records = new ArcRecords(ch == null ? 0 : ch.epg_id, date).Run(_device.Proxy.SessionState.session);
                    else
                        throw new FileNotFoundException();
                }
                else
                {
                    _records = new ArcRecords(0, date).Run(_device.Proxy.SessionState.session);
                    var groups = _records.records.GroupBy(r => r.epg_id).ToArray();
                    foreach (var kp in groups)
                    {
                        var ch = _channels.channels.Where(c => c.epg_id == kp.Key);
                        if (!ch.Any())
                            _records.records.RemoveAll(r => r.epg_id == kp.Key);
                    }
                }
                    
                    
            }

            if (!_channels.IsSuccess && !_records.IsSuccess)
            {
                if (_channels.Error == ApiError.incorrect || _channels.Error == ApiError.noconnect ||
                    _records.Error == ApiError.incorrect || _records.Error == ApiError.noconnect)
                {
                    while (!_device.Proxy.Login() || _device.Proxy.SessionState.Error == ApiError.noconnect)
                    {
                    }
                    if (!_device.Proxy.SessionState.IsSuccess)
                    {
                        throw new Exception("Ошибка подключения");
                    }
                    UpdatePlaylist(req);
                }
                else
                    switch (_records.Error)
                    {
                        case ApiError.norecord:
                            throw new Exception("Нет записей");
                        case ApiError.noconnect:
                            throw new Exception("ошибка соединения с БД");
                        case ApiError.noparam:
                            throw new Exception("ошибка входных параметров");
                    }
            }
        }
예제 #2
0
        private void UpdatePlaylist(MyWebRequest req)
        {
            if (_lastUpdate + _maxAge < DateTime.Now)
            {
                DateTime date = req.Parameters.ContainsKey("date") ? ParseDateTime(req.Parameters["date"]) : DateTime.Today;
                _channels = new ArcList().Run(_device.Proxy.SessionState.session);
                _channels.channels.RemoveAll(c => _device.Filter.Check("ttv").Find("ch" + c.id).Check());
                if (req.Parameters.ContainsKey("channel_id"))
                {
                    int channel_id = int.Parse(req.Parameters["channel_id"]);
                    var ch         = _channels.channels.FirstOrDefault(c => c.epg_id == channel_id);
                    if (ch != null)
                    {
                        _records = new ArcRecords(ch == null ? 0 : ch.epg_id, date).Run(_device.Proxy.SessionState.session);
                    }
                    else
                    {
                        throw new FileNotFoundException();
                    }
                }
                else
                {
                    _records = new ArcRecords(0, date).Run(_device.Proxy.SessionState.session);
                    var groups = _records.records.GroupBy(r => r.epg_id).ToArray();
                    foreach (var kp in groups)
                    {
                        var ch = _channels.channels.Where(c => c.epg_id == kp.Key);
                        if (!ch.Any())
                        {
                            _records.records.RemoveAll(r => r.epg_id == kp.Key);
                        }
                    }
                }
            }

            if (!_channels.IsSuccess && !_records.IsSuccess)
            {
                if (_channels.Error == ApiError.incorrect || _channels.Error == ApiError.noconnect ||
                    _records.Error == ApiError.incorrect || _records.Error == ApiError.noconnect)
                {
                    while (!_device.Proxy.Login() || _device.Proxy.SessionState.Error == ApiError.noconnect)
                    {
                    }
                    if (!_device.Proxy.SessionState.IsSuccess)
                    {
                        throw new Exception("Ошибка подключения");
                    }
                    UpdatePlaylist(req);
                }
                else
                {
                    switch (_records.Error)
                    {
                    case ApiError.norecord:
                        throw new Exception("Нет записей");

                    case ApiError.noconnect:
                        throw new Exception("ошибка соединения с БД");

                    case ApiError.noparam:
                        throw new Exception("ошибка входных параметров");
                    }
                }
            }
        }
예제 #3
0
 public override string GetPlaylist(MyWebRequest req)
 {
     try
     {
         UpdatePlaylist(req);
     }
     catch (Exception e)
     {
         return e.Message;
     }
     if (req.Parameters.ContainsKey("type"))
     {
         Playlist pl = Playlist.CreatePlaylist(req.Parameters["type"], req.Headers["host"], Playlist.ContentType.Archive);
         List<Record> arcs = new List<Record>();
         arcs.AddRange(_records.records);
         if (req.Parameters.ContainsKey("sort"))
         {
             switch (req.Parameters["sort"])
             {
                 case "channel":
                     arcs = arcs.OrderBy(arc => arc.epg_id).ToList();
                     break;
                 case "-channel":
                     arcs = arcs.OrderByDescending(arc => arc.epg_id).ToList();
                     break;
                 case "title":
                     arcs = arcs.OrderBy(arc => arc.name).ToList();
                     break;
                 case "-title":
                     arcs = arcs.OrderByDescending(arc => arc.name).ToList();
                     break;
                 case "id":
                     arcs = arcs.OrderBy(arc => arc.record_id).ToList();
                     break;
                 case "-id":
                     arcs = arcs.OrderByDescending(arc => arc.record_id).ToList();
                     break;
                 case "datetime":
                     arcs = arcs.OrderBy(arc => arc.Time).ToList();
                     break;
                 case "-datetime":
                     arcs = arcs.OrderByDescending(arc => arc.Time).ToList();
                     break;
             }
         }
         _records.CastChannels(_channels.channels);
         foreach (var ch in arcs)
         {
             if (ch.Channel != null)
                 pl.AddLine(ch, append: req.Parameters.ContainsKey("transcode") ? "&transcode=" + req.Parameters["transcode"] : "");
         }
         return pl.ToString();
     }
     DateTime date = req.Parameters.ContainsKey("date") ? ParseDateTime(req.Parameters["date"]) : DateTime.Today;
     var res = new ArcRecords(req.Parameters.ContainsKey("channel_id") ? int.Parse(req.Parameters["channel_id"]) : 0, date).Execute(_device.Proxy.SessionState.session, TypeResult.Xml);
     XDocument xd = XDocument.Load(res);
     var xchs = xd.Root.Element("records").Elements().GroupBy(e => int.Parse(e.Attribute("epg_id").Value)).ToArray();
     foreach (var xch in xchs)
     {
         if (!_channels.channels.Any(c => c.epg_id == xch.Key))
             xch.Remove();
     }
     return xd.ToString();
 }
예제 #4
0
        public override string GetPlaylist(MyWebRequest req)
        {
            try
            {
                UpdatePlaylist(req);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            if (req.Parameters.ContainsKey("type"))
            {
                Playlist      pl   = Playlist.CreatePlaylist(req.Parameters["type"], req.Headers["host"], Playlist.ContentType.Archive);
                List <Record> arcs = new List <Record>();
                arcs.AddRange(_records.records);
                if (req.Parameters.ContainsKey("sort"))
                {
                    switch (req.Parameters["sort"])
                    {
                    case "channel":
                        arcs = arcs.OrderBy(arc => arc.epg_id).ToList();
                        break;

                    case "-channel":
                        arcs = arcs.OrderByDescending(arc => arc.epg_id).ToList();
                        break;

                    case "title":
                        arcs = arcs.OrderBy(arc => arc.name).ToList();
                        break;

                    case "-title":
                        arcs = arcs.OrderByDescending(arc => arc.name).ToList();
                        break;

                    case "id":
                        arcs = arcs.OrderBy(arc => arc.record_id).ToList();
                        break;

                    case "-id":
                        arcs = arcs.OrderByDescending(arc => arc.record_id).ToList();
                        break;

                    case "datetime":
                        arcs = arcs.OrderBy(arc => arc.Time).ToList();
                        break;

                    case "-datetime":
                        arcs = arcs.OrderByDescending(arc => arc.Time).ToList();
                        break;
                    }
                }
                _records.CastChannels(_channels.channels);
                foreach (var ch in arcs)
                {
                    if (ch.Channel != null)
                    {
                        pl.AddLine(ch, append: req.Parameters.ContainsKey("transcode") ? "&transcode=" + req.Parameters["transcode"] : "");
                    }
                }
                return(pl.ToString());
            }
            DateTime  date = req.Parameters.ContainsKey("date") ? ParseDateTime(req.Parameters["date"]) : DateTime.Today;
            var       res  = new ArcRecords(req.Parameters.ContainsKey("channel_id") ? int.Parse(req.Parameters["channel_id"]) : 0, date).Execute(_device.Proxy.SessionState.session, TypeResult.Xml);
            XDocument xd   = XDocument.Load(res);
            var       xchs = xd.Root.Element("records").Elements().GroupBy(e => int.Parse(e.Attribute("epg_id").Value)).ToArray();

            foreach (var xch in xchs)
            {
                if (!_channels.channels.Any(c => c.epg_id == xch.Key))
                {
                    xch.Remove();
                }
            }
            return(xd.ToString());
        }