/// <summary>
        /// Initializes the specified my model.
        /// </summary>
        /// <param name="myModel">My model.</param>
        /// <param name="myView">My view.</param>
        /// <returns><c>true</c> if success, <c>false</c> otherwise.</returns>
        public bool initialize(MVC_Model myModel, MVC_View myView)
        {
            this.myModel = myModel;
            this.myView  = myView;

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Initializes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns><c>true</c> if success, <c>false</c> otherwise.</returns>
        public bool initialize(MVC_Model model)
        {
            this.myModel = model;
            makeController();

            this.commands();
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Initializes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns><c>true</c> if success, <c>false</c> otherwise.</returns>
        public bool initialize(MVC_Model model)
        {
            this.myModel = model;
            makeController();

            this.commands();
            return true;
        }
        /// <summary>
        /// Initializes the specified my model.
        /// </summary>
        /// <param name="myModel">My model.</param>
        /// <param name="myView">My view.</param>
        /// <returns><c>true</c> if success, <c>false</c> otherwise.</returns>
        public bool initialize(MVC_Model myModel, MVC_View myView)
        {

            this.myModel = myModel;
            this.myView = myView;

            return true;
        }
Exemple #5
0
        /// <summary>
        /// Gets the memento.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>MVC_Model.</returns>
        public MVC_Model getMemento(int id)
        {
            MVC_Model model = new MVC_Model(Mementos[id].url, Mementos[id].old_url);

            model.ReloadTimesManual = Mementos[id].ReloadTimesManual;
            model.ReloadTimesAuto   = Mementos[id].ReloadTimesAuto;
            model.VisitTime         = Mementos[id].VisitTime;
            return(model);
        }
        /// <summary>
        /// Goes the back.
        /// </summary>
        /// <returns>MVC_Model.</returns>
        public MVC_Model goBack()
        {
            if (this.caretaker.Mementos.Count == 0)
            {
                return(myModel);
            }

            this.saveMemento();

            myModel = this.getModel(this.caretaker.Mementos.Count - 2);

            return(myModel);
        }
Exemple #7
0
        /// <summary>
        /// Saves the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        public void Save(MVC_Model model)
        {
            this.Links      = new List <HtmlNode>();
            this.doc        = new HtmlDocument();
            this.loadTime   = new DateTime();
            this.accessTime = new DateTime();

            this.Links             = model.Links;
            this.doc               = model.doc;
            this.loadTime          = model.loadTime;
            this.VisitTime         = model.VisitTime;
            this.url               = model.url;
            this.accessTime        = model.accessTime;
            this.ReloadTimesManual = model.ReloadTimesManual;
            this.ReloadTimesAuto   = model.ReloadTimesAuto;
            this.old_url           = model.old_url;
            this.noChange          = model.noChanges;
            this.size              = model.size;
        }
Exemple #8
0
        /// <summary>
        /// Saves the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        public void Save(MVC_Model model)
        {
            this.Links = new List<HtmlNode>();
            this.doc = new HtmlDocument();
            this.loadTime = new DateTime();
            this.accessTime = new DateTime();

            this.Links = model.Links;
            this.doc = model.doc;
            this.loadTime = model.loadTime;
            this.VisitTime = model.VisitTime;
            this.url = model.url;
            this.accessTime = model.accessTime;
            this.ReloadTimesManual = model.ReloadTimesManual;
            this.ReloadTimesAuto = model.ReloadTimesAuto;
            this.old_url = model.old_url;
            this.noChange = model.noChanges;
            this.size = model.size;
        }
        /// <summary>
        /// News the page.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>MVC_Model.</returns>
        public MVC_Model newPage(int id)
        {
            this.saveMemento();
            string old_url = myModel.url;
            string url     = this.getURL(id);

            if (url == null)
            {
                Console.WriteLine("Greška! Nema te oznake!");
                return(myModel);
            }
            int exist = this.checkIfExist(url);

            if (exist == 0)
            {
                myModel = new MVC_Model(url, old_url);
            }
            else
            {
                myModel = this.getModel(exist);
            }

            return(myModel);
        }
Exemple #10
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();
        }
        /// <summary>
        /// Goes the back.
        /// </summary>
        /// <returns>MVC_Model.</returns>
        public MVC_Model goBack()
        {
            if (this.caretaker.Mementos.Count == 0)
                return myModel;

            this.saveMemento();

            myModel = this.getModel(this.caretaker.Mementos.Count - 2);

            return myModel;
        }
        /// <summary>
        /// News the page.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>MVC_Model.</returns>
        public MVC_Model newPage(int id)
        {
            this.saveMemento();
            string old_url = myModel.url;
            string url = this.getURL(id);
            if (url == null)
            {
                Console.WriteLine("Greška! Nema te oznake!");
                return myModel;
            }
            int exist = this.checkIfExist(url);
            if (exist == 0)
                myModel = new MVC_Model(url, old_url);
            else
                myModel = this.getModel(exist);

            return myModel;
        }
Exemple #13
0
 /// <summary>
 /// Gets the memento.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>MVC_Model.</returns>
 public MVC_Model getMemento(int id)
 {
     MVC_Model model = new MVC_Model(Mementos[id].url, Mementos[id].old_url);
     model.ReloadTimesManual = Mementos[id].ReloadTimesManual;
     model.ReloadTimesAuto = Mementos[id].ReloadTimesAuto;
     model.VisitTime = Mementos[id].VisitTime;
     return model;
 }
Exemple #14
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();
        }