/// <summary>
 /// Reloads the links manual.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param>
 public void reloadLinksManual(object source, ElapsedEventArgs e)
 {
     //Console.Write("{0}", (char)1);
     myModel.updateLinksManual();
 }
Exemple #2
0
        /// <summary>
        /// Commandses this instance.
        /// </summary>
        public void commands()
        {
            Console.WriteLine("Commands:");
            Console.WriteLine("-B - print number of links");
            Console.WriteLine("-I - print link by number");
            Console.WriteLine("-J n - go to link by number");
            Console.WriteLine("-R - refresh current web page");
            Console.WriteLine("-S - print work statistics");
            Console.WriteLine("-U - print current URL");

            Console.WriteLine("-A - back to previous page");

            Console.WriteLine("-Q - quit");
            string command = Console.ReadLine();

            if (command.Length < 2)
            {
                this.commands();
            }
            switch (command[1])
            {
            case 'B':
                Console.WriteLine("Number of links: " + myController.numLinks());
                break;

            case 'I':
                List <KeyValuePair <string, string> > links = myController.getURLs();
                int id = 0;
                foreach (KeyValuePair <string, string> link in links)
                {
                    Console.WriteLine("ID: " + id + "\tURL: " + link.Key);
                    Console.WriteLine("Type: " + myController.getType(link.Key));
                    id++;
                }
                break;

            case 'J':
                string[] commands = command.Split(' ');
                int      _id;
                if (commands.Length == 1)
                {
                    break;
                }
                if (int.TryParse(commands[1], out _id))
                {
                    string _url = myController.getURL(_id);
                    string tip  = myController.getType(_url);
                    if (tip == "link/other")
                    {
                        myModel          = myController.newPage(_id);
                        myModel.loadTime = DateTime.Now;
                        timer.Stop();
                        reloadController();
                    }
                    else if (tip == "email")
                    {
                        Process.Start(_url);
                    }
                    else
                    {
                        try
                        {
                            var request = System.Net.WebRequest.Create(_url);
                            using (var response = request.GetResponse())
                            {
                                Console.WriteLine("Name: " + Path.GetFileName(_url));
                                Console.WriteLine("Type " + response.ContentType);
                                Console.WriteLine("Size: " + response.ContentLength);
                                Console.WriteLine("Open? (y for yes) [no]");
                                string key = Console.ReadLine();
                                if (key == "y")
                                {
                                    try
                                    {
                                        WebClient client = new WebClient();
                                        Uri       uri    = new Uri(_url);
                                        client.DownloadFile(uri, Path.GetFileName(uri.LocalPath));
                                        Process.Start(Path.GetFileName(uri.LocalPath));
                                    }
                                    catch
                                    {
                                        Console.WriteLine("Greška!");
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error during parsing!");
                    break;
                }
                break;

            case 'A':
                myModel = myController.goBack();
                timer.Stop();
                reloadController();
                break;

            case 'R':
                myModel.updateLinksManual();
                break;

            case 'S':
                Console.WriteLine("Previous opened pages: ");
                myController.showStatistics();
                Console.WriteLine("Current opened page: " + this.myModel.url);
                Console.WriteLine("Waiting time: " + (myModel.VisitTime + DateTime.Now.Subtract(myModel.loadTime).Seconds));
                Console.WriteLine("Number of manual refresh: " + myModel.ReloadTimesManual);
                Console.WriteLine("Number of automatic refresh: " + myModel.ReloadTimesAuto);
                Console.WriteLine("Number of changes on the page: " + myModel.noChanges);

                break;

            case 'U':
                Console.WriteLine(myModel.url);
                break;

            case 'Q':
                return;
            }
            this.commands();
        }
Exemple #3
0
        /// <summary>
        /// Commandses this instance.
        /// </summary>
        public void commands()
        {
            Console.WriteLine("Commands:");
            Console.WriteLine("-B - print number of links");
            Console.WriteLine("-I - print link by number");
            Console.WriteLine("-J n - go to link by number");
            Console.WriteLine("-R - refresh current web page");
            Console.WriteLine("-S - print work statistics");
            Console.WriteLine("-U - print current URL");

            Console.WriteLine("-A - back to previous page");

            Console.WriteLine("-Q - quit");
            string command = Console.ReadLine();
            if (command.Length < 2)
                this.commands();
            switch (command[1])
            {
                case 'B':
                    Console.WriteLine("Number of links: " + myController.numLinks());
                    break;
                case 'I':
                    List<KeyValuePair<string, string>> links = myController.getURLs();
                    int id = 0;
                    foreach (KeyValuePair<string, string> link in links)
                    {
                        Console.WriteLine("ID: " + id + "\tURL: " + link.Key);
                        Console.WriteLine("Type: " + myController.getType(link.Key));
                        id++;
                    }
                    break;
                case 'J':
                    string[] commands = command.Split(' ');
                    int _id;
                    if (commands.Length == 1)
                        break;
                    if (int.TryParse(commands[1], out _id))
                    {
                        string _url = myController.getURL(_id);
                        string tip = myController.getType(_url);
                        if (tip == "link/other")
                        {
                            myModel = myController.newPage(_id);
                            myModel.loadTime = DateTime.Now;
                            timer.Stop();
                            reloadController();
                        }
                        else if (tip == "email")
                        {
                            Process.Start(_url);
                        }
                        else
                            try
                            {
                                var request = System.Net.WebRequest.Create(_url);
                                using (var response = request.GetResponse())
                                {
                                    Console.WriteLine("Name: " + Path.GetFileName(_url));
                                    Console.WriteLine("Type " + response.ContentType);
                                    Console.WriteLine("Size: " + response.ContentLength);
                                    Console.WriteLine("Open? (y for yes) [no]");
                                    string key = Console.ReadLine();
                                    if (key == "y")
                                    {
                                        try
                                        {
                                            WebClient client = new WebClient();
                                            Uri uri = new Uri(_url);
                                            client.DownloadFile(uri, Path.GetFileName(uri.LocalPath));
                                            Process.Start(Path.GetFileName(uri.LocalPath));

                                        }
                                        catch
                                        {
                                            Console.WriteLine("Greška!");
                                        }
                                    }

                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                    }
                    else
                    {
                        Console.WriteLine("Error during parsing!");
                        break;
                    }
                    break;
                case 'A':
                    myModel = myController.goBack();
                    timer.Stop();
                    reloadController();
                    break;
                case 'R':
                    myModel.updateLinksManual();
                    break;
                case 'S':
                    Console.WriteLine("Previous opened pages: ");
                    myController.showStatistics();
                    Console.WriteLine("Current opened page: " + this.myModel.url);
                    Console.WriteLine("Waiting time: " + (myModel.VisitTime + DateTime.Now.Subtract(myModel.loadTime).Seconds));
                    Console.WriteLine("Number of manual refresh: " + myModel.ReloadTimesManual);
                    Console.WriteLine("Number of automatic refresh: " + myModel.ReloadTimesAuto);
                    Console.WriteLine("Number of changes on the page: " + myModel.noChanges);

                    break;
                case 'U':
                    Console.WriteLine(myModel.url);
                    break;
                case 'Q':
                    return;
            }
            this.commands();
        }