示例#1
0
文件: Program.cs 项目: j4kim/Flan411
        private static string auth()
        {
            //var task = TvMazeService.Search("The walking dead");

            Console.Write("User: "******"Password: ");
            string pwd = null;

            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Enter)
                {
                    break;
                }
                pwd += key.KeyChar;
            }
            Console.WriteLine();

            User user = T411Service.AuthenticateUser(userName, pwd).Result;

            if (user == null)
            {
                return(null);
            }
            return(user.Token);
        }
示例#2
0
        private async void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            if (searchInput.Text == "")
            {
                return;
            }
            DisplayInformationMessage("Waiting for results...");

            List <Torrent> torrentsList;

            try
            {
                torrentsList = await T411Service.Search(searchInput.Text);
            }
            catch (JsonSerializationException error)
            {
                Console.WriteLine(error.Message);
                torrentsList = new List <Torrent>();
            }


            if (torrentsList.Count > 0)
            {
                torrentListView.TorrentList = torrentsList;
                torrentListView.Sort();
                DisplayTorrentsList();
            }
            else
            {
                DisplayInformationMessage("No torrents found.");
            }
        }
示例#3
0
文件: Program.cs 项目: j4kim/Flan411
        private static void t411()
        {
            if (!T411Service.VerifyToken())
            {
                auth();
            }

            while (true)
            {
                Console.Write("Search: ");
                string pattern = Console.ReadLine();

                var task = T411Service.Search(pattern, 10, T411Service.CID_SERIES);
                try
                {
                    task.Wait();
                }catch (Exception e)
                {
                    Console.WriteLine(e.InnerException.Message);
                    auth();
                    continue;
                }

                List <Torrent> results = task.Result;

                Console.WriteLine("Results: ");
                foreach (var t in results)
                {
                    Console.WriteLine($"{t.Id} : {t.Name}");
                }
                Console.WriteLine("---");
            }
        }
示例#4
0
        private async void dlButton_Click(object sender, RoutedEventArgs e)
        {
            String normalizeFileName = String.Join("_", torrent.Name.Split(PATH_INVALID_CHARS, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');

            normalizeFileName += FILE_EXTENSION;
            Console.WriteLine(normalizeFileName);
            Console.WriteLine($"Downloading torrent having id {torrent.Id}");
            try
            {
                String savedFileName = await T411Service.Download(Convert.ToInt64(torrent.Id), normalizeFileName);

                if (savedFileName != String.Empty)
                {
                    System.Diagnostics.Process.Start(savedFileName);
                }
                else
                {
                    MessageBox.Show("An error occured during either the torrent file download or opening.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception error)
            {
                MessageBox.Show($"{error.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);;
            }
        }
示例#5
0
        private async void setContent(Torrent torrent)
        {
            wb.NavigateToString("Description downloading...");
            TorrentDetail details = await T411Service.Details(int.Parse(torrent.Id));

            wb.NavigateToString(details.Description);
        }
示例#6
0
        /// <summary>
        /// Login to T411 API. Sets the credentials in the current application's properties.
        /// A User object is returned if the authentication was successful.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <User> Login(string userName, string password)
        {
            User user = null;

            if (NavigationViewModel == null)
            {
                // DEBUG
                {
                    throw new Exception($"Error::no NavigationViewModel accessible");
                }
            }


            try
            {
                user = await T411Service.AuthenticateUser(userName, password);

                if (user != null)
                {
                    // Update user's information to share it with other views
                    Application.Current.Properties["UserName"] = user.UserName;
                    Application.Current.Properties["Password"] = user.Password;
                    Application.Current.Properties["Token"]    = user.Token;
                    Application.Current.Properties["Uid"]      = user.Uid;

                    // DEBUG
                    {
                        string className   = this.GetType().Name;
                        string methodeName = new StackTrace().GetFrame(1).GetMethod().Name;
                        Console.WriteLine($"{className}::{methodeName} Token from properties: {Application.Current.Properties["Token"]}");
                        Console.WriteLine($"Your token: {user.Token}", "Authentication successful");
                    }

                    // Switch to next view if login is successful (might be DANGEROUS to put it here)
                    NavigationViewModel.SelectedViewModel = new SearchViewModel();
                }
                else
                {
                    // DEBUG
                    {
                        Console.WriteLine("Username or password might be incorrect", "Authentication failed");
                    }
                }
            }
            catch (HttpRequestException httpError)
            {
                // DEBUG
                {
                    Console.WriteLine($"{httpError.Message}", "Connection to remote server failed");
                }
            }

            return(user);
        }
示例#7
0
        public MainWindow()
        {
            InitializeComponent();
            base.DataContext = new NavigationViewModel();
            NavigationViewModel navigationViewModel = base.DataContext as NavigationViewModel;

            /*
             * DEBUG: for navigation only. We need to verify if user already authenticated once
             * (check if the credentials are present in a configuration file or a registry ...)
             * if no credentials are found selectedViweModel = LoginViewModel. Else,
             * selectedViweModel = SearchViewModel.
             **/
            if (!T411Service.VerifyToken())
            {
                navigationViewModel.SelectedViewModel = new LoginViewModel(navigationViewModel);
            }
            else
            {
                navigationViewModel.SelectedViewModel = new SearchViewModel();
            }
        }