public ServerResponse Modify() { ServerResponse response = null; try { User user = UserManager.Instance.FindUserByID(this.userid); LinkOwner results = null; try { results = user.ModifySubscription(modifiedKeywords); if (results != null) { response = new ServerResponse(user.id, Response.Success); response.AddOwnerToResponse(results); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); response = new ServerResponse(userid, Response.ServerError); } return(response); }
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)); } }
public ServerResponse AddLink() { ServerResponse response = null; try { User user = UserManager.Instance.FindUserByID(userid); LinkOwner results = null; try { results = user.AddTextUpdate(url, htmlTags, innerText); if (results != null) { UserManager.Instance.SaveUser(user); response = new ServerResponse(user.id, Response.LinkAdded); response.AddOwnerToResponse(results); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); response = new ServerResponse(userid, Response.LinkAlreadyExist); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); response = new ServerResponse(userid, Response.ServerError); } return(response); }
public void UpdateResults(LinkOwner userResults, ObjectId itemid) { if (links.ContainsKey(itemid)) { links[itemid] = userResults; } else { throw new Exception(); } }
public LinkOwner ModifySubscription(LinkOwner modifiedResults) { if (links.ContainsKey(modifiedResults.resultsid)) { LinkOwner linkOwner = DataManager.Instance.ModifyOwnership(modifiedResults); links[modifiedResults.resultsid] = linkOwner; return(linkOwner); } else { throw new Exception(); } }
public LinkOwner ManualRequest(LinkOwner owner) { try { IMongoQuery query = Query.EQ("results.k", owner.resultsid); HtmlRecord record = Database.Instance.htmlCollection.FindOne(query); return(record.results[owner.resultsid].RetrieveResults(owner.userid)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
public SyncData RetrieveData() { SyncData response = null; try { LinkOwner results = DataManager.Instance.ManualRequest(linkOwner); response = new SyncData(userid, results); } catch (Exception ex) { response = new SyncData(userid, null); throw ex; } return(response); }
// User is unsubscribing altogether public void RemoveResultsOwner(LinkOwner entryToRemove) { try { HtmlRecord record = RetrieveEntryById(entryToRemove.resultsid); record.RemoveResultsOwner(entryToRemove); Database.Instance.htmlCollection.Save(record, WriteConcern.Acknowledged); } catch (MongoWriteConcernException ex) { Console.WriteLine(ex.ToString()); throw ex; } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
// replicates CreateEntry in the event of record duplication during a parallel "Save" // /*public LinkOwner ModifyHtmlResults(IHtmlResults modifiedEntry, LinkOwner owner) * { * try * { * HtmlRecord record = Database.Instance.htmlCollection.FindOneAs<HtmlRecord>(Query.EQ("url", modifiedEntry.domain.AbsoluteUri)); * LinkOwner ownerResult = record.ModifyResults(modifiedEntry, owner); * * Database.Instance.htmlCollection.Save(record, WriteConcern.Acknowledged); * return ownerResult; * } * catch(MongoWriteConcernException ex) * { * Console.WriteLine(ex.ToString()); * throw ex; * } * catch(Exception ex) * { * Console.WriteLine(ex.ToString()); * throw ex; * } * }*/ /*public bool Edit(HtmlRecord record) * { * var result = Database.Instance.htmlCollection.FindAndModify(Query.And(Query.EQ("url", record.domain.AbsoluteUri), * Query.EQ("Version", record.version)), * null, * Update.Set("_id", record.id) * .Set("url", record.url) * .Set("domain", record.domain.ToBson()) * .Set("timeStamp", record.timeStamp) * .Set("results", record.results.ToBson()) * .Set("serverResponse", record.serverResponse) * .Inc("version", 1)); * return result.ModifiedDocument != null; * }*/ public LinkOwner ModifyOwnership(LinkOwner newOwnerResults) { try { HtmlRecord record = RetrieveEntryById(newOwnerResults.resultsid); LinkOwner linkOwner = record.ModifyOwner(newOwnerResults); Database.Instance.htmlCollection.Save(record, WriteConcern.Acknowledged); return(linkOwner); } catch (MongoWriteConcernException ex) { Console.WriteLine(ex.ToString()); throw ex; } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
public void AddOwnerToResponse(LinkOwner owner) { this.owner = owner; }
public SyncData(ObjectId id, LinkOwner results) { userid = id; userData = results; }