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 GenerateReportedSelectedTextTables(string pageUrl, string pageUrlHash, string selectionText, string selectionTextHash, ReportItEntities rie, SelectionText st, ReportedSelectedText rst) { if (!string.IsNullOrEmpty(selectionText)) { // 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 st = GetSelectionTextRecord(rie, selectionTextHash); if (st == null) { // The SrcUrl record has never been created // Create SrcUrl record st = new SelectionText(); st.Count = 1; st.Processed = false; st.SelectionText1 = selectionText; st.SelectionTextHash = selectionTextHash; st.CreatedOn = DateTime.UtcNow; st.UpdatedOn = DateTime.UtcNow; rie.SelectionTexts.Add(st); } else { // The srcUrl record has been created - update count st.Count = st.Count + 1; st.UpdatedOn = DateTime.UtcNow; } // Ok Now the Sanity Check to make sure that the Many to Many table is correctly populated if (!ReportedSelectedTextExists(rie, pageUrlHash, selectionTextHash)) { rst.PageUrlHash = pageUrlHash; rst.SelectedTextHash = selectionTextHash; rie.ReportedSelectedTexts.Add(rst); } rie.SaveChanges(); } }