<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;

namespace Umbraco.Web.Models
{
    /// <summary>
    /// Provide an abstract base class for <c>IPublishedContent</c> implementations.
	/// </summary>
	/// <remarks>This base class does which (a) consitently resolves and caches the Url, (b) provides an implementation
    /// for this[alias], and (c) provides basic content set management.</remarks>
    [DebuggerDisplay("Content Id: {Id}, Name: {Name}")]
    public abstract class PublishedContentBase : IPublishedContent
    {
        #region Content

        private string _url;

	    /// <summary>
		/// Gets the url of the content.
		/// </summary>
		/// <remarks>
		/// If this content is Content, the url that is returned is the one computed by the NiceUrlProvider, otherwise if 
		/// this content is Media, the url returned is the value found in the 'umbracoFile' property.
		/// </remarks>
		public virtual string Url
		{
			get
			{
                // should be thread-safe although it won't prevent url from being resolved more than once
				if (_url != null)
					return _url;

				switch (ItemType)
				{
					case PublishedItemType.Content:
						if (UmbracoContext.Current == null)
							throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current is null.");
						if (UmbracoContext.Current.UrlProvider == null)
							throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current.UrlProvider is null.");
						_url= UmbracoContext.Current.UrlProvider.GetUrl(Id);
						break;
					case PublishedItemType.Media:
						var prop = GetProperty(Constants.Conventions.Media.File);
						if (prop == null)
							throw new NotSupportedException("Cannot resolve a Url for a media item when there is no 'umbracoFile' property defined.");
						_url = prop.Value.ToString();
						break;
					default:
						throw new NotSupportedException();
				}

				return _url;
			}
		}

		public abstract PublishedItemType ItemType { get; }<commit_msg>U4-4928 - issue with missing media content properties<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;

namespace Umbraco.Web.Models
{
    /// <summary>
    /// Provide an abstract base class for <c>IPublishedContent</c> implementations.
	/// </summary>
	/// <remarks>This base class does which (a) consitently resolves and caches the Url, (b) provides an implementation
    /// for this[alias], and (c) provides basic content set management.</remarks>
    [DebuggerDisplay("Content Id: {Id}, Name: {Name}")]
    public abstract class PublishedContentBase : IPublishedContent
    {
        #region Content

        private string _url;

	    /// <summary>
		/// Gets the url of the content.
		/// </summary>
		/// <remarks>
		/// If this content is Content, the url that is returned is the one computed by the NiceUrlProvider, otherwise if 
		/// this content is Media, the url returned is the value found in the 'umbracoFile' property.
		/// </remarks>
		public virtual string Url
		{
			get
			{
                // should be thread-safe although it won't prevent url from being resolved more than once
				if (_url != null)
					return _url;

				switch (ItemType)
				{
					case PublishedItemType.Content:
						if (UmbracoContext.Current == null)
							throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current is null.");
						if (UmbracoContext.Current.UrlProvider == null)
							throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current.UrlProvider is null.");
						_url= UmbracoContext.Current.UrlProvider.GetUrl(Id);
						break;
					case PublishedItemType.Media:
						var prop = GetProperty(Constants.Conventions.Media.File);
						if (prop == null)
							throw new NotSupportedException("Cannot resolve a Url for a media item when there is no 'umbracoFile' property defined.");
						_url = prop.Value == null ? "" : prop.Value.ToString();
						break;
					default:
						throw new NotSupportedException();
				}

				return _url;
			}
		}

		public abstract PublishedItemType ItemType { get; }
{'fraction_non_alphanumeric': 0.0963718820861678, 'fraction_numerical': 0.0011337868480725624, 'mean_word_length': 3.0729455216989843, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2486181', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1195, 'n_words': 432}