示例#1
0
        public JsonWidget(IWidgetModel model)
        {
            if (model.Id == null)
            {
                model.Id = Guid.NewGuid().ToString("N");
            }

            Id        = model.Id;
            ModelType = model.GetType().FullName;
            ModelJson = JsonConvert.SerializeObject(model);
        }
示例#2
0
        public ContentTreeBuilder AddContent(IWidgetModel content, string zoneName = null, string parentNodeId = null)
        {
            ContentNode node   = null;
            var         config = _widgetProvider.GetWidgetConfig(content);

            _widgetProvider.Create(config.WidgetType, content);

            node = CreateContentNode(config.WidgetType, null, content, zoneName, parentNodeId);

            return(this);
        }
示例#3
0
        public IWidgetModel Create(string widgetType, string model)
        {
            var          widgetConfig = GetWidgetConfig(widgetType);
            IWidgetModel widgetModel  = null;

            if (widgetConfig == null)
            {
                throw new NullReferenceException("Could not resolve widget service " + widgetType);
            }

            model = model.Trim();

            if (!string.IsNullOrEmpty(model))
            {
                if (model.EndsWith(".json"))
                {
                    widgetModel = GetModelFromJsonFile(widgetConfig, model);
                }

                else if (model.StartsWith("{"))
                {
                    widgetModel = GetModelFromJsonString(widgetConfig, model);
                }

                else
                {
                    widgetModel = GetNamedModel(widgetConfig, model);
                }

                if (widgetModel != null)
                {
                    widgetModel.Id = KeyGen.NewGuid();
                    widgetConfig.SaveSettings(_serviceProvider, widgetModel);

                    return(widgetModel);
                }
            }

            // otherwise just create using the default model supplied by the widget
            return(Create(widgetType));
        }
示例#4
0
        private ContentNode CreateContentNode(string widgetType, ContentStyle style, IWidgetModel widgetModel, string zoneName = null, string parentNodeId = null)
        {
            var widgetConfig = _widgetProvider.GetWidgetConfig(widgetType);

            if (widgetConfig == null)
            {
                throw new Exception($"Could not build tree content. Invalid ContentType: {widgetType}.");
            }

            var widgetViewId = widgetConfig.GetDefaultViewId();

            if (widgetViewId == null)
            {
                throw new Exception($"Could not build tree content. No default view for ContentType: {widgetType}.");
            }

            if (zoneName == null)
            {
                zoneName = DEFAULT_ROOT_ZONE;
            }

            var zoneIndex = _targetTree.ContentNodes.Where(x =>
                                                           x.ParentId == parentNodeId &&
                                                           x.Zone == zoneName
                                                           ).Count();

            // if we made it this far we can create the node
            return(new ContentNode(style)
            {
                Id = Guid.NewGuid().ToString("N"),
                ContentTreeId = _targetTree.Id,
                ParentId = parentNodeId,
                Zone = zoneName,
                Index = zoneIndex,
                WidgetType = widgetType,
                WidgetId = widgetModel?.Id,
                ViewId = widgetViewId,
            });
        }
示例#5
0
        public IWidgetModel Create(string widgetType, IWidgetModel model)
        {
            var widget = GetWidgetConfig(widgetType);

            if (widget == null)
            {
                throw new NullReferenceException("Could not resolve widget service " + widgetType);
            }

            if (widget.ServiceType != null)
            {
                if (string.IsNullOrEmpty(model.Id))
                {
                    model.Id = KeyGen.NewGuid();
                }

                widget.SaveSettings(_serviceProvider, model);

                return(model);
            }

            return(null);
        }
示例#6
0
            public BranchBuilder AddChildContent(string zoneName, IWidgetModel content)
            {
                _treeBuilder.AddContent(content, zoneName, _parentNode.Id);

                return(this);
            }
示例#7
0
 public void AddRootContent(IWidgetModel content)
 {
     AddRootContent(content);
 }
示例#8
0
 public void AddRootContent(string rootZoneName, IWidgetModel content)
 {
     AddContent(content, rootZoneName);
 }