Пример #1
0
 /// <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();
 }
Пример #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("-D - delete storage");
            Console.WriteLine("-P - show storage");

            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;

                Console.WriteLine(String.Format("┌─────┬────────────────────────────────────────────────────────────┬──────────┐"));
                Console.WriteLine(String.Format("│{0, 5}│{1, -60}│{1, -10}│", "id", "url", "tip"));

                Console.WriteLine(String.Format("├─────┼────────────────────────────────────────────────────────────┼──────────┤"));

                foreach (KeyValuePair <string, string> link in links)
                {
                    Console.WriteLine("│{0, 5}│{1, -60}│{2, -10}│", id, link.Key, myController.getType(link.Key));
                    id++;
                }
                Console.WriteLine(String.Format("└─────┴────────────────────────────────────────────────────────────┴──────────┘"));
                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 type = myController.getType(_url);
                    if (type == "link/other")
                    {
                        myModel = myController.newPage(_id);
                        try
                        {
                            myController.storage.page.noUsed--;
                        }
                        catch
                        {
                        }

                        myModel.loadTime = DateTime.Now;
                        timer.Stop();
                        reloadController();
                    }
                    else if (type == "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("Error!");
                                    }
                                }
                            }
                        }
                        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 'D':
                myController.cleanStorage();
                break;

            case 'P':
                showStorage();
                break;

            case 'Q':
                return;
            }
            this.commands();
        }