public static void Test2(MongoDatabase db) { var d = new Dictionary<string, object>(); var pp = new PortalPage { Title = "This is my test", Id = "test1" }; var pc = new PortalPageColumn(); pp.Columns.Add(pc); pc.Config["width"] = 200; d["open"] = "open listener"; d["close"] = "close listener"; d["interval"] = 500; pc.Config["listeners"] = d; d = new Dictionary<string, object>(); d["open"] = "open listener"; d["close"] = "close listener"; d["interval"] = 500; pc.Config["listeners"] = d; var pt = new Portlet { Title = "test portlet 1", PortletClass = "GraphImage" }; pt.Config["width"] = 200; pt.Config["height"] = 300; pt.Config["listeners"] = d; pc.Portlets.Add(pt); db.GetCollection<PortalPage>().Save(pp); var pp2 = db.GetCollection<PortalPage>().FindOneById(pp.Id); Console.WriteLine("p2: {0}", pp2.Title); }
static void TestDeser() { var d = new Dictionary<string, object>(); var pp = new PortalPage { Title = "This is my test", Id = "test1" }; var pc = new PortalPageColumn(); pp.Columns.Add(pc); pc.Config["width"] = 200; d["open"] = "open listener"; d["close"] = "close listener"; d["interval"] = 500; pc.Config["listeners"] = d; d = new Dictionary<string, object>(); d["open"] = "open listener"; d["close"] = "close listener"; d["interval"] = 500; pc.Config["listeners"] = d; var pt = new Portlet { Title = "test portlet 1", PortletClass = "GraphImage" }; pt.Config["width"] = 200; pt.Config["height"] = 300; pt.Config["listeners"] = new Dictionary<string, object>(d); var l = new List<object>(); var d2 = new Dictionary<string, object>(); d2["name"] = "ko"; d2["value"] = 289; l.Add(d2); l.Add(new Dictionary<string, object>(d2)); pt.Config["dataFields"] = l; pc.Portlets.Add(pt); var sw = new StringWriter(); var bw = BsonWriter.Create(sw); BsonSerializer.Serialize(bw, pp); bw.Flush(); Console.WriteLine("S1: {0}", sw.ToString()); var p2 = BsonSerializer.Deserialize<PortalPage>(BsonReader.Create(new StringReader(sw.ToString()))); }
void VerifySavedPage(PortalPage pp) { try { var p2 = Db.GetCollection<PortalPage>().FindOneById(pp.Id); } catch (Exception ex) { log.Error("Error loading saved page {0}: {1}\nJSON: {2}", pp.Id, ex, Newtonsoft.Json.JsonConvert.SerializeObject(pp)); throw new Exception("Error saving page: " + Newtonsoft.Json.JsonConvert.SerializeObject(pp)); } }
protected PortalPage UpdatePageBeforeReturning(PortalPage p) { p.Editable = PageEditAllowed(p); return p; }
protected bool PageEditAllowed(PortalPage pp) { return pp.OwnerId == UserSessionContext.CurrentUserRecordId; }
public PortalPage SavePage(PortalPage pp) { if (!string.IsNullOrEmpty(pp.OwnerId) && pp.OwnerId != UserSessionContext.CurrentUserRecordId) throw new Exception("Not allowed to modify this page"); if (string.IsNullOrEmpty(pp.OwnerId)) pp.OwnerId = UserSessionContext.CurrentUserRecordId; if (pp.ACL == null) pp.ACL = new List<string>(); if (!pp.ACL.Contains(UserSessionContext.CurrentUserRecordId)) pp.ACL.Add(UserSessionContext.CurrentUserRecordId); Db.GetCollection<PortalPage>().Save(pp); VerifySavedPage(pp); return pp; }
public PortalPage CreateNewUserPage(string pageTitle, string clonePageId) { var pp = new PortalPage(); pp.Title = pageTitle; Db.GetCollection<PortalPage>().Insert(pp); return UpdatePageBeforeReturning(pp); }
public PortalPage AddNewUserPortalPage(PortalPage pp) { pp.Id = null; pp.OwnerId = UserSessionContext.CurrentUserRecordId; pp.ACL.Add(UserSessionContext.CurrentUserRecordId); Db.GetCollection<PortalPage>().Insert(pp); return UpdatePageBeforeReturning(pp) ; }