internal bool CompilePage(string path, out CompilerErrorCollection compilerErrorCollection) { Contract.Page page = Contract.Page.FromString(File.ReadAllText(path)); bool compiled = page.CompileClasses(out compilerErrorCollection); Contract.Page oldPage = this.Pages.Where(p => p.ID == page.ID).FirstOrDefault(); int pageIndex = Pages.IndexOf(oldPage); if (pageIndex != -1) { Pages[pageIndex] = page; } else { Pages.Add(page); } Debug.WriteLine("{0} = {1}", page.ID, compiled); return(compiled); }
/// <summary> /// Tries to compile a page to any possible return errors. /// This method does not save the page like <see cref="SystemLink.UpdatePage"/>. /// </summary> /// <param name="pageObject"></param> /// <returns></returns> public CompilerErrorCollection TryCompilePage(dynamic pageObject) { RequireSystemSigned(); CompilerErrorCollection compilerErrors = new CompilerErrorCollection(); Contract.Page page = PageManager.Session.Pages.Where(P => P.ID == pageObject.ID).FirstOrDefault(); if (page != null && !page.IsLocked) { page = Contract.Page.FromString(page.ToString()); // Create a copy of the page page.Domain = pageObject.Domain; page.Url = pageObject.Url; page.CompilerLanguage = pageObject.CompilerLanguage; page.References = ((ThirdParty.JsonArray)pageObject.References).Select(r => (string)r).ToList(); PageReversion pageReversion = new PageReversion() { Version = page.LatestReversion.Version + 1, Updated = DateTime.UtcNow, Classes = new List <PageClass>() }; pageReversion.Classes = ((ThirdParty.JsonArray)pageObject.LatestReversion.Classes).Select(p => new PageClass() { Name = ((dynamic)p).Name, Data = ((dynamic)p).Data }).ToList(); page.LatestReversion = pageReversion; page.CompileClasses(out compilerErrors, false); } else { compilerErrors.Add(new CompilerError("", 0, 0, "", "Page is locked.")); } return(compilerErrors); }
public CompilerErrorCollection UpdatePage(dynamic pageObject) { RequireSystemSigned(); CompilerErrorCollection compilerErrors = new CompilerErrorCollection(); Contract.Page page = PageManager.Session.Pages.Where(P => P.ID == pageObject.ID).FirstOrDefault(); if (page == null) { page = new Contract.Page() { ID = pageObject.ID, Domain = pageObject.Domain, Url = pageObject.Url, CompilerLanguage = pageObject.CompilerLanguage, References = ((ThirdParty.JsonArray)pageObject.References).Select(r => (string)r).ToList(), }; PageReversion pageReversion = new PageReversion() { Version = 1, Updated = DateTime.UtcNow, Classes = new List <PageClass>() }; pageReversion.Classes = ((ThirdParty.JsonArray)pageObject.LatestReversion.Classes).Select(p => new PageClass() { Name = ((dynamic)p).Name, Data = ((dynamic)p).Data }).ToList(); page.LatestReversion = pageReversion; PageManager.Session.AppendPageReversion(page.ID, pageReversion); PageManager.Session.Pages.Add(page); page.CompileClasses(out compilerErrors); page.Save(); } else if (!page.IsLocked) { page.Domain = pageObject.Domain; page.Url = pageObject.Url; page.CompilerLanguage = pageObject.CompilerLanguage; page.References = ((ThirdParty.JsonArray)pageObject.References).Select(r => (string)r).ToList(); PageReversion pageReversion = new PageReversion() { Version = page.LatestReversion.Version + 1, Updated = DateTime.UtcNow, Classes = new List <PageClass>() }; pageReversion.Classes = ((ThirdParty.JsonArray)pageObject.LatestReversion.Classes).Where(p => p != null).Select(p => new PageClass() { Name = ((dynamic)p).Name, Data = ((dynamic)p).Data }).ToList(); //page.Reversions.Add(pageReversion); page.LatestReversion = pageReversion; PageManager.Session.AppendPageReversion(page.ID, pageReversion); page.CompileClasses(out compilerErrors); page.Save(); } else { compilerErrors.Add(new CompilerError("", 0, 0, "", "Page is locked.")); } return(compilerErrors); }