public override void UpdatePage(IPage page) { if (page == null) throw new ArgumentNullException("page"); IPage p = GetPage(page.ID); if (p == null) throw new ChangeConflictException("Page not found or deleted"); LinqPage item = new LinqPage() { ApplicationName = this.ApplicationName, Author = page.Author, DateCreated = page.DateCreated, Description = page.Description, ID = page.ID, IsVisible = page.IsVisible, Keywords = page.Keywords, LastUpdated = p.LastUpdated, LastUpdatedBy = page.LastUpdatedBy, Layout = page.Layout, ParentID = page.Parent != null ? page.Parent.ID : default(Nullable<Guid>), SectionID = page.Section != null ? page.Section.ID : default(Nullable<Guid>), Slug = page.Slug, Title = page.Title }; using(ContentManagerDataContext db = new ContentManagerDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { Table<LinqPage> pages = db.GetTable<LinqPage>(); // Assume that "page" has been sent by client. // Attach with "true" to the change tracker to consider the entity modified // and it can be checked for optimistic concurrency because // it has a column that is marked with "RowVersion" attribute pages.Attach(item, true); try { db.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException ex) { Trace.TraceError(ex.Message); // All database values overwrite current values. foreach (ObjectChangeConflict occ in db.ChangeConflicts) occ.Resolve(RefreshMode.OverwriteCurrentValues); } catch (System.Data.Common.DbException ex) { Trace.TraceError(ex.Message); } } }
public override void DeletePage(IPage page) { if (page == null) throw new ArgumentNullException("page"); DeleteRoles(page); IPage p = GetPage(page.ID); if (p == null) return; LinqPage item = new LinqPage() { ApplicationName = this.ApplicationName, Author = page.Author, DateCreated = page.DateCreated, Description = page.Description, ID = page.ID, IsVisible = page.IsVisible, Keywords = page.Keywords, LastUpdated = p.LastUpdated, LastUpdatedBy = page.LastUpdatedBy, Layout = page.Layout, ParentID = page.Parent != null ? page.Parent.ID : default(Nullable<Guid>), Slug = page.Slug, Title = page.Title }; using (ContentManagerDataContext db = new ContentManagerDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { Table<LinqPage> pages = db.GetTable<LinqPage>(); // Set to false to indicate that the object does not have a timestamp (RowVersion) pages.Attach(item, true); pages.DeleteOnSubmit(item); try { db.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException ex) { Trace.TraceError(ex.Message); // All database values overwrite current values. foreach (ObjectChangeConflict occ in db.ChangeConflicts) occ.Resolve(RefreshMode.OverwriteCurrentValues); } catch (System.Data.Common.DbException ex) { Trace.TraceError(ex.Message); } } }
public override void InsertPage(IPage page) { if (page == null) throw new ArgumentNullException("page"); LinqPage p = new LinqPage() { ApplicationName = this.ApplicationName, Author = page.Author, DateCreated = page.DateCreated, Description = page.Description, ID = page.ID, IsVisible = page.IsVisible, Keywords = page.Keywords, LastUpdated = page.LastUpdated, LastUpdatedBy = page.LastUpdatedBy, Layout = page.Layout, ParentID = page.Parent != null ? page.Parent.ID : default(Nullable<Guid>), SectionID = page.Section != null ? page.Section.ID : default(Nullable<Guid>), Slug = page.Slug, Title = page.Title }; using(ContentManagerDataContext db = new ContentManagerDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { Table<LinqPage> pages = db.GetTable<LinqPage>(); pages.InsertOnSubmit(p); try { db.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException ex) { Trace.TraceError(ex.Message); // All database values overwrite current values. foreach (ObjectChangeConflict occ in db.ChangeConflicts) occ.Resolve(RefreshMode.OverwriteCurrentValues); } catch (System.Data.Common.DbException ex) { Trace.TraceError(ex.Message); } } }
private void ReadContentManagerStore() { if (!_isInitialized) throw new InvalidOperationException("Provider has not been initialized"); if (_categories == null) { lock (syncRoot) { if (_categories == null) { _categories = new Dictionary<Guid, LinqCategory>(); _sections = new Dictionary<Guid, LinqSection>(); _pages = new Dictionary<Guid, LinqPage>(); _roles = new NameValueCollection(); _modules = new Dictionary<Guid, LinqModule>(); XmlDocument doc = new XmlDocument(); doc.Load(_xmlFileName); #region Categories XmlNodeList nodes = doc.GetElementsByTagName("Category"); foreach (XmlNode node in nodes) { LinqCategory category = null; Guid id = new Guid(node["ID"].InnerText); if (_categories.ContainsKey(id)) { category = _categories[id]; } else { category = new LinqCategory(id); _categories.Add(id, category); } category.Name = node["Name"].InnerText; if (!string.IsNullOrEmpty(node["DateCreated"].InnerText)) category.DateCreated = DateTime.Parse(node["DateCreated"].InnerText); if (!string.IsNullOrEmpty(node["LastUpdated"].InnerText)) category.LastUpdated = DateTime.Parse(node["LastUpdated"].InnerText); if (!string.IsNullOrEmpty(node["ParentID"].InnerText)) category.ParentID = new Guid(node["ParentID"].InnerText); } #endregion #region Sections nodes = doc.GetElementsByTagName("Section"); foreach (XmlNode node in nodes) { LinqSection section = null; Guid id = new Guid(node["ID"].InnerText); if (_sections.ContainsKey(id)) { section = _sections[id]; } else { section = new LinqSection(id); _sections.Add(id, section); } section.Name = node["Name"].InnerText; section.Index = Int32.Parse(node["Index"].InnerText); section.Slug = node["Slug"].InnerText; if (!string.IsNullOrEmpty(node["DateCreated"].InnerText)) section.DateCreated = DateTime.Parse(node["DateCreated"].InnerText); if (!string.IsNullOrEmpty(node["LastUpdated"].InnerText)) section.LastUpdated = DateTime.Parse(node["LastUpdated"].InnerText); section.IsVisible = bool.Parse(node["IsVisible"].InnerText); if (!string.IsNullOrEmpty(node["ParentID"].InnerText)) section.ParentID = new Guid(node["ParentID"].InnerText); XmlNodeList roles = node.SelectNodes("./Roles/Role"); foreach (XmlNode role in roles) _roles.Add(section.ID.ToString(), role.InnerText); } #endregion #region Pages nodes = doc.GetElementsByTagName("Page"); foreach (XmlNode node in nodes) { LinqPage page = null; Guid id = new Guid(node["ID"].InnerText); if (_pages.ContainsKey(id)) { page = _pages[id]; } else { page = new LinqPage(id); _pages.Add(id, page); } page.Title = node["Title"].InnerText; page.Slug = node["Slug"].InnerText; page.Description = node["Description"].InnerText; page.Keywords = node["Keywords"].InnerText; page.Layout = node["Layout"].InnerText; if (!string.IsNullOrEmpty(node["DateCreated"].InnerText)) page.DateCreated = DateTime.Parse(node["DateCreated"].InnerText); if (!string.IsNullOrEmpty(node["LastUpdated"].InnerText)) page.LastUpdated = DateTime.Parse(node["LastUpdated"].InnerText); page.IsVisible = bool.Parse(node["IsVisible"].InnerText); page.Author = node["Author"].InnerText; page.LastUpdatedBy = node["LastUpdatedBy"].InnerText; if (!string.IsNullOrEmpty(node["ParentID"].InnerText)) page.ParentID = new Guid(node["ParentID"].InnerText); if (!string.IsNullOrEmpty(node["SectionID"].InnerText)) page.SectionID = new Guid(node["SectionID"].InnerText); XmlNodeList roles = node.SelectNodes("./Roles/Role"); foreach (XmlNode role in roles) _roles.Add(page.ID.ToString(), role.InnerText); } #endregion } } } }