예제 #1
0
        public void CreateTagsCloudWidget()
        {
            var type = "TagCloud";

            // Check any custom parameters that could cause creating the widget to fail.
            // Nothing to check in this widget, see BlogWidgetCommands.cs for an example.

            // Create the widget using the standard parameters.
            var widget = _widgetCommandsService.CreateBaseWidget(
                Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null);

            if (widget == null)
            {
                return;
            }

            // Set the custom parameters.
            widget.As <TagCloudPart>().Slug = Slug;

            // It's an optional parameter and defaults to 5.
            if (!string.IsNullOrWhiteSpace(Buckets))
            {
                int BucketsAsNumber = 0;
                if (Int32.TryParse(Buckets, out BucketsAsNumber))
                {
                    widget.As <TagCloudPart>().Buckets = BucketsAsNumber;
                }
            }

            // Publish the successfully created widget.
            _widgetCommandsService.Publish(widget);
            Context.Output.WriteLine(T("{0} widget created successfully.", type).Text);
        }
예제 #2
0
        public void Create(string type)
        {
            var widget = _widgetCommandsService.CreateBaseWidget(
                Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, Text, UseLoremIpsumText, MenuName);

            if (widget == null)
            {
                return;
            }

            _widgetCommandsService.Publish(widget);
            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }
예제 #3
0
        public void CreateRecentBlogPostsWidget()
        {
            var type = "RecentBlogPosts";

            // Check any custom parameters that could cause creating the widget to fail.
            blog = GetBlog(BlogId, BlogPath);
            if (blog == null)
            {
                Context.Output.WriteLine(T("Creating {0} widget failed: blog was not found.", type));
                return;
            }

            // Create the widget using the standard parameters.
            var widget = _widgetCommandsService.CreateBaseWidget(
                Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null);

            if (widget == null)
            {
                return;
            }

            // Publish the successfully created widget.
            widget.As <RecentBlogPostsPart>().BlogId = blog.Id;

            // Setting count to 0 means all posts. It's an optional parameter and defaults to 5.
            if (!string.IsNullOrWhiteSpace(Count))
            {
                int CountAsNumber = 0;
                if (Int32.TryParse(Count, out CountAsNumber))
                {
                    widget.As <RecentBlogPostsPart>().Count = CountAsNumber;
                }
            }

            // Publish the successfully created widget.
            _widgetCommandsService.Publish(widget);
            Context.Output.WriteLine(T("{0} widget created successfully.", type).Text);
        }