Ejemplo n.º 1
0
        public static void WriteCache(this TabBookEntity book)
        {
            string path = book.GetRecordPath(true);

            System.IO.StringWriter sw = new System.IO.StringWriter();
            //创建一个序列化对像
            System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(TabBookEntity));
            //写入缓存文件
            System.IO.File.WriteAllBytes(path, Compression.Compress(System.Text.UnicodeEncoding.Unicode.GetBytes(sw.ToString())));
            book.Modifyd = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 得到生成项文件的路径
        /// </summary>
        /// <param name="page">项文件代码</param>
        /// <param name="IsCacheFile">是不是返回项缓存文件的路径 默认为false</param>
        /// <returns>返回生成项文件的路径</returns>
        public static string GetRecordPath(this TabBookEntity book, bool IsCacheFile = false)
        {
            //得到生成文件的路径
            //基本路径
            string basePath  = AppDomain.CurrentDomain.BaseDirectory + book.Record.分类标识.ToPingYing() + "/" + book.Record.书名.ToPingYing();
            string htmlPage  = System.IO.Path.GetFullPath(basePath + ".html");
            string cachePage = System.IO.Path.GetFullPath(basePath + ".zip");

            if (IsCacheFile)
            {
                return(cachePage);
            }
            return(htmlPage);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 更新页面记录
 /// </summary>
 /// <param name="page"></param>
 public void UpdateRecord(TabBookEntity book)
 {
     //如果文件不同步则
     try
     {
         //将记录写入缓存
         book.WriteCache();
     }
     //如果写入失败则过一会儿再写入
     catch
     {
         System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.Sleep(1); book.WriteCache(); });
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 传入一个页索引 返回对应的页对象,并对对象的同步状态进行比较 如果不同步,则同步记录状态
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="book"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static TabPageEntity GetPage(this System.Collections.Concurrent.ConcurrentBag <string> keys, TabBookEntity book, string key)
        {
            //得到指定key 的记录
            var records = tygDb.文章表.Where(p => p.GUID == Guid.Parse(key));

            if (records.Count() > 0)
            {
                文章表 record = records.FirstOrDefault();



                return(new TabPageEntity()
                {
                    Record = record,
                    Book = book,
                    Issync = true,
                    Modifyd = false
                });
            }
            else
            {
                throw new IndexOutOfRangeException("没有找到指定索引的记录");
            }
        }
Ejemplo n.º 5
0
        public void UpdateRecord(RecordType recordType, string sign)
        {
            //得到枚举选项
            List <RecordType> result = EnumExtendMethod.GetEnumArray <RecordType>(recordType);

            decimal d;

            if (result.Count > 0)
            {
                switch (result[0])
                {
                case RecordType.Page:
                    Func <TygModel.文章表, bool> fun = null;
                    //如果是数据ID
                    if (decimal.TryParse(sign, out d))
                    {
                        fun = p => p.ID == d;
                    }
                    else
                    {
                        fun = p => p.GUID == Guid.Parse(sign);
                    }

                    //得到对应的记录
                    var records = tygdb.文章表.Where(fun);

                    //初始化当前访问的页面
                    TabPageEntity page = null;

                    if (records.Count() > 0)
                    {
                        var record = records.FirstOrDefault();

                        #region 初始化页面对象数据
                        //如果当前缓存记录中存在这条记录
                        if (!BooksCache.ContainsKey(record.书名表.GUID.ToString()))
                        {
                            //页面所在的分类
                            TabClassEntity Typeclass = null;
                            //如果包括分类
                            if (ClassesCache.ContainsKey(record.书名表.分类表.ID))
                            {
                                Typeclass = ClassesCache[record.书名表.分类表.ID];
                            }
                            else
                            {
                                Typeclass = new TabClassEntity()
                                {
                                    Modifyd = true,
                                };
                                Typeclass.Record = record.书名表.分类表;


                                //添加到分类表
                                ClassesCache.TryAdd(Typeclass.Record.ID, Typeclass);
                            }
                            //实例化书对像
                            TabBookEntity book = new TabBookEntity()
                            {
                                Record    = record.书名表,
                                Typeclass = Typeclass,
                                Modifyd   = true,
                            };

                            //尝试添加到数据中
                            ClassesCache[record.书名表.分类表.ID].Books.TryAdd(record.书名表.GUID.ToString(), book);


                            //如果不包含
                            if (!book.Pages.ContainsKey(sign))
                            {
                                page = new TabPageEntity()
                                {
                                    Book    = book,
                                    Issync  = false,
                                    Modifyd = true,
                                    Record  = record
                                };

                                //将页面添加到缓存集合
                                book.Pages.TryAdd(record.本记录GUID.ToString(), page);
                            }
                            //添加到书的缓存集合
                            BooksCache.TryAdd(record.书名表.GUID.ToString(), book);
                        }
                        #endregion

                        //得到书本对象的数据
                        page = BooksCache[record.书名表.GUID.ToString()].Pages[record.本记录GUID.ToString()];
                        page.Record.总访问次数++;
                        page.Record.最后访问时间 = DateTime.Now;
                        page.Record.书名表.总点击++;
                        page.Record.书名表.周点击++;
                    }

                    break;

                case RecordType.Book:

                    Func <TygModel.书名表, bool> bookfun = null;
                    //如果是数据ID
                    if (decimal.TryParse(sign, out d))
                    {
                        bookfun = p => p.ID == d;
                    }
                    else
                    {
                        bookfun = p => p.GUID == Guid.Parse(sign);
                    }
                    //得到对应的记录
                    var bookrecords = tygdb.书名表.Where(bookfun);
                    if (bookrecords.Count() > 0)
                    {
                        var record = bookrecords.FirstOrDefault();
                        #region 初始化页面对象数据
                        //如果当前缓存记录中存在这条记录
                        if (!BooksCache.ContainsKey(record.GUID.ToString()))
                        {
                            //页面所在的分类
                            TabClassEntity Typeclass = null;
                            //如果包括分类
                            if (ClassesCache.ContainsKey(record.分类表.ID))
                            {
                                Typeclass = ClassesCache[record.分类表.ID];
                            }
                            else
                            {
                                Typeclass = new TabClassEntity()
                                {
                                    Modifyd = true,
                                };
                                Typeclass.Record = record.分类表;

                                //添加到分类表
                                ClassesCache.TryAdd(Typeclass.Record.ID, Typeclass);
                            }
                            //实例化书对像
                            TabBookEntity book = new TabBookEntity()
                            {
                                Record    = record,
                                Typeclass = Typeclass,
                                Modifyd   = true,
                            };
                            BooksCache.TryAdd(record.GUID.ToString(), book);
                        }
                        //更新状态
                        BooksCache[record.GUID.ToString()].Modifyd = true;

                        #endregion
                        record.总点击++;
                        record.周点击++;
                    }


                    break;

                case RecordType.ClassEntity:

                    break;
                }
            }

            #region 查看记录不是不和缓存数据中的记录相等 如果不相当则更新较旧的记录

            #endregion
        }