Exemplo n.º 1
0
        public LinkFeedParams ModifySubscription(ObjectId recordid, ObjectId resultsid,
                                                 string htmlTags, HashSet <string> keywords)
        {
            LinkFeedParams parameters = null;

            if (links.ContainsKey(resultsid))
            {
                if (links[resultsid].htmlTags == htmlTags)
                {
                    links[resultsid].ReplaceKeywords(keywords);
                    parameters = links[resultsid];
                }
                else
                {
                    IHtmlRecord record = DataManager.Instance.GetHtmlRecord(recordid);
                    record.RemoveResults(resultsid, id);
                    IHtmlResults results = record.AddResults(htmlTags, id);
                    parameters = new LinkFeedParams(record.recordid, results.resultsid,
                                                    record.domain.AbsoluteUri, results.htmlTags, keywords);
                    DataManager.Instance.SaveHtmlRecord(record);
                    links.Add(results.resultsid, parameters);
                }
            }
            return(parameters);
        }
Exemplo n.º 2
0
 public void RemoveAllLinks()
 {
     foreach (LinkFeedParams linkParams in links.Values)
     {
         IHtmlRecord record = DataManager.Instance.GetHtmlRecord(linkParams.recordid);
         record.RemoveResults(linkParams.resultsid, id);
     }
 }
Exemplo n.º 3
0
 public void SaveHtmlRecord(IHtmlRecord record)
 {
     Database.Instance.htmlCollection.Save(record, WriteConcern.Acknowledged);
     if (!jobSchedule.JobInSchedule(record.recordid))
     {
         jobSchedule.AddNewJob(record.recordid, DateTime.UtcNow);
         scheduleJobsProc.Interrupt();
     }
 }
Exemplo n.º 4
0
 public void RemoveLink(ObjectId resultsid)
 {
     if (links.ContainsKey(resultsid))
     {
         ObjectId    recordid = links[resultsid].recordid;
         IHtmlRecord record   = DataManager.Instance.GetHtmlRecord(recordid);
         record.RemoveResults(resultsid, id);
         links.Remove(resultsid);
         DataManager.Instance.SaveHtmlRecord(record);
     }
 }
Exemplo n.º 5
0
        public IHtmlRecord CreateHtmlRecord(Uri domain)
        {
            IHtmlRecord record = Database.Instance.htmlCollection.FindOneAs <HtmlRecord>
                                     (Query.EQ("url", domain.AbsoluteUri)) as IHtmlRecord;

            if (record == null)
            {
                record = new HtmlRecord(domain);
            }

            return(record);
        }
Exemplo n.º 6
0
        public LinkFeedParams AddLinkFeed(string url, string htmlTags, HashSet <string> keywords)
        {
            if (!links.Any(pair => pair.Value.url == url &&
                           pair.Value.htmlTags == htmlTags))
            {
                IHtmlRecord    record     = DataManager.Instance.CreateHtmlRecord(new Uri(url));
                IHtmlResults   results    = record.AddResults(htmlTags, id);
                LinkFeedParams parameters = new LinkFeedParams(record.recordid, results.resultsid,
                                                               record.domain.AbsoluteUri, results.htmlTags, keywords);
                DataManager.Instance.SaveHtmlRecord(record);
                links.Add(results.resultsid, parameters);

                return(parameters);
            }
            else
            {
                throw new Exception();
            }
        }
Exemplo n.º 7
0
        public List <Tuple <LinkFeedParams, List <UserLink> > > GetAllLinkFeeds()
        {
            List <Tuple <LinkFeedParams, List <UserLink> > > linkFeeds = new List <Tuple <LinkFeedParams, List <UserLink> > >();

            foreach (KeyValuePair <ObjectId, LinkFeedParams> pair in links)
            {
                IHtmlRecord     record  = DataManager.Instance.GetHtmlRecord(pair.Value.recordid);
                IHtmlResults    results = record.GetHtmlResults(pair.Value.resultsid);
                List <UserLink> userLinks;
                if (pair.Value.keywords != null)
                {
                    userLinks = results.GetLinkFeedResults(pair.Value.keywords);
                }
                else
                {
                    userLinks = results.GetLinkFeedResults(new HashSet <string>());
                }

                linkFeeds.Add(new Tuple <LinkFeedParams, List <UserLink> >(pair.Value, userLinks));
                pair.Value.UpdateTimeStamp();
            }
            return(linkFeeds);
        }