Model Migration from 1.5 to 2.0

This step can be skipped if you do not have any custom (not SCORE) components in your site.

There are several changes to models that will affect current SCORE 1.5 users when migrating to 2.0.

#1 - Model Definition Items are Moved in the Sitecore Content Tree

During SCORE 2.0, models were moved in the Sitecore content tree.  Since renderings store a link (not a reference) to the model definition item, moving them causes a breaking change.  

If you used any of the SCORE models in your own custom renderings, you will have to update those links to the new location for the model.

#2 - Base Model Type

If you have created your own models and inherited from the SCORE base model types - the base type might have changed.  

If you wish to expose the Show/Hide rendering parameter selections and created your own rendering parameter template to extend our own base templates, you will need to inherit from a different based type -

Score.UI.Web.Areas.ScoreUI.Models.BaseComponentRenderingModel

#3 - Sitecore Items Cleanup

If you have duplicate /sitecore/layout/Models/ScoreUI items, delete one with ID: {AD42AA1E-5299-4658-9565-0B5154721BD0}, and all of its contents. In breaking links dialog, select Link To Another Item, and pick /sitecore/layout/Models/ScoreUI/Base Component. 

#4 - Code Changes to the Models

The pattern we used to create the model classes is new in SCORE 2.0.  In the new development pattern, we have separate the two aspects of the model classes that we utilize - processing rendering parameters and consuming a datasource item.  

An example SCORE 2.0 Rendering Model reads as follows:

namespace Score.BootstrapUI.Web.Areas.ScoreBootstrapUI.Models.Containers
{

    using Score.UI.Data.DatasourceItems;
    using Score.UI.Data.RenderingParameters;
    using Score.UI.Web;
    using Score.UI.Web.Areas.ScoreUI.Models;
    using Score.UI.Web.Helpers;
    using Sitecore.Data.Items;
    using Sitecore.Mvc.Presentation;

    /// <summary>Describes the rendering model for a stripe component.</summary>
    public class StripeRenderingModel : RenderingModelBase<StripeParameters, StripeItem>
    {
        /// <summary>Initializes a new instance of the <see cref="StripeRenderingModel"/> class.</summary>
        public StripeRenderingModel() : base(ScoreStyles.Stripe) { }

        protected StripeRenderingModel(string componentClass) : base(componentClass) { }

        public override void Initialize(Rendering rendering)
        {
            base.Initialize(rendering);
            if (this.HasDatasource)
            {
                CssHelper.AttachStyleForColorAndBackground(this, this.Datasource);
            }
            this.Classes.Add(this.RenderingParameters.BackgroundClass);
        }

        protected override StripeItem InitializeDatasource(Item item)
        {
            StripeItem datasource;
            return StripeItem.TryParse(item, out datasource) ? datasource : null;
        }
    }
}
using Score.Data.Extensions;
using Sitecore.Mvc.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Score.UI.Data.RenderingParameters
{
  public class BaseComponentParameters : CustomRenderingParameters
  {
    public const string ShowHideParameterName = "Show Hide";
    public virtual string ShowHideClass { get; protected set; }
    public virtual string ClassSelection { get; protected set; }
    public virtual string RenderingClass { get; protected set; }
    public override void LoadRenderingParameters(Rendering rendering)

    {
      if (rendering == null) {
        throw new ArgumentNullException("rendering");
      }

      this.RenderingClass = RenderingParametersExtensions.GetUserFriendlyValue(rendering.Parameters, "class", "Value", true);
      IEnumerable<string> friendlyValueList = RenderingParametersExtensions.GetUserFriendlyValueList(rendering.Parameters, "Show Hide", "Value", true);
      this.ShowHideClass = Enumerable.Any<string>(friendlyValueList) ? string.Join(" ", friendlyValueList) : (string) null;
    }
  }
}
using Score.Custom.FieldTypes;
using Score.Data.Extensions;
using Sitecore.Data;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;

namespace Score.UI.Data.DatasourceItems
{
  public class StripeItem : ScoreUIItem, IBackgroundDescriptor

  {
    public static readonly ID Template = new ID("{AD7E58C5-E2A1-47BF-BB17-EFF93CD6C14A}");
    public const string BackgroundColorFieldName = "Background Color";
    public const string ForegroundColorFieldName = "Text Color";
    public const string BackgroundImageFieldName = "Background Image";
    public SimpleColorValueField BackgroundColorField { get; private set; }
    public SimpleColorValueField ForegroundColorField { get; private set; }
    public ImageField BackgroundImageField { get; private set; }
    protected internal StripeItem(Item item)
      : base(item)
    {
      this.BackgroundColorField = (SimpleColorValueField) item.Fields["Background Color"];
      this.ForegroundColorField = (SimpleColorValueField) item.Fields["Text Color"];
      this.BackgroundImageField = (ImageField) item.Fields["Background Image"];
    }
    public static implicit operator StripeItem(Item innerItem)
    {
      if (innerItem == null) {
        return (StripeItem) null;
      }
      return new StripeItem(innerItem);
    }

    public static implicit operator Item(StripeItem customItem)
    {
      if (customItem == null) {
        return (Item) null;
      }
      return customItem.InnerItem;
    }
    public static bool TryParse(Item item, out StripeItem parsedItem)
    {
      parsedItem = item == null || !ItemExtensions.IsDerived(item, StripeItem.Template, false) ? (StripeItem) null : new StripeItem(item);
      return parsedItem != null;
    }
  }
}

 

#5 - Wrapper Class Property in Customer Built Views

In any Razor views that are attached to custom components that inherit from 1.5 base SCORE model classes, there will be a change to the name of the existing property WrapperClasses to just Classes


Here is an example view

@model Score.BootstrapUI.Web.Areas.ScoreBootstrapUI.Models.Containers.StripeRenderingModel

<div class="@Model.Classes">

    @if (Sitecore.Context.PageMode.IsPageEditorEditing)
    {
        <div class="@ScoreStyles.EditFieldGroup">
            <span class="@ScoreStyles.EditField">
                <label>@Translate.Text(StripeItem.BackgroundImageFieldName):</label>
                @Html.Sitecore().Field(StripeItem.BackgroundImageFieldName, new { maxWidth = 75, maxHeight = 75 })
            </span>

            <span class="@ScoreStyles.EditField">
                <label>@Translate.Text(StripeItem.ForegroundColorFieldName):</label>
                @Html.Sitecore().Field(StripeItem.ForegroundColorFieldName)
            </span>

            <span class="@ScoreStyles.EditField">
                <label>@Translate.Text(StripeItem.BackgroundColorFieldName):</label>
                @Html.Sitecore().Field(StripeItem.BackgroundColorFieldName)
            </span>
        </div>

    }
    @Html.Sitecore().DynamicPlaceholder("Page Stripe")
</div>