示例#1
0
        public FactKeyWithCells GetFactKeyWithCells(int index)
        {
            var result             = new FactKeyWithCells();
            FactKeyDictionary page = null;

            if (index >= LastPage.IndexStartAt && index < LastPage.IndexEndAt)
            {
                page = LastPage;
            }
            else
            {
                int pid = index / NrItemsPerPage;
                page     = this.Pages[pid];
                LastPage = page;
            }
            if (!page.IsLoaded)
            {
                //if (page.ID == 21)
                //{
                //}
                LoadPage(page);
            }
            if (page.LookupOfIndexes.ContainsKey(index))
            {
                result = page.LookupOfIndexes[index];
            }
            return(result);
        }
示例#2
0
        public void AddCellToFactUnsafe(FactKeyDictionary page, int index, int cellix)
        {
            FactsManager.FactsOfPages[index].Add(cellix);
            FactsManager.FactsOfPages.AddCellToFact(index, cellix);
            page.IsDirty = true;
            //if (index == 1100000)
            //{
            //    Console.WriteLine(Utilities.Converters.DateTimeToString(DateTime.Now, Utilities.Converters.DateTimeFormat) + ": " + "Adding "+index);

            //}
        }
示例#3
0
        public FactKeyDictionary CreatePage(PeristenceEnum peristence)
        {
            var page = new FactKeyDictionary();

            page.ID           = this.Pages.Count;
            page.NrMaxItems   = this.NrItemsPerPage;
            page.IndexStartAt = page.ID * page.NrMaxItems;
            page.IndexEndAt   = page.IndexStartAt + page.NrMaxItems;
            this.Pages.Add(page);
            page.PeristenceState = peristence;
            LastPage             = page;
            return(page);
        }
示例#4
0
        public FactKeyDictionary CreatePage()
        {
            Log("Creating Page " + this.Pages.Count);
            var page = new FactKeyDictionary();

            page.ID           = this.Pages.Count;
            page.NrMaxItems   = this.NrItemsPerPage;
            page.IndexStartAt = page.ID * page.NrMaxItems;
            page.IndexEndAt   = page.IndexStartAt + page.NrMaxItems;
            this.Pages.Add(page);
            AddIDToLoadedPages(page.ID);
            LastPage = page;
            return(page);
        }
示例#5
0
        private void Unload(FactKeyDictionary page)
        {
            page.PeristenceState = PeristenceEnum.Unloading;
            if (page.ID == 11)
            {
            }
            Log("UnLoading page" + page.ID);

            lock (page.Locker)
            {
                if (page.IsDirty)
                {
                    SaveToFS(page);
                }
                else
                {
                    page.Clear(Log);
                }
                RemoveIDFromLoadedPages(page.ID);
                page.PeristenceState = PeristenceEnum.Unloaded;
            }
        }
示例#6
0
        public void LoadPage(FactKeyDictionary page)
        {
            Log("Loading page" + page.ID);
            //Utilities.Logger.WriteLine("Loading page" + page.ID);
            page.PeristenceState = PeristenceEnum.Loading;
            var filepath = GetFilePath(page.ID);

            lock (page.Locker)
            {
                // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader(filepath))
                {
                    while (sr.Peek() >= 0)
                    {
                        String line = sr.ReadLine();
                        var    kv   = page.Save(line);
                    }
                    page.IsDirty = false;
                }
                // Read the stream to a string, and write the string to the console.


                page.PeristenceState = PeristenceEnum.Loaded;


                if (NrLoadedPages != 0 && LoadedPages.Count > NrLoadedPages)
                {
                    var ix = 0;
                    if (LoadedPages[ix] == page.ID)
                    {
                        ix++;
                    }
                    Unload(ix);
                }
                AddIDToLoadedPages(page.ID);
                LastPage = page;
            }
        }
示例#7
0
        //public object Locker = new Object();
        public void SaveToFS(FactKeyDictionary page, Boolean unload = true)
        {
            Task.Run(
                () =>
            {
                lock (page.Locker)
                {
                    var state            = page.PeristenceState;
                    page.PeristenceState = PeristenceEnum.Saving;
                    var msg = String.Format("Saveing page{0} to FS", page.ID);
                    Log(msg);
                    //Utilities.Logger.WriteLine(msg);

                    var path = GetFilePath(page.ID);
                    Utilities.FS.EnsurePath(path);
                    //Utilities.FS.WriteAllText(path, page.Content());
                    using (System.IO.StreamWriter fsw = new System.IO.StreamWriter(path, false))
                    {
                        foreach (var item in page.LookupOfIndexes)
                        {
                            fsw.WriteLine(FactKeyDictionary.Content(item));
                        }
                        page.PeristenceState = state;
                    }

                    Log(String.Format("page{0} was saved to FS", page.ID));

                    page.IsDirty = false;
                    if (unload)
                    {
                        page.Clear(Log);
                        RemoveIDFromLoadedPages(page.ID);
                        page.PeristenceState = PeristenceEnum.Unloaded;
                    }
                }
            });
        }