Asp.net源码专业站
首页->博客空间->SpaceBuilder v1.0正式版源码>>BasicWebControls/Manage/SystemManage/RebuildIndex.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
当前文件:文件类型 SpaceBuiderV10Source/BasicWebControls/Manage/SystemManage/RebuildIndex.cs[28K,2009-6-12 11:55:08]打开代码结构图
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.Collections.Generic; 9using System.Text; 10using SpaceBuilder.Components; 11using SpaceBuilder.Posts.Permissions; 12using System.Web.UI.WebControls; 13using SpaceBuilder.LuceneSearch.Configuration; 14using System.IO; 15using SpaceBuilder.Utils; 16using SpaceBuilder.Blogs.Components; 17using TunyNet.Data.Utils; 18using SpaceBuilder.Posts.Components; 19using TunyNet.Utils; 20using SpaceBuilder.Galleries.Components; 21using SpaceBuilder.Forums.Components; 22using SpaceBuilder.Clubs.Components; 23using SpaceBuilder.LuceneSearch.PostSearch; 24using SpaceBuilder.Files.Components; 25using SpaceBuilder.Bookmarks.Components; 26using SpaceBuilder.Controls.Utils; 27using SpaceBuilder.LuceneSearch.UserSearch; 28 29namespace SpaceBuilder.Web.Manage.Controls 30{ 31 public class RebuildIndex : ManageBaseControl 32 { 33 SBContext wlContext; 34 35 protected override void Authorize() 36 { 37 if (!SBContext.Current.User.IsAdministrator) 38 PermissionBase.RedirectOrExcpetion(SBExceptionType.AccessDenied); 39 } 40 41 protected override void OnInit(EventArgs e) 42 { 43 if (SkinName == null) 44 SkinName = "Skin-RebuildIndex.ascx"; 45 46 wlContext = SBContext.Current; 47 48 base.OnInit(e); 49 } 50 51 protected override void OnLoad(EventArgs e) 52 { 53 base.OnLoad(e); 54 EnsureChildControls(); 55 if (!Page.IsPostBack) 56 BindData(); 57 } 58 59 60 Child Controls 76 77 protected override void AttachChildControls() 78 { 79 statusMessage = FindControl("StatusMessage") as StatusMessage; 80 81 postIndexPath = FindControl("PostIndexPath") as Literal; 82 postIndexFolderSize = FindControl("PostIndexFolderSize") as Literal; 83 postIndexLastUpdateTime = FindControl("PostIndexLastUpdateTime") as Literal; 84 rebuildPostIndexButton = FindControl("RebuildPostIndexButton") as LinkButton; 85 rebuildPostIndexButton.Click += new EventHandler(RebuildPostIndexButton_Click); 86 87 88 userIndexPath = FindControl("UserIndexPath") as Literal; 89 userIndexFolderSize = FindControl("UserIndexFolderSize") as Literal; 90 userIndexLastUpdateTime = FindControl("UserIndexLastUpdateTime") as Literal; 91 rebuildUserIndexButton = FindControl("RebuildUserIndexButton") as LinkButton; 92 rebuildUserIndexButton.Click += new EventHandler(RebuildUserIndexButton_Click); 93 } 94 95 void BindData() 96 { 97 PostIndex 137 138 139 UserIndex 179 180 } 181 182 /// <summary> 183 /// 重建Post索引 184 /// </summary> 185 void RebuildPostIndexButton_Click(object sender, EventArgs e) 186 { 187 string indexTempPath = Path.Combine(SearchConfiguration.Instance().PostIndexDirectory, "temp"); 188 try 189 { 190 if (Directory.Exists(indexTempPath)) 191 Directory.Delete(indexTempPath, true); 192 } 193 catch { } 194 195 IList<PostSearchItem> postSearchItems = new List<PostSearchItem>(); 196 int indexedCount = 0; 197 198 索引Blog 221 222 索引图片 247 248 索引论坛/资讯 289 290 索引文件 315 316 317 索引网摘 342 343 statusMessage.Visible = true; 344 statusMessage.MessageType = StatusMessageType.Success; 345 statusMessage.Text = string.Format("博客、相册、文件、网摘、论坛索引重建成功,请把目录({0})下的文件清空,并把目录({1})下的所有文件拷贝过来", SearchConfiguration.Instance().PostIndexDirectory, indexTempPath); 346 347 } 348 349 350 void RebuildUserIndexButton_Click(object sender, EventArgs e) 351 { 352 string indexTempPath = Path.Combine(SearchConfiguration.Instance().PersonUserIndexDirectory, "temp"); 353 try 354 { 355 if (Directory.Exists(indexTempPath)) 356 Directory.Delete(indexTempPath, true); 357 } 358 catch { } 359 360 PersonUserQuery query = new PersonUserQuery(); 361 query.AccountStatus = UserAccountStatus.All; 362 query.IncludeHiddenUsers = true; 363 query.IgnorePaging = true; 364 query.PageSize = ValueHelper.GetSafeSqlInt(int.MaxValue); 365 366 PagingDataSet<PersonUser> personUserSet = Users.GetPersonUsers(query, false, false); 367 368 PersonUserIndexServer.Insert(personUserSet.Records, indexTempPath); 369 370 statusMessage.Visible = true; 371 statusMessage.MessageType = StatusMessageType.Success; 372 statusMessage.Text = string.Format("用户索引重建成功,请把目录({0})下的文件清空,并把目录({1})下的所有文件拷贝过来", SearchConfiguration.Instance().PersonUserIndexDirectory, indexTempPath); 373 374 } 375 376 377 /// <summary> 378 /// 从ForumPost转换为PostSearchItem 379 /// </summary> 380 private PostSearchItem PopulatePostSearchItemFromForumPost(ForumPost post, Club club) 381 { 382 PostSearchItem postSearchItem = null; 383 384 if (club == null) //站点资讯 385 { 386 if (post.Forum != null && post.Forum.ForumType == ForumType.Announcement) 387 { 388 postSearchItem = new PostSearchItem(); 389 postSearchItem.ApplicationType = ApplicationType.Forum; 390 //postSearchItem.ClubID = itemForIndex.ClubID; 391 //postSearchItem.ClubName; 392 postSearchItem.UserID = post.UserID; 393 postSearchItem.SectionID = post.SectionID; 394 postSearchItem.SectionName = post.Section.SectionName; 395 postSearchItem.ThreadID = post.ThreadID; 396 postSearchItem.PostID = post.PostID; 397 398 postSearchItem.Author = post.Author; 399 postSearchItem.Subject = HtmlUtils.TrimHtml(post.Subject); 400 postSearchItem.Body = HtmlUtils.TrimHtml(post.Body); 401 postSearchItem.LastUpdatedDate = post.PostDate; 402 postSearchItem.IsPublic = post.IsApproved; 403 404 postSearchItem.PostUrl = ChannelUrls.Instance().NewsShow(post.PostID); 405 } 406 } 407 else 408 { 409 postSearchItem = new PostSearchItem(); 410 postSearchItem.ApplicationType = ApplicationType.Forum; 411 postSearchItem.ClubID = club.ClubID; 412 postSearchItem.ClubName = club.ClubName; 413 postSearchItem.UserID = post.UserID; 414 postSearchItem.SectionID = post.SectionID; 415 postSearchItem.SectionName = post.Section.SectionName; 416 postSearchItem.ThreadID = post.ThreadID; 417 postSearchItem.PostID = post.PostID; 418 419 postSearchItem.Author = post.Author; 420 postSearchItem.Subject = HtmlUtils.TrimHtml(post.Subject); 421 postSearchItem.Body = HtmlUtils.TrimHtml(post.Body); 422 //postSearchItem.Tags = null; 423 postSearchItem.LastUpdatedDate = post.PostDate; 424 425 postSearchItem.IsPublic = post.IsApproved; 426 //postSearchItem.CategoryID 427 428 if (post.Forum != null && post.Forum.ForumType == ForumType.Announcement) 429 { 430 postSearchItem.PostUrl = ClubUrls.Instance().PlacardShow(club.DomainName, post.ThreadID); 431 } 432 else 433 { 434 switch (post.Forum.DisplayLocation) 435 { 436 case ForumDisplayLocation.Club: 437 postSearchItem.PostUrl = ForumUrls.Instance().ClubChannelShowThread(club.DomainName, post.ThreadID); 438 postSearchItem.SectionUrl = ForumUrls.Instance().ClubChannelShowForum(club.DomainName, post.SectionID); 439 break; 440 case ForumDisplayLocation.Forum: 441 postSearchItem.PostUrl = ForumUrls.Instance().ShowThread(post.ThreadID); 442 postSearchItem.SectionUrl = ForumUrls.Instance().ShowForum(post.SectionID); 443 break; 444 } 445 446 if (post.User != null && !post.User.IsAnonymous) 447 postSearchItem.UserProfileUrl = UserUrls.Instance().UserProfile(post.User.UserName, post.User.UserType); 448 } 449 } 450 451 return postSearchItem; 452 } 453 454 /// <summary> 455 /// 从WeblogPost转换为PostSearchItem 456 /// </summary> 457 private PostSearchItem PopulatePostSearchItemFromWeblogPost(BlogThread weblogPost) 458 { 459 PostSearchItem postSearchItem = new PostSearchItem(); 460 postSearchItem.ApplicationType = ApplicationType.Blog; 461 postSearchItem.ClubID = 0; 462 postSearchItem.UserID = weblogPost.UserID; 463 postSearchItem.SectionID = weblogPost.SectionID; 464 postSearchItem.ThreadID = weblogPost.ThreadID; 465 postSearchItem.PostID = weblogPost.PostID; 466 postSearchItem.Author = weblogPost.Author; 467 postSearchItem.Subject = HtmlUtils.TrimHtml(weblogPost.Subject); 468 postSearchItem.Body = HtmlUtils.TrimHtml(weblogPost.Body); 469 470 if (weblogPost.Tags.Count > 0) 471 { 472 string[] tagNames = new string[weblogPost.Tags.Count]; 473 for (int i = 0; i < weblogPost.Tags.Count; i++) 474 { 475 tagNames[i] = weblogPost.Tags[i].TagName; 476 } 477 postSearchItem.Tags = tagNames; 478 } 479 480 postSearchItem.LastUpdatedDate = weblogPost.LastRepliedDate; 481 482 postSearchItem.IsPublic = weblogPost.IsPublic; 483 //postSearchItem.CategoryID 484 485 Weblog blog = null; 486 try 487 { 488 blog = weblogPost.Weblog; 489 } 490 catch 491 { } 492 493 if (blog != null) 494 { 495 if (!ValueHelper.IsNullOrEmpty(blog.SectionName)) 496 postSearchItem.SectionName = blog.SectionName; 497 else 498 postSearchItem.SectionName = weblogPost.Author + "的博客"; 499 500 postSearchItem.PostUrl = BlogUrls.Instance().ShowPost(weblogPost, blog); 501 postSearchItem.SectionUrl = UserUrls.Instance().BlogHome(blog.ApplicationKey); 502 if (weblogPost.User != null && !weblogPost.User.IsAnonymous) 503 postSearchItem.UserProfileUrl = UserUrls.Instance().UserProfile(weblogPost.User.UserName, weblogPost.User.UserType); 504 else 505 postSearchItem.UserProfileUrl = string.Empty; 506 } 507 508 return postSearchItem; 509 } 510 511 /// <summary> 512 /// 从Picture转换为PostSearchItem 513 /// </summary> 514 private PostSearchItem PopulatePostSearchItemFromPicture(Picture picture) 515 { 516 PostSearchItem postSearchItem = new PostSearchItem(); 517 postSearchItem.ApplicationType = ApplicationType.Gallery; 518 postSearchItem.ClubID = 0; 519 postSearchItem.UserID = picture.UserID; 520 postSearchItem.SectionID = picture.SectionID; 521 postSearchItem.ThreadID = picture.ThreadID; 522 postSearchItem.PostID = picture.PostID; 523 524 postSearchItem.Author = picture.Author; 525 postSearchItem.Subject = HtmlUtils.TrimHtml(picture.Subject); 526 postSearchItem.Body = HtmlUtils.TrimHtml(picture.Body); 527 if (picture.Tags.Count > 0) 528 { 529 string[] tagNames = new string[picture.Tags.Count]; 530 for (int i = 0; i < picture.Tags.Count; i++) 531 { 532 tagNames[i] = picture.Tags[i].TagName; 533 } 534 postSearchItem.Tags = tagNames; 535 } 536 537 postSearchItem.LastUpdatedDate = picture.LastRepliedDate; 538 539 postSearchItem.IsPublic = picture.IsPublic; 540 //postSearchItem.CategoryID 541 542 Gallery gallery = picture.Gallery; 543 if (gallery != null) 544 { 545 546 if (!ValueHelper.IsNullOrEmpty(gallery.SectionName)) 547 postSearchItem.SectionName = gallery.SectionName; 548 else 549 postSearchItem.SectionName = picture.Author + "的相册"; 550 551 postSearchItem.PostUrl = GalleryUrls.Instance().ViewPicture(gallery.ApplicationKey, picture.PostID); 552 postSearchItem.SectionUrl = UserUrls.Instance().ViewGallery(gallery.ApplicationKey); 553 if (picture.User != null && !picture.User.IsAnonymous) 554 postSearchItem.UserProfileUrl = UserUrls.Instance().UserProfile(picture.User.UserName, picture.User.UserType); 555 else 556 postSearchItem.UserProfileUrl = string.Empty; 557 } 558 559 return postSearchItem; 560 561 } 562 563 /// <summary> 564 /// 从FileThread转换为PostSearchItem 565 /// </summary> 566 private PostSearchItem PopulatePostSearchItemFromFileThread(FileThread fileThread) 567 { 568 if (fileThread == null) 569 return null; 570 else 571 { 572 FileSection fileSection = fileThread.FileSection; 573 if (fileSection != null) 574 { 575 PostSearchItem postSearchItem = new PostSearchItem(); 576 postSearchItem.ApplicationType = ApplicationType.FileGallery; 577 postSearchItem.ClubID = 0; 578 postSearchItem.UserID = fileThread.UserID; 579 postSearchItem.SectionID = fileThread.SectionID; 580 if (!ValueHelper.IsNullOrEmpty(fileSection.SectionName)) 581 postSearchItem.SectionName = fileSection.SectionName; 582 else 583 postSearchItem.SectionName = fileThread.Author + "的文件"; 584 585 postSearchItem.ThreadID = fileThread.ThreadID; 586 postSearchItem.PostID = fileThread.PostID; 587 588 postSearchItem.Author = fileThread.Author; 589 postSearchItem.Subject = HtmlUtils.TrimHtml(fileThread.Subject); 590 postSearchItem.Body = HtmlUtils.TrimHtml(fileThread.Body); 591 if (fileThread.Tags.Count > 0) 592 { 593 string[] tagNames = new string[fileThread.Tags.Count]; 594 for (int i = 0; i < fileThread.Tags.Count; i++) 595 { 596 tagNames[i] = fileThread.Tags[i].TagName; 597 } 598 postSearchItem.Tags = tagNames; 599 } 600 601 postSearchItem.LastUpdatedDate = fileThread.PostDate; 602 603 postSearchItem.IsPublic = fileThread.IsPublic; 604 //postSearchItem.CategoryID 605 606 postSearchItem.PostUrl = FileUrls.Instance().ViewFile(fileSection.ApplicationKey, fileThread.PostID); 607 postSearchItem.SectionUrl = FileUrls.Instance().FileHome(fileSection.ApplicationKey); 608 if (fileThread.User != null && !fileThread.User.IsAnonymous) 609 postSearchItem.UserProfileUrl = UserUrls.Instance().UserProfile(fileThread.User.UserName, fileThread.User.UserType); 610 else 611 postSearchItem.UserProfileUrl = string.Empty; 612 613 return postSearchItem; 614 } 615 616 return null; 617 } 618 } 619 620 /// <summary> 621 /// 从bookmark转换为PostSearchItem 622 /// </summary> 623 private PostSearchItem PopulatePostSearchItemFromBookmark(Bookmark bookmark) 624 { 625 if (bookmark == null) 626 return null; 627 else 628 { 629 PostSearchItem postSearchItem = new PostSearchItem(); 630 postSearchItem.ApplicationType = ApplicationType.Bookmark; 631 postSearchItem.ClubID = 0; 632 postSearchItem.UserID = bookmark.UserID; 633 634 //postSearchItem.SectionID = 635 postSearchItem.SectionName = bookmark.Author + "的网摘"; 636 //postSearchItem.ThreadID = 637 postSearchItem.PostID = bookmark.BookmarkID; 638 639 postSearchItem.Author = bookmark.Author; 640 postSearchItem.Subject = HtmlUtils.TrimHtml(bookmark.Title); 641 postSearchItem.Body = HtmlUtils.TrimHtml(bookmark.Brief); 642 if (bookmark.Tags.Count > 0) 643 { 644 string[] tagNames = new string[bookmark.Tags.Count]; 645 for (int i = 0; i < bookmark.Tags.Count; i++) 646 { 647 tagNames[i] = bookmark.Tags[i].TagName; 648 } 649 postSearchItem.Tags = tagNames; 650 } 651 652 postSearchItem.LastUpdatedDate = bookmark.CreateDate; 653 654 postSearchItem.IsPublic = !bookmark.IsPrivate; 655 postSearchItem.CategoryID = (int)bookmark.Category; 656 657 658 UserBookmarkQuery ubq = new UserBookmarkQuery(); 659 ubq.BookmarkID = bookmark.BookmarkID; 660 ubq.PrivateType = PrivateType.All; 661 ubq.IncludeTags = true; 662 ubq.PageSize = 100; 663 ubq.IgnorePaging = true; 664 PagingDataSet<UserBookmark> pds_BookmarkUsers = SpaceBuilder.Bookmarks.Components.Bookmarks.GetUserBookmarks(ubq); 665 if (pds_BookmarkUsers != null && pds_BookmarkUsers.Records.Count > 0) 666 { 667 int[] relativeUserIDs = new int[pds_BookmarkUsers.Records.Count]; 668 for (int i = 0; i < pds_BookmarkUsers.Records.Count; i++) 669 { 670 relativeUserIDs[i] = pds_BookmarkUsers.Records[i].UserID; 671 } 672 postSearchItem.RelativeUserIDs = relativeUserIDs; 673 } 674 675 postSearchItem.PostUrl = ChannelUrls.Instance().ShowBookmark(bookmark.BookmarkID); 676 postSearchItem.SectionUrl = UserUrls.Instance().UserChannelHome(bookmark.UserID, UserDomainMenuType.Bookmark); 677 678 postSearchItem.UserProfileUrl = UserUrls.Instance().UserChannelHome(bookmark.UserID, UserDomainMenuType.Profile); 679 680 return postSearchItem; 681 } 682 } 683 684 685 686 } 687} 688 689 690
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.0正式版源码