/// <summary>
 /// Gets the channel info dto.
 /// </summary>
 /// <param name="info">The info.</param>
 /// <returns>ChannelInfoDto.</returns>
 public ChannelInfoDto GetChannelInfoDto(ChannelInfo info)
 {
     return new ChannelInfoDto
     {
         Name = info.Name,
         ServiceName = info.ServiceName
     };
 }
Exemple #2
0
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var path = Path.Combine(_config.ApplicationPaths.ItemsByNamePath, "tvchannels", _fileSystem.GetValidFilename(channelInfo.Name));

            var fileInfo = new DirectoryInfo(path);

            var isNew = false;

            if (!fileInfo.Exists)
            {
                _logger.Debug("Creating directory {0}", path);

                Directory.CreateDirectory(path);
                fileInfo = new DirectoryInfo(path);

                if (!fileInfo.Exists)
                {
                    throw new IOException("Path not created: " + path);
                }

                isNew = true;
            }

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null || !string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase))
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
                    DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
                    Path = path
                };

                isNew = true;
            }

            item.ChannelType = channelInfo.ChannelType;
            item.ExternalId = channelInfo.Id;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            var replaceImages = new List<ImageType>();

            if (!string.Equals(item.ProviderImageUrl, channelInfo.ImageUrl, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }
            if (!string.Equals(item.ProviderImagePath, channelInfo.ImagePath, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }

            item.ProviderImageUrl = channelInfo.ImageUrl;
            item.HasProviderImage = channelInfo.HasImage;
            item.ProviderImagePath = channelInfo.ImagePath;
            
            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            await item.RefreshMetadata(new MetadataRefreshOptions
            {
                ForceSave = isNew,
                ReplaceImages = replaceImages.Distinct().ToList()

            }, cancellationToken);

            return item;
        }
Exemple #3
0
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, Guid parentFolderId, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null)
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = DateTime.UtcNow,
                };

                isNew = true;
            }

            if (!string.Equals(channelInfo.Id, item.ExternalId))
            {
                isNew = true;
            }
            item.ExternalId = channelInfo.Id;

            item.ChannelType = channelInfo.ChannelType;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            //if (!string.Equals(item.ProviderImageUrl, channelInfo.ImageUrl, StringComparison.OrdinalIgnoreCase))
            //{
            //    isNew = true;
            //    replaceImages.Add(ImageType.Primary);
            //}
            //if (!string.Equals(item.ProviderImagePath, channelInfo.ImagePath, StringComparison.OrdinalIgnoreCase))
            //{
            //    isNew = true;
            //    replaceImages.Add(ImageType.Primary);
            //}

            if (!item.HasImage(ImageType.Primary))
            {
                if (!string.IsNullOrWhiteSpace(channelInfo.ImagePath))
                {
                    item.SetImagePath(ImageType.Primary, channelInfo.ImagePath);
                }
                else if (!string.IsNullOrWhiteSpace(channelInfo.ImageUrl))
                {
                    item.SetImagePath(ImageType.Primary, channelInfo.ImageUrl);
                }
            }

            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
            {
                ForceSave = isNew

            }, cancellationToken);

            return item;
        }
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null)
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = DateTime.UtcNow,
                };

                isNew = true;
            }

            item.ChannelType = channelInfo.ChannelType;
            item.ExternalId = channelInfo.Id;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            var replaceImages = new List<ImageType>();

            if (!string.Equals(item.ProviderImageUrl, channelInfo.ImageUrl, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }
            if (!string.Equals(item.ProviderImagePath, channelInfo.ImagePath, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }

            item.ProviderImageUrl = channelInfo.ImageUrl;
            item.HasProviderImage = channelInfo.HasImage;
            item.ProviderImagePath = channelInfo.ImagePath;

            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            await item.RefreshMetadata(new MetadataRefreshOptions
            {
                ForceSave = isNew,
                ReplaceImages = replaceImages.Distinct().ToList()

            }, cancellationToken);

            return item;
        }
Exemple #5
0
        public TunerChannelMapping GetTunerChannelMapping(ChannelInfo channel, List<NameValuePair> mappings, List<ChannelInfo> providerChannels)
        {
            var result = new TunerChannelMapping
            {
                Name = channel.Number + " " + channel.Name,
                Number = channel.Number
            };

            var mapping = mappings.FirstOrDefault(i => string.Equals(i.Name, channel.Number, StringComparison.OrdinalIgnoreCase));
            var providerChannelNumber = channel.Number;

            if (mapping != null)
            {
                providerChannelNumber = mapping.Value;
            }

            var providerChannel = providerChannels.FirstOrDefault(i => string.Equals(i.Number, providerChannelNumber, StringComparison.OrdinalIgnoreCase));

            if (providerChannel != null)
            {
                result.ProviderChannelNumber = providerChannel.Number;
                result.ProviderChannelName = providerChannel.Name;
            }

            return result;
        }
        public Task<IEnumerable<ChannelInfo>> BuildChannelInfos(CancellationToken cancellationToken)
        {
            return Task.Factory.StartNew<IEnumerable<ChannelInfo>>(() =>
            {
                lock (_data)
                {
                    List<ChannelInfo> result = new List<ChannelInfo>();
                    foreach (KeyValuePair<int, HTSMessage> entry in _data)
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos, call canceled - returning part list.");
                            return result;
                        }

                        HTSMessage m = entry.Value;

                        ChannelInfo ci = new ChannelInfo();
                        ci.Id = "" + entry.Key;

                        ci.ImagePath = "";

                        if (m.containsField("channelIcon"))
                        {
                            string channelIcon = m.getString("channelIcon");
                            Uri uriResult;
                            bool uriCheckResult = Uri.TryCreate(channelIcon, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp;
                            if (uriCheckResult)
                            {
                                ci.ImageUrl = channelIcon;
                            }
                            else if (channelIcon.ToLower().StartsWith("picon://"))
                            {
                                ci.HasImage = true;
                                _piconData.Add(ci.Id, channelIcon);
                            }
                            else
                            {
                                _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos: channelIcon '" + channelIcon +
                                    "' can not be handled properly for channelID '" + ci.Id + "'!");
                            }
                        }
                        if (m.containsField("channelName"))
                        {
                            string name = m.getString("channelName");
                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }
                            ci.Name = m.getString("channelName");
                        }

                        if (m.containsField("channelNumber"))
                        {
                            int chNo = m.getInt("channelNumber");
                            ci.Number = "" + chNo;
                        }

                        Boolean serviceFound = false;
                        if (m.containsField("services"))
                        {
                            IList tunerInfoList = m.getList("services");
                            if (tunerInfoList != null && tunerInfoList.Count > 0)
                            {
                                HTSMessage firstServiceInList = (HTSMessage)tunerInfoList[0];
                                if (firstServiceInList.containsField("type"))
                                {
                                    string type = firstServiceInList.getString("type").ToLower();
                                    switch (type)
                                    {
                                        case "radio":
                                            ci.ChannelType = ChannelType.Radio;
                                            serviceFound = true;
                                            break;
                                        case "sdtv":
                                        case "hdtv":
                                            ci.ChannelType = ChannelType.TV;
                                            serviceFound = true;
                                            break;
                                        case "other":
                                            switch (_channelType4Other.ToLower())
                                            {
                                                case "tv":
                                                    _logger.Info("[TVHclient] ChannelDataHelper: map service tag 'Other' to 'TV'.");
                                                    ci.ChannelType = ChannelType.TV;
                                                    serviceFound = true;
                                                    break;
                                                case "radio":
                                                    _logger.Info("[TVHclient] ChannelDataHelper: map service tag 'Other' to 'Radio'.");
                                                    ci.ChannelType = ChannelType.Radio;
                                                    serviceFound = true;
                                                    break;
                                                default:
                                                    _logger.Info("[TVHclient] ChannelDataHelper: don't map service tag 'Other' - will be ignored.");
                                                    break;
                                            }
                                            break;
                                        default:
                                            _logger.Info("[TVHclient] ChannelDataHelper: unkown service tag '" + type + "' - will be ignored.");
                                            break;
                                    }
                                }
                            }
                        }
                        if (!serviceFound)
                        {
                            _logger.Info("[TVHclient] ChannelDataHelper: unable to detect service-type (tvheadend tag!!!) from service list:" + m.ToString());
                            continue;
                        }

                        _logger.Info("[TVHclient] ChannelDataHelper: Adding channel \n" + m.ToString());

                        result.Add(ci);
                    }
                    return result;
                }
            });
        }
        /// <summary>
        /// Gets the channels async.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{IEnumerable{ChannelInfo}}.</returns>
        public async Task<IEnumerable<ChannelInfo>> GetChannelsAsync(CancellationToken cancellationToken)
        {
            List<ChannelInfo> ret = new List<ChannelInfo>();

            _logger.Info("[MythTV] Start GetChannels Async, retrieve all channels");

            await GetCallsign(string.Empty, cancellationToken); //call to build the cache
            using (var releaser = await _channelsLock.LockAsync()) 
            {
                List<string> foundChannels = new List<string>();

                foreach (var channel in _channelCache.Values)
                {
                    if (!foundChannels.Contains(channel.CallSign.ToLower()))
                    {
                        ChannelInfo ci = new ChannelInfo()
                                {
                                    Name = channel.ChannelName,
                                    Number = channel.ChanNum,
                                    Id = channel.ChanId.ToString(_usCulture),
                                    HasImage = false
                                };

                        if (!string.IsNullOrWhiteSpace(channel.IconURL) && Plugin.Instance.Configuration.LoadChannelIcons)
                        {
                            ci.HasImage = true;
                            ci.ImageUrl = string.Format("{0}/Guide/GetChannelIcon?ChanId={1}", Plugin.Instance.Configuration.WebServiceUrl, channel.ChanId);
                        }

                        ret.Add(ci);
                        foundChannels.Add(channel.CallSign.ToLower());
                    }
                }
            }
            return ret;
        }
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var path = Path.Combine(_config.ApplicationPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name));

            var fileInfo = new DirectoryInfo(path);

            var isNew = false;

            if (!fileInfo.Exists)
            {
                Directory.CreateDirectory(path);
                fileInfo = new DirectoryInfo(path);

                if (!fileInfo.Exists)
                {
                    throw new IOException("Path not created: " + path);
                }

                isNew = true;
            }

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null)
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
                    DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
                    Path = path
                };

                isNew = true;
            }

            item.ChannelType = channelInfo.ChannelType;
            item.ProviderImageUrl = channelInfo.ImageUrl;
            item.HasProviderImage = channelInfo.HasImage;
            item.ProviderImagePath = channelInfo.ImagePath;
            item.ExternalId = channelInfo.Id;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            // Set this now so we don't cause additional file system access during provider executions
            item.ResetResolveArgs(fileInfo);

            await item.RefreshMetadata(cancellationToken, forceSave: isNew, resetResolveArgs: false);

            return item;
        }
 private ILiveTvService GetService(ChannelInfo channel)
 {
     return _services.FirstOrDefault(i => string.Equals(channel.ServiceName, i.Name, StringComparison.OrdinalIgnoreCase));
 }
        private async Task<Channel> GetChannel(ChannelInfo channelInfo, CancellationToken cancellationToken)
        {
            var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.ServiceName), _fileSystem.GetValidFilename(channelInfo.Name));

            var fileInfo = new DirectoryInfo(path);

            var isNew = false;

            if (!fileInfo.Exists)
            {
                Directory.CreateDirectory(path);
                fileInfo = new DirectoryInfo(path);

                if (!fileInfo.Exists)
                {
                    throw new IOException("Path not created: " + path);
                }

                isNew = true;
            }

            var type = typeof(Channel);

            var id = (path + channelInfo.Number).GetMBId(type);

            var item = _itemRepo.RetrieveItem(id) as Channel;

            if (item == null)
            {
                item = new Channel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
                    DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
                    Path = path,
                    ChannelId = channelInfo.Id,
                    ChannelNumber = channelInfo.Number,
                    ServiceName = channelInfo.ServiceName
                };

                isNew = true;
            }

            // Set this now so we don't cause additional file system access during provider executions
            item.ResetResolveArgs(fileInfo);

            await item.RefreshMetadata(cancellationToken, forceSave: isNew, resetResolveArgs: false);

            return item;
        }
        public Task<IEnumerable<ChannelInfo>> buildChannelInfos(CancellationToken cancellationToken)
        {
            return Task.Factory.StartNew<IEnumerable<ChannelInfo>>(() =>
            {
                lock (_data)
                {
                    List<ChannelInfo> result = new List<ChannelInfo>();
                    foreach (KeyValuePair<int, HTSMessage> entry in _data)
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos, call canceled - returning part list.");
                            return result;
                        }

                        HTSMessage m = entry.Value;

                        ChannelInfo ci = new ChannelInfo();
                        ci.Id = "" + entry.Key;

                        ci.ImagePath = "";

                        if (m.containsField("channelIcon"))
                        {
                            string channelIcon = m.getString("channelIcon");
                            Uri uriResult;
                            bool uriCheckResult = Uri.TryCreate(channelIcon, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp;
                            if (uriCheckResult)
                            {
                                ci.ImageUrl = channelIcon;
                            }
                            else
                            {
                                _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos: channelIcon '" + channelIcon + "' is not a valid HTTP URL!");
                            }
                        }
                        if (m.containsField("channelName"))
                        {
                            string name = m.getString("channelName");
                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }
                            ci.Name = m.getString("channelName");
                        }

                        if (m.containsField("channelNumber"))
                        {
                            int chNo = m.getInt("channelNumber");
                            ci.Number = "" + chNo;
                        }

                        if (m.containsField("services"))
                        {
                            IList tunerInfoList = m.getList("services");
                            HTSMessage firstServiceInList = (HTSMessage)tunerInfoList[0];
                            if (firstServiceInList.containsField("type"))
                            {
                                string type = firstServiceInList.getString("type");

                                switch (type)
                                {
                                    case "Radio":
                                        ci.ChannelType = ChannelType.Radio;
                                        //continue;
                                        break;
                                    case "SDTV":
                                    case "HDTV":
                                        ci.ChannelType = ChannelType.TV;
                                        break;
                                    default:
                                        _logger.Error("[TVHclient] ChannelDataHelper: unkown service type '" + type + "'.");
                                        break;
                                }
                            }
                        }
                        else
                        {
                            _logger.Error("[TVHclient] ChannelDataHelper: unable to detect service-type from service list:" + m.ToString());
                            continue;
                        }
                        result.Add(ci);
                    }
                    return result;
                }
            });
        }
        /// <summary>
        /// Gets the channels async.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{List<ChannelInfo>}.</returns>
        public async Task<List<ChannelInfo>> GetChannelsForTVBouquetAsync(CancellationToken cancellationToken, String sRef)
        {
            _logger.Info("[VuPlus] Start GetChannelsForTVBouquetAsync, retrieve all channels for TV Bouquet " + sRef);
            await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);

            var protocol = "http";
            if (Plugin.Instance.Configuration.UseSecureHTTPS)
                protocol = "https";

            var baseUrl = protocol + "://" + Plugin.Instance.Configuration.HostName + ":" + Plugin.Instance.Configuration.WebInterfacePort;

            var baseUrlPicon = protocol + "://" + Plugin.Instance.Configuration.WebInterfaceUsername + ":" + Plugin.Instance.Configuration.WebInterfacePassword + "@" + Plugin.Instance.Configuration.HostName + ":" + Plugin.Instance.Configuration.WebInterfacePort;

            var url = string.Format("{0}/web/getservices?sRef={1}", baseUrl, sRef);

            UtilsHelper.DebugInformation(_logger, string.Format("[VuPlus] GetChannelsForTVBouquetAsync url: {0}", url));

            var options = new HttpRequestOptions
            {
                CancellationToken = cancellationToken,
                Url = url,
                UserAgent = "vuplus-pvraddon-agent/1.0"
            };

            if (!string.IsNullOrEmpty(Plugin.Instance.Configuration.WebInterfaceUsername))
            {
                string authInfo = Plugin.Instance.Configuration.WebInterfaceUsername + ":" + Plugin.Instance.Configuration.WebInterfacePassword;
                authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
                options.RequestHeaders["Authorization"] = "Basic " + authInfo;

                baseUrlPicon = protocol + "://" + Plugin.Instance.Configuration.WebInterfaceUsername + ":" + Plugin.Instance.Configuration.WebInterfacePassword + "@" + Plugin.Instance.Configuration.HostName + ":" + Plugin.Instance.Configuration.WebInterfacePort;

            }

            using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    string xmlResponse = reader.ReadToEnd();
                    UtilsHelper.DebugInformation(_logger, string.Format("[VuPlus] GetChannelsForTVBouquetAsync response: {0}", xmlResponse));

                    try
                    {
                        var xml = new XmlDocument();
                        xml.LoadXml(xmlResponse);

                        List<ChannelInfo> channelInfos = new List<ChannelInfo>();

                        // Load channels for specified TV Bouquet only

                        int count = 1;

                        XmlNodeList e2services = xml.GetElementsByTagName("e2service");
                        foreach (XmlNode xmlNode in e2services)
                        {
                            var channelInfo = new ChannelInfo();

                            var e2servicereference = "?";
                            var e2servicename = "?";

                            foreach (XmlNode node in xmlNode.ChildNodes)
                            {
                                if (node.Name == "e2servicereference")
                                {
                                    e2servicereference = node.InnerText;
                                }
                                else if (node.Name == "e2servicename")
                                {
                                    e2servicename = node.InnerText;
                                }
                            }

                            // Check whether the current element is not just a label
                            if (!e2servicereference.StartsWith("1:64:"))
                            {
                                //check for radio channel
                                if (e2servicereference.Contains("radio"))
                                    channelInfo.ChannelType = ChannelType.Radio;
                                else
                                    channelInfo.ChannelType = ChannelType.TV;

                                channelInfo.HasImage = true;
                                channelInfo.Id = e2servicereference;

                                // image name is name is e2servicereference with last char removed, then replace all : with _, then add .png
                                var imageName = e2servicereference.Remove(e2servicereference.Length - 1);
                                imageName = imageName.Replace(":", "_");
                                imageName = imageName + ".png";
                                //var imageUrl = string.Format("{0}/picon/{1}", baseUrl, imageName);
                                var imageUrl = string.Format("{0}/picon/{1}", baseUrlPicon, imageName);

                                if (Plugin.Instance.Configuration.FetchPiconsFromWebInterface)
                                {
                                    channelInfo.ImagePath = null;
                                    //channelInfo.ImageUrl = WebUtility.UrlEncode(imageUrl);
                                    channelInfo.ImageUrl = imageUrl;
                                }
                                else
                                {
                                    channelInfo.ImagePath = Plugin.Instance.Configuration.PiconsPath + imageName;
                                    channelInfo.ImageUrl = null;
                                }

                                channelInfo.Name = e2servicename;
                                channelInfo.Number = count.ToString();

                                channelInfos.Add(channelInfo);
                                count = count + 1;
                            }
                            else
                            {
                                UtilsHelper.DebugInformation(_logger, string.Format("[VuPlus] ignoring channel {0}", e2servicereference));
                            }
                        }
                        return channelInfos;
                    }
                    catch (Exception e)
                    {
                        _logger.Error("[VuPlus] Failed to parse channel information.");
                        _logger.Error(string.Format("[VuPlus] GetChannelsForTVBouquetAsync error: {0}", e.Message));
                        throw new ApplicationException("Failed to parse channel information.");
                    }
                }
            }
        }
        /// <summary>
        /// Checks connection to VuPlus and retrieves service reference for channel if only one bouquet.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="tvBouquet">The TV Bouquet.</param>
        /// <returns>Task{String>}.</returns>
        public async Task<String> InitiateSession(CancellationToken cancellationToken, String tvBouquet)
        {
            _logger.Info("[VuPlus] Start InitiateSession, validates connection and returns Bouquet reference if required");
            //await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);

            var protocol = "http";
            if (Plugin.Instance.Configuration.UseSecureHTTPS)
                protocol = "https";

            var baseUrl = protocol + "://" + Plugin.Instance.Configuration.HostName + ":" + Plugin.Instance.Configuration.WebInterfacePort;

            var url = string.Format("{0}/web/getservices", baseUrl);
            UtilsHelper.DebugInformation(_logger, string.Format("[VuPlus] InitiateSession url: {0}", url));

            var options = new HttpRequestOptions
            {
                CancellationToken = cancellationToken,
                Url = url,
            };

            if (!string.IsNullOrEmpty(Plugin.Instance.Configuration.WebInterfaceUsername))
            {
                string authInfo = Plugin.Instance.Configuration.WebInterfaceUsername + ":" + Plugin.Instance.Configuration.WebInterfacePassword;
                authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
                options.RequestHeaders["Authorization"] = "Basic " + authInfo;
            }

            using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    string xmlResponse = reader.ReadToEnd();
                    UtilsHelper.DebugInformation(_logger, string.Format("[VuPlus] InitiateSession response: {0}", xmlResponse));

                    try
                    {
                        var xml = new XmlDocument();
                        xml.LoadXml(xmlResponse);

                        String tvBouquetReference = null;

                        XmlNodeList e2services = xml.GetElementsByTagName("e2service");

                        // If TV Bouquet passed find associated service reference
                        if (!string.IsNullOrEmpty(tvBouquet))
                        {
                            foreach (XmlNode xmlNode in e2services)
                            {
                                var channelInfo = new ChannelInfo();

                                var e2servicereference = "?";
                                var e2servicename = "?";

                                foreach (XmlNode node in xmlNode.ChildNodes)
                                {
                                    if (node.Name == "e2servicereference")
                                    {
                                        e2servicereference = node.InnerText;
                                    }
                                    else if (node.Name == "e2servicename")
                                    {
                                        e2servicename = node.InnerText;
                                    }
                                }
                                if (tvBouquet == e2servicename)
                                {
                                    tvBouquetReference = e2servicereference;
                                    return tvBouquetReference;
                                }
                            }
                            // make sure we have found the TV Bouquet
                            if (!string.IsNullOrEmpty(tvBouquet))
                            {
                                _logger.Error("[VuPlus] Failed to find TV Bouquet specified in VuPlus configuration.");
                                throw new ApplicationException("Failed to find TV Bouquet specified in VuPlus configuration.");
                            }
                        }
                        return tvBouquetReference;
                    }
                    catch (Exception e)
                    {
                        _logger.Error("[VuPlus] Failed to parse services information.");
                        _logger.Error(string.Format("[VuPlus] InitiateSession error: {0}", e.Message));
                        throw new ApplicationException("Failed to connect to VuPlus.");
                    }

                }
            }
        }