示例#1
0
        public void NewPage(string url)
        {
            Page page = new Page
            {
                url = url,
                addedDateTime = DateTime.Now,
                lastUsedDateTime = DateTime.Now,
                noUsed = 0
            };
            StringBuilder storageNameBuilder = new StringBuilder();
            storageNameBuilder.Append(path);
            Uri uri = new Uri(url);
            
            string filename = System.IO.Path.GetFileName(uri.LocalPath);
            storageNameBuilder.Append("\\page_");
            storageNameBuilder.Append(uri.Host);
            storageNameBuilder.Append("_");
            storageNameBuilder.Append(System.IO.Path.GetFileName(uri.LocalPath));
            page.localStorageName = storageNameBuilder.ToString();

            HtmlWeb hw = new HtmlWeb();

            HtmlDocument document = hw.Load(url);
            FileStream fs = File.OpenWrite(page.localStorageName);
            StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
            
            document.Save(writer);
            
            this.Size += fs.Length;
            page.size = fs.Length;
            
            writer.Close();
            fs.Close();

            
            while((this.Pages != null) && ((MaxSize < this.Size) || (MaxPageNum < this.Pages.Count)) && (this.Pages.Count >= 1))
            if (this.isNS)
            {
                this.Pages = this.Pages.OrderByDescending(x => x.addedDateTime).ToList();
                this.Size -= this.Pages[0].size;
                File.Delete(this.Pages[0].localStorageName);
                DnevnikRada.add("Deleted page " + this.Pages[0].url + " in " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + ". Used " + this.Pages[0].noUsed + " times, loaded " + this.Pages[0].addedDateTime + ". Last time loaded at: " + this.Pages[0].lastUsedDateTime);
                Console.WriteLine("Deleted page " + this.Pages[0].url + " in " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + ". Used " + this.Pages[0].noUsed + " times, loaded " + this.Pages[0].addedDateTime + ". Last time loaded at: " + this.Pages[0].lastUsedDateTime);
                this.Pages.Remove(this.Pages[0]);
            }
            else
            {
                this.Pages = this.Pages.OrderByDescending(x => x.noUsed).ToList();
                this.Size--;
                File.Delete(this.Pages[0].localStorageName);
                DnevnikRada.add("Deleted page " + this.Pages[0].url + " in " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + ". Used " + this.Pages[0].noUsed + " times during " + DateTime.Now.Subtract(this.Pages[0].addedDateTime).Seconds.ToString(CultureInfo.InvariantCulture) + " seconds, loaded " + this.Pages[0].addedDateTime + ". Last time loaded at: " + this.Pages[0].lastUsedDateTime);
                Console.WriteLine("Deleted page " + this.Pages[0].url + " in " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + ". Used " + this.Pages[0].noUsed + " times, loaded " + this.Pages[0].addedDateTime + ". Last time loaded at: " + this.Pages[0].lastUsedDateTime);
                this.Pages.Remove(this.Pages[0]);
            }
            
            this.Pages.Add(page);
            this.page = page;

            DnevnikRada.add("Loaded page " + url + " u " + DateTime.Now.ToString(CultureInfo.InvariantCulture));
        }
        /// <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;
        }
示例#3
0
        public MVC_Model(Page page, string old_url)
        {
            this.url = page.url;
            this.local_url = page.localStorageName;
            this.old_url = old_url;
            this.isLocal = true;

            init();
        }
示例#4
0
        public Storage(SerializationInfo info, StreamingContext ctxt)
        {
            this.Pages = (List<Page>) info.GetValue("Pages", typeof (List<Page>));
            this.page = (Page) info.GetValue("page", typeof (Page));
            this.Size = (long) info.GetValue("Size", typeof (long));
            this.MaxSize = (long) info.GetValue("MaxSize", typeof (long));
            this.MaxPageNum = (long) info.GetValue("MaxPageNum", typeof (long));
            this.isNS = (bool) info.GetValue("isNS", typeof (bool));
            this.path = (string) info.GetValue("path", typeof (string));

        }
示例#5
0
 public Page GetPage(string url)
 {
     if (Pages == null)
         return null;
     foreach(Page page in Pages)
     {
         if (page.url == url)
         {
             this.page = page;
             page.noUsed++;
             page.lastUsedDateTime = DateTime.Now;
             return page;
         }
     }
     this.page = null;
     return null;
 }
示例#6
0
        public void Use(string url)
        {
            Page page = GetPage(url);
            page.lastUsedDateTime = DateTime.Now;
            page.noUsed++;
            this.page = page;

        }