예제 #1
0
        public Tuple <ServerResponse, LinkFeedParams> AddLinkFeed(string userid, string url,
                                                                  string htmlTags, HashSet <string> keywords)
        {
            Tuple <ServerResponse, LinkFeedParams> response = null;
            ObjectId userObjId = ObjectId.Parse(userid);

            try
            {
                User user = UserManager.Instance.FindUserByID(userObjId);
                try
                {
                    LinkFeedParams results = user.AddLinkFeed(url, htmlTags, keywords);
                    UserManager.Instance.SaveUser(user);
                    response = new Tuple <ServerResponse, LinkFeedParams>(ServerResponse.Success, results);
                }
                catch (Exception ex)
                {
                    WriteLog(ex);
                    response = new Tuple <ServerResponse, LinkFeedParams>(ServerResponse.LinkAlreadyExists, null);
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                response = new Tuple <ServerResponse, LinkFeedParams>(ServerResponse.ServerError, null);
            }
            return(response);
        }
예제 #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 Tuple <ServerResponse, LinkFeedParams> ModifyFeed(string userid, string recordid, string resultsid,
                                                                 string htmlTags, HashSet <string> keywords)
        {
            Tuple <ServerResponse, LinkFeedParams> response = null;
            ObjectId userObjId = ObjectId.Parse(userid);

            try
            {
                User           user         = UserManager.Instance.FindUserByID(userObjId);
                ObjectId       recordObjId  = ObjectId.Parse(recordid);
                ObjectId       resultsObjId = ObjectId.Parse(resultsid);
                LinkFeedParams parameters   = user.ModifySubscription(recordObjId, resultsObjId, htmlTags, keywords);
                UserManager.Instance.SaveUser(user);
                response = new Tuple <ServerResponse, LinkFeedParams>(ServerResponse.Success, parameters);
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                response = new Tuple <ServerResponse, LinkFeedParams>(ServerResponse.ServerError, null);
            }

            return(response);
        }