public virtual bool IsUpNeeded(string moduleName, long contentVersion)
 {
     using (var rootApi = CmsContext.CreateApiContextOf <RootApiContext>())
     {
         return(!rootApi.IsContentMigrated(moduleName, contentVersion));
     }
 }
 public virtual void UpPerformed(string moduleName, long contentVersion)
 {
     using (var rootApi = CmsContext.CreateApiContextOf <RootApiContext>())
     {
         using (var transactionScope = new TransactionScope())
         {
             rootApi.ContentMigrated(moduleName, contentVersion);
             transactionScope.Complete();
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Ups the specified configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public override void Up(ICmsConfiguration configuration)
        {
            using (var blogsApi = CmsContext.CreateApiContextOf <BlogsApiContext>())
            {
                var blogs = blogsApi.GetBlogPosts(new GetBlogPostsRequest(includePrivate: true, includeUnpublished: true, includeNotActive: true)).Items;
                if (!blogs.Any())
                {
                    return;
                }

                var updateRequests = new List <UpdateBlogPostRequest>();

                using (var pagesApi = CmsContext.CreateApiContextOf <PagesApiContext>())
                {
                    foreach (var blog in blogs)
                    {
                        var requestToGet = new GetPageContentsRequest(blog.Id, e => e.Content is BlogPostContent, includeUnpublished: true, includeNotActive: true);
                        var pageContent  = pagesApi.GetPageContents(requestToGet).FirstOrDefault();
                        if (pageContent == null)
                        {
                            continue;
                        }

                        var content = pageContent.Content as HtmlContent;
                        if (content == null)
                        {
                            continue;
                        }

                        updateRequests.Add(new UpdateBlogPostRequest {
                            Id = blog.Id, ActivationDate = content.ActivationDate, ExpirationDate = content.ExpirationDate,
                        });
                    }
                }

                using (var transactionScope = new TransactionScope())
                {
                    foreach (var request in updateRequests)
                    {
                        blogsApi.UpdateBlogPost(request);
                    }

                    transactionScope.Complete();
                }
            }
        }
        public override void Up(ICmsConfiguration configuration)
        {
            using (var pagesApi = CmsContext.CreateApiContextOf <PagesApiContext>())
            {
                const string WidgetPath = "~/Areas/bcms-newsletter/Views/Widgets/SubscribeToNewsletter.cshtml";
                var          request    = new GetServerControlWidgetsRequest(e => e.Url == WidgetPath);
                var          widgets    = pagesApi.GetServerControlWidgets(request);
                if (widgets.Items.Count > 0)
                {
                    return;
                }

                using (var transactionScope = new TransactionScope())
                {
                    pagesApi.CreateServerControlWidget(
                        new CreateServerControlWidgetRequest()
                    {
                        Name       = "Newsletter Widget",
                        WidgetPath = WidgetPath,
                        Options    =
                            new List <ContentOptionDto>()
                        {
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Email placeholder", DefaultValue = "email..."
                            },
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Label title", DefaultValue = "Subscribe to newsletter"
                            },
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Submit title", DefaultValue = "Submit"
                            },
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Submit is disabled", DefaultValue = "false"
                            }
                        }
                    });
                    transactionScope.Complete();
                }
            }
        }
        public override void Up(ICmsConfiguration configuration)
        {
            using (var pagesApi = CmsContext.CreateApiContextOf <PagesApiContext>())
            {
                var request = new GetPagesRequest(page => page.PageUrl == Urls.Page404, includeUnpublished: true, includePrivate: true);
                var add404  = configuration.Installation.Install404ErrorPage && !pagesApi.GetPages(request).Items.Any();

                request = new GetPagesRequest(page => page.PageUrl == Urls.Page500, includeUnpublished: true, includePrivate: true);
                var add500 = configuration.Installation.Install500ErrorPage && !pagesApi.GetPages(request).Items.Any();

                request = new GetPagesRequest(page => page.PageUrl == Urls.DefaultPage, includeUnpublished: true, includePrivate: true);
                var addDefault = configuration.Installation.InstallDefaultPage && !pagesApi.GetPages(request).Items.Any();

                if (!add404 && !add500 && !addDefault)
                {
                    return;
                }

                using (var transactionScope = new TransactionScope())
                {
                    var layout       = AddLayout(pagesApi);
                    var headerWidget = AddHtmlWidget(pagesApi, "Header", "<a href=\"/\" class=\"bcms-logo\"><img src=\"/file/bcms-pages/content/styles/images/logo.png\" alt=\"Better CMS\"></a>");
                    var footerWidget = AddHtmlWidget(pagesApi, "Footer", "<span class=\"copyright\">Better CMS 2012 ©</span>");

                    if (add404)
                    {
                        Add404ErrorPage(pagesApi, layout, headerWidget, footerWidget);
                    }

                    if (add500)
                    {
                        Add500ErrorPage(pagesApi, layout, headerWidget, footerWidget);
                    }

                    if (addDefault)
                    {
                        AddDefaultPage(pagesApi, layout, headerWidget, footerWidget);
                    }

                    transactionScope.Complete();
                }
            }
        }
Exemple #6
0
        public ActionResult TestApi()
        {
            /*PagesApiContext.Events.PageCreated += EventsOnPageCreated;
             *
             * PagesApiContext.Events.OnPageCreated(new PageProperties());
             *
             * ApiContext.Events.HostStart += Core_HostStart;*/

            var message = string.Empty;

            DataListResponse <BlogPost> results;

            using (var api = CmsContext.CreateApiContextOf <BlogsApiContext>())
            {
                using (var papi = CmsContext.CreateApiContextOf <PagesApiContext>())
                {
                    var aRequest = new GetContentHistoryRequest(new Guid("AE04E233-4E88-4A9F-87BC-A1CC00F2C173"));
                    var aresults = papi.GetContentHistory(aRequest);

                    if (aresults.Items.Count > 0)
                    {
                        message = string.Format("{0}<br />Total count:{2},  Item titles: {1}", message, string.Join("; ", aresults.Items.Select(t => t.Name)), aresults.TotalCount);
                    }

                    aRequest = new GetContentHistoryRequest(new Guid("AE04E233-4E88-4A9F-87BC-A1CC00F2C173"), a => a.Name.ToLower().Contains("poop"), o => o.Name, orderDescending: true);
                    aresults = papi.GetContentHistory(aRequest);

                    if (aresults.Items.Count > 0)
                    {
                        message = string.Format("{0}<br />Total count:{2},  Item titles: {1}", message, string.Join("; ", aresults.Items.Select(t => t.Name)), aresults.TotalCount);
                    }

                    /*var request = new GetDataRequest<Layout>(3, 2, orderDescending:true, order:t =>t.Name);
                     * results = pagesApi.GetLayouts(request);*/

                    /*var request = new GetDataRequest<LayoutRegion>(orderDescending: true, order: t => t.Region.RegionIdentifier);
                     * request.AddPaging(2, 2);*/

                    /*var request = new GetBlogPostsRequest(b => b.ExpirationDate.HasValue, includePrivate: true, includeUnpublished: true, itemsCount: 3);
                     * results = api.GetBlogPosts(request);
                     *
                     * if (results.Items.Count > 0)
                     * {
                     *  message = string.Format(
                     *      "{0}<br />Total count:{2},  Item titles: {1}", message, string.Join("; ", results.Items.Select(t => t.Title)), results.TotalCount);
                     * }
                     *
                     * request = new GetBlogPostsRequest(order: b => b.Title, orderDescending: true, includePrivate: true, includeUnpublished: true);
                     * request.AddPaging(3, 3);
                     * results = api.GetBlogPosts(request);
                     *
                     * if (results.Items.Count > 0)
                     * {
                     *  message = string.Format(
                     *      "{0}<br />Total count:{2}, Item titles: {1}", message, string.Join("; ", results.Items.Select(t => t.Title)), results.TotalCount);
                     * }
                     *
                     * request = new GetBlogPostsRequest(
                     *  order: b => b.Title, orderDescending: true, itemsCount: 5, startItemNumber: 3, includeUnpublished: true, includePrivate: true);
                     * results = api.GetBlogPosts(request);*/
                }
            }

            return(Content(message));
        }