Пример #1
0
        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();
            }
        }
Пример #2
0
        private void GenerateReportedSrcsTables(string pageUrl, string pageUrlHash, string srcUrl, string srcUrlHash, ReportItEntities rie, SrcUrl su, ReportedSrcUrl rsu)
        {
            if (!string.IsNullOrEmpty(srcUrl))
            {
                // 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
                su = GetSourceUrlRecord(rie, srcUrlHash);
                if (su == null)
                {
                    // The SrcUrl record has never been created
                    // Create SrcUrl record
                    su = new SrcUrl();
                    su.Count = 1;
                    su.Processed = false;
                    su.SrcUrl1 = srcUrl;
                    su.SrcUrlHash = srcUrlHash;
                    su.CreatedOn = DateTime.UtcNow;
                    su.UpdatedOn = DateTime.UtcNow;
                    rie.SrcUrls.Add(su);
                }
                else
                {
                    // The srcUrl record has been created - update count
                    su.Count = su.Count + 1;
                    su.UpdatedOn = DateTime.UtcNow;
                }

                // Ok Now the Sanity Check to make sure that the Many to Many table is correctly populated
                if (!ReportedSrcUrlsExists(rie, pageUrlHash, srcUrlHash))
                {
                    rsu.PageUrlHash = pageUrlHash;
                    rsu.SrcUrlHash = srcUrlHash;
                    rie.ReportedSrcUrls.Add(rsu);
                }
                rie.SaveChanges();
            }
        }