private void ConvertAds() { BonSoChinDataContext bonSoChinContext = new BonSoChinDataContext(); VBBDataContext context = new VBBDataContext(); short maxVForumId = (short)(from vForum1 in context.Forums select vForum1.Forumid).Max(); long maxVThreadId = (from vThread1 in context.Threads select vThread1.Threadid).Max(); int maxPostId = (int)(from vPost1 in context.Posts select vPost1.Postid).Max(); var vPostId = maxPostId; VBBContext.Forum vForum = new VBBContext.Forum { Title = "Ads", Titleclean = "Ads", Description = "Ads", Descriptionclean = "Ads", Displayorder = 1, // replycount Replycount = 0, Lastpost = 0, Lastposter = "", Lastposterid = 0, Lastpostid = 0, Lastthread = "", Lastthreadid = 0, Newpostemail = "", Newthreademail = "", Parentid = -1, Parentlist = "", Childlist = "", Defaultsortfield = "lastpost", Defaultsortorder = "desc", Threadcount = 0, Options = 86017, }; PopulateUShort(vForum); short vForumId = (short)(maxVForumId + 1); short superForumId = vForumId; vForum.Forumid = (short)(maxVForumId + 1); vForum.Parentlist = vForumId + ",-1"; vForum.Childlist = vForumId + ",-1"; context.Forums.InsertOnSubmit(vForum); context.SubmitChanges(); // ---------------------------------- CREATE SUB FORUM ----------------------------------- var adsCategories4source = (from ads1 in bonSoChinContext.Adcategories select ads1).ToList(); foreach (Adcategory adcategory in adsCategories4source) { VBBContext.Forum vSubForum = new VBBContext.Forum { Title = adcategory.Adcategory1, Titleclean = adcategory.Adcategory1, Description = adcategory.Adcategory1, Descriptionclean = adcategory.Adcategory1, Displayorder = 1, // replycount Replycount = 0, Lastpost = 0, Lastposter = "", Lastposterid = 0, Lastpostid = 0, Lastthread = "", Lastthreadid = 0, Newpostemail = "", Newthreademail = "", Parentid = superForumId, Parentlist = "", Childlist = "", Defaultsortfield = "lastpost", Defaultsortorder = "desc", Threadcount = 0, Options = 221127, }; PopulateUShort(vSubForum); ++vForumId; vSubForum.Forumid = vForumId; vSubForum.Parentlist = vForumId + "," + vSubForum.Parentid + ",-1"; vSubForum.Childlist = vForumId + ",-1"; // ---------------------------------- CREATE Thread ----------------------------------- var ads4source = (from ads1 in bonSoChinContext.Ads where ads1.Adcategoryid == adcategory.Adcategoryid select ads1).ToList(); foreach (Ads ads in ads4source) { var vThreadId = ++maxVThreadId; int dtline = ConvertToUnixTimestamp(ads.Addateposted); Thread vThread = new Thread(); vThread.Title = ads.Adtitle; vThread.Prefixid = ""; vThread.Forumid = vForumId; vThread.Open = 1; vThread.Visible = 1; vThread.Dateline = ConvertToUnixTimestamp(ads.Addateposted); var postMemberInThread = (from member1 in bonSoChinContext.Members where (member1.Memberid == ads.Adaddedby) select member1).FirstOrDefault(); var postUserInThread = (from user1 in context.Users where user1.Username.Equals(postMemberInThread.Memberlogin.Trim()) select user1).FirstOrDefault(); vThread.Postuserid = postUserInThread.Userid; vThread.Postusername = postMemberInThread.Memberlogin; vThread.Lastposter = ""; vThread.Notes = ""; vThread.Similar = ""; PopulateUShort(vThread); vPostId++; // 1st post entered Post v1Post = new Post { Threadid = vThreadId, Title = "", Dateline = ConvertToUnixTimestamp(ads.Addateposted), Pagetext = ads.Adtext, Allowsmilie = 1, Ipaddress = "127.0.0.1", Visible = 1, Parentid = vPostId, Userid = vThread.Postuserid, Username = vThread.Postusername, }; // insert post parser Postparsed postparsed1 = new Postparsed { Dateline = v1Post.Dateline, Postid = vPostId, Styleid = 1, Languageid = 1, Hasimages = 0, Pagetexthtml = v1Post.Pagetext, }; context.Posts.InsertOnSubmit(v1Post); context.Postparseds.InsertOnSubmit(postparsed1); UpdateStatusOfForumAndThread(vThread, vSubForum, v1Post, vPostId, vThreadId); vForum.Threadcount++; vThread.Firstpostid = vPostId; vSubForum.Lastthread = vThread.Title.ToString(); vSubForum.Lastthreadid = vThreadId; vForum.Lastthread = vThread.Title.ToString(); vForum.Lastthreadid = vThreadId; vSubForum.Threadcount++; vSubForum.Replycount++; vForum.Replycount++; vThread.Replycount = 0; Threadview vThreadview = new Threadview(); vThreadview.Threadid = vThreadId; context.Threads.InsertOnSubmit(vThread); } context.Forums.InsertOnSubmit(vSubForum); } context.SubmitChanges(); }
private void ConvertEvents() { BonSoChinDataContext bonSoChinContext = new BonSoChinDataContext(); VBBDataContext context = new VBBDataContext(); // process null users var lackingMembers = (from msg in bonSoChinContext.Eventregistrations where msg.Memberid == null select msg).ToList(); string tempUser = "******"; int tempUserCount = 1; foreach (Eventregistration lackingMember in lackingMembers) { string salt = FetchUserSalt(3); User user = new User { Username = lackingMember.Regfirstname + lackingMember.Reglastname + "TEMP",//tempUser + string.Format("{0:000}", tempUserCount++), Password = CreatePassword("bscpassword", salt), Usergroupid = 2, Passworddate = DateTime.Now, Email = "*****@*****.**", Showvbcode = 1, Showbirthday = 0, Usertitle = "Junior Member", Joindate = ConvertToUnixTimestamp(DateTime.Now), Lastvisit = 1273158780, Daysprune = -1, Lastactivity = 1273158780, Reputation = 10, Reputationlevelid = 5, Timezoneoffset = "7", Options = 45108311, Birthday = "", Birthdaysearch = DateTime.Now, Posts = 0, Maxposts = -1, Startofweek = 1, Autosubscribe = -1, Salt = salt, Showblogcss = 1, }; string img = "000.gif"; user.Avatarid = (short)(from avt in context.Avatars where avt.Avatarpath.Equals(img) select avt.Avatarid).FirstOrDefault(); PopulateUShort(user); context.Users.InsertOnSubmit(user); } context.SubmitChanges(); short maxVForumId = (short)(from vForum1 in context.Forums select vForum1.Forumid).Max(); long maxVThreadId = (from vThread1 in context.Threads select vThread1.Threadid).Max(); int maxPostId = (int)(from vPost1 in context.Posts select vPost1.Postid).Max(); var vPostId = maxPostId; int maxEventId = (int)(from vPost1 in context.Events select vPost1.Eventid).Max(); VBBContext.Forum vForum = new VBBContext.Forum { Title = "Sự kiện", Titleclean = "Sự kiện", Description = "Sự kiện", Descriptionclean = "Sự kiện", Displayorder = 1, // replycount Replycount = 0, Lastpost = 0, Lastposter = "", Lastposterid = 0, Lastpostid = 0, Lastthread = "", Lastthreadid = 0, Newpostemail = "", Newthreademail = "", Parentid = -1, Parentlist = "", Childlist = "", Defaultsortfield = "lastpost", Defaultsortorder = "desc", Threadcount = 0, Options = 221127, }; PopulateUShort(vForum); short vForumId = (short)(maxVForumId + 1); short superForumId = vForumId; vForum.Forumid = (short)(maxVForumId + 1); vForum.Parentlist = vForumId + ",-1"; vForum.Childlist = vForumId + ",-1"; context.Forums.InsertOnSubmit(vForum); context.SubmitChanges(); // ---------------------------------- CREATE SUB FORUM ----------------------------------- var events = (from @event in bonSoChinContext.Events select @event).ToList(); /*foreach (Event @event in events) { VBBContext.Forum vSubForum = new VBBContext.Forum { Title = @event.Articlecategory1, Titleclean = @event.Articlecategory1, Description = @event.Articlecategory1, Descriptionclean = @event.Articlecategory1, Displayorder = 1, // replycount Replycount = 0, Lastpost = 0, Lastposter = "", Lastposterid = 0, Lastpostid = 0, Lastthread = "", Lastthreadid = 0, Newpostemail = "", Newthreademail = "", Parentid = superForumId, Parentlist = "", Childlist = "", Defaultsortfield = "lastpost", Defaultsortorder = "desc", Threadcount = 0, Options = 221127, }; PopulateUShort(vSubForum); ++vForumId; vSubForum.Forumid = vForumId; vSubForum.Parentlist = vForumId + "," + vSubForum.Parentid + ",-1"; vSubForum.Childlist = vForumId + ",-1";*/ // ---------------------------------- CREATE Thread ----------------------------------- /* var article4source = (from articles1 in bonSoChinContext.Events where articles1.Articlecategoryid == @event.Articlecategoryid select articles1).ToList();*/ foreach (Event @event in events) { DateTime? dateStart = null; DateTime? dateAdded = null; dateStart = @event.Eventdatestart; dateAdded = @event.Eventdateadded; if(@event.Eventdateadded == null) { if (@event.Eventdatestart != null) dateAdded = @event.Eventdatestart; } else { if (@event.Eventdatestart == null) dateStart = @event.Eventdateadded; } if(dateAdded ==null && dateStart == null) { dateAdded = dateStart = new DateTime(2007, 1, 1); } var vThreadId = ++maxVThreadId; int dtline = ConvertToUnixTimestamp(dateAdded); Thread vThread = new Thread(); vThread.Title = @event.Eventname; vThread.Prefixid = ""; vThread.Forumid = vForumId; short allowReplies = short.Parse(@event.Eventallowregistrations.GetValueOrDefault().ToString()); vThread.Open = allowReplies; vThread.Visible = 1; vThread.Dateline = ConvertToUnixTimestamp(dateAdded); int postMemberInThreadId = 126; if (@event.Eventaddedby != null) postMemberInThreadId = @event.Eventaddedby.Value; var postMemberInThread = (from member1 in bonSoChinContext.Members where (member1.Memberid == postMemberInThreadId) select member1).FirstOrDefault(); var postUserInThread = (from user1 in context.Users where user1.Username.Equals(postMemberInThread.Memberlogin.Trim()) select user1).FirstOrDefault(); vThread.Postuserid = postUserInThread.Userid; vThread.Postusername = postMemberInThread.Memberlogin; vThread.Lastposter = ""; vThread.Notes = ""; vThread.Similar = ""; PopulateUShort(vThread); vPostId++; // 1st post entered Post v1Post = new Post { Threadid = vThreadId, Title = "", Dateline = ConvertToUnixTimestamp(dateAdded), Pagetext = @event.Eventdesc, Allowsmilie = 1, Ipaddress = "127.0.0.1", Visible = 1, Parentid = vPostId, Userid = vThread.Postuserid, Username = vThread.Postusername, }; // insert post parser Postparsed postparsed1 = new Postparsed { Dateline = v1Post.Dateline, Postid = vPostId, Styleid = 1, Languageid = 1, Hasimages = 0, Pagetexthtml = v1Post.Pagetext, }; context.Posts.InsertOnSubmit(v1Post); context.Postparseds.InsertOnSubmit(postparsed1); //v1Post.Postid = vPostId; UpdateStatusOfForumAndThread(vThread, vForum, v1Post, vPostId, vThreadId); vForum.Threadcount++; vThread.Firstpostid = vPostId; /*vSubForum.Lastthread = vThread.Title.ToString(); vSubForum.Lastthreadid = vThreadId;*/ vForum.Lastthread = vThread.Title.ToString(); vForum.Lastthreadid = vThreadId; /*vSubForum.Threadcount++; vSubForum.Replycount++;*/ vForum.Replycount++; vThread.Replycount = 0; Threadview vThreadview = new Threadview(); vThreadview.Threadid = vThreadId; context.Threads.InsertOnSubmit(vThread); // insert event #region INSERT events maxEventId++; VBBContext.Event vbbEvent = new VBBContext.Event(); vbbEvent.Calendarid = 1; vbbEvent.Allowsmilies = 1; vbbEvent.Customfields = @"a:0:{}"; vbbEvent.Dateline = ConvertToUnixTimestamp(dateAdded); vbbEvent.Datelinefrom = ConvertToUnixTimestamp(dateStart); vbbEvent.Datelineto = ConvertToUnixTimestamp(@event.Eventdateend); vbbEvent.Dst = 0; vbbEvent.Event1 = @event.Eventdesc; vbbEvent.Recurring = 0; vbbEvent.Recuroption = ""; vbbEvent.Title = @event.Eventname; vbbEvent.Utc = new decimal(7.00); vbbEvent.Visible = 1; vbbEvent.Userid = vThread.Postuserid; context.Events.InsertOnSubmit(vbbEvent); // insert subribe event VBBContext.Subscribeevent subscribeevent = new Subscribeevent(); subscribeevent.Eventid = maxEventId; subscribeevent.Lastreminder = 0; subscribeevent.Reminder = 259200; subscribeevent.Userid = vThread.Postuserid; context.Subscribeevents.InsertOnSubmit(subscribeevent); #endregion // insert replies #region INSERT REPLIES if (allowReplies == 1) { var replies = from reg in bonSoChinContext.Eventregistrations where reg.Eventid == @event.Eventid select reg; int postCount = 1; foreach (Eventregistration post in replies.ToList()) { // ---------------------------------- CREATE POSTS ----------------------------------- vPostId++; Post vPost = new Post(); //vPost.Postid = vPostId; vPost.Threadid = vThreadId; vPost.Title = ""; vPost.Dateline = v1Post.Dateline; vPost.Pagetext = post.Regcomments; vPost.Allowsmilie = 1; vPost.Ipaddress = "127.0.0.1"; vPost.Visible = 1; vPost.Parentid = vPostId; #region post user postMemberInThread = (from member1 in bonSoChinContext.Members where (member1.Memberid == post.Memberid) select member1).FirstOrDefault(); if (postMemberInThread == null) { postUserInThread = (from user1 in context.Users where user1.Username.Equals(post.Regfirstname + post.Reglastname + "TEMP") select user1).FirstOrDefault(); if (postUserInThread != null) { vPost.Userid = postUserInThread.Userid; vPost.Username = postUserInThread.Username; } else { } } else { postUserInThread = (from user1 in context.Users where user1.Username.Equals(postMemberInThread.Memberlogin.Trim()) select user1).FirstOrDefault(); vPost.Userid = postUserInThread.Userid; vPost.Username = postMemberInThread.Memberlogin; } #endregion PopulateUShort(vPost); //context.SubmitChanges(); /*postId = (int) (from vPost1 in context.Posts select vPost1.Postid).Max();*/ vThread.Replycount++; vForum.Threadcount++; vForum.Replycount++; postCount++; vThread.Lastpostid = vPostId; vThread.Lastposter = vPost.Username; vThread.Lastposterid = vPost.Userid; vThread.Lastpost = vPost.Dateline; // update thread & forum UpdateStatusOfForumAndThread(vThread, vForum, vPost, vPostId, vThreadId); //postId++; context.Posts.InsertOnSubmit(vPost); // insert post parser Postparsed postparsed = new Postparsed(); postparsed.Dateline = vPost.Dateline; postparsed.Postid = vPostId; postparsed.Styleid = 1; postparsed.Languageid = 1; postparsed.Hasimages = 0; postparsed.Pagetexthtml = vPost.Pagetext; context.Postparseds.InsertOnSubmit(postparsed); } #endregion } } //context.Forums.InsertOnSubmit(vSubForum); /*}*/ context.SubmitChanges(); }
private void ConvertForum(BackgroundWorker sender) { BonSoChinDataContext bonSoChinContext = new BonSoChinDataContext(); VBBDataContext context = new VBBDataContext(); // process null users var lackingMembers = (from msg in bonSoChinContext.Messages where !bonSoChinContext.Members.Any(c => c.Memberid == msg.Memberidauthor) select msg.Messageauthor).Distinct<string>().ToList(); string tempUser = "******"; int tempUserCount = 1; /*foreach (string lackingMember in lackingMembers) { string salt = FetchUserSalt(3); User user = new User { Username = lackingMember,//tempUser + string.Format("{0:000}", tempUserCount++), Password = CreatePassword("bscpassword", salt), Usergroupid = 2, Passworddate = DateTime.Now, Email = "*****@*****.**", Showvbcode = 1, Showbirthday = 0, Usertitle = "Junior Member", Joindate = ConvertToUnixTimestamp(DateTime.Now), Lastvisit = 1273158780, Daysprune = -1, Lastactivity = 1273158780, Reputation = 10, Reputationlevelid = 5, Timezoneoffset = "7", Options = 45108311, Birthday = "", Birthdaysearch = DateTime.Now, Posts = 0, Maxposts = -1, Startofweek = 1, Autosubscribe = -1, Salt = salt, Showblogcss = 1, }; string img = "000.gif"; user.Avatarid = (short)(from avt in context.Avatars where avt.Avatarpath.Equals(img) select avt.Avatarid).FirstOrDefault(); PopulateUShort(user); context.Users.InsertOnSubmit(user); }*/ string salt = FetchUserSalt(3); User user = new User { Username = "******",//tempUser + string.Format("{0:000}", tempUserCount++), Password = CreatePassword("bscpassword", salt), Usergroupid = 2, Passworddate = DateTime.Now, Email = "*****@*****.**", Showvbcode = 1, Showbirthday = 0, Usertitle = "Junior Member", Joindate = ConvertToUnixTimestamp(DateTime.Now), Lastvisit = 1273158780, Daysprune = -1, Lastactivity = 1273158780, Reputation = 10, Reputationlevelid = 5, Timezoneoffset = "7", Options = 45108311, Birthday = "", Birthdaysearch = DateTime.Now, Posts = 0, Maxposts = -1, Startofweek = 1, Autosubscribe = -1, Salt = salt, Showblogcss = 1, }; string img = "000.gif"; user.Avatarid = (short)(from avt in context.Avatars where avt.Avatarpath.Equals(img) select avt.Avatarid).FirstOrDefault(); PopulateUShort(user); context.Users.InsertOnSubmit(user); context.SubmitChanges(); var forum4source = (from fr in bonSoChinContext.Forums orderby fr.Forumid ascending select fr).ToList(); int maxVForumId = (from vForum1 in context.Forums select vForum1.Forumid).Max(); long maxVThreadId = (from vThread1 in context.Threads select vThread1.Threadid).Max(); int maxPostId = (int)(from vPost1 in context.Posts select vPost1.Postid).Max(); int forumcount = 1; long totalThreadsCount = (from message in bonSoChinContext.Messages where message.Messageparentid.HasValue == false select message).Count(); long currentThreadsCount = 0; long totalPostsCount = (from message in bonSoChinContext.Messages select message).Count(); long currentPostCount = 0; //context.SubmitChanges(); var unknowUser = (from user2 in context.Users where user2.Username.Equals("UNKNOWN") select user2).FirstOrDefault(); var TotalThreads = (from message in bonSoChinContext.Messages select message).ToList(); // ---------------------------------- CREATE FORUM ----------------------------------- foreach (Forum forum in forum4source) { VBBContext.Forum vForum = new VBBContext.Forum { Title = forum.Forumname, Titleclean = forum.Forumname, Description = forum.Forumdescription, Descriptionclean = forum.Forumdescription, Displayorder = 1, // replycount Replycount = 0, Lastpost = 0, Lastposter = "", Lastposterid = 0, Lastpostid = 0, Lastthread = "", Lastthreadid = 0, Newpostemail = "", Newthreademail = "", Parentid = -1, Parentlist = "", Childlist = "", Defaultsortfield = "lastpost", Defaultsortorder = "desc", Threadcount = 0, Options = 221127, }; PopulateUShort(vForum); //int vForumId = (from vForum1 in context.Forums select vForum1.Forumid).Max(); int vForumId = ++maxVForumId; vForum.Forumid = vForumId; vForum.Parentlist = vForumId + ",-1"; vForum.Childlist = vForumId + ",-1"; //context.SubmitChanges(); context.Forums.InsertOnSubmit(vForum); int forumId = forum.Forumid; // insert thread /*var thread4source = (from message in bonSoChinContext.Messages where message.Forumid == forumId //&& (message.Messageparentid.Equals("") || message.Messageparentid == null) && (message.Messageparentid.HasValue == false) orderby message.Messagedateentered select message).ToList();*/ var thread4Source = (from message in TotalThreads where message.Forumid == forumId //&& (message.Messageparentid.Equals("") || message.Messageparentid == null) && (message.Messageparentid.HasValue == false) orderby message.Messagedateentered select message).ToList(); int totalThreads = thread4Source.Count; currentThreadsCount += totalThreads; Console.WriteLine("Dang convert tong so thread " + currentThreadsCount + " / " + totalThreadsCount); int threadCount = 0; sender.ReportProgress(10, new UserProgress(forum.Forumname, (int)currentThreadsCount, (int)totalThreadsCount)); // ---------------------------------- CREATE THREADS ----------------------------------- foreach (Message thread in thread4Source) { var vThreadId = ++maxVThreadId; Thread vThread = new Thread(); vThread.Title = thread.Messagetopic; vThread.Prefixid = ""; vThread.Forumid = vForumId; vThread.Open = 1; vThread.Visible = 1; vThread.Dateline = ConvertToUnixTimestamp(thread.Messagedateentered); #region thread user var postMemberInThread = (from member1 in bonSoChinContext.Members where (member1.Memberid == thread.Memberidauthor) select member1).FirstOrDefault(); if ( //thread.Memberidauthor ==null !thread.Memberidauthor.HasValue || postMemberInThread == null) { /*var postUserInThread = (from user1 in context.Users where user1.Username.Equals(thread.Messageauthor) select user1).FirstOrDefault(); if (postUserInThread != null) { vThread.Postuserid = postUserInThread.Userid; vThread.Postusername = postUserInThread.Username; } else {*/ vThread.Postuserid = unknowUser.Userid; vThread.Postusername = unknowUser.Username; /*}*/ } else { var postUserInThread = (from user1 in context.Users where user1.Username.Equals(postMemberInThread.Memberlogin.Trim()) select user1).FirstOrDefault(); vThread.Postuserid = postUserInThread.Userid; vThread.Postusername = postMemberInThread.Memberlogin; } #endregion vThread.Lastposter = ""; vThread.Notes = ""; vThread.Similar = ""; PopulateUShort(vThread); context.Threads.InsertOnSubmit(vThread); // create first post int vPostId = 0; if (vPostId == 0) { vThread.Firstpostid = maxPostId + 1; } vPostId = ++maxPostId; // 1st post entered Post v1Post = new Post { Threadid = vThreadId, Title = "", Dateline = ConvertToUnixTimestamp(thread.Messagedateentered), Pagetext = thread.Messagecontent, Allowsmilie = 1, Ipaddress = "127.0.0.1", Visible = 1, Parentid = vPostId, Userid = vThread.Postuserid, Username = vThread.Postusername, }; //v1Post.Pagetext = ReplaceString(v1Post.Pagetext); // insert post parser Postparsed postparsed1 = new Postparsed { Dateline = v1Post.Dateline, Postid = vPostId, Styleid = 1, Languageid = 1, Hasimages = 0, Pagetexthtml = v1Post.Pagetext, }; //postparsed1.Pagetexthtml = ReplaceString(postparsed1.Pagetexthtml); context.Posts.InsertOnSubmit(v1Post); context.Postparseds.InsertOnSubmit(postparsed1); currentPostCount += 1; UpdateStatusOfForumAndThread(vThread, vForum, v1Post, vPostId, vThreadId); vForum.Lastthread = vThread.Dateline.ToString(); vForum.Lastthreadid = vThreadId; vForum.Threadcount++; vThread.Replycount = 0; int threadId = thread.Messageid; // insert post /*var post4source = (from message1 in bonSoChinContext.Messages where message1.Forumid == forumId && (message1.Messageparentid == threadId) orderby message1.Messageid ascending select message1).ToList();*/ var post4source = (from message1 in TotalThreads where message1.Forumid == forumId && (message1.Messageparentid == threadId) orderby message1.Messageid ascending select message1).ToList(); currentPostCount += post4source.Count; Console.WriteLine("Dang convert tong so post " + currentPostCount + " / " + totalPostsCount); int postCount = 1; // ---------------------------------- CREATE POSTS ----------------------------------- foreach (Message post in post4source) { vPostId = ++maxPostId; Post vPost = new Post(); vPost.Threadid = vThreadId; vPost.Title = ""; vPost.Dateline = ConvertToUnixTimestamp(post.Messagedateentered); vPost.Pagetext = post.Messagecontent; vPost.Allowsmilie = 1; vPost.Ipaddress = "127.0.0.1"; vPost.Visible = 1; vPost.Parentid = vPostId; //vPost.Pagetext = ReplaceString(vPost.Pagetext); #region post user postMemberInThread = (from member1 in bonSoChinContext.Members where (member1.Memberid == post.Memberidauthor) //where (member1.Memberid == 1093) select member1).FirstOrDefault(); if (//post.Memberidauthor == null !post.Memberidauthor.HasValue || postMemberInThread == null) { vPost.Userid = unknowUser.Userid; vPost.Username = unknowUser.Username; } else { var postUserInThread = (from user1 in context.Users where user1.Username.Equals(postMemberInThread.Memberlogin.Trim()) select user1).FirstOrDefault(); vPost.Userid = postUserInThread.Userid; vPost.Username = postMemberInThread.Memberlogin; } #endregion PopulateUShort(vPost); vThread.Replycount++; vForum.Threadcount++; vForum.Replycount++; postCount++; if (postCount == post4source.Count()) { vThread.Lastpostid = vPostId; vThread.Lastposter = vPost.Username; vThread.Lastposterid = vPost.Userid; vThread.Lastpost = vPost.Dateline; } //postId++; context.Posts.InsertOnSubmit(vPost); // insert post parser Postparsed postparsed = new Postparsed(); postparsed.Dateline = vPost.Dateline; postparsed.Postid = vPostId; postparsed.Styleid = 1; postparsed.Languageid = 1; postparsed.Hasimages = 0; postparsed.Pagetexthtml = vPost.Pagetext; context.Postparseds.InsertOnSubmit(postparsed); // update thread & forum UpdateStatusOfForumAndThread(vThread, vForum, vPost, vPostId, vThreadId); } vForum.Lastthread = vThread.Title.ToString(); vForum.Lastthreadid = vThreadId; Threadview vThreadview = new Threadview(); vThreadview.Threadid = vThreadId; //context.SubmitChanges(); } context.SubmitChanges(); } context.SubmitChanges(); }
private void ConvertUser(BackgroundWorker sender) { BonSoChinDataContext bonSoChinContext = new BonSoChinDataContext(); VBBDataContext context = new VBBDataContext(); var avatarsource = (from member in bonSoChinContext.Members select member.Memberimage).Distinct<string>().ToList(); int count = 1; sender.ReportProgress(10, new UserProgress("avatar", count++, avatarsource.Count())); // ----------------------- AVATARS TABLE ------------------------------------ foreach (string avatarImg in avatarsource) { string img; if (avatarImg == null) img = "000.gif"; else img = avatarImg.ToString(); string number = img.Substring(0, img.IndexOf(".")); number = RemoveAllSpecialCharacter(number); Avatar avatar = new Avatar { Avatarid = Int32.Parse(number), Avatarpath = img, Displayorder = 1, Imagecategoryid = 3, Title = "", Minimumposts = 0 }; context.Avatars.InsertOnSubmit(avatar); } context.SubmitChanges(); // ----------------------- USERS TABLE ------------------------------------ var result = (from member in bonSoChinContext.Members select member).ToList(); count = 1; sender.ReportProgress(10, new UserProgress("user", count++, result.Count())); foreach (Member member in result) { string salt = FetchUserSalt(3); int test = ConvertToUnixTimestamp(member.Memberdateadded); User user = new User { Userid = (uint)member.Memberid, Username = member.Memberlogin.Trim(), Password = CreatePassword(member.Memberpassword.Trim(), salt), Passworddate = DateTime.Now, Email = member.Memberemail, Showvbcode = 1, Showbirthday = 0, //Usertitle = "Junior Member", Usertitle = (from title in context.Usertitles where title.Minposts < member.Numberofmessages orderby title.Usertitleid ascending select title.Title).FirstOrDefault(), Joindate = ConvertToUnixTimestamp(member.Memberdateadded), //1273158780, //; Lastvisit = 1273158780, Daysprune = -1, Lastactivity = 1273158780, Reputation = 10, Reputationlevelid = 5, Timezoneoffset = "7", Options = 45108311, Birthday = member.Memberdateadded.Value.ToString("yyyy-MM-dd"), Birthdaysearch = DateTime.Now, Posts = (long)member.Numberofmessages, Maxposts = -1, Startofweek = 1, Autosubscribe = -1, Salt = salt, Showblogcss = 1 }; string img = "000.gif"; if (member.Memberimage != null) { img = member.Memberimage; } user.Avatarid = (short)(from avt in context.Avatars where avt.Avatarpath.Equals(img) select avt.Avatarid).FirstOrDefault(); switch (member.Securitylevelid) { case 1: user.Usergroupid = 2; break; case 2: user.Usergroupid = 7; break; case 3: user.Usergroupid = 6; break; default: user.Usergroupid = 2; break; } PopulateUShort(user); context.Users.InsertOnSubmit(user); // userfield Userfield userfield = new Userfield(); userfield.Userid = (uint)member.Memberid; context.Userfields.InsertOnSubmit(userfield); // usertextfield Usertextfield usertextfield = new Usertextfield(); usertextfield.Userid = (uint)member.Memberid; context.Usertextfields.InsertOnSubmit(usertextfield); //} } context.SubmitChanges(); }