示例#1
0
        public LinkOwner CreateEntry(IHtmlResults newUpdate, ObjectId userid)
        {
            try
            {
                HtmlRecord record      = Database.Instance.htmlCollection.FindOneAs <HtmlRecord>(Query.EQ("url", newUpdate.domain.AbsoluteUri));
                LinkOwner  ownerResult = null;
                if (record == null)
                {
                    record      = new HtmlRecord(newUpdate.domain);
                    ownerResult = record.AddResults(newUpdate, userid);
                    Database.Instance.htmlCollection.Save(record, WriteConcern.Acknowledged);
                    jobSchedule.AddNewJob(record.id, record.timeStamp);
                    processJobs.Set();
                }
                else
                {
                    ownerResult = record.AddResults(newUpdate, userid);
                    Database.Instance.htmlCollection.Save(record, WriteConcern.Acknowledged);
                }

                return(ownerResult);
            }
            catch (MongoWriteConcernException ex)
            {
                Console.WriteLine(ex.ToString());
                // TODO: stop potential stack overflow exception
                return(CreateEntry(newUpdate, userid));
            }
        }
示例#2
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);
        }
示例#3
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();
            }
        }
示例#4
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);
        }