public GamervineService() { // Name the Windows Service ServiceName = "Gamervine Service"; _dataTimer.Elapsed += new System.Timers.ElapsedEventHandler(dataTimer_Elapsed); _postTimer.Elapsed += new System.Timers.ElapsedEventHandler(postTimer_Elapsed); _nextXboxDataID = XboxData.GetNextKey(); _nextPostHistoryID = PostHistory.GetNextKey(); }
public async Task <ActionResult> PostHistory() { PostHistory userHistory = new PostHistory(); User UserInfo = new User(); List <Posting> PostInfo = new List <Posting>(); //List<Comment> CommentInfo = new List<Comment>(); using (var client = new HttpClient()) { //Passing service base url client.BaseAddress = new Uri("https://jsonplaceholder.typicode.com/"); client.DefaultRequestHeaders.Clear(); //Define request data format to JSON client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource HttpResponseMessage Res = await client.GetAsync("https://jsonplaceholder.typicode.com/users/" + 1); HttpResponseMessage Res2 = await client.GetAsync("https://jsonplaceholder.typicode.com/posts?userId=1"); //HttpResponseMessage Res3 = await client.GetAsync("https://jsonplaceholder.typicode.com/comment?postId=" + 1); //Check response sucessful if (Res.IsSuccessStatusCode) { var Response = Res.Content.ReadAsStringAsync().Result; UserInfo = JsonConvert.DeserializeObject <User>(Response); } if (Res2.IsSuccessStatusCode) { var Response2 = Res2.Content.ReadAsStringAsync().Result; PostInfo = JsonConvert.DeserializeObject <List <Posting> >(Response2); } /*if (Res3.IsSuccessStatusCode) * { * var Response = Res.Content.ReadAsStringAsync().Result; * CommentInfo = JsonConvert.DeserializeObject<List<Comment>>(Response); * }*/ userHistory.id = UserInfo.id; userHistory.name = UserInfo.name; userHistory.username = UserInfo.username; userHistory.email = UserInfo.email; userHistory.post = PostInfo; //Return the User list to view return(View(userHistory)); } }
public virtual async Task <ApiPostHistoryServerResponseModel> Get(int id) { PostHistory record = await this.PostHistoryRepository.Get(id); if (record == null) { return(null); } else { return(this.DalPostHistoryMapper.MapEntityToModel(record)); } }
public void MapEntityToModelList() { var mapper = new DALPostHistoryMapper(); PostHistory item = new PostHistory(); item.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1); List <ApiPostHistoryServerResponseModel> response = mapper.MapEntityToModel(new List <PostHistory>() { { item } }); response.Count.Should().Be(1); }
public void MapEFToBOList() { var mapper = new DALPostHistoryMapper(); PostHistory entity = new PostHistory(); entity.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, "A", "A", "A", 1); List <BOPostHistory> response = mapper.MapEFToBO(new List <PostHistory>() { entity }); response.Count.Should().Be(1); }
public virtual async Task <CreateResponse <ApiPostHistoryServerResponseModel> > Create( ApiPostHistoryServerRequestModel model) { CreateResponse <ApiPostHistoryServerResponseModel> response = ValidationResponseFactory <ApiPostHistoryServerResponseModel> .CreateResponse(await this.PostHistoryModelValidator.ValidateCreateAsync(model)); if (response.Success) { PostHistory record = this.DalPostHistoryMapper.MapModelToEntity(default(int), model); record = await this.PostHistoryRepository.Create(record); response.SetRecord(this.DalPostHistoryMapper.MapEntityToModel(record)); await this.mediator.Publish(new PostHistoryCreatedNotification(response.Record)); } return(response); }
public virtual BOPostHistory MapEFToBO( PostHistory ef) { var bo = new BOPostHistory(); bo.SetProperties( ef.Id, ef.Comment, ef.CreationDate, ef.PostHistoryTypeId, ef.PostId, ef.RevisionGUID, ef.Text, ef.UserDisplayName, ef.UserId); return(bo); }
public void MapModelToEntity() { var mapper = new DALPostHistoryMapper(); ApiPostHistoryServerRequestModel model = new ApiPostHistoryServerRequestModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1); PostHistory response = mapper.MapModelToEntity(1, model); response.Comment.Should().Be("A"); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostHistoryTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RevisionGUID.Should().Be("A"); response.Text.Should().Be("A"); response.UserDisplayName.Should().Be("A"); response.UserId.Should().Be(1); }
public async void Get_ShouldReturnRecords() { var mock = new ServiceMockFacade <IPostHistoryService, IPostHistoryRepository>(); var record = new PostHistory(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new PostHistoryService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object, mock.DALMapperMockFactory.DALPostHistoryMapperMock); ApiPostHistoryServerResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public virtual PostHistory MapBOToEF( BOPostHistory bo) { PostHistory efPostHistory = new PostHistory(); efPostHistory.SetProperties( bo.Comment, bo.CreationDate, bo.Id, bo.PostHistoryTypeId, bo.PostId, bo.RevisionGUID, bo.Text, bo.UserDisplayName, bo.UserId); return(efPostHistory); }
public void MapEntityToModel() { var mapper = new DALPostHistoryMapper(); PostHistory item = new PostHistory(); item.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1); ApiPostHistoryServerResponseModel response = mapper.MapEntityToModel(item); response.Comment.Should().Be("A"); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.PostHistoryTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RevisionGUID.Should().Be("A"); response.Text.Should().Be("A"); response.UserDisplayName.Should().Be("A"); response.UserId.Should().Be(1); }
public void MapEFToBO() { var mapper = new DALPostHistoryMapper(); PostHistory entity = new PostHistory(); entity.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, "A", "A", "A", 1); BOPostHistory response = mapper.MapEFToBO(entity); response.Comment.Should().Be("A"); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.PostHistoryTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RevisionGUID.Should().Be("A"); response.Text.Should().Be("A"); response.UserDisplayName.Should().Be("A"); response.UserId.Should().Be(1); }
public void MapBOToEF() { var mapper = new DALPostHistoryMapper(); var bo = new BOPostHistory(); bo.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1); PostHistory response = mapper.MapBOToEF(bo); response.Comment.Should().Be("A"); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.PostHistoryTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RevisionGUID.Should().Be("A"); response.Text.Should().Be("A"); response.UserDisplayName.Should().Be("A"); response.UserId.Should().Be(1); }
public async Task <ICollection <IPostHistory> > ParseAsync(CancellationToken cancellationToken = default) { var posts = AppDomain.CurrentDomain.BaseDirectory + $"{this.path}/PostHistory.xml"; this.logger.LogInformation($"Setting PostHistory.xml path to {posts}"); if (!File.Exists(posts)) { throw new FileNotFoundException($"The PostHistory.xml file does not exist at {posts}"); } var xelement = await File.ReadAllTextAsync(posts, cancellationToken); var postXElement = XElement.Parse(xelement); var postItems = new BlockingCollection <PostHistory>(); Parallel.ForEach(postXElement.Elements("row"), e => { // ReSharper disable PossibleNullReferenceException try { var post = new PostHistory(); post.RevisionGUID = e.Attribute("RevisionGUID")?.Value; post.Id = e.Attribute("Id") != null ? long.Parse(e.Attribute("Id")?.Value) : 0; post.PostId = e.Attribute("PostId") != null ? long.Parse(e.Attribute("PostId")?.Value) : (long?)null; post.CreationDate = e.Attribute("CreationDate") != null ? DateTime.Parse(e.Attribute("CreationDate").Value) : DateTime.UtcNow; post.UserId = e.Attribute("UserId") != null ? long.Parse(e.Attribute("UserId")?.Value) : 1; post.PostHistoryTypeId = e.Attribute("PostHistoryTypeId") != null ? int.Parse(e.Attribute("PostHistoryTypeId")?.Value) : 0; post.Comment = e.Attribute("Comment")?.Value ?? "no_comment"; post.Text = e.Attribute("Text")?.Value ?? "no_text"; // ReSharper restore PossibleNullReferenceException postItems.Add(post); // Console.WriteLine($"Added post: {post.Title}"); } catch (Exception ex) { this.logger.LogError(ex, $"PostHistory Parser {ex.Message}"); } }); this.logger.LogInformation($"Parsed {postItems.Count} post histories."); return(postItems.ToArray()); }
public virtual PostHistory MapModelToEntity( int id, ApiPostHistoryServerRequestModel model ) { PostHistory item = new PostHistory(); item.SetProperties( id, model.Comment, model.CreationDate, model.PostHistoryTypeId, model.PostId, model.RevisionGUID, model.Text, model.UserDisplayName, model.UserId); return(item); }
public virtual async Task <UpdateResponse <ApiPostHistoryServerResponseModel> > Update( int id, ApiPostHistoryServerRequestModel model) { var validationResult = await this.PostHistoryModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { PostHistory record = this.DalPostHistoryMapper.MapModelToEntity(id, model); await this.PostHistoryRepository.Update(record); record = await this.PostHistoryRepository.Get(id); ApiPostHistoryServerResponseModel apiModel = this.DalPostHistoryMapper.MapEntityToModel(record); await this.mediator.Publish(new PostHistoryUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiPostHistoryServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiPostHistoryServerResponseModel> .UpdateResponse(validationResult)); } }
private void postStatusToPing() { GamervineDataContext dataContext = new GamervineDataContext(); try { var users = from u in dataContext.Users join up in dataContext.UserPrefs on u.UserId equals up.UserId join gt in dataContext.Gamertags on u.UserId equals gt.UserId where gt.State != 2 select new { u.UserId, u.PingFmKey, up.PublishGameFrequency, up.PublishInterval, up.PublishStatus, up.PublishUniqueStatus, up.StatusFormat, gt.TagId, gt.State, gt.Type }; foreach (var user in users) { var latestData = from xd in dataContext.XboxData where xd.TagId == user.TagId orderby xd.RetrieveDate descending select xd; string status = bcXboxData.GetStatusString(user.StatusFormat, latestData.First()); var lastPost = from ph in dataContext.PostHistories where ph.UserId == user.UserId orderby ph.PostDate descending select ph; string strLastPost = string.Empty; if (lastPost.Count() > 0) { strLastPost = lastPost.First().PostString; } if (strLastPost.Equals(string.Empty) || !status.ToLower().Equals(strLastPost.ToLower())) { if ((strLastPost.ToLower().Contains(" is currently offline. last seen ") && !status.ToLower().Contains(" is currently offline. last seen ")) || (!strLastPost.ToLower().Contains(" is currently offline. last seen ") && status.ToLower().Contains(" is currently offline. last seen ")) || (!strLastPost.ToLower().Contains(" is currently offline. last seen ") && !status.ToLower().Contains(" is currently offline. last seen "))) { //Hit the Ping.fm service PingFMApi.api_key = "29e2b905210c5a0cf77f74e2462f8ea4"; PingFMApi ping = new PingFMApi(user.PingFmKey); PingFMApi.PingResponse pr = ping.Post(new PingFMApi.OutgoingMessage(status)); //Record the post history in the database PostHistory ph = new PostHistory(); ph.PostDate = DateTime.UtcNow; ph.PostHistoryId = _nextPostHistoryID++; ph.PostString = status; ph.UserId = user.UserId; dataContext.PostHistories.InsertOnSubmit(ph); } } } } finally { dataContext.SubmitChanges(); } }
public virtual ApiPostHistoryServerResponseModel MapEntityToModel( PostHistory item) { var model = new ApiPostHistoryServerResponseModel(); model.SetProperties(item.Id, item.Comment, item.CreationDate, item.PostHistoryTypeId, item.PostId, item.RevisionGUID, item.Text, item.UserDisplayName, item.UserId); if (item.PostHistoryTypeIdNavigation != null) { var postHistoryTypeIdModel = new ApiPostHistoryTypeServerResponseModel(); postHistoryTypeIdModel.SetProperties( item.PostHistoryTypeIdNavigation.Id, item.PostHistoryTypeIdNavigation.RwType); model.SetPostHistoryTypeIdNavigation(postHistoryTypeIdModel); } if (item.PostIdNavigation != null) { var postIdModel = new ApiPostServerResponseModel(); postIdModel.SetProperties( item.PostIdNavigation.Id, item.PostIdNavigation.AcceptedAnswerId, item.PostIdNavigation.AnswerCount, item.PostIdNavigation.Body, item.PostIdNavigation.ClosedDate, item.PostIdNavigation.CommentCount, item.PostIdNavigation.CommunityOwnedDate, item.PostIdNavigation.CreationDate, item.PostIdNavigation.FavoriteCount, item.PostIdNavigation.LastActivityDate, item.PostIdNavigation.LastEditDate, item.PostIdNavigation.LastEditorDisplayName, item.PostIdNavigation.LastEditorUserId, item.PostIdNavigation.OwnerUserId, item.PostIdNavigation.ParentId, item.PostIdNavigation.PostTypeId, item.PostIdNavigation.Score, item.PostIdNavigation.Tag, item.PostIdNavigation.Title, item.PostIdNavigation.ViewCount); model.SetPostIdNavigation(postIdModel); } if (item.UserIdNavigation != null) { var userIdModel = new ApiUserServerResponseModel(); userIdModel.SetProperties( item.UserIdNavigation.Id, item.UserIdNavigation.AboutMe, item.UserIdNavigation.AccountId, item.UserIdNavigation.Age, item.UserIdNavigation.CreationDate, item.UserIdNavigation.DisplayName, item.UserIdNavigation.DownVote, item.UserIdNavigation.EmailHash, item.UserIdNavigation.LastAccessDate, item.UserIdNavigation.Location, item.UserIdNavigation.Reputation, item.UserIdNavigation.UpVote, item.UserIdNavigation.View, item.UserIdNavigation.WebsiteUrl); model.SetUserIdNavigation(userIdModel); } return(model); }
static void Main(string[] args) { string oradb = "Data Source=ORCL;User Id=hr;Password=hr;"; OracleConnection conn = new OracleConnection(oradb); postlist = new List <Memory>(); userlist = new List <Memory>(); taglist = new List <TagMemory>(); // C# //XDocument doc = XDocument.Load("F:\\ai.stackexchange.com\\Tags.xml"); //int count = 0; //int communityCount = 1; //int userCount = 1; //int postCount = 1; //int badgeCount = 1; //int commentCount = 1; //int postHistoryCount = 1; //int postLinkCount = 1; //int tagCount = 1; //int voteCount = 1; //int tagCommunity = 1; int count = 0; int communityCount = 135; long userCount = 1507406; long tagCount = 44400; long tagCommunity = 44400; long postCount = 2236598; long badgeCount = 2785725; long postLinkCount = 269869; long commentCount = 3706084; long postHistoryCount = 6725606; long voteCount = 9774694; XmlReader reader; var directories = Directory.GetDirectories("D:\\Datasource"); foreach (String dir in directories) { count++; if (count <= 134) { continue; } //if (count == 135) break; Console.WriteLine(new DirectoryInfo(dir).Name); //Community conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT into communities VALUES(" + communityCount + ",'" + new DirectoryInfo(dir).Name + "') "; cmd.CommandType = CommandType.Text; OracleDataReader dr; dr = cmd.ExecuteReader(); dr.Read(); conn.Close(); Console.WriteLine(dir + "\\Users.xml"); reader = XmlReader.Create(dir + "\\Users.xml"); while (reader.Read()) { Users user = new Users(); GlobalUsers globalUser = new GlobalUsers(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { user.localId = Convert.ToInt32(reader.GetAttribute("Id")); user.reputation = Convert.ToInt32(reader.GetAttribute("Reputation")); user.creationDate = reader.GetAttribute("CreationDate"); globalUser.displayName = reader.GetAttribute("DisplayName"); user.lastAccessDate = reader.GetAttribute("LastAccessDate"); globalUser.websiteUrl = reader.GetAttribute("WebsiteUrl"); globalUser.userLocation = reader.GetAttribute("Location"); globalUser.aboutMe = reader.GetAttribute("AboutMe"); user.views = Convert.ToInt32(reader.GetAttribute("Views")); globalUser.profileImageUrl = reader.GetAttribute("ProfileImageUrl"); globalUser.accountId = Convert.ToInt32(reader.GetAttribute("AccountId")); //if (globalUser.accountId == -1) globalUser.accountId = 1; user.accountId = globalUser.accountId; user.accountId = Convert.ToInt32(reader.GetAttribute("AccountId")); globalUser.age = Convert.ToInt32(reader.GetAttribute("Age")); conn.Open(); cmd.CommandText = "SELECT COUNT(*) FROM GLOBALUSERS WHERE ACCOUNTID = " + globalUser.accountId; cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); while (dr.Read()) { if (dr.GetInt32(0) == 0) { try { cmd.CommandText = "INSERT INTO GLOBALUSERS VALUES(" + globalUser.accountId + ",q'[" + globalUser.displayName + "]',q'[" + globalUser.websiteUrl + "]',q'[" + globalUser.userLocation + "]',q'[" + StringExt.Truncate(globalUser.aboutMe, 3000) + "]',q'[" + globalUser.profileImageUrl + "]'," + globalUser.age + " ) "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); } catch (Exception e) { cmd.CommandText = "INSERT INTO GLOBALUSERS VALUES(" + globalUser.accountId + ",q'[" + globalUser.displayName + "]',q'[" + globalUser.websiteUrl + "]',q'[" + globalUser.userLocation + "]',q'[]',q'[" + globalUser.profileImageUrl + "]'," + globalUser.age + " ) "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); } //conn.Close(); } //conn.Open(); cmd.CommandText = "INSERT INTO USERS VALUES(" + userCount + "," + communityCount + "," + user.accountId + "," + user.localId + "," + user.reputation + ",to_timestamp('" + user.creationDate + "','yyyy-mm-dd\"T\"hh24:mi:ss.ff3'),to_timestamp('" + user.lastAccessDate + "','yyyy-mm-dd\"T\"hh24:mi:ss.ff3')," + user.views + ") "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); userlist.Add(new Memory { localId = user.localId, globalId = userCount }); conn.Close(); break; } userCount++; } } Console.WriteLine(dir + "\\Tags.xml"); reader = XmlReader.Create(dir + "\\Tags.xml"); while (reader.Read()) { Tags tag = new Tags(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { if (debugging) { Console.WriteLine("Id: " + reader.GetAttribute("Id")); } //tag.Id = Convert.ToInt32(reader.GetAttribute("Id")); tag.TagName = reader.GetAttribute("TagName"); tag.Count = Convert.ToInt32(reader.GetAttribute("Count")); tag.ExcerptPostId = (reader.GetAttribute("ExcerptPostId") == null) ? -2 : Convert.ToInt32(reader.GetAttribute("ExcerptPostId")); tag.WikiPostId = (reader.GetAttribute("WikiPostId") == null) ? -2 : Convert.ToInt32(reader.GetAttribute("WikiPostId")); if (debugging) { Console.Write(tag.Id + " " + tag.TagName + " " + tag.Count); if (tag.ExcerptPostId != -1) { Console.Write(" " + tag.ExcerptPostId); } if (tag.WikiPostId != -1) { Console.Write(" " + tag.WikiPostId); } Console.WriteLine(); } conn.Open(); cmd.CommandText = "INSERT into tags VALUES(" + tagCount + ",q'[" + tag.TagName + "]'," + tag.Count + "," + validate(tag.ExcerptPostId) + "," + validate(tag.WikiPostId) + ") "; cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); taglist.Add(new TagMemory { tagStr = tag.TagName, globalId = tagCount }); conn.Close(); tagCount++; } } Console.WriteLine(dir + "\\Posts.xml"); reader = XmlReader.Create(dir + "\\Posts.xml"); while (reader.Read()) { Posts post = new Posts(); GlobalUsers globalUser = new GlobalUsers(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { post.localId = Convert.ToInt32(reader.GetAttribute("Id")); post.postTypeId = Convert.ToInt32(reader.GetAttribute("PostTypeId")); post.acceptedAnswerId = reader.GetAttribute("AcceptedAnswerId") == null ? -2 : Convert.ToInt64(reader.GetAttribute("AcceptedAnswerId")); post.parentId = reader.GetAttribute("ParentId") == null ? -2 : Convert.ToInt64(reader.GetAttribute("ParentId")); post.creationDate = reader.GetAttribute("CreationDate"); post.score = Convert.ToInt32(reader.GetAttribute("Score")); post.viewCount = reader.GetAttribute("ViewCount") == null ? -2 : Convert.ToInt32(reader.GetAttribute("ViewCount")); post.postBody = StringExt.Truncate(reader.GetAttribute("Body"), 3500); post.ownerUserId = reader.GetAttribute("OwnerUserId") == null ? -2 : Convert.ToInt64(reader.GetAttribute("OwnerUserId")); post.ownerDisplayName = reader.GetAttribute("OwnerDisplayName"); post.lastEditorUserId = reader.GetAttribute("LastEditorUserId") == null ? -2 : Convert.ToInt64(reader.GetAttribute("LastEditorUserId")); post.lastEditorDisplayName = reader.GetAttribute("LastEditorDisplayName"); post.lastEditDate = reader.GetAttribute("LastEditDate"); post.lastActivityDate = reader.GetAttribute("LastActivityDate"); post.title = reader.GetAttribute("Title"); string tagstring = reader.GetAttribute("Tags"); post.answerCount = Convert.ToInt32(reader.GetAttribute("AnswerCount")); post.commentCount = Convert.ToInt32(reader.GetAttribute("CommentCount")); post.favoriteCount = Convert.ToInt32(reader.GetAttribute("FavoriteCount")); post.closedDate = reader.GetAttribute("ClosedDate"); post.communityOwnedDate = reader.GetAttribute("CommunityOwnedDate"); if (post.ownerUserId != -2) { post.ownerUserId = finduser(post.ownerUserId); //if (post.ownerUserId != -2) //{ // conn.Open(); // cmd.CommandText = "SELECT USERID from USERS WHERE COMMUNITYID= " + communityCount + " AND LOCALID = " + post.ownerUserId; // cmd.CommandType = CommandType.Text; // dr = cmd.ExecuteReader(); // while (dr.Read()) // { // post.ownerUserId = dr.GetInt32(0); // break; // } // conn.Close(); //} } if (post.lastEditorUserId != -2) { post.lastEditorUserId = finduser(post.lastEditorUserId); //if (post.lastEditorUserId != -2) //{ // conn.Open(); // cmd.CommandText = "SELECT USERID from USERS WHERE COMMUNITYID= " + communityCount + " AND LOCALID = " + post.lastEditorUserId; // cmd.CommandType = CommandType.Text; // dr = cmd.ExecuteReader(); // while (dr.Read()) // { // post.lastEditorUserId = dr.GetInt32(0); // break; // } // conn.Close(); //} } conn.Open(); try { cmd.CommandText = "INSERT INTO POSTS VALUES(" + postCount + "," + communityCount + "," + post.localId + "," + post.postTypeId + "," + validate(post.acceptedAnswerId) + "," + validate(post.parentId) + "," + formDate(post.creationDate) + "," + post.score + "," + post.viewCount + ",q'[" + StringExt.Truncate(post.postBody, 3500) + "]'," + validate(post.ownerUserId) + ",q'[" + post.ownerDisplayName + "]'," + validate(post.lastEditorUserId) + ",q'[" + post.lastEditorDisplayName + "]'," + formDate(post.lastEditDate) + "," + formDate(post.lastActivityDate) + ",q'[" + StringExt.Truncate(post.title, 3500) + "]'," + post.answerCount + "," + post.commentCount + "," + post.favoriteCount + "," + formDate(post.closedDate) + "," + formDate(post.communityOwnedDate) + ") "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); } catch (Exception e) { cmd.CommandText = "INSERT INTO POSTS VALUES(" + postCount + "," + communityCount + "," + post.localId + "," + post.postTypeId + "," + validate(post.acceptedAnswerId) + "," + validate(post.parentId) + "," + formDate(post.creationDate) + "," + post.score + "," + post.viewCount + ",q'[]'," + validate(post.ownerUserId) + ",q'[" + post.ownerDisplayName + "]'," + validate(post.lastEditorUserId) + ",q'[" + post.lastEditorDisplayName + "]'," + formDate(post.lastEditDate) + "," + formDate(post.lastActivityDate) + ",q'[" + StringExt.Truncate(post.title, 3500) + "]'," + post.answerCount + "," + post.commentCount + "," + post.favoriteCount + "," + formDate(post.closedDate) + "," + formDate(post.communityOwnedDate) + ") "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); } postlist.Add(new Memory { localId = post.localId, globalId = postCount }); conn.Close(); //insert tags of posts if (tagstring != null) { foreach (string str in tagSeperate(tagstring)) { long tagid = -2; if (debugging) { Console.WriteLine(str); } tagid = findtag(str); //conn.Open(); //cmd.CommandText = "SELECT TAGID from TAGS WHERE TAGID >=" + tagCommunity + " and TAGNAME like q'[" + str + "]'"; //if (debugging)Console.WriteLine(cmd.CommandText); //cmd.CommandType = CommandType.Text; //dr = cmd.ExecuteReader(); //while (dr.Read()) //{ // tagid = dr.GetInt32(0); // break; //} //conn.Close(); conn.Open(); cmd.CommandText = "INSERT into POSTTAGES VALUES(" + tagid + "," + postCount + ") "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); conn.Close(); } } postCount++; } } //Update post table Console.WriteLine("Updating Posts"); if (true) { conn.Open(); cmd.CommandText = "SELECT POSTID,PARENTID,ACCEPTEDANSWERID from POSTS WHERE COMMUNITYID=" + communityCount + " and (PARENTID is not NULL or ACCEPTEDANSWERID is not NULL)"; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); while (dr.Read()) { Posts post = new Posts(); post.postId = dr.GetInt32(0); //post.communityId = dr.GetInt32(1); try { post.parentId = dr.GetInt32(1); } catch { post.parentId = -2; } try { post.acceptedAnswerId = dr.GetInt32(2); } catch { post.acceptedAnswerId = -2; } if (post.acceptedAnswerId != -2) { post.acceptedAnswerId = findpost(post.acceptedAnswerId); //OracleConnection conn2 = new OracleConnection(oradb); //cmd.Connection = conn2; //conn2.Open(); //cmd.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + post.acceptedAnswerId + " AND COMMUNITYID= " + communityCount; //cmd.CommandType = CommandType.Text; //OracleDataReader dr2 = cmd.ExecuteReader(); //while (dr2.Read()) //{ // post.acceptedAnswerId = dr2.GetInt32(0); // break; //} //conn2.Close(); } if (post.parentId != -2) { post.parentId = findpost(post.parentId); //OracleConnection conn2 = new OracleConnection(oradb); //cmd.Connection = conn2; //conn2.Open(); //cmd.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + post.parentId + " AND COMMUNITYID= " + communityCount; //cmd.CommandType = CommandType.Text; //OracleDataReader dr2 = cmd.ExecuteReader(); //while (dr2.Read()) //{ // post.parentId = dr2.GetInt32(0); // break; //} //conn2.Close(); } OracleConnection conn3 = new OracleConnection(oradb); cmd.Connection = conn3; conn3.Open(); cmd.CommandText = "UPDATE POSTS SET ACCEPTEDANSWERID=" + validate(post.acceptedAnswerId) + " , PARENTID=" + validate(post.parentId) + " WHERE POSTID=" + post.postId; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; OracleDataReader dr3 = cmd.ExecuteReader(); conn3.Close(); //conn.Open(); } conn.Close(); } cmd.Connection = conn; Console.WriteLine(dir + "\\Badges.xml"); reader = XmlReader.Create(dir + "\\Badges.xml"); while (reader.Read()) { Badges badge = new Badges(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { if (debugging) { Console.WriteLine("Id: " + reader.GetAttribute("Id")); } //tag.Id = Convert.ToInt32(reader.GetAttribute("Id")); badge.badgesName = reader.GetAttribute("Name"); badge.userId = Convert.ToInt32(reader.GetAttribute("UserId")); badge.date = reader.GetAttribute("Date"); badge.badgesClass = Convert.ToInt32(reader.GetAttribute("Class")); badge.tagbased = reader.GetAttribute("TagBased"); badge.userId = finduser(badge.userId); //conn.Open(); //cmd.CommandText = "SELECT USERID from USERS WHERE COMMUNITYID= " + communityCount + " AND LOCALID = " + badge.userId; //cmd.CommandType = CommandType.Text; //dr = cmd.ExecuteReader(); //while (dr.Read()) //{ // badge.userId = dr.GetInt32(0); // break; //} //conn.Close(); conn.Open(); cmd.CommandText = "INSERT into Badges VALUES(" + badgeCount + "," + badge.userId + "," + communityCount + ",q'[" + badge.badgesName + "]'," + formDate(badge.date) + "," + badge.badgesClass + ",q'[" + badge.tagbased + "]') "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); conn.Close(); badgeCount++; } } Console.WriteLine(dir + "\\PostLinks.xml"); reader = XmlReader.Create(dir + "\\PostLinks.xml"); while (reader.Read()) { PostLinks link = new PostLinks(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { if (debugging) { Console.WriteLine("Id: " + reader.GetAttribute("Id")); } link.creationDate = reader.GetAttribute("CreationDate"); link.postId = Convert.ToInt32(reader.GetAttribute("PostId")); link.releatedPostId = Convert.ToInt32(reader.GetAttribute("RelatedPostId")); link.linkTypeId = Convert.ToInt32(reader.GetAttribute("LinkTypeId")); link.postId = findpost(link.postId); link.releatedPostId = findpost(link.releatedPostId); //conn.Open(); //cmd.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + link.postId + " AND COMMUNITYID= " + communityCount; //cmd.CommandType = CommandType.Text; //dr = cmd.ExecuteReader(); //link.postId = -2; //while (dr.Read()) //{ // link.postId = dr.GetInt32(0); // break; //} //conn.Close(); //conn.Open(); //cmd.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + link.releatedPostId + " AND COMMUNITYID= " + communityCount; //cmd.CommandType = CommandType.Text; // dr = cmd.ExecuteReader(); //link.releatedPostId = -2; //while (dr.Read()) //{ // link.releatedPostId = dr.GetInt32(0); // break; //} //conn.Close(); conn.Open(); cmd.CommandText = "INSERT into POSTLINKS VALUES(" + postLinkCount + "," + formDate(link.creationDate) + "," + validate(link.postId) + "," + validate(link.releatedPostId) + "," + link.linkTypeId + ") "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); conn.Close(); postLinkCount++; } } Console.WriteLine(dir + "\\Comments.xml"); reader = XmlReader.Create(dir + "\\Comments.xml"); while (reader.Read()) { Comments comment = new Comments(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { if (debugging) { Console.WriteLine("Id: " + reader.GetAttribute("Id")); } comment.postId = Convert.ToInt32(reader.GetAttribute("PostId")); comment.score = Convert.ToInt32(reader.GetAttribute("Score")); comment.text = reader.GetAttribute("Text"); comment.creationDate = reader.GetAttribute("CreationDate"); comment.userDisplayName = reader.GetAttribute("UserDisplayName"); comment.userId = reader.GetAttribute("UserId") == null ? -2 : Convert.ToInt32(reader.GetAttribute("UserId")); comment.postId = findpost(comment.postId); //conn.Open(); //cmd.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + comment.postId + " AND COMMUNITYID= " + communityCount; //cmd.CommandType = CommandType.Text; //dr = cmd.ExecuteReader(); //comment.postId = -2; //while (dr.Read()) //{ // comment.postId = dr.GetInt32(0); // break; //} //conn.Close(); if (comment.userId != -2) { comment.userId = finduser(comment.userId); //conn.Open(); //cmd.CommandText = "SELECT USERID from USERS WHERE COMMUNITYID= " + communityCount + " AND LOCALID = " + comment.userId; //cmd.CommandType = CommandType.Text; //dr = cmd.ExecuteReader(); //while (dr.Read()) //{ // comment.userId = dr.GetInt32(0); // break; //} //conn.Close(); } conn.Open(); cmd.CommandText = "INSERT into COMMENTS VALUES(" + commentCount + "," + validate(comment.postId) + "," + comment.score + ",q'[" + StringExt.Truncate(comment.text, 3500) + "]'," + formDate(comment.creationDate) + ",q'[" + comment.userDisplayName + "]'," + validate(comment.userId) + ") "; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); conn.Close(); commentCount++; } } Console.WriteLine(dir + "\\PostHistory.xml"); reader = XmlReader.Create(dir + "\\PostHistory.xml"); while (reader.Read()) { PostHistory history = new PostHistory(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { //if (Convert.ToInt32(reader.GetAttribute("Id")) <= 134359) { // continue; //} if (debugging) { Console.WriteLine("Id: " + reader.GetAttribute("Id")); } history.postHistoryTypeId = Convert.ToInt32(reader.GetAttribute("PostHistoryTypeId")); history.postId = Convert.ToInt32(reader.GetAttribute("PostId")); history.revisionGuid = reader.GetAttribute("RevisionGUID"); history.creationDate = reader.GetAttribute("CreationDate"); history.userDisplayName = reader.GetAttribute("UserDisplayName"); history.userId = reader.GetAttribute("UserId") == null ? -2 : Convert.ToInt32(reader.GetAttribute("UserId")); history.postHistoryComment = reader.GetAttribute("Comment"); history.text = reader.GetAttribute("Text"); history.postId = findpost(history.postId); //conn.Open(); //cmd.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + history.postId + " AND COMMUNITYID= " + communityCount; //cmd.CommandType = CommandType.Text; //dr = cmd.ExecuteReader(); //history.postId = -2; //while (dr.Read()) //{ // history.postId = dr.GetInt32(0); // break; //} //conn.Close(); if (history.userId != -2) { history.userId = finduser(history.userId); //conn.Open(); //OracleCommand cmd2 = new OracleCommand(); //cmd2.Connection = conn; //cmd2.CommandText = "SELECT USERID from USERS WHERE COMMUNITYID= " + communityCount + " AND LOCALID = " + history.userId; //cmd2.CommandType = CommandType.Text; //dr = cmd2.ExecuteReader(); //while (dr.Read()) //{ // history.userId = dr.GetInt32(0); // break; //} //cmd2.Dispose(); //conn.Close(); } conn.Open(); try { cmd.CommandText = "INSERT into POSTHISTORY VALUES(" + postHistoryCount + "," + history.postHistoryTypeId + "," + validate(history.postId) + ",q'[" + StringExt.Truncate(history.revisionGuid, 3500) + "]'," + formDate(history.creationDate) + "," + validate(history.userId) + ",q'[" + history.userDisplayName + "]',q'[" + StringExt.Truncate(history.postHistoryComment, 3500) + "]',q'[" + StringExt.Truncate(history.text, 3500) + "]')"; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); } catch (Exception e) { cmd.CommandText = "INSERT into POSTHISTORY VALUES(" + postHistoryCount + "," + history.postHistoryTypeId + "," + validate(history.postId) + ",q'[" + StringExt.Truncate(history.revisionGuid, 3500) + "]'," + formDate(history.creationDate) + "," + validate(history.userId) + ",q'[" + history.userDisplayName + "]',q'[" + StringExt.Truncate(history.postHistoryComment, 3500) + "]',q'[]')"; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); } conn.Close(); postHistoryCount++; } } Console.WriteLine(dir + "\\Votes.xml"); reader = XmlReader.Create(dir + "\\Votes.xml"); while (reader.Read()) { Votes vote = new Votes(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "row") { //if (Convert.ToInt32(reader.GetAttribute("Id")) <= 720) //{ // continue; //} if (debugging) { Console.WriteLine("Id: " + reader.GetAttribute("Id")); } vote.postId = Convert.ToInt32(reader.GetAttribute("PostId")); vote.voteTypeId = Convert.ToInt32(reader.GetAttribute("VoteTypeId")); vote.voterUserId = reader.GetAttribute("UserId") == null ? -2 : Convert.ToInt32(reader.GetAttribute("UserId")); vote.creationDate = reader.GetAttribute("CreationDate"); vote.bountyAmount = reader.GetAttribute("BountyAmount") == null ? -2 : Convert.ToInt32(reader.GetAttribute("BountyAmount")); vote.postId = findpost(vote.postId); // conn.Open(); //OracleCommand cmd3 = new OracleCommand(); //cmd3.Connection = conn; //cmd3.CommandText = "SELECT POSTID from POSTS WHERE LOCALID=" + vote.postId + " AND COMMUNITYID= " + communityCount; //cmd3.CommandType = CommandType.Text; //dr = cmd3.ExecuteReader(); //vote.postId = -2; //while (dr.Read()) //{ // vote.postId = dr.GetInt32(0); // break; //} //cmd3.Dispose(); //conn.Close(); if (vote.voterUserId != -2) { vote.voterUserId = finduser(vote.voterUserId); //conn.Open(); //OracleCommand cmd2 = new OracleCommand(); //cmd2.Connection = conn; //cmd2.CommandText = "SELECT USERID from USERS WHERE COMMUNITYID= " + communityCount + " AND LOCALID = " + vote.voterUserId; //cmd2.CommandType = CommandType.Text; //dr = cmd2.ExecuteReader(); //while (dr.Read()) //{ // vote.voterUserId = dr.GetInt32(0); // break; //} //cmd2.Dispose(); //conn.Close(); } //OracleCommand cmd4 = new OracleCommand(); //try //{ conn.Open(); //cmd4.Connection = conn; cmd.CommandText = "INSERT into VOTES VALUES(" + voteCount + "," + validate(vote.postId) + "," + vote.voteTypeId + "," + validate(vote.voterUserId) + "," + formDate(vote.creationDate) + "," + validate(vote.bountyAmount) + ")"; if (debugging) { Console.WriteLine(cmd.CommandText); } cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); //cmd.Dispose(); conn.Close(); // } //catch //{ // Console.WriteLine(cmd.CommandText); //} // voteCount++; } } tagCommunity = tagCount; communityCount++; postlist = null; userlist = null; taglist = null; GC.Collect(); postlist = new List <Memory>(); userlist = new List <Memory>(); taglist = new List <TagMemory>(); Console.WriteLine("Community: " + communityCount + " User: "******" Posts: " + postCount + "\nTags: " + tagCount + " Badges: " + badgeCount + " PostLinkS: " + postLinkCount + "\nComments: " + commentCount + " PostHistory: " + postHistoryCount + " Votes: " + voteCount); } //conn.Close(); conn.Dispose(); }
public void DoWork() { GamervineDataContext dataContext = new GamervineDataContext(); try { //Get all jobs where the user & gamertags are active and the next run time is in the past or now var jobs = from j in dataContext.Jobs join gt in dataContext.Gamertags on j.TagId equals gt.TagId join u in dataContext.Users on gt.UserId equals u.UserId where gt.State == State.Active.GetHashCode() && u.State == State.Active.GetHashCode() && j.NextRunTime <= DateTime.UtcNow select j; foreach (Job job in jobs) { try { IJobHandler jobHandler = JobHandlerFactory.GetHandlerForType(job.Type); string post = jobHandler.GetPost(dataContext, job); if (!post.Equals(string.Empty)) { var socialConnectors = from sc in dataContext.UserSocialConnections join gtsc in dataContext.GamertagSocialConnections on sc.UserSocialConnectionId equals gtsc.UserSocialConnectionId where gtsc.TagId == job.TagId select sc; if (socialConnectors.Count() > 0) { foreach (UserSocialConnection conn in socialConnectors) { ISocialConnector socialConnector = SocialConnectorFactory.GetSocialConnectorForType(conn.Type); socialConnector.Post(conn, post); } } else { //TODO: Perform logic to flag the account that it doesn't have social connectors and they should sign up } //Do any post work that the handler may need to do jobHandler.PostWork(dataContext, job); //Record the post history in the database PostHistory ph = new PostHistory(); ph.PostDate = DateTime.UtcNow; ph.PostHistoryId = Guid.NewGuid().ToString(); ph.PostString = post; ph.PostType = job.Type; ph.TagId = job.TagId; dataContext.PostHistories.InsertOnSubmit(ph); } job.NextRunTime = job.CalculateNextRunTime(); job.LastRunTime = DateTime.UtcNow; } catch (Exception ex) { Debug.WriteLine("Exception occurred in PostService.DoWork processing Job ID #" + job.JobId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); } finally { try { dataContext.SubmitChanges(); } catch (Exception ex) { Debug.WriteLine("Exception occurred in PostService.DoWork -> dataContext.SubmitChanges for Job ID #" + job.JobId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); } } } } catch (Exception ex) { Debug.WriteLine("Exception occurred in PostService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); } finally { Debug.WriteLine("PostService DoWork completed at " + DateTime.Now.ToString()); } }