Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }