/// <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, long maxSize, bool isByte, bool isNS, bool isClean, string path) { this.myModel = model; makeController(maxSize, isByte, isNS, isClean, path); this.commands(); return true; }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { string url = args[0]; int sekunde; if (!int.TryParse(args[1], out sekunde)) return; /* http://www.rfc-editor.org/rfc/ */ MVC_Model myModel = new MVC_Model(url); MVC_View myView = new MVC_View(sekunde); myView.initialize(myModel); }
/// <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; }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { string url = args[0]; int sekunde; if (!int.TryParse(args[1], out sekunde)) { return; } /* * http://www.rfc-editor.org/rfc/ */ MVC_Model myModel = new MVC_Model(url); MVC_View myView = new MVC_View(sekunde); myView.initialize(myModel); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { string url = args[0]; string path = args[1]; int sekunde; if (!int.TryParse(args[2], out sekunde)) return; int maxSize; if (!int.TryParse(args[3], out maxSize)) return; bool isByte = args[4] == "KB"; bool isNS; bool isClean; if (isByte) { maxSize *= 1024; isNS = args[5] == "NS"; try { isClean = args[6] == "clean"; } catch { isClean = false; } } else { isNS = args[4] == "NS"; try { isClean = args[5] == "clean"; } catch { isClean = false; } } /* http://www.rfc-editor.org/rfc/ */ MVC_Model myModel; Storage storage; if (!isClean) { try { tdukaric_zadaca_3.storage.LoadStorage(); } catch { storage = new Storage(maxSize, isByte, isNS, path); tdukaric_zadaca_3.storage.SaveStorage(storage); } storage = tdukaric_zadaca_3.storage.LoadStorage(); Page page = storage.GetPage(url); if (page != null) myModel = new MVC_Model(page); else { myModel = new MVC_Model(url); } } else myModel = new MVC_Model(url); MVC_View myView = new MVC_View(sekunde); myView.initialize(myModel, maxSize, isByte, isNS, isClean, path); }
/// <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("Error! Type doesn't exist!"); return myModel; } Page page = storage.GetPage(url); if (page != null) { myModel = new MVC_Model(page, old_url); return myModel; } int exist = this.checkIfExist(url); Page existInstorage = storage.pageExist(url); if (exist == 0) myModel = new MVC_Model(url, old_url); else { myModel = this.getModel(exist); } return myModel; }
/// <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; activePage = storage.GetPage(myModel.url); if (activePage == null) { storage.NewPage(myModel.url); activePage = storage.GetPage(myModel.url); } SaveStorage(); return true; }
/// <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(); }