private async Task CreateRows(IEnumerable <Row> rows, HtmlNode parent, NicheShackContext context)
        {
            foreach (Row row in rows)
            {
                // Create the row
                HtmlNode tr = await row.Create(parent, context);

                foreach (Column column in row.Columns)
                {
                    // Create the column
                    HtmlNode td = await column.Create(tr, context);


                    // Create the widget
                    Widget   widget     = GetWidget(column.WidgetData.WidgetType, column.WidgetData);
                    HtmlNode widgetNode = await widget.Create(td, context);

                    if (column.WidgetData.WidgetType == WidgetType.Container)
                    {
                        ContainerWidget container = (ContainerWidget)column.WidgetData;

                        if (container.Rows != null && container.Rows.Count() > 0)
                        {
                            await CreateRows(container.Rows, widgetNode, context);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public override Widget Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            Widget widget     = null;
            int    startDepth = reader.CurrentDepth;


            while (reader.Read())
            {
                // Return the widget when we are at the end of the object
                if (reader.TokenType == JsonTokenType.EndObject && reader.CurrentDepth == startDepth)
                {
                    return(widget);
                }



                // If we are reading a property name
                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    string property = reader.GetString();

                    // If the property name is widget type
                    if (property == "widgetType")
                    {
                        reader.Read();
                        WidgetType widgetType = (WidgetType)reader.GetInt32();

                        // Get the widget
                        switch (widgetType)
                        {
                        case WidgetType.Button:
                            widget = new ButtonWidget();
                            break;

                        case WidgetType.Text:
                            widget = new TextWidget();
                            break;

                        case WidgetType.Image:
                            widget = new ImageWidget();
                            break;

                        case WidgetType.Container:
                            widget = new ContainerWidget();
                            break;

                        case WidgetType.Line:
                            widget = new LineWidget();
                            break;

                        case WidgetType.Video:
                            widget = new VideoWidget();
                            break;

                        case WidgetType.ProductGroup:
                            widget = new ProductGroupWidget();
                            break;

                        case WidgetType.Shop:
                            widget = new ShopWidget();
                            break;

                        case WidgetType.Carousel:
                            widget = new CarouselWidget();
                            break;

                        case WidgetType.Grid:
                            widget = new GridWidget();
                            break;
                        }

                        widget.WidgetType = widgetType;
                    }
                    else
                    {
                        // Set each property for the widget
                        widget.SetProperty(property, ref reader, options);
                    }
                }
            }

            throw new JsonException();
        }