예제 #1
0
파일: TvForm.cs 프로젝트: ldj-droid/FoxIPTV
        /// <summary>The LibVLC EncounteredError event handler</summary>
        /// <param name="sender">The object that triggered the event</param>
        /// <param name="e">The event arguments</param>
        private void VlcControl_EncounteredError(object sender, VlcMediaPlayerEncounteredErrorEventArgs e)
        {
            TvCore.LogError($"[.NET] VlcControl_EncounteredError({e})");

            this.InvokeIfRequired(() =>
            {
                SetErrorState();
                playerStatusLabel.Text = Resources.TvForm_Error;
            });
        }
예제 #2
0
        /// <summary>A <see cref="Button"/> click handler, used to remove a favorite from the favorite channels list</summary>
        /// <param name="sender">The sender of this event</param>
        /// <param name="e">The event arguments</param>
        private void ButtonFavoriteRemove_Click(object sender, EventArgs e)
        {
            var channelIdx = int.Parse(treeViewFavoriteChannels.SelectedNode.Name);

            var channel = TvCore.Channels.Find(x => x.Index == TvCore.ChannelIndexList[channelIdx]);

            if (channel == null)
            {
                TvCore.LogError("[.NET] Channel was not found when removing a favorite channel");
                return;
            }

            TvCore.RemoveFavoriteChannel(channel.Id);

            LoadAll();
        }
예제 #3
0
        public async Task <bool> IsAuthenticated()
        {
            TvCore.LogDebug($"[{Title}] IsAuthenticated() called...");

            var authDataFile = Path.Combine(TvCore.UserStoragePath, ServiceDataFilename);

            Uri domainUri = null;

            Uri authUrl;

            if (!File.Exists(authDataFile))
            {
                TvCore.LogDebug($"[{Title}] IsAuthenticated(): No authentication file found...");

                if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password) || string.IsNullOrWhiteSpace(Services))
                {
                    TvCore.LogError($"[{Title}] IsAuthenticated(): Username/Password/ServiceURL is empty");

                    return(false);
                }

                if (!Uri.IsWellFormedUriString(Services, UriKind.Absolute))
                {
                    TvCore.LogError($"[{Title}] IsAuthenticated(): ServiceURL is not a well formed link");

                    return(false);
                }

                domainUri = new Uri(Services);

                authUrl = new Uri($"http://{domainUri.DnsSafeHost}/{string.Format(AuthenticationUrl, Username, Password)}");

                SaveAuthentication = true;
            }
            else
            {
                _authData = JsonConvert.DeserializeObject <AuthResponse>(File.ReadAllText(authDataFile).Unprotect());

                authUrl = new Uri(BuildUri(AuthenticationUrl));
            }

            TvCore.LogDebug($"[{Title}] IsAuthenticated(): Checking server authentication...");

            using (var wc = new WebClient())
            {
                wc.Headers.Add("user-agent", TvCore.ServiceUserAgentString);

                try
                {
                    var data = await wc.DownloadStringTaskAsync(authUrl);

                    _authData = JsonConvert.DeserializeObject <AuthResponse>(data);

                    _authData.Server.UserUrl  = domainUri?.DnsSafeHost ?? string.Empty;
                    _authData.Server.UserPort = domainUri?.Port ?? 0;

                    TvCore.LogDebug($"[{Title}] IsAuthenticated(): Checking server connection SUCCESS! IsAuthenticated: {_authData.User.Authenticated}");
                }
                catch (Exception ex)
                {
                    TvCore.LogError($"[{Title}] IsAuthenticated(): Checking server authentication ERROR: {ex.Message}");

                    return(false);
                }
            }

            if (_authData == null)
            {
                return(false);
            }

            if (_authData.User.Authenticated != 1)
            {
                return(false);
            }

            TvCore.LogDebug($"[{Title}] IsAuthenticated(): Server authentication SUCCESS! Server address: {_authData.Server.Url}");

            if (!SaveAuthentication)
            {
                TvCore.LogDebug($"[{Title}] IsAuthenticated(): Not Saving User Authentication...");

                TvCore.LogInfo($"[{Title}] Log-in successful");

                return(true);
            }

            TvCore.LogDebug($"[{Title}] IsAuthenticated(): Saving auth data...");

            File.WriteAllText(authDataFile, JsonConvert.SerializeObject(_authData).Protect());

            TvCore.LogInfo($"[{Title}] Log-in successful");

            return(true);
        }