Пример #1
0
 public BookAddress(string name,
                    BookCategory category,
                    [ParameterRepository(typeof(List <BookCover>))]
                    IEnumerable <BookCover> photos)
 {
     this.Name     = name;
     this.Category = category;
     this._Photos  = new DomainCollection <BookCover>(BookAddress.PhotosProperty, photos);
     this.OnConstructed();
 }
Пример #2
0
        private static void AssertBookCategory(BookCategory obj, IDbConnection conn)
        {
            var data = conn.QueryFirstOrDefault("select * from BookCategory where id=@id", new { Id = obj.Id });

            if (obj.IsEmpty())
            {
                Assert.IsNull(data);
                return;
            }
            Assert.AreEqual(data.Name, obj.Name);
        }
Пример #3
0
        public static void FillBook(Book book)
        {
            var categoryMain = new BookCategory(15)
            {
                Name = "主要分类"
            };

            var category1 = new BookCategory(1)
            {
                Name = "分类1"
            };

            var category2 = new BookCategory(2)
            {
                Name = "分类2"
            };

            Author author1 = new Author("作者1", Sex.Female, Person.Empty);
            Author author2 = new Author("作者2", Sex.Male, Person.Empty);
            Author author3 = new Author("作者3", Sex.Male, Person.Empty);
            Author author4 = new Author("作者4", Sex.Female, Person.Empty);

            var autohrs = new Author[] { author1, author2, author3, author4 };


            var photo1        = new BookCover("照片1", "p1", new Author("照片1的作者", Sex.Male, Person.Empty), autohrs);
            var photo2        = new BookCover("照片2", "p2", new Author("照片2的作者", Sex.Female, Person.Empty), autohrs);
            var photo3        = new BookCover("照片3", "p3", new Author("照片3的作者", Sex.Female, Person.Empty), autohrs);
            var photo4        = new BookCover("照片4", "p4", new Author("照片4的作者", Sex.Male, Person.Empty), autohrs);
            var wuhanPhoto    = new BookCover("武汉的照片", "1", new Author("小王", Sex.Male, Person.Empty), autohrs);
            var beijingPhoto  = new BookCover("北京的照片", "2", new Author("老王", Sex.Male, Person.Empty), autohrs);
            var shangHaiPhoto = new BookCover("上海的照片", "3", new Author("小赵", Sex.Female, Person.Empty), autohrs);

            var wuhan = new BookAddress("武汉", BookCategory.Empty, new BookCover[] {
                wuhanPhoto, photo1, photo2
            });

            var beiJing = new BookAddress("北京", BookCategory.Empty, new BookCover[] {
                beijingPhoto, photo2, photo3
            });

            var shangHai = new BookAddress("上海", BookCategory.Empty, new BookCover[] {
                shangHaiPhoto, photo1, photo3
            });

            var bookMark1 = new Bookmark(1)
            {
                PageIndex = 1,
                Cover     = new BookCover("书签1的封面", "1", new Author("书签1的封面的作者", Sex.Female, Person.Empty), Array.Empty <Author>())
            };

            bookMark1.AddCover(photo1);
            bookMark1.AddCover(photo2);

            var bookMark18 = new Bookmark(2)
            {
                PageIndex = 18,
            };

            bookMark18.AddCover(photo1);
            bookMark18.AddCover(photo3);

            var bookMark20 = new Bookmark(3)
            {
                PageIndex = 20
            };

            bookMark20.AddCover(photo4);

            book.Name            = "第一本书";
            book.Category        = categoryMain;
            book.ErrorPageIndexs = new int[] { 1, 2, 3, 4, 5, 6 };
            book.SaleTime        = DateTime.Now;

            book.SetSignature("第一本书的个性签名");
            book.SetCreator(new Author("第一本书的作者", Sex.Female, Person.Empty));

            book.SetSignature2("第二个个性签名");

            book.Cover = new BookCover("主要的封面", "1", new Author("作者", Sex.Female, Person.Empty), autohrs);

            //添加相关分类
            book.AddRelatedCategory(category1);
            book.AddRelatedCategory(category2);

            book.SourceAddress = wuhan;
            book.AddSaleAddress(beiJing);
            book.AddSaleAddress(shangHai);

            book.MainBookmark  = bookMark1;
            book.FirstBookmark = bookMark1;
            book.LastBookmark  = bookMark18;

            book.AddBookmark(bookMark1);
            book.AddBookmark(bookMark18);
            book.AddBookmark(bookMark20);

            book.AddPoster(new BookPoster("第1个海报", "第1个提供商"));
            book.AddPoster(new BookPoster("第2个海报", "第2个提供商"));
            book.AddPoster(new BookPoster("第3个海报", "第3个提供商"));

            var reader1 = new BookReader(1)
            {
                Name = "张三丰",
                Sex  = Sex.Female
            };

            var reader2 = new BookReader(2)
            {
                Name = "周芷诺",
                Sex  = Sex.Male
            };

            bookMark1.AddReader(reader1);
            bookMark1.AddReader(reader2);

            {
                var repository = Repository.Create <IBookCategoryRepository>();
                repository.Add(categoryMain);
                repository.Add(category1);
                repository.Add(category2);
            }

            {
                var repository = Repository.Create <IBookRepository>();
                repository.Add(book);
            }
        }
Пример #4
0
 public void AddRelatedCategory(BookCategory category)
 {
     this._RelatedCategories.Add(category);
 }
Пример #5
0
        public void Deadlock()
        {
            DataPortal.Dispose();
            DataPortal.RuntimeBuild();

            var category = new BookCategory(1)
            {
                Name = "物理"
            };

            var book1 = new Book(Guid.NewGuid())
            {
                Name     = "第1本书",
                Category = category,
                Cover    = new BookCover("封面1", string.Empty, Author.Empty, Array.Empty <Author>())
            };

            var book2 = new Book(Guid.NewGuid())
            {
                Name     = "第2本书",
                Category = category,
                Cover    = new BookCover("封面2", string.Empty, Author.Empty, Array.Empty <Author>())
            };

            var book3 = new Book(Guid.NewGuid())
            {
                Name     = "第3本书",
                Category = category,
                Cover    = new BookCover("封面3", string.Empty, Author.Empty, Array.Empty <Author>())
            };

            var repository         = Repository.Create <IBookRepository>();
            var categoryRepository = Repository.Create <IBookCategoryRepository>();

            this.BeginTransaction(true);
            categoryRepository.Add(category);

            repository.Add(book1);
            repository.Add(book2);
            repository.Add(book3);

            this.Commit();



            //多线程操作
            var group1 = new Guid[] { book1.Id, book2.Id, book3.Id };
            var group2 = new Guid[] { book2.Id, book1.Id, book3.Id };
            var group3 = new Guid[] { book3.Id, book1.Id, book2.Id };
            var group4 = new Guid[] { book3.Id, book2.Id, book1.Id };

            var groups = new List <Guid[]>();

            groups.Add(group1);
            groups.Add(group2);
            groups.Add(group3);
            groups.Add(group4);


            Parallel.For(0, 20, (index) =>
            {
                var i = index % groups.Count;

                try
                {
                    UpdateBooks(groups[i]);
                }
                catch (DataVersionException)
                {
                }
            });

            DataPortal.Dispose();
        }