public void Post([FromBody]string value) { // Parts received separated by , // PageUrl -- The Url of the page being reported [0] // SrcUrl -- The SrcUrl of any Image being reported [1] // LinkUrl -- The Url of any link that is being reported [2] // SelectionText -- Any Text that is being reported [3..n] try { if (value != null) { // Get the Reported values and Hashes of them string pu = GetPageUrl(value); string pageUrlHash = GetSHA512(pu); string pageUrl = Security.Encrypt(pu, pageUrlHash); string srcUrl = Security.Encrypt(GetSrcUrl(value), pageUrlHash); //string pageUrl = pu; //string srcUrl = GetSrcUrl(value); string srcUrlHash = null; if (!string.IsNullOrEmpty(srcUrl)) srcUrlHash = GetSHA512(srcUrl); string lulu = GetLinkUrl(value); string linkUrlHash = null; if (!string.IsNullOrEmpty(lulu)) linkUrlHash = GetSHA512(lulu); string linkUrl = Security.Encrypt(lulu, linkUrlHash); //string linkUrl = lulu; string stst = GetSelectionText(value); string selectionTextHash = null; if (!string.IsNullOrEmpty(stst)) selectionTextHash = GetSHA512(stst); string selectionText = Security.Encrypt(stst, selectionTextHash); //string selectionText = stst; ReportItEntities rie = new ReportItEntities(); rie.Database.Connection.Open(); // Connect to the Database // Generate our tables EUReported eur = new EUReported(); SrcUrl su = new SrcUrl(); ReportedSrcUrl rsu = new ReportedSrcUrl(); LinkUrl lu = new LinkUrl(); ReportedLinkUrl rlu = new ReportedLinkUrl(); SelectionText st = new SelectionText(); ReportedSelectedText rst = new ReportedSelectedText(); if (!string.IsNullOrEmpty(pageUrl)) { GenerateReportedSrcsTables(pageUrl, pageUrlHash, srcUrl, srcUrlHash, rie, su, rsu); GenerateReportedLinksTables(pageUrl, pageUrlHash, linkUrl, linkUrlHash, rie, lu, rlu); GenerateReportedSelectedTextTables(pageUrl, pageUrlHash, selectionText, selectionTextHash, rie, st, rst); } else { //Just drop out the bottom -no PageUrl == nothing to process } rie.Database.Connection.Close(); } // return "Nothing received"; } catch (Exception) { // return ex.InnerException.ToString(); } }
private void GenerateReportedLinksTables(string pageUrl, string pageUrlHash, string linkUrl, string linkUrlHash, ReportItEntities rie, LinkUrl lu, ReportedLinkUrl rlu) { if (!string.IsNullOrEmpty(linkUrl)) { // Does the pageUrl exist? // Does the srcUrl exist? // Do they both exist in the ReportedSrcUrls table? They should be it is nice to have a sanity check EUReported puRecord = GetPageUrlRecord(rie, pageUrlHash); if (puRecord == null) { // The page record has never been created // Create Page Record puRecord = new EUReported(); puRecord.Count = 1; puRecord.PageUrl = pageUrl; puRecord.PageUrlHash = pageUrlHash; puRecord.Processed = false; puRecord.CreatedOn = DateTime.UtcNow; puRecord.UpdatedOn = DateTime.UtcNow; rie.EUReporteds.Add(puRecord); } else { // The page record has been created - update count puRecord.Count = puRecord.Count + 1; puRecord.UpdatedOn = DateTime.UtcNow; } // Ok now check to see if the SrcUrl exists lu = GetLinkUrlRecord(rie, linkUrlHash); if (lu == null) { // The SrcUrl record has never been created // Create SrcUrl record lu = new LinkUrl(); lu.Count = 1; lu.Processed = false; lu.LinkUrl1 = linkUrl; lu.LinkUrlHash = linkUrlHash; lu.CreatedOn = DateTime.UtcNow; lu.UpdatedOn = DateTime.UtcNow; rie.LinkUrls.Add(lu); } else { // The srcUrl record has been created - update count lu.Count = lu.Count + 1; lu.UpdatedOn = DateTime.UtcNow; } // Ok Now the Sanity Check to make sure that the Many to Many table is correctly populated if (!ReportedLinkUrlsExists(rie, pageUrlHash, linkUrlHash)) { rlu.PageUrlHash = pageUrlHash; rlu.LinkUrlHash = linkUrlHash; rie.ReportedLinkUrls.Add(rlu); } rie.SaveChanges(); } }