diff --git a/.gitignore b/.gitignore index 210ba2ec87..81c60b6019 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,4 @@ preserve.belle /src/Umbraco.Web.UI/appsettings-schema.*.json /tests/Umbraco.Tests.Integration/appsettings-schema.json /tests/Umbraco.Tests.Integration/appsettings-schema.*.json +/src/Umbraco.Cms/appsettings-schema.json diff --git a/Directory.Build.props b/Directory.Build.props index 7b4f5c7794..dd6f8126b1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -29,9 +29,9 @@ + false true - - 10.2.1 + 11.0.0-rc1 true true diff --git a/src/Umbraco.Cms.Persistence.SqlServer/CompatibilitySuppressions.xml b/src/Umbraco.Cms.Persistence.SqlServer/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Cms.Persistence.SqlServer/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Cms.Persistence.Sqlite/CompatibilitySuppressions.xml b/src/Umbraco.Cms.Persistence.Sqlite/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Cms.Persistence.Sqlite/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Cms.StaticAssets/CompatibilitySuppressions.xml b/src/Umbraco.Cms.StaticAssets/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Cms.StaticAssets/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Core/CompatibilitySuppressions.xml b/src/Umbraco.Core/CompatibilitySuppressions.xml index 7baad05aa0..e34b117b9a 100644 --- a/src/Umbraco.Core/CompatibilitySuppressions.xml +++ b/src/Umbraco.Core/CompatibilitySuppressions.xml @@ -1,7 +1,45 @@  - PKV006 - net6.0 + CP0006 + M:Umbraco.Cms.Core.Deploy.IDataTypeConfigurationConnector.FromArtifact(Umbraco.Cms.Core.Models.IDataType,System.String,Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Deploy.IDataTypeConfigurationConnector.ToArtifact(Umbraco.Cms.Core.Models.IDataType,System.Collections.Generic.ICollection{Umbraco.Cms.Core.Deploy.ArtifactDependency},Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Deploy.IServiceConnector.GetArtifact(System.Object,Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Deploy.IServiceConnector.GetArtifact(Umbraco.Cms.Core.Udi,Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Deploy.IValueConnector.FromArtifact(System.String,Umbraco.Cms.Core.Models.IPropertyType,System.Object,Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Deploy.IValueConnector.ToArtifact(System.Object,Umbraco.Cms.Core.Models.IPropertyType,System.Collections.Generic.ICollection{Umbraco.Cms.Core.Deploy.ArtifactDependency},Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true \ No newline at end of file diff --git a/src/Umbraco.Core/Media/Exif/BitConverterEx.cs b/src/Umbraco.Core/Media/Exif/BitConverterEx.cs deleted file mode 100644 index f6cc50f801..0000000000 --- a/src/Umbraco.Core/Media/Exif/BitConverterEx.cs +++ /dev/null @@ -1,346 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// An endian-aware converter for converting between base data types -/// and an array of bytes. -/// -internal class BitConverterEx -{ - #region Public Enums - - /// - /// Represents the byte order. - /// - public enum ByteOrder - { - LittleEndian = 1, - BigEndian = 2, - } - - #endregion - - #region Member Variables - - private readonly ByteOrder mFrom; - private readonly ByteOrder mTo; - - #endregion - - #region Constructors - - public BitConverterEx(ByteOrder from, ByteOrder to) - { - mFrom = from; - mTo = to; - } - - #endregion - - #region Properties - - /// - /// Indicates the byte order in which data is stored in this platform. - /// - public static ByteOrder SystemByteOrder => - BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian; - - #endregion - - #region Predefined Values - - /// - /// Returns a bit converter that converts between little-endian and system byte-order. - /// - public static BitConverterEx LittleEndian => new BitConverterEx(ByteOrder.LittleEndian, SystemByteOrder); - - /// - /// Returns a bit converter that converts between big-endian and system byte-order. - /// - public static BitConverterEx BigEndian => new BitConverterEx(ByteOrder.BigEndian, SystemByteOrder); - - /// - /// Returns a bit converter that does not do any byte-order conversion. - /// - public static BitConverterEx SystemEndian => new BitConverterEx(SystemByteOrder, SystemByteOrder); - - #endregion - - #region Static Methods - - /// - /// Converts the given array of bytes to a Unicode character. - /// - public static char ToChar(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 2, from, to); - return BitConverter.ToChar(data, 0); - } - - /// - /// Converts the given array of bytes to a 16-bit unsigned integer. - /// - public static ushort ToUInt16(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 2, from, to); - return BitConverter.ToUInt16(data, 0); - } - - /// - /// Converts the given array of bytes to a 32-bit unsigned integer. - /// - public static uint ToUInt32(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 4, from, to); - return BitConverter.ToUInt32(data, 0); - } - - /// - /// Converts the given array of bytes to a 64-bit unsigned integer. - /// - public static ulong ToUInt64(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 8, from, to); - return BitConverter.ToUInt64(data, 0); - } - - /// - /// Converts the given array of bytes to a 16-bit signed integer. - /// - public static short ToInt16(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 2, from, to); - return BitConverter.ToInt16(data, 0); - } - - /// - /// Converts the given array of bytes to a 32-bit signed integer. - /// - public static int ToInt32(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 4, from, to); - return BitConverter.ToInt32(data, 0); - } - - /// - /// Converts the given array of bytes to a 64-bit signed integer. - /// - public static long ToInt64(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 8, from, to); - return BitConverter.ToInt64(data, 0); - } - - /// - /// Converts the given array of bytes to a single precision floating number. - /// - public static float ToSingle(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 4, from, to); - return BitConverter.ToSingle(data, 0); - } - - /// - /// Converts the given array of bytes to a double precision floating number. - /// - public static double ToDouble(byte[] value, long startIndex, ByteOrder from, ByteOrder to) - { - var data = CheckData(value, startIndex, 8, from, to); - return BitConverter.ToDouble(data, 0); - } - - /// - /// Converts the given 16-bit unsigned integer to an array of bytes. - /// - public static byte[] GetBytes(ushort value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given 32-bit unsigned integer to an array of bytes. - /// - public static byte[] GetBytes(uint value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given 64-bit unsigned integer to an array of bytes. - /// - public static byte[] GetBytes(ulong value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given 16-bit signed integer to an array of bytes. - /// - public static byte[] GetBytes(short value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given 32-bit signed integer to an array of bytes. - /// - public static byte[] GetBytes(int value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given 64-bit signed integer to an array of bytes. - /// - public static byte[] GetBytes(long value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given single precision floating-point number to an array of bytes. - /// - public static byte[] GetBytes(float value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - /// - /// Converts the given double precision floating-point number to an array of bytes. - /// - public static byte[] GetBytes(double value, ByteOrder from, ByteOrder to) - { - var data = BitConverter.GetBytes(value); - data = CheckData(data, from, to); - return data; - } - - #endregion - - #region Instance Methods - - /// - /// Converts the given array of bytes to a 16-bit unsigned integer. - /// - public char ToChar(byte[] value, long startIndex) => ToChar(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a 16-bit unsigned integer. - /// - public ushort ToUInt16(byte[] value, long startIndex) => ToUInt16(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a 32-bit unsigned integer. - /// - public uint ToUInt32(byte[] value, long startIndex) => ToUInt32(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a 64-bit unsigned integer. - /// - public ulong ToUInt64(byte[] value, long startIndex) => ToUInt64(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a 16-bit signed integer. - /// - public short ToInt16(byte[] value, long startIndex) => ToInt16(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a 32-bit signed integer. - /// - public int ToInt32(byte[] value, long startIndex) => ToInt32(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a 64-bit signed integer. - /// - public long ToInt64(byte[] value, long startIndex) => ToInt64(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a single precision floating number. - /// - public float ToSingle(byte[] value, long startIndex) => ToSingle(value, startIndex, mFrom, mTo); - - /// - /// Converts the given array of bytes to a double precision floating number. - /// - public double ToDouble(byte[] value, long startIndex) => ToDouble(value, startIndex, mFrom, mTo); - - /// - /// Converts the given 16-bit unsigned integer to an array of bytes. - /// - public byte[] GetBytes(ushort value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given 32-bit unsigned integer to an array of bytes. - /// - public byte[] GetBytes(uint value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given 64-bit unsigned integer to an array of bytes. - /// - public byte[] GetBytes(ulong value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given 16-bit signed integer to an array of bytes. - /// - public byte[] GetBytes(short value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given 32-bit signed integer to an array of bytes. - /// - public byte[] GetBytes(int value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given 64-bit signed integer to an array of bytes. - /// - public byte[] GetBytes(long value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given single precision floating-point number to an array of bytes. - /// - public byte[] GetBytes(float value) => GetBytes(value, mFrom, mTo); - - /// - /// Converts the given double precision floating-point number to an array of bytes. - /// - public byte[] GetBytes(double value) => GetBytes(value, mFrom, mTo); - - #endregion - - #region Private Helpers - - /// - /// Reverse the array of bytes as needed. - /// - private static byte[] CheckData(byte[] value, long startIndex, long length, ByteOrder from, ByteOrder to) - { - var data = new byte[length]; - Array.Copy(value, startIndex, data, 0, length); - if (from != to) - { - Array.Reverse(data); - } - - return data; - } - - /// - /// Reverse the array of bytes as needed. - /// - private static byte[] CheckData(byte[] value, ByteOrder from, ByteOrder to) => - CheckData(value, 0, value.Length, from, to); - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs b/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs deleted file mode 100644 index e8dc7c4eb9..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs +++ /dev/null @@ -1,392 +0,0 @@ -using System.Globalization; -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Converts between exif data types and array of bytes. -/// -internal class ExifBitConverter : BitConverterEx -{ - #region Constructors - - public ExifBitConverter(ByteOrder from, ByteOrder to) - : base(from, to) - { - } - - #endregion - - #region Static Methods - - /// - /// Returns an ASCII string converted from the given byte array. - /// - public static string ToAscii(byte[] data, bool endatfirstnull, Encoding encoding) - { - var len = data.Length; - if (endatfirstnull) - { - len = Array.IndexOf(data, (byte)0); - if (len == -1) - { - len = data.Length; - } - } - - return encoding.GetString(data, 0, len); - } - - /// - /// Returns an ASCII string converted from the given byte array. - /// - public static string ToAscii(byte[] data, Encoding encoding) => ToAscii(data, true, encoding); - - /// - /// Returns a string converted from the given byte array. - /// from the numeric value of each byte. - /// - public static string ToString(byte[] data) - { - var sb = new StringBuilder(); - foreach (var b in data) - { - sb.Append(b); - } - - return sb.ToString(); - } - - /// - /// Returns a DateTime object converted from the given byte array. - /// - public static DateTime ToDateTime(byte[] data, bool hastime) - { - var str = ToAscii(data, Encoding.ASCII); - var parts = str.Split(':', ' '); - try - { - if (hastime && parts.Length == 6) - { - // yyyy:MM:dd HH:mm:ss - // This is the expected format though some cameras - // can use single digits. See Issue 21. - return new DateTime( - int.Parse(parts[0], CultureInfo.InvariantCulture), - int.Parse(parts[1], CultureInfo.InvariantCulture), - int.Parse(parts[2], CultureInfo.InvariantCulture), - int.Parse(parts[3], CultureInfo.InvariantCulture), - int.Parse(parts[4], CultureInfo.InvariantCulture), - int.Parse(parts[5], CultureInfo.InvariantCulture)); - } - - if (!hastime && parts.Length == 3) - { - // yyyy:MM:dd - return new DateTime( - int.Parse(parts[0], CultureInfo.InvariantCulture), - int.Parse(parts[1], CultureInfo.InvariantCulture), - int.Parse(parts[2], CultureInfo.InvariantCulture)); - } - - return DateTime.MinValue; - } - catch (ArgumentOutOfRangeException) - { - return DateTime.MinValue; - } - catch (ArgumentException) - { - return DateTime.MinValue; - } - } - - /// - /// Returns a DateTime object converted from the given byte array. - /// - public static DateTime ToDateTime(byte[] data) => ToDateTime(data, true); - - /// - /// Returns an unsigned rational number converted from the first - /// eight bytes of the given byte array. The first four bytes are - /// assumed to be the numerator and the next four bytes are the - /// denominator. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static MathEx.UFraction32 ToURational(byte[] data, ByteOrder frombyteorder) - { - var num = new byte[4]; - var den = new byte[4]; - Array.Copy(data, 0, num, 0, 4); - Array.Copy(data, 4, den, 0, 4); - return new MathEx.UFraction32( - ToUInt32(num, 0, frombyteorder, SystemByteOrder), - ToUInt32(den, 0, frombyteorder, SystemByteOrder)); - } - - /// - /// Returns a signed rational number converted from the first - /// eight bytes of the given byte array. The first four bytes are - /// assumed to be the numerator and the next four bytes are the - /// denominator. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static MathEx.Fraction32 ToSRational(byte[] data, ByteOrder frombyteorder) - { - var num = new byte[4]; - var den = new byte[4]; - Array.Copy(data, 0, num, 0, 4); - Array.Copy(data, 4, den, 0, 4); - return new MathEx.Fraction32( - ToInt32(num, 0, frombyteorder, SystemByteOrder), - ToInt32(den, 0, frombyteorder, SystemByteOrder)); - } - - /// - /// Returns an array of 16-bit unsigned integers converted from - /// the given byte array. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static ushort[] ToUShortArray(byte[] data, int count, ByteOrder frombyteorder) - { - var numbers = new ushort[count]; - for (uint i = 0; i < count; i++) - { - var num = new byte[2]; - Array.Copy(data, i * 2, num, 0, 2); - numbers[i] = ToUInt16(num, 0, frombyteorder, SystemByteOrder); - } - - return numbers; - } - - /// - /// Returns an array of 32-bit unsigned integers converted from - /// the given byte array. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static uint[] ToUIntArray(byte[] data, int count, ByteOrder frombyteorder) - { - var numbers = new uint[count]; - for (uint i = 0; i < count; i++) - { - var num = new byte[4]; - Array.Copy(data, i * 4, num, 0, 4); - numbers[i] = ToUInt32(num, 0, frombyteorder, SystemByteOrder); - } - - return numbers; - } - - /// - /// Returns an array of 32-bit signed integers converted from - /// the given byte array. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static int[] ToSIntArray(byte[] data, int count, ByteOrder byteorder) - { - var numbers = new int[count]; - for (uint i = 0; i < count; i++) - { - var num = new byte[4]; - Array.Copy(data, i * 4, num, 0, 4); - numbers[i] = ToInt32(num, 0, byteorder, SystemByteOrder); - } - - return numbers; - } - - /// - /// Returns an array of unsigned rational numbers converted from - /// the given byte array. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static MathEx.UFraction32[] ToURationalArray(byte[] data, int count, ByteOrder frombyteorder) - { - var numbers = new MathEx.UFraction32[count]; - for (uint i = 0; i < count; i++) - { - var num = new byte[4]; - var den = new byte[4]; - Array.Copy(data, i * 8, num, 0, 4); - Array.Copy(data, (i * 8) + 4, den, 0, 4); - numbers[i].Set( - ToUInt32(num, 0, frombyteorder, SystemByteOrder), - ToUInt32(den, 0, frombyteorder, SystemByteOrder)); - } - - return numbers; - } - - /// - /// Returns an array of signed rational numbers converted from - /// the given byte array. - /// Numbers are converted from the given byte-order to platform byte-order. - /// - public static MathEx.Fraction32[] ToSRationalArray(byte[] data, int count, ByteOrder frombyteorder) - { - var numbers = new MathEx.Fraction32[count]; - for (uint i = 0; i < count; i++) - { - var num = new byte[4]; - var den = new byte[4]; - Array.Copy(data, i * 8, num, 0, 4); - Array.Copy(data, (i * 8) + 4, den, 0, 4); - numbers[i].Set( - ToInt32(num, 0, frombyteorder, SystemByteOrder), - ToInt32(den, 0, frombyteorder, SystemByteOrder)); - } - - return numbers; - } - - /// - /// Converts the given ascii string to an array of bytes optionally adding a null terminator. - /// - public static byte[] GetBytes(string value, bool addnull, Encoding encoding) - { - if (addnull) - { - value += '\0'; - } - - return encoding.GetBytes(value); - } - - /// - /// Converts the given ascii string to an array of bytes without adding a null terminator. - /// - public static byte[] GetBytes(string value, Encoding encoding) => GetBytes(value, false, encoding); - - /// - /// Converts the given datetime to an array of bytes with a null terminator. - /// - public static byte[] GetBytes(DateTime value, bool hastime) - { - var str = string.Empty; - if (hastime) - { - str = value.ToString("yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture); - } - else - { - str = value.ToString("yyyy:MM:dd", CultureInfo.InvariantCulture); - } - - return GetBytes(str, true, Encoding.ASCII); - } - - /// - /// Converts the given unsigned rational number to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(MathEx.UFraction32 value, ByteOrder tobyteorder) - { - var num = GetBytes(value.Numerator, SystemByteOrder, tobyteorder); - var den = GetBytes(value.Denominator, SystemByteOrder, tobyteorder); - var data = new byte[8]; - Array.Copy(num, 0, data, 0, 4); - Array.Copy(den, 0, data, 4, 4); - return data; - } - - /// - /// Converts the given signed rational number to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(MathEx.Fraction32 value, ByteOrder tobyteorder) - { - var num = GetBytes(value.Numerator, SystemByteOrder, tobyteorder); - var den = GetBytes(value.Denominator, SystemByteOrder, tobyteorder); - var data = new byte[8]; - Array.Copy(num, 0, data, 0, 4); - Array.Copy(den, 0, data, 4, 4); - return data; - } - - /// - /// Converts the given array of 16-bit unsigned integers to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(ushort[] value, ByteOrder tobyteorder) - { - var data = new byte[2 * value.Length]; - for (var i = 0; i < value.Length; i++) - { - var num = GetBytes(value[i], SystemByteOrder, tobyteorder); - Array.Copy(num, 0, data, i * 2, 2); - } - - return data; - } - - /// - /// Converts the given array of 32-bit unsigned integers to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(uint[] value, ByteOrder tobyteorder) - { - var data = new byte[4 * value.Length]; - for (var i = 0; i < value.Length; i++) - { - var num = GetBytes(value[i], SystemByteOrder, tobyteorder); - Array.Copy(num, 0, data, i * 4, 4); - } - - return data; - } - - /// - /// Converts the given array of 32-bit signed integers to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(int[] value, ByteOrder tobyteorder) - { - var data = new byte[4 * value.Length]; - for (var i = 0; i < value.Length; i++) - { - var num = GetBytes(value[i], SystemByteOrder, tobyteorder); - Array.Copy(num, 0, data, i * 4, 4); - } - - return data; - } - - /// - /// Converts the given array of unsigned rationals to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(MathEx.UFraction32[] value, ByteOrder tobyteorder) - { - var data = new byte[8 * value.Length]; - for (var i = 0; i < value.Length; i++) - { - var num = GetBytes(value[i].Numerator, SystemByteOrder, tobyteorder); - var den = GetBytes(value[i].Denominator, SystemByteOrder, tobyteorder); - Array.Copy(num, 0, data, i * 8, 4); - Array.Copy(den, 0, data, (i * 8) + 4, 4); - } - - return data; - } - - /// - /// Converts the given array of signed rationals to an array of bytes. - /// Numbers are converted from the platform byte-order to the given byte-order. - /// - public static byte[] GetBytes(MathEx.Fraction32[] value, ByteOrder tobyteorder) - { - var data = new byte[8 * value.Length]; - for (var i = 0; i < value.Length; i++) - { - var num = GetBytes(value[i].Numerator, SystemByteOrder, tobyteorder); - var den = GetBytes(value[i].Denominator, SystemByteOrder, tobyteorder); - Array.Copy(num, 0, data, i * 8, 4); - Array.Copy(den, 0, data, (i * 8) + 4, 4); - } - - return data; - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/ExifEnums.cs b/src/Umbraco.Core/Media/Exif/ExifEnums.cs deleted file mode 100644 index 5e27b8dd24..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifEnums.cs +++ /dev/null @@ -1,297 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -internal enum Compression : ushort -{ - Uncompressed = 1, - CCITT1D = 2, - Group3Fax = 3, - Group4Fax = 4, - LZW = 5, - JPEG = 6, - PackBits = 32773, -} - -internal enum PhotometricInterpretation : ushort -{ - WhiteIsZero = 0, - BlackIsZero = 1, - RGB = 2, - RGBPalette = 3, - TransparencyMask = 4, - CMYK = 5, - YCbCr = 6, - CIELab = 8, -} - -internal enum Orientation : ushort -{ - Normal = 1, - MirroredVertically = 2, - Rotated180 = 3, - MirroredHorizontally = 4, - RotatedLeftAndMirroredVertically = 5, - RotatedRight = 6, - RotatedLeft = 7, - RotatedRightAndMirroredVertically = 8, -} - -internal enum PlanarConfiguration : ushort -{ - ChunkyFormat = 1, - PlanarFormat = 2, -} - -internal enum YCbCrPositioning : ushort -{ - Centered = 1, - CoSited = 2, -} - -internal enum ResolutionUnit : ushort -{ - Inches = 2, - Centimeters = 3, -} - -internal enum ColorSpace : ushort -{ - SRGB = 1, - Uncalibrated = 0xfff, -} - -internal enum ExposureProgram : ushort -{ - NotDefined = 0, - Manual = 1, - Normal = 2, - AperturePriority = 3, - ShutterPriority = 4, - - /// - /// Biased toward depth of field. - /// - Creative = 5, - - /// - /// Biased toward fast shutter speed. - /// - Action = 6, - - /// - /// For closeup photos with the background out of focus. - /// - Portrait = 7, - - /// - /// For landscape photos with the background in focus. - /// - Landscape = 8, -} - -internal enum MeteringMode : ushort -{ - Unknown = 0, - Average = 1, - CenterWeightedAverage = 2, - Spot = 3, - MultiSpot = 4, - Pattern = 5, - Partial = 6, - Other = 255, -} - -internal enum LightSource : ushort -{ - Unknown = 0, - Daylight = 1, - Fluorescent = 2, - Tungsten = 3, - Flash = 4, - FineWeather = 9, - CloudyWeather = 10, - Shade = 11, - - /// - /// D 5700 – 7100K - /// - DaylightFluorescent = 12, - - /// - /// N 4600 – 5400K - /// - DayWhiteFluorescent = 13, - - /// - /// W 3900 – 4500K - /// - CoolWhiteFluorescent = 14, - - /// - /// WW 3200 – 3700K - /// - WhiteFluorescent = 15, - StandardLightA = 17, - StandardLightB = 18, - StandardLightC = 19, - D55 = 20, - D65 = 21, - D75 = 22, - D50 = 23, - ISOStudioTungsten = 24, - OtherLightSource = 255, -} - -[Flags] -internal enum Flash : ushort -{ - FlashDidNotFire = 0, - StrobeReturnLightNotDetected = 4, - StrobeReturnLightDetected = 2, - FlashFired = 1, - CompulsoryFlashMode = 8, - AutoMode = 16, - NoFlashFunction = 32, - RedEyeReductionMode = 64, -} - -internal enum SensingMethod : ushort -{ - NotDefined = 1, - OneChipColorAreaSensor = 2, - TwoChipColorAreaSensor = 3, - ThreeChipColorAreaSensor = 4, - ColorSequentialAreaSensor = 5, - TriLinearSensor = 7, - ColorSequentialLinearSensor = 8, -} - -internal enum FileSource : byte // UNDEFINED -{ - DSC = 3, -} - -internal enum SceneType : byte // UNDEFINED -{ - DirectlyPhotographedImage = 1, -} - -internal enum CustomRendered : ushort -{ - NormalProcess = 0, - CustomProcess = 1, -} - -internal enum ExposureMode : ushort -{ - Auto = 0, - Manual = 1, - AutoBracket = 2, -} - -internal enum WhiteBalance : ushort -{ - Auto = 0, - Manual = 1, -} - -internal enum SceneCaptureType : ushort -{ - Standard = 0, - Landscape = 1, - Portrait = 2, - NightScene = 3, -} - -internal enum GainControl : ushort -{ - None = 0, - LowGainUp = 1, - HighGainUp = 2, - LowGainDown = 3, - HighGainDown = 4, -} - -internal enum Contrast : ushort -{ - Normal = 0, - Soft = 1, - Hard = 2, -} - -internal enum Saturation : ushort -{ - Normal = 0, - Low = 1, - High = 2, -} - -internal enum Sharpness : ushort -{ - Normal = 0, - Soft = 1, - Hard = 2, -} - -internal enum SubjectDistanceRange : ushort -{ - Unknown = 0, - Macro = 1, - CloseView = 2, - DistantView = 3, -} - -internal enum GPSLatitudeRef : byte // ASCII -{ - North = 78, // 'N' - South = 83, // 'S' -} - -internal enum GPSLongitudeRef : byte // ASCII -{ - West = 87, // 'W' - East = 69, // 'E' -} - -internal enum GPSAltitudeRef : byte -{ - AboveSeaLevel = 0, - BelowSeaLevel = 1, -} - -internal enum GPSStatus : byte // ASCII -{ - MeasurementInProgress = 65, // 'A' - MeasurementInteroperability = 86, // 'V' -} - -internal enum GPSMeasureMode : byte // ASCII -{ - TwoDimensional = 50, // '2' - ThreeDimensional = 51, // '3' -} - -internal enum GPSSpeedRef : byte // ASCII -{ - KilometersPerHour = 75, // 'K' - MilesPerHour = 77, // 'M' - Knots = 78, // 'N' -} - -internal enum GPSDirectionRef : byte // ASCII -{ - TrueDirection = 84, // 'T' - MagneticDirection = 77, // 'M' -} - -internal enum GPSDistanceRef : byte // ASCII -{ - Kilometers = 75, // 'K' - Miles = 77, // 'M' - Knots = 78, // 'N' -} - -internal enum GPSDifferential : ushort -{ - MeasurementWithoutDifferentialCorrection = 0, - DifferentialCorrectionApplied = 1, -} diff --git a/src/Umbraco.Core/Media/Exif/ExifExceptions.cs b/src/Umbraco.Core/Media/Exif/ExifExceptions.cs index bd4426e15a..9f78bd9e15 100644 --- a/src/Umbraco.Core/Media/Exif/ExifExceptions.cs +++ b/src/Umbraco.Core/Media/Exif/ExifExceptions.cs @@ -7,6 +7,7 @@ namespace Umbraco.Cms.Core.Media.Exif; /// /// [Serializable] +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class NotValidExifFileException : Exception { /// diff --git a/src/Umbraco.Core/Media/Exif/ExifExtendedProperty.cs b/src/Umbraco.Core/Media/Exif/ExifExtendedProperty.cs deleted file mode 100644 index ffa31f0cc1..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifExtendedProperty.cs +++ /dev/null @@ -1,487 +0,0 @@ -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents an enumerated value. -/// -internal class ExifEnumProperty : ExifProperty - where T : notnull -{ - protected bool mIsBitField; - protected T mValue; - - public ExifEnumProperty(ExifTag tag, T value, bool isbitfield) - : base(tag) - { - mValue = value; - mIsBitField = isbitfield; - } - - public ExifEnumProperty(ExifTag tag, T value) - : this(tag, value, false) - { - } - - public new T Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (T)value; - } - - public bool IsBitField => mIsBitField; - - public override ExifInterOperability Interoperability - { - get - { - var tagid = ExifTagFactory.GetTagID(mTag); - - Type type = typeof(T); - Type basetype = Enum.GetUnderlyingType(type); - - if (type == typeof(FileSource) || type == typeof(SceneType)) - { - // UNDEFINED - return new ExifInterOperability(tagid, 7, 1, new[] { (byte)(object)mValue }); - } - - if (type == typeof(GPSLatitudeRef) || type == typeof(GPSLongitudeRef) || - type == typeof(GPSStatus) || type == typeof(GPSMeasureMode) || - type == typeof(GPSSpeedRef) || type == typeof(GPSDirectionRef) || - type == typeof(GPSDistanceRef)) - { - // ASCII - return new ExifInterOperability(tagid, 2, 2, new byte[] { (byte)(object)mValue, 0 }); - } - - if (basetype == typeof(byte)) - { - // BYTE - return new ExifInterOperability(tagid, 1, 1, new[] { (byte)(object)mValue }); - } - - if (basetype == typeof(ushort)) - { - // SHORT - return new ExifInterOperability( - tagid, - 3, - 1, - BitConverterEx.GetBytes((ushort)(object)mValue, BitConverterEx.SystemByteOrder, BitConverterEx.SystemByteOrder)); - } - - throw new InvalidOperationException( - $"An invalid enum type ({basetype.FullName}) was provided for type {type.FullName}"); - } - } - - public static implicit operator T(ExifEnumProperty obj) => obj.mValue; - - public override string? ToString() => mValue.ToString(); -} - -/// -/// Represents an ASCII string. (EXIF Specification: UNDEFINED) Used for the UserComment field. -/// -internal class ExifEncodedString : ExifProperty -{ - protected string mValue; - - public ExifEncodedString(ExifTag tag, string value, Encoding encoding) - : base(tag) - { - mValue = value; - Encoding = encoding; - } - - public new string Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (string)value; - } - - public Encoding Encoding { get; set; } - - public override ExifInterOperability Interoperability - { - get - { - var enc = string.Empty; - if (Encoding == null) - { - enc = "\0\0\0\0\0\0\0\0"; - } - else if (Encoding.EncodingName == "US-ASCII") - { - enc = "ASCII\0\0\0"; - } - else if (Encoding.EncodingName == "Japanese (JIS 0208-1990 and 0212-1990)") - { - enc = "JIS\0\0\0\0\0"; - } - else if (Encoding.EncodingName == "Unicode") - { - enc = "Unicode\0"; - } - else - { - enc = "\0\0\0\0\0\0\0\0"; - } - - var benc = Encoding.ASCII.GetBytes(enc); - var bstr = Encoding == null ? Encoding.ASCII.GetBytes(mValue) : Encoding.GetBytes(mValue); - var data = new byte[benc.Length + bstr.Length]; - Array.Copy(benc, 0, data, 0, benc.Length); - Array.Copy(bstr, 0, data, benc.Length, bstr.Length); - - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 7, (uint)data.Length, data); - } - } - - public static implicit operator string(ExifEncodedString obj) => obj.mValue; - - public override string ToString() => mValue; -} - -/// -/// Represents an ASCII string formatted as DateTime. (EXIF Specification: ASCII) Used for the date time fields. -/// -internal class ExifDateTime : ExifProperty -{ - protected DateTime mValue; - - public ExifDateTime(ExifTag tag, DateTime value) - : base(tag) => - mValue = value; - - public new DateTime Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (DateTime)value; - } - - public override ExifInterOperability Interoperability => - new(ExifTagFactory.GetTagID(mTag), 2, 20, ExifBitConverter.GetBytes(mValue, true)); - - public static implicit operator DateTime(ExifDateTime obj) => obj.mValue; - - public override string ToString() => mValue.ToString("yyyy.MM.dd HH:mm:ss"); -} - -/// -/// Represents the exif version as a 4 byte ASCII string. (EXIF Specification: UNDEFINED) -/// Used for the ExifVersion, FlashpixVersion, InteroperabilityVersion and GPSVersionID fields. -/// -internal class ExifVersion : ExifProperty -{ - protected string mValue; - - public ExifVersion(ExifTag tag, string value) - : base(tag) - { - if (value.Length > 4) - { - mValue = value[..4]; - } - else if (value.Length < 4) - { - mValue = value + new string(' ', 4 - value.Length); - } - else - { - mValue = value; - } - } - - public new string Value - { - get => mValue; - set => mValue = value[..4]; - } - - protected override object _Value - { - get => Value; - set => Value = (string)value; - } - - public override ExifInterOperability Interoperability - { - get - { - if (mTag == ExifTag.ExifVersion || mTag == ExifTag.FlashpixVersion || - mTag == ExifTag.InteroperabilityVersion) - { - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 7, 4, Encoding.ASCII.GetBytes(mValue)); - } - - var data = new byte[4]; - for (var i = 0; i < 4; i++) - { - data[i] = byte.Parse(mValue[0].ToString()); - } - - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 7, 4, data); - } - } - - public override string ToString() => mValue; -} - -/// -/// Represents the location and area of the subject (EXIF Specification: 2xSHORT) -/// The coordinate values, width, and height are expressed in relation to the -/// upper left as origin, prior to rotation processing as per the Rotation tag. -/// -internal class ExifPointSubjectArea : ExifUShortArray -{ - public ExifPointSubjectArea(ExifTag tag, ushort[] value) - : base(tag, value) - { - } - - public ExifPointSubjectArea(ExifTag tag, ushort x, ushort y) - : base(tag, new[] { x, y }) - { - } - - public ushort X - { - get => mValue[0]; - set => mValue[0] = value; - } - - protected new ushort[] Value - { - get => mValue; - set => mValue = value; - } - - public ushort Y - { - get => mValue[1]; - set => mValue[1] = value; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendFormat("({0:d}, {1:d})", mValue[0], mValue[1]); - return sb.ToString(); - } -} - -/// -/// Represents the location and area of the subject (EXIF Specification: 3xSHORT) -/// The coordinate values, width, and height are expressed in relation to the -/// upper left as origin, prior to rotation processing as per the Rotation tag. -/// -internal class ExifCircularSubjectArea : ExifPointSubjectArea -{ - public ExifCircularSubjectArea(ExifTag tag, ushort[] value) - : base(tag, value) - { - } - - public ExifCircularSubjectArea(ExifTag tag, ushort x, ushort y, ushort d) - : base(tag, new[] { x, y, d }) - { - } - - public ushort Diamater - { - get => mValue[2]; - set => mValue[2] = value; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendFormat("({0:d}, {1:d}) {2:d}", mValue[0], mValue[1], mValue[2]); - return sb.ToString(); - } -} - -/// -/// Represents the location and area of the subject (EXIF Specification: 4xSHORT) -/// The coordinate values, width, and height are expressed in relation to the -/// upper left as origin, prior to rotation processing as per the Rotation tag. -/// -internal class ExifRectangularSubjectArea : ExifPointSubjectArea -{ - public ExifRectangularSubjectArea(ExifTag tag, ushort[] value) - : base(tag, value) - { - } - - public ExifRectangularSubjectArea(ExifTag tag, ushort x, ushort y, ushort w, ushort h) - : base(tag, new[] { x, y, w, h }) - { - } - - public ushort Width - { - get => mValue[2]; - set => mValue[2] = value; - } - - public ushort Height - { - get => mValue[3]; - set => mValue[3] = value; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendFormat("({0:d}, {1:d}) ({2:d} x {3:d})", mValue[0], mValue[1], mValue[2], mValue[3]); - return sb.ToString(); - } -} - -/// -/// Represents GPS latitudes and longitudes (EXIF Specification: 3xRATIONAL) -/// -internal class GPSLatitudeLongitude : ExifURationalArray -{ - public GPSLatitudeLongitude(ExifTag tag, MathEx.UFraction32[] value) - : base(tag, value) - { - } - - public GPSLatitudeLongitude(ExifTag tag, float d, float m, float s) - : base(tag, new[] { new(d), new MathEx.UFraction32(m), new MathEx.UFraction32(s) }) - { - } - - public MathEx.UFraction32 Degrees - { - get => mValue[0]; - set => mValue[0] = value; - } - - protected new MathEx.UFraction32[] Value - { - get => mValue; - set => mValue = value; - } - - public MathEx.UFraction32 Minutes - { - get => mValue[1]; - set => mValue[1] = value; - } - - public MathEx.UFraction32 Seconds - { - get => mValue[2]; - set => mValue[2] = value; - } - - public static explicit operator float(GPSLatitudeLongitude obj) => obj.ToFloat(); - - public float ToFloat() => (float)Degrees + ((float)Minutes / 60.0f) + ((float)Seconds / 3600.0f); - - public override string ToString() => - string.Format("{0:F2}°{1:F2}'{2:F2}\"", (float)Degrees, (float)Minutes, (float)Seconds); -} - -/// -/// Represents a GPS time stamp as UTC (EXIF Specification: 3xRATIONAL) -/// -internal class GPSTimeStamp : ExifURationalArray -{ - public GPSTimeStamp(ExifTag tag, MathEx.UFraction32[] value) - : base(tag, value) - { - } - - public GPSTimeStamp(ExifTag tag, float h, float m, float s) - : base(tag, new[] { new(h), new MathEx.UFraction32(m), new MathEx.UFraction32(s) }) - { - } - - public MathEx.UFraction32 Hour - { - get => mValue[0]; - set => mValue[0] = value; - } - - protected new MathEx.UFraction32[] Value - { - get => mValue; - set => mValue = value; - } - - public MathEx.UFraction32 Minute - { - get => mValue[1]; - set => mValue[1] = value; - } - - public MathEx.UFraction32 Second - { - get => mValue[2]; - set => mValue[2] = value; - } - - public override string ToString() => - string.Format("{0:F2}:{1:F2}:{2:F2}\"", (float)Hour, (float)Minute, (float)Second); -} - -/// -/// Represents an ASCII string. (EXIF Specification: BYTE) -/// Used by Windows XP. -/// -internal class WindowsByteString : ExifProperty -{ - protected string mValue; - - public WindowsByteString(ExifTag tag, string value) - : base(tag) => - mValue = value; - - public new string Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (string)value; - } - - public override ExifInterOperability Interoperability - { - get - { - var data = Encoding.Unicode.GetBytes(mValue); - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 1, (uint)data.Length, data); - } - } - - public static implicit operator string(WindowsByteString obj) => obj.mValue; - - public override string ToString() => mValue; -} diff --git a/src/Umbraco.Core/Media/Exif/ExifFileTypeDescriptor.cs b/src/Umbraco.Core/Media/Exif/ExifFileTypeDescriptor.cs deleted file mode 100644 index a07ade9963..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifFileTypeDescriptor.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System.ComponentModel; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Provides a custom type descriptor for an ExifFile instance. -/// -internal sealed class ExifFileTypeDescriptionProvider : TypeDescriptionProvider -{ - public ExifFileTypeDescriptionProvider() - : this(TypeDescriptor.GetProvider(typeof(ImageFile))) - { - } - - public ExifFileTypeDescriptionProvider(TypeDescriptionProvider parent) - : base(parent) - { - } - - /// - /// Gets a custom type descriptor for the given type and object. - /// - /// The type of object for which to retrieve the type descriptor. - /// - /// An instance of the type. Can be null if no instance was passed to the - /// . - /// - /// - /// An that can provide metadata for the type. - /// - public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object? instance) => - new ExifFileTypeDescriptor(base.GetTypeDescriptor(objectType, instance), instance); -} - -/// -/// Expands ExifProperty objects contained in an ExifFile as separate properties. -/// -internal sealed class ExifFileTypeDescriptor : CustomTypeDescriptor -{ - private readonly ImageFile? owner; - - public ExifFileTypeDescriptor(ICustomTypeDescriptor? parent, object? instance) - : base(parent) => - owner = (ImageFile?)instance; - - public override PropertyDescriptorCollection GetProperties(Attribute[]? attributes) => GetProperties(); - - /// - /// Returns a collection of property descriptors for the object represented by this type descriptor. - /// - /// - /// A containing the property descriptions for the - /// object represented by this type descriptor. The default is - /// . - /// - public override PropertyDescriptorCollection GetProperties() - { - // Enumerate the original set of properties and create our new set with it - var properties = new List(); - - if (owner is not null) - { - foreach (ExifProperty prop in owner.Properties) - { - var pd = new ExifPropertyDescriptor(prop); - properties.Add(pd); - } - } - - // Finally return the list - return new PropertyDescriptorCollection(properties.ToArray(), true); - } -} - -internal sealed class ExifPropertyDescriptor : PropertyDescriptor -{ - private readonly ExifProperty linkedProperty; - private readonly object originalValue; - - public ExifPropertyDescriptor(ExifProperty property) - : base(property.Name, new Attribute[] { new BrowsableAttribute(true) }) - { - linkedProperty = property; - originalValue = property.Value; - } - - public override Type ComponentType => typeof(JPEGFile); - - public override bool IsReadOnly => false; - - public override Type PropertyType => linkedProperty.Value.GetType(); - - public override bool CanResetValue(object component) => true; - - public override object GetValue(object? component) => linkedProperty.Value; - - public override void ResetValue(object component) => linkedProperty.Value = originalValue; - - public override void SetValue(object? component, object? value) - { - if (value is not null) - { - linkedProperty.Value = value; - } - } - - public override bool ShouldSerializeValue(object component) => false; -} diff --git a/src/Umbraco.Core/Media/Exif/ExifInterOperability.cs b/src/Umbraco.Core/Media/Exif/ExifInterOperability.cs deleted file mode 100644 index d2d9f8be6a..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifInterOperability.cs +++ /dev/null @@ -1,55 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents interoperability data for an exif tag in the platform byte order. -/// -internal struct ExifInterOperability -{ - public ExifInterOperability(ushort tagid, ushort typeid, uint count, byte[] data) - { - TagID = tagid; - TypeID = typeid; - Count = count; - Data = data; - } - - /// - /// Gets the tag ID defined in the Exif standard. - /// - public ushort TagID { get; } - - /// - /// Gets the type code defined in the Exif standard. - /// - /// 1 = BYTE (byte) - /// 2 = ASCII (byte array) - /// 3 = SHORT (ushort) - /// 4 = LONG (uint) - /// 5 = RATIONAL (2 x uint: numerator, denominator) - /// 6 = BYTE (sbyte) - /// 7 = UNDEFINED (byte array) - /// 8 = SSHORT (short) - /// 9 = SLONG (int) - /// 10 = SRATIONAL (2 x int: numerator, denominator) - /// 11 = FLOAT (float) - /// 12 = DOUBLE (double) - /// - /// - public ushort TypeID { get; } - - /// - /// Gets the byte count or number of components. - /// - public uint Count { get; } - - /// - /// Gets the field value as an array of bytes. - /// - public byte[] Data { get; } - - /// - /// Returns the string representation of this instance. - /// - /// - public override string ToString() => string.Format("Tag: {0}, Type: {1}, Count: {2}, Data Length: {3}", TagID, TypeID, Count, Data.Length); -} diff --git a/src/Umbraco.Core/Media/Exif/ExifProperty.cs b/src/Umbraco.Core/Media/Exif/ExifProperty.cs deleted file mode 100644 index 6d742bb3ba..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifProperty.cs +++ /dev/null @@ -1,672 +0,0 @@ -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the abstract base class for an Exif property. -/// -internal abstract class ExifProperty -{ - protected IFD mIFD; - protected string? mName; - protected ExifTag mTag; - - public ExifProperty(ExifTag tag) - { - mTag = tag; - mIFD = ExifTagFactory.GetTagIFD(tag); - } - - /// - /// Gets the Exif tag associated with this property. - /// - public ExifTag Tag => mTag; - - /// - /// Gets the IFD section containing this property. - /// - public IFD IFD => mIFD; - - /// - /// Gets or sets the name of this property. - /// - public string Name - { - get - { - if (string.IsNullOrEmpty(mName)) - { - return ExifTagFactory.GetTagName(mTag); - } - - return mName; - } - set => mName = value; - } - - /// - /// Gets or sets the value of this property. - /// - public object Value - { - get => _Value; - set => _Value = value; - } - - protected abstract object _Value { get; set; } - - /// - /// Gets interoperability data for this property. - /// - public abstract ExifInterOperability Interoperability { get; } -} - -/// -/// Represents an 8-bit unsigned integer. (EXIF Specification: BYTE) -/// -internal class ExifByte : ExifProperty -{ - protected byte mValue; - - public ExifByte(ExifTag tag, byte value) - : base(tag) => - mValue = value; - - public new byte Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = Convert.ToByte(value); - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 1, 1, new[] { mValue }); - - public static implicit operator byte(ExifByte obj) => obj.mValue; - - public override string ToString() => mValue.ToString(); -} - -/// -/// Represents an array of 8-bit unsigned integers. (EXIF Specification: BYTE with count > 1) -/// -internal class ExifByteArray : ExifProperty -{ - protected byte[] mValue; - - public ExifByteArray(ExifTag tag, byte[] value) - : base(tag) => - mValue = value; - - public new byte[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (byte[])value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 1, (uint)mValue.Length, mValue); - - public static implicit operator byte[](ExifByteArray obj) => obj.mValue; - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (var b in mValue) - { - sb.Append(b); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} - -/// -/// Represents an ASCII string. (EXIF Specification: ASCII) -/// -internal class ExifAscii : ExifProperty -{ - protected string mValue; - - public ExifAscii(ExifTag tag, string value, Encoding encoding) - : base(tag) - { - mValue = value; - Encoding = encoding; - } - - public new string Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (string)value; - } - - public Encoding Encoding { get; } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 2, - (uint)mValue.Length + 1, - ExifBitConverter.GetBytes(mValue, true, Encoding)); - - public static implicit operator string(ExifAscii obj) => obj.mValue; - - public override string ToString() => mValue; -} - -/// -/// Represents a 16-bit unsigned integer. (EXIF Specification: SHORT) -/// -internal class ExifUShort : ExifProperty -{ - protected ushort mValue; - - public ExifUShort(ExifTag tag, ushort value) - : base(tag) => - mValue = value; - - public new ushort Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = Convert.ToUInt16(value); - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 3, - 1, - BitConverterEx.GetBytes(mValue, BitConverterEx.SystemByteOrder, BitConverterEx.SystemByteOrder)); - - public static implicit operator ushort(ExifUShort obj) => obj.mValue; - - public override string ToString() => mValue.ToString(); -} - -/// -/// Represents an array of 16-bit unsigned integers. -/// (EXIF Specification: SHORT with count > 1) -/// -internal class ExifUShortArray : ExifProperty -{ - protected ushort[] mValue; - - public ExifUShortArray(ExifTag tag, ushort[] value) - : base(tag) => - mValue = value; - - public new ushort[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (ushort[])value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 3, - (uint)mValue.Length, - ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static implicit operator ushort[](ExifUShortArray obj) => obj.mValue; - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (var b in mValue) - { - sb.Append(b); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} - -/// -/// Represents a 32-bit unsigned integer. (EXIF Specification: LONG) -/// -internal class ExifUInt : ExifProperty -{ - protected uint mValue; - - public ExifUInt(ExifTag tag, uint value) - : base(tag) => - mValue = value; - - public new uint Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = Convert.ToUInt32(value); - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 4, - 1, - BitConverterEx.GetBytes(mValue, BitConverterEx.SystemByteOrder, BitConverterEx.SystemByteOrder)); - - public static implicit operator uint(ExifUInt obj) => obj.mValue; - - public override string ToString() => mValue.ToString(); -} - -/// -/// Represents an array of 16-bit unsigned integers. -/// (EXIF Specification: LONG with count > 1) -/// -internal class ExifUIntArray : ExifProperty -{ - protected uint[] mValue; - - public ExifUIntArray(ExifTag tag, uint[] value) - : base(tag) => - mValue = value; - - public new uint[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (uint[])value; - } - - public override ExifInterOperability Interoperability => new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 3, (uint)mValue.Length, ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static implicit operator uint[](ExifUIntArray obj) => obj.mValue; - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (var b in mValue) - { - sb.Append(b); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} - -/// -/// Represents a rational number defined with a 32-bit unsigned numerator -/// and denominator. (EXIF Specification: RATIONAL) -/// -internal class ExifURational : ExifProperty -{ - protected MathEx.UFraction32 mValue; - - public ExifURational(ExifTag tag, uint numerator, uint denominator) - : base(tag) => - mValue = new MathEx.UFraction32(numerator, denominator); - - public ExifURational(ExifTag tag, MathEx.UFraction32 value) - : base(tag) => - mValue = value; - - public new MathEx.UFraction32 Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (MathEx.UFraction32)value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 5, - 1, - ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static explicit operator float(ExifURational obj) => (float)obj.mValue; - - public override string ToString() => mValue.ToString(); - - public float ToFloat() => (float)mValue; - - public uint[] ToArray() => new[] { mValue.Numerator, mValue.Denominator }; -} - -/// -/// Represents an array of unsigned rational numbers. -/// (EXIF Specification: RATIONAL with count > 1) -/// -internal class ExifURationalArray : ExifProperty -{ - protected MathEx.UFraction32[] mValue; - - public ExifURationalArray(ExifTag tag, MathEx.UFraction32[] value) - : base(tag) => - mValue = value; - - public new MathEx.UFraction32[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (MathEx.UFraction32[])value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 5, - (uint)mValue.Length, - ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static explicit operator float[](ExifURationalArray obj) - { - var result = new float[obj.mValue.Length]; - for (var i = 0; i < obj.mValue.Length; i++) - { - result[i] = (float)obj.mValue[i]; - } - - return result; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (MathEx.UFraction32 b in mValue) - { - sb.Append(b.ToString()); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} - -/// -/// Represents a byte array that can take any value. (EXIF Specification: UNDEFINED) -/// -internal class ExifUndefined : ExifProperty -{ - protected byte[] mValue; - - public ExifUndefined(ExifTag tag, byte[] value) - : base(tag) => - mValue = value; - - public new byte[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (byte[])value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 7, (uint)mValue.Length, mValue); - - public static implicit operator byte[](ExifUndefined obj) => obj.mValue; - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (var b in mValue) - { - sb.Append(b); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} - -/// -/// Represents a 32-bit signed integer. (EXIF Specification: SLONG) -/// -internal class ExifSInt : ExifProperty -{ - protected int mValue; - - public ExifSInt(ExifTag tag, int value) - : base(tag) => - mValue = value; - - public new int Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = Convert.ToInt32(value); - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 9, - 1, - BitConverterEx.GetBytes(mValue, BitConverterEx.SystemByteOrder, BitConverterEx.SystemByteOrder)); - - public static implicit operator int(ExifSInt obj) => obj.mValue; - - public override string ToString() => mValue.ToString(); -} - -/// -/// Represents an array of 32-bit signed integers. -/// (EXIF Specification: SLONG with count > 1) -/// -internal class ExifSIntArray : ExifProperty -{ - protected int[] mValue; - - public ExifSIntArray(ExifTag tag, int[] value) - : base(tag) => - mValue = value; - - public new int[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (int[])value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 9, - (uint)mValue.Length, - ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static implicit operator int[](ExifSIntArray obj) => obj.mValue; - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (var b in mValue) - { - sb.Append(b); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} - -/// -/// Represents a rational number defined with a 32-bit signed numerator -/// and denominator. (EXIF Specification: SRATIONAL) -/// -internal class ExifSRational : ExifProperty -{ - protected MathEx.Fraction32 mValue; - - public ExifSRational(ExifTag tag, int numerator, int denominator) - : base(tag) => - mValue = new MathEx.Fraction32(numerator, denominator); - - public ExifSRational(ExifTag tag, MathEx.Fraction32 value) - : base(tag) => - mValue = value; - - public new MathEx.Fraction32 Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (MathEx.Fraction32)value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 10, - 1, - ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static explicit operator float(ExifSRational obj) => (float)obj.mValue; - - public override string ToString() => mValue.ToString(); - - public float ToFloat() => (float)mValue; - - public int[] ToArray() => new[] { mValue.Numerator, mValue.Denominator }; -} - -/// -/// Represents an array of signed rational numbers. -/// (EXIF Specification: SRATIONAL with count > 1) -/// -internal class ExifSRationalArray : ExifProperty -{ - protected MathEx.Fraction32[] mValue; - - public ExifSRationalArray(ExifTag tag, MathEx.Fraction32[] value) - : base(tag) => - mValue = value; - - public new MathEx.Fraction32[] Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (MathEx.Fraction32[])value; - } - - public override ExifInterOperability Interoperability => - new ExifInterOperability( - ExifTagFactory.GetTagID(mTag), - 10, - (uint)mValue.Length, - ExifBitConverter.GetBytes(mValue, BitConverterEx.SystemByteOrder)); - - public static explicit operator float[](ExifSRationalArray obj) - { - var result = new float[obj.mValue.Length]; - for (var i = 0; i < obj.mValue.Length; i++) - { - result[i] = (float)obj.mValue[i]; - } - - return result; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append('['); - foreach (MathEx.Fraction32 b in mValue) - { - sb.Append(b.ToString()); - sb.Append(' '); - } - - sb.Remove(sb.Length - 1, 1); - sb.Append(']'); - return sb.ToString(); - } -} diff --git a/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs b/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs deleted file mode 100644 index f77f0c89cd..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs +++ /dev/null @@ -1,493 +0,0 @@ -using System.Collections; -using System.Diagnostics.CodeAnalysis; -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents a collection of objects. -/// -internal class ExifPropertyCollection : IDictionary -{ - #region Constructor - - internal ExifPropertyCollection(ImageFile parentFile) - { - parent = parentFile; - items = new Dictionary(); - } - - #endregion - - #region Member Variables - - private readonly ImageFile parent; - private readonly Dictionary items; - - #endregion - - #region Properties - - /// - /// Gets the number of elements contained in the collection. - /// - public int Count => items.Count; - - /// - /// Gets a collection containing the keys in this collection. - /// - public ICollection Keys => items.Keys; - - /// - /// Gets a collection containing the values in this collection. - /// - public ICollection Values => items.Values; - - /// - /// Gets or sets the with the specified key. - /// - public ExifProperty this[ExifTag key] - { - get => items[key]; - set - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, value); - } - } - - #endregion - - #region ExifProperty Collection Setters - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, byte value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifByte(key, value)); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, string value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - if (key == ExifTag.WindowsTitle || key == ExifTag.WindowsComment || key == ExifTag.WindowsAuthor || - key == ExifTag.WindowsKeywords || key == ExifTag.WindowsSubject) - { - items.Add(key, new WindowsByteString(key, value)); - } - else - { - items.Add(key, new ExifAscii(key, value, parent.Encoding)); - } - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, ushort value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifUShort(key, value)); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, int value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifSInt(key, value)); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, uint value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifUInt(key, value)); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, float value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifURational(key, new MathEx.UFraction32(value))); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, double value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifURational(key, new MathEx.UFraction32(value))); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, object value) - { - Type type = value.GetType(); - if (type.IsEnum) - { - Type etype = typeof(ExifEnumProperty<>).MakeGenericType(type); - var prop = Activator.CreateInstance(etype, key, value); - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - if (prop is ExifProperty exifProperty) - { - items.Add(key, exifProperty); - } - } - else - { - throw new ArgumentException("No exif property exists for this tag.", "value"); - } - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - /// String encoding. - public void Set(ExifTag key, string value, Encoding encoding) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifEncodedString(key, value, encoding)); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// The value of tag. - public void Set(ExifTag key, DateTime value) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifDateTime(key, value)); - } - - /// - /// Sets the with the specified key. - /// - /// The tag to set. - /// Angular degrees (or clock hours for a timestamp). - /// Angular minutes (or clock minutes for a timestamp). - /// Angular seconds (or clock seconds for a timestamp). - public void Set(ExifTag key, float d, float m, float s) - { - if (items.ContainsKey(key)) - { - items.Remove(key); - } - - items.Add(key, new ExifURationalArray(key, new[] { new(d), new MathEx.UFraction32(m), new MathEx.UFraction32(s) })); - } - - #endregion - - #region Instance Methods - - /// - /// Adds the specified item to the collection. - /// - /// The to add to the collection. - public void Add(ExifProperty item) - { - ExifProperty? oldItem = null; - if (items.TryGetValue(item.Tag, out oldItem)) - { - items[item.Tag] = item; - } - else - { - items.Add(item.Tag, item); - } - } - - /// - /// Removes all items from the collection. - /// - public void Clear() => items.Clear(); - - /// - /// Determines whether the collection contains an element with the specified key. - /// - /// The key to locate in the collection. - /// - /// true if the collection contains an element with the key; otherwise, false. - /// - /// - /// is null. - /// - public bool ContainsKey(ExifTag key) => items.ContainsKey(key); - - /// - /// Removes the element with the specified key from the collection. - /// - /// The key of the element to remove. - /// - /// true if the element is successfully removed; otherwise, false. This method also returns false if - /// was not found in the original collection. - /// - /// - /// is null. - /// - public bool Remove(ExifTag key) => items.Remove(key); - - /// - /// Removes all items with the given IFD from the collection. - /// - /// The IFD section to remove. - public void Remove(IFD ifd) - { - var toRemove = new List(); - foreach (KeyValuePair item in items) - { - if (item.Value.IFD == ifd) - { - toRemove.Add(item.Key); - } - } - - foreach (ExifTag tag in toRemove) - { - items.Remove(tag); - } - } - - /// - /// Gets the value associated with the specified key. - /// - /// The key whose value to get. - /// - /// When this method returns, the value associated with the specified key, if the key is found; - /// otherwise, the default value for the type of the parameter. This parameter is passed - /// uninitialized. - /// - /// - /// true if the collection contains an element with the specified key; otherwise, false. - /// - /// - /// is null. - /// - public bool TryGetValue(ExifTag key, [MaybeNullWhen(false)] out ExifProperty value) => - items.TryGetValue(key, out value); - - /// - /// Returns an enumerator that iterates through a collection. - /// - /// - /// An object that can be used to iterate through the collection. - /// - public IEnumerator GetEnumerator() => Values.GetEnumerator(); - - #endregion - - #region Hidden Interface - - /// - /// Adds an element with the provided key and value to the . - /// - /// The object to use as the key of the element to add. - /// The object to use as the value of the element to add. - /// - /// is null. - /// - /// - /// An element with the same key already exists in the - /// . - /// - /// - /// The is - /// read-only. - /// - void IDictionary.Add(ExifTag key, ExifProperty value) => Add(value); - - /// - /// Adds an item to the . - /// - /// The object to add to the . - /// - /// The is - /// read-only. - /// - void ICollection>.Add(KeyValuePair item) => - Add(item.Value); - - bool ICollection>.Contains(KeyValuePair item) => - throw new NotSupportedException(); - - /// - /// Copies the elements of the to an - /// , starting at a particular index. - /// - /// - /// The one-dimensional that is the destination of the elements copied - /// from . The must have - /// zero-based indexing. - /// - /// The zero-based index in at which copying begins. - /// - /// is null. - /// - /// - /// is less than 0. - /// - /// - /// is multidimensional.-or- is equal to or greater than the - /// length of .-or-The number of elements in the source - /// is greater than the available space from - /// to the end of the destination .-or-Type - /// cannot be cast automatically to the type of the destination . - /// - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException("array"); - } - - if (arrayIndex < 0) - { - throw new ArgumentOutOfRangeException("arrayIndex"); - } - - if (array.Rank > 1) - { - throw new ArgumentException("Destination array is multidimensional.", "array"); - } - - if (arrayIndex >= array.Length) - { - throw new ArgumentException("arrayIndex is equal to or greater than the length of destination array", "array"); - } - - if (arrayIndex + items.Count > array.Length) - { - throw new ArgumentException("There is not enough space in destination array.", "array"); - } - - var i = 0; - foreach (KeyValuePair item in items) - { - if (i >= arrayIndex) - { - array[i] = item; - } - - i++; - } - } - - /// - /// Gets a value indicating whether the is read-only. - /// - /// true if the is read-only; otherwise, false. - bool ICollection>.IsReadOnly => false; - - /// - /// Removes the first occurrence of a specific object from the - /// . - /// - /// The object to remove from the . - /// - /// true if was successfully removed from the - /// ; otherwise, false. This method also returns false if - /// is not found in the original . - /// - /// - /// The is - /// read-only. - /// - bool ICollection>.Remove(KeyValuePair item) => - throw new NotSupportedException(); - - /// - /// Returns an enumerator that iterates through a collection. - /// - /// - /// An object that can be used to iterate through the collection. - /// - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - IEnumerator> IEnumerable>.GetEnumerator() => - items.GetEnumerator(); - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/ExifPropertyFactory.cs b/src/Umbraco.Core/Media/Exif/ExifPropertyFactory.cs deleted file mode 100644 index 4290dcaf7c..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifPropertyFactory.cs +++ /dev/null @@ -1,598 +0,0 @@ -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Creates exif properties from interoperability parameters. -/// -internal static class ExifPropertyFactory -{ - #region Static Methods - - /// - /// Creates an ExifProperty from the given interoperability parameters. - /// - /// The tag id of the exif property. - /// The type id of the exif property. - /// Byte or component count. - /// Field data as an array of bytes. - /// Byte order of value. - /// IFD section containing this property. - /// The encoding to be used for text metadata when the source encoding is unknown. - /// an ExifProperty initialized from the interoperability parameters. - public static ExifProperty Get(ushort tag, ushort type, uint count, byte[] value, BitConverterEx.ByteOrder byteOrder, IFD ifd, Encoding encoding) - { - var conv = new BitConverterEx(byteOrder, BitConverterEx.SystemByteOrder); - - // Find the exif tag corresponding to given tag id - ExifTag etag = ExifTagFactory.GetExifTag(ifd, tag); - - if (ifd == IFD.Zeroth) - { - // Compression - if (tag == 0x103) - { - return new ExifEnumProperty(ExifTag.Compression, (Compression)conv.ToUInt16(value, 0)); - } - - // PhotometricInterpretation - if (tag == 0x106) - { - return new ExifEnumProperty( - ExifTag.PhotometricInterpretation, - (PhotometricInterpretation)conv.ToUInt16(value, 0)); - } - - // Orientation - if (tag == 0x112) - { - return new ExifEnumProperty(ExifTag.Orientation, (Orientation)conv.ToUInt16(value, 0)); - } - - // PlanarConfiguration - if (tag == 0x11c) - { - return new ExifEnumProperty( - ExifTag.PlanarConfiguration, - (PlanarConfiguration)conv.ToUInt16(value, 0)); - } - - // YCbCrPositioning - if (tag == 0x213) - { - return new ExifEnumProperty( - ExifTag.YCbCrPositioning, - (YCbCrPositioning)conv.ToUInt16(value, 0)); - } - - // ResolutionUnit - if (tag == 0x128) - { - return new ExifEnumProperty( - ExifTag.ResolutionUnit, - (ResolutionUnit)conv.ToUInt16(value, 0)); - } - - // DateTime - if (tag == 0x132) - { - return new ExifDateTime(ExifTag.DateTime, ExifBitConverter.ToDateTime(value)); - } - - if (tag == 0x9c9b || tag == 0x9c9c || // Windows tags - tag == 0x9c9d || tag == 0x9c9e || tag == 0x9c9f) - { - return new WindowsByteString( - etag, - Encoding.Unicode.GetString(value).TrimEnd(Constants.CharArrays.NullTerminator)); - } - } - else if (ifd == IFD.EXIF) - { - // ExifVersion - if (tag == 0x9000) - { - return new ExifVersion(ExifTag.ExifVersion, ExifBitConverter.ToAscii(value, Encoding.ASCII)); - } - - // FlashpixVersion - if (tag == 0xa000) - { - return new ExifVersion(ExifTag.FlashpixVersion, ExifBitConverter.ToAscii(value, Encoding.ASCII)); - } - - // ColorSpace - if (tag == 0xa001) - { - return new ExifEnumProperty(ExifTag.ColorSpace, (ColorSpace)conv.ToUInt16(value, 0)); - } - - // UserComment - if (tag == 0x9286) - { - // Default to ASCII - Encoding enc = Encoding.ASCII; - bool hasenc; - if (value.Length < 8) - { - hasenc = false; - } - else - { - hasenc = true; - var encstr = enc.GetString(value, 0, 8); - if (string.Compare(encstr, "ASCII\0\0\0", StringComparison.OrdinalIgnoreCase) == 0) - { - enc = Encoding.ASCII; - } - else if (string.Compare(encstr, "JIS\0\0\0\0\0", StringComparison.OrdinalIgnoreCase) == 0) - { - enc = Encoding.GetEncoding("Japanese (JIS 0208-1990 and 0212-1990)"); - } - else if (string.Compare(encstr, "Unicode\0", StringComparison.OrdinalIgnoreCase) == 0) - { - enc = Encoding.Unicode; - } - else - { - hasenc = false; - } - } - - var val = (hasenc ? enc.GetString(value, 8, value.Length - 8) : enc.GetString(value)).Trim( - Constants.CharArrays.NullTerminator); - - return new ExifEncodedString(ExifTag.UserComment, val, enc); - } - - // DateTimeOriginal - if (tag == 0x9003) - { - return new ExifDateTime(ExifTag.DateTimeOriginal, ExifBitConverter.ToDateTime(value)); - } - - // DateTimeDigitized - if (tag == 0x9004) - { - return new ExifDateTime(ExifTag.DateTimeDigitized, ExifBitConverter.ToDateTime(value)); - } - - // ExposureProgram - if (tag == 0x8822) - { - return new ExifEnumProperty( - ExifTag.ExposureProgram, - (ExposureProgram)conv.ToUInt16(value, 0)); - } - - // MeteringMode - if (tag == 0x9207) - { - return new ExifEnumProperty(ExifTag.MeteringMode, (MeteringMode)conv.ToUInt16(value, 0)); - } - - // LightSource - if (tag == 0x9208) - { - return new ExifEnumProperty(ExifTag.LightSource, (LightSource)conv.ToUInt16(value, 0)); - } - - // Flash - if (tag == 0x9209) - { - return new ExifEnumProperty(ExifTag.Flash, (Flash)conv.ToUInt16(value, 0), true); - } - - // SubjectArea - if (tag == 0x9214) - { - if (count == 3) - { - return new ExifCircularSubjectArea( - ExifTag.SubjectArea, - ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)); - } - - if (count == 4) - { - return new ExifRectangularSubjectArea( - ExifTag.SubjectArea, - ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)); - } - - return new ExifPointSubjectArea( - ExifTag.SubjectArea, - ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)); - } - - // FocalPlaneResolutionUnit - if (tag == 0xa210) - { - return new ExifEnumProperty( - ExifTag.FocalPlaneResolutionUnit, - (ResolutionUnit)conv.ToUInt16(value, 0), - true); - } - - // SubjectLocation - if (tag == 0xa214) - { - return new ExifPointSubjectArea( - ExifTag.SubjectLocation, - ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)); - } - - // SensingMethod - if (tag == 0xa217) - { - return new ExifEnumProperty( - ExifTag.SensingMethod, - (SensingMethod)conv.ToUInt16(value, 0), - true); - } - - // FileSource - if (tag == 0xa300) - { - return new ExifEnumProperty(ExifTag.FileSource, (FileSource)conv.ToUInt16(value, 0), true); - } - - // SceneType - if (tag == 0xa301) - { - return new ExifEnumProperty(ExifTag.SceneType, (SceneType)conv.ToUInt16(value, 0), true); - } - - // CustomRendered - if (tag == 0xa401) - { - return new ExifEnumProperty( - ExifTag.CustomRendered, - (CustomRendered)conv.ToUInt16(value, 0), - true); - } - - // ExposureMode - if (tag == 0xa402) - { - return new ExifEnumProperty(ExifTag.ExposureMode, (ExposureMode)conv.ToUInt16(value, 0), true); - } - - // WhiteBalance - if (tag == 0xa403) - { - return new ExifEnumProperty(ExifTag.WhiteBalance, (WhiteBalance)conv.ToUInt16(value, 0), true); - } - - // SceneCaptureType - if (tag == 0xa406) - { - return new ExifEnumProperty( - ExifTag.SceneCaptureType, - (SceneCaptureType)conv.ToUInt16(value, 0), - true); - } - - // GainControl - if (tag == 0xa407) - { - return new ExifEnumProperty(ExifTag.GainControl, (GainControl)conv.ToUInt16(value, 0), true); - } - - // Contrast - if (tag == 0xa408) - { - return new ExifEnumProperty(ExifTag.Contrast, (Contrast)conv.ToUInt16(value, 0), true); - } - - // Saturation - if (tag == 0xa409) - { - return new ExifEnumProperty(ExifTag.Saturation, (Saturation)conv.ToUInt16(value, 0), true); - } - - // Sharpness - if (tag == 0xa40a) - { - return new ExifEnumProperty(ExifTag.Sharpness, (Sharpness)conv.ToUInt16(value, 0), true); - } - - // SubjectDistanceRange - if (tag == 0xa40c) - { - return new ExifEnumProperty( - ExifTag.SubjectDistanceRange, - (SubjectDistanceRange)conv.ToUInt16(value, 0), - true); - } - } - else if (ifd == IFD.GPS) - { - // GPSVersionID - if (tag == 0) - { - return new ExifVersion(ExifTag.GPSVersionID, ExifBitConverter.ToString(value)); - } - - // GPSLatitudeRef - if (tag == 1) - { - return new ExifEnumProperty(ExifTag.GPSLatitudeRef, (GPSLatitudeRef)value[0]); - } - - // GPSLatitude - if (tag == 2) - { - return new GPSLatitudeLongitude( - ExifTag.GPSLatitude, - ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)); - } - - // GPSLongitudeRef - if (tag == 3) - { - return new ExifEnumProperty(ExifTag.GPSLongitudeRef, (GPSLongitudeRef)value[0]); - } - - // GPSLongitude - if (tag == 4) - { - return new GPSLatitudeLongitude( - ExifTag.GPSLongitude, - ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)); - } - - // GPSAltitudeRef - if (tag == 5) - { - return new ExifEnumProperty(ExifTag.GPSAltitudeRef, (GPSAltitudeRef)value[0]); - } - - // GPSTimeStamp - if (tag == 7) - { - return new GPSTimeStamp( - ExifTag.GPSTimeStamp, - ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)); - } - - // GPSStatus - if (tag == 9) - { - return new ExifEnumProperty(ExifTag.GPSStatus, (GPSStatus)value[0]); - } - - // GPSMeasureMode - if (tag == 10) - { - return new ExifEnumProperty(ExifTag.GPSMeasureMode, (GPSMeasureMode)value[0]); - } - - // GPSSpeedRef - if (tag == 12) - { - return new ExifEnumProperty(ExifTag.GPSSpeedRef, (GPSSpeedRef)value[0]); - } - - // GPSTrackRef - if (tag == 14) - { - return new ExifEnumProperty(ExifTag.GPSTrackRef, (GPSDirectionRef)value[0]); - } - - // GPSImgDirectionRef - if (tag == 16) - { - return new ExifEnumProperty(ExifTag.GPSImgDirectionRef, (GPSDirectionRef)value[0]); - } - - // GPSDestLatitudeRef - if (tag == 19) - { - return new ExifEnumProperty(ExifTag.GPSDestLatitudeRef, (GPSLatitudeRef)value[0]); - } - - // GPSDestLatitude - if (tag == 20) - { - return new GPSLatitudeLongitude( - ExifTag.GPSDestLatitude, - ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)); - } - - // GPSDestLongitudeRef - if (tag == 21) - { - return new ExifEnumProperty(ExifTag.GPSDestLongitudeRef, (GPSLongitudeRef)value[0]); - } - - // GPSDestLongitude - if (tag == 22) - { - return new GPSLatitudeLongitude( - ExifTag.GPSDestLongitude, - ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)); - } - - // GPSDestBearingRef - if (tag == 23) - { - return new ExifEnumProperty(ExifTag.GPSDestBearingRef, (GPSDirectionRef)value[0]); - } - - // GPSDestDistanceRef - if (tag == 25) - { - return new ExifEnumProperty(ExifTag.GPSDestDistanceRef, (GPSDistanceRef)value[0]); - } - - // GPSDate - if (tag == 29) - { - return new ExifDateTime(ExifTag.GPSDateStamp, ExifBitConverter.ToDateTime(value, false)); - } - - // GPSDifferential - if (tag == 30) - { - return new ExifEnumProperty( - ExifTag.GPSDifferential, - (GPSDifferential)conv.ToUInt16(value, 0)); - } - } - else if (ifd == IFD.Interop) - { - // InteroperabilityIndex - if (tag == 1) - { - return new ExifAscii(ExifTag.InteroperabilityIndex, ExifBitConverter.ToAscii(value, Encoding.ASCII), Encoding.ASCII); - } - - // InteroperabilityVersion - if (tag == 2) - { - return new ExifVersion( - ExifTag.InteroperabilityVersion, - ExifBitConverter.ToAscii(value, Encoding.ASCII)); - } - } - else if (ifd == IFD.First) - { - // Compression - if (tag == 0x103) - { - return new ExifEnumProperty( - ExifTag.ThumbnailCompression, - (Compression)conv.ToUInt16(value, 0)); - } - - // PhotometricInterpretation - if (tag == 0x106) - { - return new ExifEnumProperty( - ExifTag.ThumbnailPhotometricInterpretation, - (PhotometricInterpretation)conv.ToUInt16(value, 0)); - } - - // Orientation - if (tag == 0x112) - { - return new ExifEnumProperty( - ExifTag.ThumbnailOrientation, - (Orientation)conv.ToUInt16(value, 0)); - } - - // PlanarConfiguration - if (tag == 0x11c) - { - return new ExifEnumProperty( - ExifTag.ThumbnailPlanarConfiguration, - (PlanarConfiguration)conv.ToUInt16(value, 0)); - } - - // YCbCrPositioning - if (tag == 0x213) - { - return new ExifEnumProperty( - ExifTag.ThumbnailYCbCrPositioning, - (YCbCrPositioning)conv.ToUInt16(value, 0)); - } - - // ResolutionUnit - if (tag == 0x128) - { - return new ExifEnumProperty( - ExifTag.ThumbnailResolutionUnit, - (ResolutionUnit)conv.ToUInt16(value, 0)); - } - - // DateTime - if (tag == 0x132) - { - return new ExifDateTime(ExifTag.ThumbnailDateTime, ExifBitConverter.ToDateTime(value)); - } - } - - // 1 = BYTE An 8-bit unsigned integer. - if (type == 1) - { - if (count == 1) - { - return new ExifByte(etag, value[0]); - } - - return new ExifByteArray(etag, value); - } - - // 2 = ASCII An 8-bit byte containing one 7-bit ASCII code. - if (type == 2) - { - return new ExifAscii(etag, ExifBitConverter.ToAscii(value, encoding), encoding); - } - - // 3 = SHORT A 16-bit (2-byte) unsigned integer. - if (type == 3) - { - if (count == 1) - { - return new ExifUShort(etag, conv.ToUInt16(value, 0)); - } - - return new ExifUShortArray(etag, ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)); - } - - // 4 = LONG A 32-bit (4-byte) unsigned integer. - if (type == 4) - { - if (count == 1) - { - return new ExifUInt(etag, conv.ToUInt32(value, 0)); - } - - return new ExifUIntArray(etag, ExifBitConverter.ToUIntArray(value, (int)count, byteOrder)); - } - - // 5 = RATIONAL Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator. - if (type == 5) - { - if (count == 1) - { - return new ExifURational(etag, ExifBitConverter.ToURational(value, byteOrder)); - } - - return new ExifURationalArray(etag, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)); - } - - // 7 = UNDEFINED An 8-bit byte that can take any value depending on the field definition. - if (type == 7) - { - return new ExifUndefined(etag, value); - } - - // 9 = SLONG A 32-bit (4-byte) signed integer (2's complement notation). - if (type == 9) - { - if (count == 1) - { - return new ExifSInt(etag, conv.ToInt32(value, 0)); - } - - return new ExifSIntArray(etag, ExifBitConverter.ToSIntArray(value, (int)count, byteOrder)); - } - - // 10 = SRATIONAL Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator. - if (type == 10) - { - if (count == 1) - { - return new ExifSRational(etag, ExifBitConverter.ToSRational(value, byteOrder)); - } - - return new ExifSRationalArray(etag, ExifBitConverter.ToSRationalArray(value, (int)count, byteOrder)); - } - - throw new ArgumentException("Unknown property type."); - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/ExifTag.cs b/src/Umbraco.Core/Media/Exif/ExifTag.cs deleted file mode 100644 index 0ffd754836..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifTag.cs +++ /dev/null @@ -1,310 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the tags associated with exif fields. -/// -internal enum ExifTag -{ - // **************************** - // Zeroth IFD - // **************************** - NewSubfileType = IFD.Zeroth + 254, - SubfileType = IFD.Zeroth + 255, - ImageWidth = IFD.Zeroth + 256, - ImageLength = IFD.Zeroth + 257, - BitsPerSample = IFD.Zeroth + 258, - Compression = IFD.Zeroth + 259, - PhotometricInterpretation = IFD.Zeroth + 262, - Threshholding = IFD.Zeroth + 263, - CellWidth = IFD.Zeroth + 264, - CellLength = IFD.Zeroth + 265, - FillOrder = IFD.Zeroth + 266, - DocumentName = IFD.Zeroth + 269, - ImageDescription = IFD.Zeroth + 270, - Make = IFD.Zeroth + 271, - Model = IFD.Zeroth + 272, - StripOffsets = IFD.Zeroth + 273, - Orientation = IFD.Zeroth + 274, - SamplesPerPixel = IFD.Zeroth + 277, - RowsPerStrip = IFD.Zeroth + 278, - StripByteCounts = IFD.Zeroth + 279, - MinSampleValue = IFD.Zeroth + 280, - MaxSampleValue = IFD.Zeroth + 281, - XResolution = IFD.Zeroth + 282, - YResolution = IFD.Zeroth + 283, - PlanarConfiguration = IFD.Zeroth + 284, - PageName = IFD.Zeroth + 285, - XPosition = IFD.Zeroth + 286, - YPosition = IFD.Zeroth + 287, - FreeOffsets = IFD.Zeroth + 288, - FreeByteCounts = IFD.Zeroth + 289, - GrayResponseUnit = IFD.Zeroth + 290, - GrayResponseCurve = IFD.Zeroth + 291, - T4Options = IFD.Zeroth + 292, - T6Options = IFD.Zeroth + 293, - ResolutionUnit = IFD.Zeroth + 296, - PageNumber = IFD.Zeroth + 297, - TransferFunction = IFD.Zeroth + 301, - Software = IFD.Zeroth + 305, - DateTime = IFD.Zeroth + 306, - Artist = IFD.Zeroth + 315, - HostComputer = IFD.Zeroth + 316, - Predictor = IFD.Zeroth + 317, - WhitePoint = IFD.Zeroth + 318, - PrimaryChromaticities = IFD.Zeroth + 319, - ColorMap = IFD.Zeroth + 320, - HalftoneHints = IFD.Zeroth + 321, - TileWidth = IFD.Zeroth + 322, - TileLength = IFD.Zeroth + 323, - TileOffsets = IFD.Zeroth + 324, - TileByteCounts = IFD.Zeroth + 325, - InkSet = IFD.Zeroth + 332, - InkNames = IFD.Zeroth + 333, - NumberOfInks = IFD.Zeroth + 334, - DotRange = IFD.Zeroth + 336, - TargetPrinter = IFD.Zeroth + 337, - ExtraSamples = IFD.Zeroth + 338, - SampleFormat = IFD.Zeroth + 339, - SMinSampleValue = IFD.Zeroth + 340, - SMaxSampleValue = IFD.Zeroth + 341, - TransferRange = IFD.Zeroth + 342, - JPEGProc = IFD.Zeroth + 512, - JPEGInterchangeFormat = IFD.Zeroth + 513, - JPEGInterchangeFormatLength = IFD.Zeroth + 514, - JPEGRestartInterval = IFD.Zeroth + 515, - JPEGLosslessPredictors = IFD.Zeroth + 517, - JPEGPointTransforms = IFD.Zeroth + 518, - JPEGQTables = IFD.Zeroth + 519, - JPEGDCTables = IFD.Zeroth + 520, - JPEGACTables = IFD.Zeroth + 521, - YCbCrCoefficients = IFD.Zeroth + 529, - YCbCrSubSampling = IFD.Zeroth + 530, - YCbCrPositioning = IFD.Zeroth + 531, - ReferenceBlackWhite = IFD.Zeroth + 532, - Copyright = IFD.Zeroth + 33432, - - // Pointers to other IFDs - EXIFIFDPointer = IFD.Zeroth + 34665, - GPSIFDPointer = IFD.Zeroth + 34853, - - // Windows Tags - WindowsTitle = IFD.Zeroth + 0x9c9b, - WindowsComment = IFD.Zeroth + 0x9c9c, - WindowsAuthor = IFD.Zeroth + 0x9c9d, - WindowsKeywords = IFD.Zeroth + 0x9c9e, - WindowsSubject = IFD.Zeroth + 0x9c9f, - - // Rating - Rating = IFD.Zeroth + 0x4746, - RatingPercent = IFD.Zeroth + 0x4749, - - // Microsoft specifying padding and offset tags - ZerothIFDPadding = IFD.Zeroth + 0xea1c, - - // **************************** - // EXIF Tags - // **************************** - ExifVersion = IFD.EXIF + 36864, - FlashpixVersion = IFD.EXIF + 40960, - ColorSpace = IFD.EXIF + 40961, - ComponentsConfiguration = IFD.EXIF + 37121, - CompressedBitsPerPixel = IFD.EXIF + 37122, - PixelXDimension = IFD.EXIF + 40962, - PixelYDimension = IFD.EXIF + 40963, - MakerNote = IFD.EXIF + 37500, - UserComment = IFD.EXIF + 37510, - RelatedSoundFile = IFD.EXIF + 40964, - DateTimeOriginal = IFD.EXIF + 36867, - DateTimeDigitized = IFD.EXIF + 36868, - SubSecTime = IFD.EXIF + 37520, - SubSecTimeOriginal = IFD.EXIF + 37521, - SubSecTimeDigitized = IFD.EXIF + 37522, - ExposureTime = IFD.EXIF + 33434, - FNumber = IFD.EXIF + 33437, - ExposureProgram = IFD.EXIF + 34850, - SpectralSensitivity = IFD.EXIF + 34852, - ISOSpeedRatings = IFD.EXIF + 34855, - OECF = IFD.EXIF + 34856, - ShutterSpeedValue = IFD.EXIF + 37377, - ApertureValue = IFD.EXIF + 37378, - BrightnessValue = IFD.EXIF + 37379, - ExposureBiasValue = IFD.EXIF + 37380, - MaxApertureValue = IFD.EXIF + 37381, - SubjectDistance = IFD.EXIF + 37382, - MeteringMode = IFD.EXIF + 37383, - LightSource = IFD.EXIF + 37384, - Flash = IFD.EXIF + 37385, - FocalLength = IFD.EXIF + 37386, - SubjectArea = IFD.EXIF + 37396, - FlashEnergy = IFD.EXIF + 41483, - SpatialFrequencyResponse = IFD.EXIF + 41484, - FocalPlaneXResolution = IFD.EXIF + 41486, - FocalPlaneYResolution = IFD.EXIF + 41487, - FocalPlaneResolutionUnit = IFD.EXIF + 41488, - SubjectLocation = IFD.EXIF + 41492, - ExposureIndex = IFD.EXIF + 41493, - SensingMethod = IFD.EXIF + 41495, - FileSource = IFD.EXIF + 41728, - SceneType = IFD.EXIF + 41729, - CFAPattern = IFD.EXIF + 41730, - CustomRendered = IFD.EXIF + 41985, - ExposureMode = IFD.EXIF + 41986, - WhiteBalance = IFD.EXIF + 41987, - DigitalZoomRatio = IFD.EXIF + 41988, - FocalLengthIn35mmFilm = IFD.EXIF + 41989, - SceneCaptureType = IFD.EXIF + 41990, - GainControl = IFD.EXIF + 41991, - Contrast = IFD.EXIF + 41992, - Saturation = IFD.EXIF + 41993, - Sharpness = IFD.EXIF + 41994, - DeviceSettingDescription = IFD.EXIF + 41995, - SubjectDistanceRange = IFD.EXIF + 41996, - ImageUniqueID = IFD.EXIF + 42016, - InteroperabilityIFDPointer = IFD.EXIF + 40965, - - // Microsoft specifying padding and offset tags - ExifIFDPadding = IFD.EXIF + 0xea1c, - OffsetSchema = IFD.EXIF + 0xea1d, - - // **************************** - // GPS Tags - // **************************** - GPSVersionID = IFD.GPS + 0, - GPSLatitudeRef = IFD.GPS + 1, - GPSLatitude = IFD.GPS + 2, - GPSLongitudeRef = IFD.GPS + 3, - GPSLongitude = IFD.GPS + 4, - GPSAltitudeRef = IFD.GPS + 5, - GPSAltitude = IFD.GPS + 6, - GPSTimeStamp = IFD.GPS + 7, - GPSSatellites = IFD.GPS + 8, - GPSStatus = IFD.GPS + 9, - GPSMeasureMode = IFD.GPS + 10, - GPSDOP = IFD.GPS + 11, - GPSSpeedRef = IFD.GPS + 12, - GPSSpeed = IFD.GPS + 13, - GPSTrackRef = IFD.GPS + 14, - GPSTrack = IFD.GPS + 15, - GPSImgDirectionRef = IFD.GPS + 16, - GPSImgDirection = IFD.GPS + 17, - GPSMapDatum = IFD.GPS + 18, - GPSDestLatitudeRef = IFD.GPS + 19, - GPSDestLatitude = IFD.GPS + 20, - GPSDestLongitudeRef = IFD.GPS + 21, - GPSDestLongitude = IFD.GPS + 22, - GPSDestBearingRef = IFD.GPS + 23, - GPSDestBearing = IFD.GPS + 24, - GPSDestDistanceRef = IFD.GPS + 25, - GPSDestDistance = IFD.GPS + 26, - GPSProcessingMethod = IFD.GPS + 27, - GPSAreaInformation = IFD.GPS + 28, - GPSDateStamp = IFD.GPS + 29, - GPSDifferential = IFD.GPS + 30, - - // **************************** - // InterOp Tags - // **************************** - InteroperabilityIndex = IFD.Interop + 1, - InteroperabilityVersion = IFD.Interop + 2, - RelatedImageWidth = IFD.Interop + 0x1001, - RelatedImageHeight = IFD.Interop + 0x1002, - - // **************************** - // First IFD TIFF Tags - // **************************** - ThumbnailImageWidth = IFD.First + 256, - ThumbnailImageLength = IFD.First + 257, - ThumbnailBitsPerSample = IFD.First + 258, - ThumbnailCompression = IFD.First + 259, - ThumbnailPhotometricInterpretation = IFD.First + 262, - ThumbnailOrientation = IFD.First + 274, - ThumbnailSamplesPerPixel = IFD.First + 277, - ThumbnailPlanarConfiguration = IFD.First + 284, - ThumbnailYCbCrSubSampling = IFD.First + 530, - ThumbnailYCbCrPositioning = IFD.First + 531, - ThumbnailXResolution = IFD.First + 282, - ThumbnailYResolution = IFD.First + 283, - ThumbnailResolutionUnit = IFD.First + 296, - ThumbnailStripOffsets = IFD.First + 273, - ThumbnailRowsPerStrip = IFD.First + 278, - ThumbnailStripByteCounts = IFD.First + 279, - ThumbnailJPEGInterchangeFormat = IFD.First + 513, - ThumbnailJPEGInterchangeFormatLength = IFD.First + 514, - ThumbnailTransferFunction = IFD.First + 301, - ThumbnailWhitePoint = IFD.First + 318, - ThumbnailPrimaryChromaticities = IFD.First + 319, - ThumbnailYCbCrCoefficients = IFD.First + 529, - ThumbnailReferenceBlackWhite = IFD.First + 532, - ThumbnailDateTime = IFD.First + 306, - ThumbnailImageDescription = IFD.First + 270, - ThumbnailMake = IFD.First + 271, - ThumbnailModel = IFD.First + 272, - ThumbnailSoftware = IFD.First + 305, - ThumbnailArtist = IFD.First + 315, - ThumbnailCopyright = IFD.First + 33432, - - // **************************** - // JFIF Tags - // **************************** - - /// - /// Represents the JFIF version. - /// - JFIFVersion = IFD.JFIF + 1, - - /// - /// Represents units for X and Y densities. - /// - JFIFUnits = IFD.JFIF + 101, - - /// - /// Horizontal pixel density. - /// - XDensity = IFD.JFIF + 102, - - /// - /// Vertical pixel density - /// - YDensity = IFD.JFIF + 103, - - /// - /// Thumbnail horizontal pixel count. - /// - JFIFXThumbnail = IFD.JFIF + 201, - - /// - /// Thumbnail vertical pixel count. - /// - JFIFYThumbnail = IFD.JFIF + 202, - - /// - /// JFIF JPEG thumbnail. - /// - JFIFThumbnail = IFD.JFIF + 203, - - /// - /// Code which identifies the JFIF extension. - /// - JFXXExtensionCode = IFD.JFXX + 1, - - /// - /// Thumbnail horizontal pixel count. - /// - JFXXXThumbnail = IFD.JFXX + 101, - - /// - /// Thumbnail vertical pixel count. - /// - JFXXYThumbnail = IFD.JFXX + 102, - - /// - /// The 256-Color RGB palette. - /// - JFXXPalette = IFD.JFXX + 201, - - /// - /// JFIF thumbnail. The thumbnail will be either a JPEG, - /// a 256 color palette bitmap, or a 24-bit RGB bitmap. - /// - JFXXThumbnail = IFD.JFXX + 202, -} diff --git a/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs b/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs deleted file mode 100644 index 726da925aa..0000000000 --- a/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs +++ /dev/null @@ -1,63 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -internal static class ExifTagFactory -{ - #region Static Methods - - /// - /// Returns the ExifTag corresponding to the given tag id. - /// - public static ExifTag GetExifTag(IFD ifd, ushort tagid) => (ExifTag)(ifd + tagid); - - /// - /// Returns the tag id corresponding to the given ExifTag. - /// - public static ushort GetTagID(ExifTag exiftag) - { - IFD ifd = GetTagIFD(exiftag); - return (ushort)((int)exiftag - (int)ifd); - } - - /// - /// Returns the IFD section containing the given tag. - /// - public static IFD GetTagIFD(ExifTag tag) => (IFD)((int)tag / 100000 * 100000); - - /// - /// Returns the string representation for the given exif tag. - /// - public static string GetTagName(ExifTag tag) - { - var name = Enum.GetName(typeof(ExifTag), tag); - if (name == null) - { - return "Unknown"; - } - - return name; - } - - /// - /// Returns the string representation for the given tag id. - /// - public static string GetTagName(IFD ifd, ushort tagid) => GetTagName(GetExifTag(ifd, tagid)); - - /// - /// Returns the string representation for the given exif tag including - /// IFD section and tag id. - /// - public static string GetTagLongName(ExifTag tag) - { - var ifdname = Enum.GetName(typeof(IFD), GetTagIFD(tag)); - var name = Enum.GetName(typeof(ExifTag), tag); - if (name == null) - { - name = "Unknown"; - } - - var tagidname = GetTagID(tag).ToString(); - return ifdname + ": " + name + " (" + tagidname + ")"; - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/IFD.cs b/src/Umbraco.Core/Media/Exif/IFD.cs deleted file mode 100644 index cda3cdcb69..0000000000 --- a/src/Umbraco.Core/Media/Exif/IFD.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the IFD section containing tags. -/// -internal enum IFD -{ - Unknown = 0, - Zeroth = 100000, - EXIF = 200000, - GPS = 300000, - Interop = 400000, - First = 500000, - MakerNote = 600000, - JFIF = 700000, - JFXX = 800000, -} diff --git a/src/Umbraco.Core/Media/Exif/ImageFile.cs b/src/Umbraco.Core/Media/Exif/ImageFile.cs deleted file mode 100644 index 23ea615be9..0000000000 --- a/src/Umbraco.Core/Media/Exif/ImageFile.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System.ComponentModel; -using System.Text; -using Umbraco.Cms.Core.Media.TypeDetector; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the base class for image files. -/// -[TypeDescriptionProvider(typeof(ExifFileTypeDescriptionProvider))] -internal abstract class ImageFile -{ - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - protected ImageFile() - { - Format = ImageFileFormat.Unknown; - Properties = new ExifPropertyCollection(this); - Encoding = Encoding.Default; - } - - #endregion - - #region Properties - - /// - /// Returns the format of the . - /// - public ImageFileFormat Format { get; protected set; } - - /// - /// Gets the collection of Exif properties contained in the . - /// - public ExifPropertyCollection Properties { get; } - - /// - /// Gets or sets the embedded thumbnail image. - /// - public ImageFile? Thumbnail { get; set; } - - /// - /// Gets or sets the Exif property with the given key. - /// - /// The Exif tag associated with the Exif property. - public ExifProperty this[ExifTag key] - { - get => Properties[key]; - set => Properties[key] = value; - } - - /// - /// Gets the encoding used for text metadata when the source encoding is unknown. - /// - public Encoding Encoding { get; protected set; } - - #endregion - - #region Instance Methods - - /// - /// Saves the to the specified file. - /// - /// A string that contains the name of the file. - public virtual void Save(string filename) - { - using (var stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) - { - Save(stream); - } - } - - /// - /// Saves the to the specified stream. - /// - /// A to save image data to. - public abstract void Save(Stream stream); - - #endregion - - #region Static Methods - - /// - /// Creates an from the specified file. - /// - /// A string that contains the name of the file. - /// The created from the file. - public static ImageFile? FromFile(string filename) => FromFile(filename, Encoding.Default); - - /// - /// Creates an from the specified file. - /// - /// A string that contains the name of the file. - /// The encoding to be used for text metadata when the source encoding is unknown. - /// The created from the file. - public static ImageFile? FromFile(string filename, Encoding encoding) - { - using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return FromStream(stream, encoding); - } - } - - /// - /// Creates an from the specified data stream. - /// - /// A that contains image data. - /// The created from the file. - public static ImageFile? FromStream(Stream stream) => FromStream(stream, Encoding.Default); - - /// - /// Creates an from the specified data stream. - /// - /// A that contains image data. - /// The encoding to be used for text metadata when the source encoding is unknown. - /// The created from the file. - public static ImageFile? FromStream(Stream stream, Encoding encoding) - { - // JPEG - if (JpegDetector.IsOfType(stream)) - { - return new JPEGFile(stream, encoding); - } - - // TIFF - if (TIFFDetector.IsOfType(stream)) - { - return new TIFFFile(stream, encoding); - } - - // SVG - if (SvgDetector.IsOfType(stream)) - { - return new SvgFile(stream); - } - - // We don't know - return null; - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/ImageFileDirectory.cs b/src/Umbraco.Core/Media/Exif/ImageFileDirectory.cs deleted file mode 100644 index 299e7619f9..0000000000 --- a/src/Umbraco.Core/Media/Exif/ImageFileDirectory.cs +++ /dev/null @@ -1,100 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents an image file directory. -/// -internal class ImageFileDirectory -{ - /// - /// Initializes a new instance of the class. - /// - public ImageFileDirectory() - { - Fields = new List(); - Strips = new List(); - } - - /// - /// The fields contained in this IFD. - /// - public List Fields { get; } - - /// - /// Offset to the next IFD. - /// - public uint NextIFDOffset { get; private set; } - - /// - /// Compressed image data. - /// - public List Strips { get; } - - /// - /// Returns a initialized from the given byte data. - /// - /// The data. - /// The offset into . - /// The byte order of . - /// A initialized from the given byte data. - public static ImageFileDirectory FromBytes(byte[] data, uint offset, BitConverterEx.ByteOrder byteOrder) - { - var ifd = new ImageFileDirectory(); - var conv = new BitConverterEx(byteOrder, BitConverterEx.SystemByteOrder); - - var stripOffsets = new List(); - var stripLengths = new List(); - - // Count - var fieldcount = conv.ToUInt16(data, offset); - - // Read fields - for (uint i = 0; i < fieldcount; i++) - { - var fieldoffset = offset + 2 + (12 * i); - var field = ImageFileDirectoryEntry.FromBytes(data, fieldoffset, byteOrder); - ifd.Fields.Add(field); - - // Read strip offsets - if (field.Tag == 273) - { - var baselen = field.Data.Length / (int)field.Count; - for (uint j = 0; j < field.Count; j++) - { - var val = new byte[baselen]; - Array.Copy(field.Data, j * baselen, val, 0, baselen); - var stripOffset = field.Type == 3 ? BitConverter.ToUInt16(val, 0) : BitConverter.ToUInt32(val, 0); - stripOffsets.Add(stripOffset); - } - } - - // Read strip lengths - if (field.Tag == 279) - { - var baselen = field.Data.Length / (int)field.Count; - for (uint j = 0; j < field.Count; j++) - { - var val = new byte[baselen]; - Array.Copy(field.Data, j * baselen, val, 0, baselen); - var stripLength = field.Type == 3 ? BitConverter.ToUInt16(val, 0) : BitConverter.ToUInt32(val, 0); - stripLengths.Add(stripLength); - } - } - } - - // Save strips - if (stripOffsets.Count != stripLengths.Count) - { - throw new NotValidTIFFileException(); - } - - for (var i = 0; i < stripOffsets.Count; i++) - { - ifd.Strips.Add(new TIFFStrip(data, stripOffsets[i], stripLengths[i])); - } - - // Offset to next ifd - ifd.NextIFDOffset = conv.ToUInt32(data, offset + 2 + (12 * fieldcount)); - - return ifd; - } -} diff --git a/src/Umbraco.Core/Media/Exif/ImageFileDirectoryEntry.cs b/src/Umbraco.Core/Media/Exif/ImageFileDirectoryEntry.cs deleted file mode 100644 index a3863b6a69..0000000000 --- a/src/Umbraco.Core/Media/Exif/ImageFileDirectoryEntry.cs +++ /dev/null @@ -1,144 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents an entry in the image file directory. -/// -internal struct ImageFileDirectoryEntry -{ - /// - /// The tag that identifies the field. - /// - public ushort Tag; - - /// - /// Field type identifier. - /// - public ushort Type; - - /// - /// Count of Type. - /// - public uint Count; - - /// - /// Field data. - /// - public byte[] Data; - - /// - /// Initializes a new instance of the struct. - /// - /// The tag that identifies the field. - /// Field type identifier. - /// Count of Type. - /// Field data. - public ImageFileDirectoryEntry(ushort tag, ushort type, uint count, byte[] data) - { - Tag = tag; - Type = type; - Count = count; - Data = data; - } - - /// - /// Returns a initialized from the given byte data. - /// - /// The data. - /// The offset into . - /// The byte order of . - /// A initialized from the given byte data. - public static ImageFileDirectoryEntry FromBytes(byte[] data, uint offset, BitConverterEx.ByteOrder byteOrder) - { - // Tag ID - var tag = BitConverterEx.ToUInt16(data, offset, byteOrder, BitConverterEx.SystemByteOrder); - - // Tag Type - var type = BitConverterEx.ToUInt16(data, offset + 2, byteOrder, BitConverterEx.SystemByteOrder); - - // Count of Type - var count = BitConverterEx.ToUInt32(data, offset + 4, byteOrder, BitConverterEx.SystemByteOrder); - - // Field value or offset to field data - var value = new byte[4]; - Array.Copy(data, offset + 8, value, 0, 4); - - // Calculate the bytes we need to read - var baselength = GetBaseLength(type); - var totallength = count * baselength; - - // If field value does not fit in 4 bytes - // the value field is an offset to the actual - // field value - if (totallength > 4) - { - var dataoffset = BitConverterEx.ToUInt32(value, 0, byteOrder, BitConverterEx.SystemByteOrder); - value = new byte[totallength]; - Array.Copy(data, dataoffset, value, 0, totallength); - } - - // Reverse array order if byte orders are different - if (byteOrder != BitConverterEx.SystemByteOrder) - { - for (uint i = 0; i < count; i++) - { - var val = new byte[baselength]; - Array.Copy(value, i * baselength, val, 0, baselength); - Array.Reverse(val); - Array.Copy(val, 0, value, i * baselength, baselength); - } - } - - return new ImageFileDirectoryEntry(tag, type, count, value); - } - - /// - /// Gets the base byte length for the given type. - /// - /// Type identifier. - private static uint GetBaseLength(ushort type) - { - // BYTE and SBYTE - if (type == 1 || type == 6) - { - return 1; - } - - // ASCII and UNDEFINED - if (type == 2 || type == 7) - { - return 1; - } - - // SHORT and SSHORT - if (type == 3 || type == 8) - { - return 2; - } - - // LONG and SLONG - if (type == 4 || type == 9) - { - return 4; - } - - // RATIONAL (2xLONG) and SRATIONAL (2xSLONG) - if (type == 5 || type == 10) - { - return 8; - } - - // FLOAT - if (type == 11) - { - return 4; - } - - // DOUBLE - if (type == 12) - { - return 8; - } - - throw new ArgumentException("Unknown type identifier.", "type"); - } -} diff --git a/src/Umbraco.Core/Media/Exif/ImageFileFormat.cs b/src/Umbraco.Core/Media/Exif/ImageFileFormat.cs deleted file mode 100644 index fe30c713b2..0000000000 --- a/src/Umbraco.Core/Media/Exif/ImageFileFormat.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the format of the . -/// -internal enum ImageFileFormat -{ - /// - /// The file is not recognized. - /// - Unknown, - - /// - /// The file is a JPEG/Exif or JPEG/JFIF file. - /// - JPEG, - - /// - /// The file is a TIFF File. - /// - TIFF, - - /// - /// The file is a SVG File. - /// - SVG, -} diff --git a/src/Umbraco.Core/Media/Exif/JFIFEnums.cs b/src/Umbraco.Core/Media/Exif/JFIFEnums.cs deleted file mode 100644 index 438d7bf3d4..0000000000 --- a/src/Umbraco.Core/Media/Exif/JFIFEnums.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the units for the X and Y densities -/// for a JFIF file. -/// -internal enum JFIFDensityUnit : byte -{ - /// - /// No units, XDensity and YDensity specify the pixel aspect ratio. - /// - None = 0, - - /// - /// XDensity and YDensity are dots per inch. - /// - DotsPerInch = 1, - - /// - /// XDensity and YDensity are dots per cm. - /// - DotsPerCm = 2, -} - -/// -/// Represents the JFIF extension. -/// -internal enum JFIFExtension : byte -{ - /// - /// Thumbnail coded using JPEG. - /// - ThumbnailJPEG = 0x10, - - /// - /// Thumbnail stored using a 256-Color RGB palette. - /// - ThumbnailPaletteRGB = 0x11, - - /// - /// Thumbnail stored using 3 bytes/pixel (24-bit) RGB values. - /// - Thumbnail24BitRGB = 0x13, -} diff --git a/src/Umbraco.Core/Media/Exif/JFIFExtendedProperty.cs b/src/Umbraco.Core/Media/Exif/JFIFExtendedProperty.cs deleted file mode 100644 index 71ea89228d..0000000000 --- a/src/Umbraco.Core/Media/Exif/JFIFExtendedProperty.cs +++ /dev/null @@ -1,76 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the JFIF version as a 16 bit unsigned integer. (EXIF Specification: SHORT) -/// -internal class JFIFVersion : ExifUShort -{ - public JFIFVersion(ExifTag tag, ushort value) - : base(tag, value) - { - } - - /// - /// Gets the major version. - /// - public byte Major => (byte)(mValue >> 8); - - /// - /// Gets the minor version. - /// - public byte Minor => (byte)(mValue - ((mValue >> 8) * 256)); - - public override string ToString() => string.Format("{0}.{1:00}", Major, Minor); -} - -/// -/// Represents a JFIF thumbnail. (EXIF Specification: BYTE) -/// -internal class JFIFThumbnailProperty : ExifProperty -{ - protected JFIFThumbnail mValue; - - public JFIFThumbnailProperty(ExifTag tag, JFIFThumbnail value) - : base(tag) => - mValue = value; - - public new JFIFThumbnail Value - { - get => mValue; - set => mValue = value; - } - - protected override object _Value - { - get => Value; - set => Value = (JFIFThumbnail)value; - } - - public override ExifInterOperability Interoperability - { - get - { - if (mValue.Format == JFIFThumbnail.ImageFormat.BMP24Bit) - { - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 1, (uint)mValue.PixelData.Length, mValue.PixelData); - } - - if (mValue.Format == JFIFThumbnail.ImageFormat.BMPPalette) - { - var data = new byte[mValue.Palette.Length + mValue.PixelData.Length]; - Array.Copy(mValue.Palette, data, mValue.Palette.Length); - Array.Copy(mValue.PixelData, 0, data, mValue.Palette.Length, mValue.PixelData.Length); - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 1, (uint)data.Length, data); - } - - if (mValue.Format == JFIFThumbnail.ImageFormat.JPEG) - { - return new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 1, (uint)mValue.PixelData.Length, mValue.PixelData); - } - - throw new InvalidOperationException("Unknown thumbnail type."); - } - } - - public override string ToString() => mValue.Format.ToString(); -} diff --git a/src/Umbraco.Core/Media/Exif/JFIFThumbnail.cs b/src/Umbraco.Core/Media/Exif/JFIFThumbnail.cs deleted file mode 100644 index cafa804c3a..0000000000 --- a/src/Umbraco.Core/Media/Exif/JFIFThumbnail.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents a JFIF thumbnail. -/// -internal class JFIFThumbnail -{ - #region Public Enums - - public enum ImageFormat - { - JPEG, - BMPPalette, - BMP24Bit, - } - - #endregion - - #region Properties - - /// - /// Gets the 256 color RGB palette. - /// - public byte[] Palette { get; } - - /// - /// Gets raw image data. - /// - public byte[] PixelData { get; } - - /// - /// Gets the image format. - /// - public ImageFormat Format { get; } - - #endregion - - #region Constructors - - protected JFIFThumbnail() - { - Palette = new byte[0]; - PixelData = new byte[0]; - } - - public JFIFThumbnail(ImageFormat format, byte[] data) - : this() - { - Format = format; - PixelData = data; - } - - public JFIFThumbnail(byte[] palette, byte[] data) - : this() - { - Format = ImageFormat.BMPPalette; - Palette = palette; - PixelData = data; - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/JPEGExceptions.cs b/src/Umbraco.Core/Media/Exif/JPEGExceptions.cs index c44d6d1db0..4781415d7c 100644 --- a/src/Umbraco.Core/Media/Exif/JPEGExceptions.cs +++ b/src/Umbraco.Core/Media/Exif/JPEGExceptions.cs @@ -7,6 +7,7 @@ namespace Umbraco.Cms.Core.Media.Exif; /// /// [Serializable] +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class NotValidJPEGFileException : Exception { /// diff --git a/src/Umbraco.Core/Media/Exif/JPEGFile.cs b/src/Umbraco.Core/Media/Exif/JPEGFile.cs deleted file mode 100644 index bdf7208ea0..0000000000 --- a/src/Umbraco.Core/Media/Exif/JPEGFile.cs +++ /dev/null @@ -1,1110 +0,0 @@ -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the binary view of a JPEG compressed file. -/// -internal class JPEGFile : ImageFile -{ - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// A that contains image data. - /// The encoding to be used for text metadata when the source encoding is unknown. - protected internal JPEGFile(Stream stream, Encoding encoding) - { - Format = ImageFileFormat.JPEG; - Sections = new List(); - TrailingData = new byte[0]; - Encoding = encoding; - - stream.Seek(0, SeekOrigin.Begin); - - // Read the Start of Image (SOI) marker. SOI marker is represented - // with two bytes: 0xFF, 0xD8. - var markerbytes = new byte[2]; - if (stream.Read(markerbytes, 0, 2) != 2 || markerbytes[0] != 0xFF || markerbytes[1] != 0xD8) - { - throw new NotValidJPEGFileException(); - } - - stream.Seek(0, SeekOrigin.Begin); - - // Search and read sections until we reach the end of file. - while (stream.Position != stream.Length) - { - // Read the next section marker. Section markers are two bytes - // with values 0xFF, 0x?? where ?? must not be 0x00 or 0xFF. - if (stream.Read(markerbytes, 0, 2) != 2 || markerbytes[0] != 0xFF || markerbytes[1] == 0x00 || - markerbytes[1] == 0xFF) - { - throw new NotValidJPEGFileException(); - } - - var marker = (JPEGMarker)markerbytes[1]; - - var header = new byte[0]; - - // SOI, EOI and RST markers do not contain any header - if (marker != JPEGMarker.SOI && marker != JPEGMarker.EOI && - !(marker >= JPEGMarker.RST0 && marker <= JPEGMarker.RST7)) - { - // Length of the header including the length bytes. - // This value is a 16-bit unsigned integer - // in big endian byte-order. - var lengthbytes = new byte[2]; - if (stream.Read(lengthbytes, 0, 2) != 2) - { - throw new NotValidJPEGFileException(); - } - - long length = BitConverterEx.BigEndian.ToUInt16(lengthbytes, 0); - - // Read section header. - header = new byte[length - 2]; - var bytestoread = header.Length; - while (bytestoread > 0) - { - var count = Math.Min(bytestoread, 4 * 1024); - var bytesread = stream.Read(header, header.Length - bytestoread, count); - if (bytesread == 0) - { - throw new NotValidJPEGFileException(); - } - - bytestoread -= bytesread; - } - } - - // Start of Scan (SOS) sections and RST sections are immediately - // followed by entropy coded data. For that, we need to read until - // the next section marker once we reach a SOS or RST. - var entropydata = new byte[0]; - if (marker == JPEGMarker.SOS || (marker >= JPEGMarker.RST0 && marker <= JPEGMarker.RST7)) - { - var position = stream.Position; - - // Search for the next section marker - while (true) - { - // Search for an 0xFF indicating start of a marker - var nextbyte = 0; - do - { - nextbyte = stream.ReadByte(); - if (nextbyte == -1) - { - throw new NotValidJPEGFileException(); - } - } - while ((byte)nextbyte != 0xFF); - - // Skip filler bytes (0xFF) - do - { - nextbyte = stream.ReadByte(); - if (nextbyte == -1) - { - throw new NotValidJPEGFileException(); - } - } - while ((byte)nextbyte == 0xFF); - - // Looks like a section marker. The next byte must not be 0x00. - if ((byte)nextbyte != 0x00) - { - // We reached a section marker. Calculate the - // length of the entropy coded data. - stream.Seek(-2, SeekOrigin.Current); - var edlength = stream.Position - position; - stream.Seek(-edlength, SeekOrigin.Current); - - // Read entropy coded data - entropydata = new byte[edlength]; - var bytestoread = entropydata.Length; - while (bytestoread > 0) - { - var count = Math.Min(bytestoread, 4 * 1024); - var bytesread = stream.Read(entropydata, entropydata.Length - bytestoread, count); - if (bytesread == 0) - { - throw new NotValidJPEGFileException(); - } - - bytestoread -= bytesread; - } - - break; - } - } - } - - // Store section. - var section = new JPEGSection(marker, header, entropydata); - Sections.Add(section); - - // Some propriety formats store data past the EOI marker - if (marker == JPEGMarker.EOI) - { - var bytestoread = (int)(stream.Length - stream.Position); - TrailingData = new byte[bytestoread]; - while (bytestoread > 0) - { - var count = Math.Min(bytestoread, 4 * 1024); - var bytesread = stream.Read(TrailingData, TrailingData.Length - bytestoread, count); - if (bytesread == 0) - { - throw new NotValidJPEGFileException(); - } - - bytestoread -= bytesread; - } - } - } - - // Read metadata sections - ReadJFIFAPP0(); - ReadJFXXAPP0(); - ReadExifAPP1(); - - // Process the maker note - _makerNoteProcessed = false; - } - - #endregion - - #region Member Variables - - private JPEGSection? _jfifApp0; - private JPEGSection? _jfxxApp0; - private JPEGSection? _exifApp1; - private uint _makerNoteOffset; - private long _exifIfdFieldOffset; - private long _gpsIfdFieldOffset; - private long _interopIfdFieldOffset; - private long _firstIfdFieldOffset; - private long _thumbOffsetLocation; - private long _thumbSizeLocation; - private uint _thumbOffsetValue; - private uint _thumbSizeValue; - private readonly bool _makerNoteProcessed; - - #endregion - - #region Properties - - /// - /// Gets or sets the byte-order of the Exif properties. - /// - public BitConverterEx.ByteOrder ByteOrder { get; set; } - - /// - /// Gets or sets the sections contained in the . - /// - public List Sections { get; } - - /// - /// Gets or sets non-standard trailing data following the End of Image (EOI) marker. - /// - public byte[] TrailingData { get; } - - #endregion - - #region Instance Methods - - /// - /// Saves the JPEG/Exif image to the given stream. - /// - /// The stream of the JPEG/Exif file. - /// - /// Determines whether the maker note offset of - /// the original file will be preserved. - /// - public void Save(Stream stream, bool preserveMakerNote) - { - WriteJFIFApp0(); - WriteJFXXApp0(); - WriteExifApp1(preserveMakerNote); - - // Write sections - foreach (JPEGSection section in Sections) - { - // Section header (including length bytes and section marker) - // must not exceed 64 kB. - if (section.Header.Length + 2 + 2 > 64 * 1024) - { - throw new SectionExceeds64KBException(); - } - - // APP sections must have a header. - // Otherwise skip the entire section. - if (section.Marker >= JPEGMarker.APP0 && section.Marker <= JPEGMarker.APP15 && section.Header.Length == 0) - { - continue; - } - - // Write section marker - stream.Write(new byte[] { 0xFF, (byte)section.Marker }, 0, 2); - - // SOI, EOI and RST markers do not contain any header - if (section.Marker != JPEGMarker.SOI && section.Marker != JPEGMarker.EOI && - !(section.Marker >= JPEGMarker.RST0 && section.Marker <= JPEGMarker.RST7)) - { - // Header length including the length field itself - stream.Write(BitConverterEx.BigEndian.GetBytes((ushort)(section.Header.Length + 2)), 0, 2); - - // Write section header - if (section.Header.Length != 0) - { - stream.Write(section.Header, 0, section.Header.Length); - } - } - - // Write entropy coded data - if (section.EntropyData.Length != 0) - { - stream.Write(section.EntropyData, 0, section.EntropyData.Length); - } - } - - // Write trailing data, if any - if (TrailingData.Length != 0) - { - stream.Write(TrailingData, 0, TrailingData.Length); - } - } - - /// - /// Saves the JPEG/Exif image with the given filename. - /// - /// The path to the JPEG/Exif file. - /// - /// Determines whether the maker note offset of - /// the original file will be preserved. - /// - public void Save(string filename, bool preserveMakerNote) - { - using (var stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) - { - Save(stream, preserveMakerNote); - } - } - - /// - /// Saves the JPEG/Exif image with the given filename. - /// - /// The path to the JPEG/Exif file. - public override void Save(string filename) => Save(filename, true); - - /// - /// Saves the JPEG/Exif image to the given stream. - /// - /// The stream of the JPEG/Exif file. - public override void Save(Stream stream) => Save(stream, true); - - #endregion - - #region Private Helper Methods - - /// - /// Reads the APP0 section containing JFIF metadata. - /// - private void ReadJFIFAPP0() - { - // Find the APP0 section containing JFIF metadata - _jfifApp0 = Sections.Find(a => a.Marker == JPEGMarker.APP0 && - a.Header.Length >= 5 && - Encoding.ASCII.GetString(a.Header, 0, 5) == "JFIF\0"); - - // If there is no APP0 section, return. - if (_jfifApp0 == null) - { - return; - } - - var header = _jfifApp0.Header; - BitConverterEx jfifConv = BitConverterEx.BigEndian; - - // Version - var version = jfifConv.ToUInt16(header, 5); - Properties.Add(new JFIFVersion(ExifTag.JFIFVersion, version)); - - // Units - var unit = header[7]; - Properties.Add(new ExifEnumProperty(ExifTag.JFIFUnits, (JFIFDensityUnit)unit)); - - // X and Y densities - var xdensity = jfifConv.ToUInt16(header, 8); - Properties.Add(new ExifUShort(ExifTag.XDensity, xdensity)); - var ydensity = jfifConv.ToUInt16(header, 10); - Properties.Add(new ExifUShort(ExifTag.YDensity, ydensity)); - - // Thumbnails pixel count - var xthumbnail = header[12]; - Properties.Add(new ExifByte(ExifTag.JFIFXThumbnail, xthumbnail)); - var ythumbnail = header[13]; - Properties.Add(new ExifByte(ExifTag.JFIFYThumbnail, ythumbnail)); - - // Read JFIF thumbnail - var n = xthumbnail * ythumbnail; - var jfifThumbnail = new byte[n]; - Array.Copy(header, 14, jfifThumbnail, 0, n); - Properties.Add(new JFIFThumbnailProperty(ExifTag.JFIFThumbnail, new JFIFThumbnail(JFIFThumbnail.ImageFormat.JPEG, jfifThumbnail))); - } - - /// - /// Replaces the contents of the APP0 section with the JFIF properties. - /// - private bool WriteJFIFApp0() - { - // Which IFD sections do we have? - var ifdjfef = new List(); - foreach (ExifProperty prop in Properties) - { - if (prop.IFD == IFD.JFIF) - { - ifdjfef.Add(prop); - } - } - - if (ifdjfef.Count == 0) - { - // Nothing to write - return false; - } - - // Create a memory stream to write the APP0 section to - var ms = new MemoryStream(); - - // JFIF identifier - ms.Write(Encoding.ASCII.GetBytes("JFIF\0"), 0, 5); - - // Write tags - foreach (ExifProperty prop in ifdjfef) - { - ExifInterOperability interop = prop.Interoperability; - var data = interop.Data; - if (BitConverterEx.SystemByteOrder != BitConverterEx.ByteOrder.BigEndian && interop.TypeID == 3) - { - Array.Reverse(data); - } - - ms.Write(data, 0, data.Length); - } - - ms.Close(); - - // Return APP0 header - if (_jfifApp0 is not null) - { - _jfifApp0.Header = ms.ToArray(); - return true; - } - - return false; - } - - /// - /// Reads the APP0 section containing JFIF extension metadata. - /// - private void ReadJFXXAPP0() - { - // Find the APP0 section containing JFIF metadata - _jfxxApp0 = Sections.Find(a => a.Marker == JPEGMarker.APP0 && - a.Header.Length >= 5 && - Encoding.ASCII.GetString(a.Header, 0, 5) == "JFXX\0"); - - // If there is no APP0 section, return. - if (_jfxxApp0 == null) - { - return; - } - - var header = _jfxxApp0.Header; - - // Version - var version = (JFIFExtension)header[5]; - Properties.Add(new ExifEnumProperty(ExifTag.JFXXExtensionCode, version)); - - // Read thumbnail - if (version == JFIFExtension.ThumbnailJPEG) - { - var data = new byte[header.Length - 6]; - Array.Copy(header, 6, data, 0, data.Length); - Properties.Add(new JFIFThumbnailProperty(ExifTag.JFXXThumbnail, new JFIFThumbnail(JFIFThumbnail.ImageFormat.JPEG, data))); - } - else if (version == JFIFExtension.Thumbnail24BitRGB) - { - // Thumbnails pixel count - var xthumbnail = header[6]; - Properties.Add(new ExifByte(ExifTag.JFXXXThumbnail, xthumbnail)); - var ythumbnail = header[7]; - Properties.Add(new ExifByte(ExifTag.JFXXYThumbnail, ythumbnail)); - var data = new byte[3 * xthumbnail * ythumbnail]; - Array.Copy(header, 8, data, 0, data.Length); - Properties.Add(new JFIFThumbnailProperty(ExifTag.JFXXThumbnail, new JFIFThumbnail(JFIFThumbnail.ImageFormat.BMP24Bit, data))); - } - else if (version == JFIFExtension.ThumbnailPaletteRGB) - { - // Thumbnails pixel count - var xthumbnail = header[6]; - Properties.Add(new ExifByte(ExifTag.JFXXXThumbnail, xthumbnail)); - var ythumbnail = header[7]; - Properties.Add(new ExifByte(ExifTag.JFXXYThumbnail, ythumbnail)); - var palette = new byte[768]; - Array.Copy(header, 8, palette, 0, palette.Length); - var data = new byte[xthumbnail * ythumbnail]; - Array.Copy(header, 8 + 768, data, 0, data.Length); - Properties.Add(new JFIFThumbnailProperty(ExifTag.JFXXThumbnail, new JFIFThumbnail(palette, data))); - } - } - - /// - /// Replaces the contents of the APP0 section with the JFIF extension properties. - /// - private bool WriteJFXXApp0() - { - // Which IFD sections do we have? - var ifdjfef = new List(); - foreach (ExifProperty prop in Properties) - { - if (prop.IFD == IFD.JFXX) - { - ifdjfef.Add(prop); - } - } - - if (ifdjfef.Count == 0) - { - // Nothing to write - return false; - } - - // Create a memory stream to write the APP0 section to - var ms = new MemoryStream(); - - // JFIF identifier - ms.Write(Encoding.ASCII.GetBytes("JFXX\0"), 0, 5); - - // Write tags - foreach (ExifProperty prop in ifdjfef) - { - ExifInterOperability interop = prop.Interoperability; - var data = interop.Data; - if (BitConverterEx.SystemByteOrder != BitConverterEx.ByteOrder.BigEndian && interop.TypeID == 3) - { - Array.Reverse(data); - } - - ms.Write(data, 0, data.Length); - } - - ms.Close(); - - if (_jfxxApp0 is not null) - { - // Return APP0 header - _jfxxApp0.Header = ms.ToArray(); - return true; - } - - return false; - } - - /// - /// Reads the APP1 section containing Exif metadata. - /// - private void ReadExifAPP1() - { - // Find the APP1 section containing Exif metadata - _exifApp1 = Sections.Find(a => a.Marker == JPEGMarker.APP1 && - a.Header.Length >= 6 && - Encoding.ASCII.GetString(a.Header, 0, 6) == "Exif\0\0"); - - // If there is no APP1 section, add a new one after the last APP0 section (if any). - if (_exifApp1 == null) - { - var insertionIndex = Sections.FindLastIndex(a => a.Marker == JPEGMarker.APP0); - if (insertionIndex == -1) - { - insertionIndex = 0; - } - - insertionIndex++; - _exifApp1 = new JPEGSection(JPEGMarker.APP1); - Sections.Insert(insertionIndex, _exifApp1); - if (BitConverterEx.SystemByteOrder == BitConverterEx.ByteOrder.LittleEndian) - { - ByteOrder = BitConverterEx.ByteOrder.LittleEndian; - } - else - { - ByteOrder = BitConverterEx.ByteOrder.BigEndian; - } - - return; - } - - var header = _exifApp1.Header; - var ifdqueue = new SortedList(); - _makerNoteOffset = 0; - - // TIFF header - var tiffoffset = 6; - if (header[tiffoffset] == 0x49 && header[tiffoffset + 1] == 0x49) - { - ByteOrder = BitConverterEx.ByteOrder.LittleEndian; - } - else if (header[tiffoffset] == 0x4D && header[tiffoffset + 1] == 0x4D) - { - ByteOrder = BitConverterEx.ByteOrder.BigEndian; - } - else - { - throw new NotValidExifFileException(); - } - - // TIFF header may have a different byte order - BitConverterEx.ByteOrder tiffByteOrder = ByteOrder; - if (BitConverterEx.LittleEndian.ToUInt16(header, tiffoffset + 2) == 42) - { - tiffByteOrder = BitConverterEx.ByteOrder.LittleEndian; - } - else if (BitConverterEx.BigEndian.ToUInt16(header, tiffoffset + 2) == 42) - { - tiffByteOrder = BitConverterEx.ByteOrder.BigEndian; - } - else - { - throw new NotValidExifFileException(); - } - - // Offset to 0th IFD - var ifd0offset = (int)BitConverterEx.ToUInt32(header, tiffoffset + 4, tiffByteOrder, BitConverterEx.SystemByteOrder); - ifdqueue.Add(ifd0offset, IFD.Zeroth); - - var conv = new BitConverterEx(ByteOrder, BitConverterEx.SystemByteOrder); - var thumboffset = -1; - var thumblength = 0; - var thumbtype = -1; - - // Read IFDs - while (ifdqueue.Count != 0) - { - var ifdoffset = tiffoffset + ifdqueue.Keys[0]; - IFD currentifd = ifdqueue.Values[0]; - ifdqueue.RemoveAt(0); - - // Field count - var fieldcount = conv.ToUInt16(header, ifdoffset); - for (short i = 0; i < fieldcount; i++) - { - // Read field info - var fieldoffset = ifdoffset + 2 + (12 * i); - var tag = conv.ToUInt16(header, fieldoffset); - var type = conv.ToUInt16(header, fieldoffset + 2); - var count = conv.ToUInt32(header, fieldoffset + 4); - var value = new byte[4]; - Array.Copy(header, fieldoffset + 8, value, 0, 4); - - // Fields containing offsets to other IFDs - if (currentifd == IFD.Zeroth && tag == 0x8769) - { - var exififdpointer = (int)conv.ToUInt32(value, 0); - ifdqueue.Add(exififdpointer, IFD.EXIF); - } - else if (currentifd == IFD.Zeroth && tag == 0x8825) - { - var gpsifdpointer = (int)conv.ToUInt32(value, 0); - ifdqueue.Add(gpsifdpointer, IFD.GPS); - } - else if (currentifd == IFD.EXIF && tag == 0xa005) - { - var interopifdpointer = (int)conv.ToUInt32(value, 0); - ifdqueue.Add(interopifdpointer, IFD.Interop); - } - - // Save the offset to maker note data - if (currentifd == IFD.EXIF && tag == 37500) - { - _makerNoteOffset = conv.ToUInt32(value, 0); - } - - // Calculate the bytes we need to read - uint baselength = 0; - if (type == 1 || type == 2 || type == 7) - { - baselength = 1; - } - else if (type == 3) - { - baselength = 2; - } - else if (type == 4 || type == 9) - { - baselength = 4; - } - else if (type == 5 || type == 10) - { - baselength = 8; - } - - var totallength = count * baselength; - - // If field value does not fit in 4 bytes - // the value field is an offset to the actual - // field value - var fieldposition = 0; - if (totallength > 4) - { - fieldposition = tiffoffset + (int)conv.ToUInt32(value, 0); - value = new byte[totallength]; - Array.Copy(header, fieldposition, value, 0, totallength); - } - - // Compressed thumbnail data - if (currentifd == IFD.First && tag == 0x201) - { - thumbtype = 0; - thumboffset = (int)conv.ToUInt32(value, 0); - } - else if (currentifd == IFD.First && tag == 0x202) - { - thumblength = (int)conv.ToUInt32(value, 0); - } - - // Uncompressed thumbnail data - if (currentifd == IFD.First && tag == 0x111) - { - thumbtype = 1; - - // Offset to first strip - if (type == 3) - { - thumboffset = conv.ToUInt16(value, 0); - } - else - { - thumboffset = (int)conv.ToUInt32(value, 0); - } - } - else if (currentifd == IFD.First && tag == 0x117) - { - thumblength = 0; - for (var j = 0; j < count; j++) - { - if (type == 3) - { - thumblength += conv.ToUInt16(value, 0); - } - else - { - thumblength += (int)conv.ToUInt32(value, 0); - } - } - } - - // Create the exif property from the interop data - ExifProperty prop = ExifPropertyFactory.Get(tag, type, count, value, ByteOrder, currentifd, Encoding); - Properties.Add(prop); - } - - // 1st IFD pointer - var firstifdpointer = (int)conv.ToUInt32(header, ifdoffset + 2 + (12 * fieldcount)); - if (firstifdpointer != 0) - { - ifdqueue.Add(firstifdpointer, IFD.First); - } - - // Read thumbnail - if (thumboffset != -1 && thumblength != 0 && Thumbnail == null) - { - if (thumbtype == 0) - { - using (var ts = new MemoryStream(header, tiffoffset + thumboffset, thumblength)) - { - Thumbnail = FromStream(ts); - } - } - } - } - } - - /// - /// Replaces the contents of the APP1 section with the Exif properties. - /// - private bool WriteExifApp1(bool preserveMakerNote) - { - // Zero out IFD field offsets. We will fill those as we write the IFD sections - _exifIfdFieldOffset = 0; - _gpsIfdFieldOffset = 0; - _interopIfdFieldOffset = 0; - _firstIfdFieldOffset = 0; - - // We also do not know the location of the embedded thumbnail yet - _thumbOffsetLocation = 0; - _thumbOffsetValue = 0; - _thumbSizeLocation = 0; - _thumbSizeValue = 0; - - // Write thumbnail tags if they are missing, remove otherwise - if (Thumbnail == null) - { - Properties.Remove(ExifTag.ThumbnailJPEGInterchangeFormat); - Properties.Remove(ExifTag.ThumbnailJPEGInterchangeFormatLength); - } - else - { - if (!Properties.ContainsKey(ExifTag.ThumbnailJPEGInterchangeFormat)) - { - Properties.Add(new ExifUInt(ExifTag.ThumbnailJPEGInterchangeFormat, 0)); - } - - if (!Properties.ContainsKey(ExifTag.ThumbnailJPEGInterchangeFormatLength)) - { - Properties.Add(new ExifUInt(ExifTag.ThumbnailJPEGInterchangeFormatLength, 0)); - } - } - - // Which IFD sections do we have? - var ifdzeroth = new Dictionary(); - var ifdexif = new Dictionary(); - var ifdgps = new Dictionary(); - var ifdinterop = new Dictionary(); - var ifdfirst = new Dictionary(); - - foreach (ExifProperty prop in Properties) - { - switch (prop.IFD) - { - case IFD.Zeroth: - ifdzeroth.Add(prop.Tag, prop); - break; - case IFD.EXIF: - ifdexif.Add(prop.Tag, prop); - break; - case IFD.GPS: - ifdgps.Add(prop.Tag, prop); - break; - case IFD.Interop: - ifdinterop.Add(prop.Tag, prop); - break; - case IFD.First: - ifdfirst.Add(prop.Tag, prop); - break; - } - } - - // Add IFD pointers if they are missing - // We will write the pointer values later on - if (ifdexif.Count != 0 && !ifdzeroth.ContainsKey(ExifTag.EXIFIFDPointer)) - { - ifdzeroth.Add(ExifTag.EXIFIFDPointer, new ExifUInt(ExifTag.EXIFIFDPointer, 0)); - } - - if (ifdgps.Count != 0 && !ifdzeroth.ContainsKey(ExifTag.GPSIFDPointer)) - { - ifdzeroth.Add(ExifTag.GPSIFDPointer, new ExifUInt(ExifTag.GPSIFDPointer, 0)); - } - - if (ifdinterop.Count != 0 && !ifdexif.ContainsKey(ExifTag.InteroperabilityIFDPointer)) - { - ifdexif.Add(ExifTag.InteroperabilityIFDPointer, new ExifUInt(ExifTag.InteroperabilityIFDPointer, 0)); - } - - // Remove IFD pointers if IFD sections are missing - if (ifdexif.Count == 0 && ifdzeroth.ContainsKey(ExifTag.EXIFIFDPointer)) - { - ifdzeroth.Remove(ExifTag.EXIFIFDPointer); - } - - if (ifdgps.Count == 0 && ifdzeroth.ContainsKey(ExifTag.GPSIFDPointer)) - { - ifdzeroth.Remove(ExifTag.GPSIFDPointer); - } - - if (ifdinterop.Count == 0 && ifdexif.ContainsKey(ExifTag.InteroperabilityIFDPointer)) - { - ifdexif.Remove(ExifTag.InteroperabilityIFDPointer); - } - - if (ifdzeroth.Count == 0 && ifdgps.Count == 0 && ifdinterop.Count == 0 && ifdfirst.Count == 0 && - Thumbnail == null) - { - // Nothing to write - return false; - } - - // We will need these BitConverters to write byte-ordered data - var bceExif = new BitConverterEx(BitConverterEx.SystemByteOrder, ByteOrder); - - // Create a memory stream to write the APP1 section to - var ms = new MemoryStream(); - - // Exif identifier - ms.Write(Encoding.ASCII.GetBytes("Exif\0\0"), 0, 6); - - // TIFF header - // Byte order - var tiffoffset = ms.Position; - ms.Write(ByteOrder == BitConverterEx.ByteOrder.LittleEndian ? new byte[] { 0x49, 0x49 } : new byte[] { 0x4D, 0x4D }, 0, 2); - - // TIFF ID - ms.Write(bceExif.GetBytes((ushort)42), 0, 2); - - // Offset to 0th IFD - ms.Write(bceExif.GetBytes((uint)8), 0, 4); - - // Write IFDs - WriteIFD(ms, ifdzeroth, IFD.Zeroth, tiffoffset, preserveMakerNote); - var exififdrelativeoffset = (uint)(ms.Position - tiffoffset); - WriteIFD(ms, ifdexif, IFD.EXIF, tiffoffset, preserveMakerNote); - var gpsifdrelativeoffset = (uint)(ms.Position - tiffoffset); - WriteIFD(ms, ifdgps, IFD.GPS, tiffoffset, preserveMakerNote); - var interopifdrelativeoffset = (uint)(ms.Position - tiffoffset); - WriteIFD(ms, ifdinterop, IFD.Interop, tiffoffset, preserveMakerNote); - var firstifdrelativeoffset = (uint)(ms.Position - tiffoffset); - WriteIFD(ms, ifdfirst, IFD.First, tiffoffset, preserveMakerNote); - - // Now that we now the location of IFDs we can go back and write IFD offsets - if (_exifIfdFieldOffset != 0) - { - ms.Seek(_exifIfdFieldOffset, SeekOrigin.Begin); - ms.Write(bceExif.GetBytes(exififdrelativeoffset), 0, 4); - } - - if (_gpsIfdFieldOffset != 0) - { - ms.Seek(_gpsIfdFieldOffset, SeekOrigin.Begin); - ms.Write(bceExif.GetBytes(gpsifdrelativeoffset), 0, 4); - } - - if (_interopIfdFieldOffset != 0) - { - ms.Seek(_interopIfdFieldOffset, SeekOrigin.Begin); - ms.Write(bceExif.GetBytes(interopifdrelativeoffset), 0, 4); - } - - if (_firstIfdFieldOffset != 0) - { - ms.Seek(_firstIfdFieldOffset, SeekOrigin.Begin); - ms.Write(bceExif.GetBytes(firstifdrelativeoffset), 0, 4); - } - - // We can write thumbnail location now - if (_thumbOffsetLocation != 0) - { - ms.Seek(_thumbOffsetLocation, SeekOrigin.Begin); - ms.Write(bceExif.GetBytes(_thumbOffsetValue), 0, 4); - } - - if (_thumbSizeLocation != 0) - { - ms.Seek(_thumbSizeLocation, SeekOrigin.Begin); - ms.Write(bceExif.GetBytes(_thumbSizeValue), 0, 4); - } - - ms.Close(); - - if (_exifApp1 is not null) - { - // Return APP1 header - _exifApp1.Header = ms.ToArray(); - return true; - } - - return false; - } - - private void WriteIFD(MemoryStream stream, Dictionary ifd, IFD ifdtype, long tiffoffset, bool preserveMakerNote) - { - var conv = new BitConverterEx(BitConverterEx.SystemByteOrder, ByteOrder); - - // Create a queue of fields to write - var fieldqueue = new Queue(); - foreach (ExifProperty prop in ifd.Values) - { - if (prop.Tag != ExifTag.MakerNote) - { - fieldqueue.Enqueue(prop); - } - } - - // Push the maker note data to the end - if (ifd.ContainsKey(ExifTag.MakerNote)) - { - fieldqueue.Enqueue(ifd[ExifTag.MakerNote]); - } - - // Offset to start of field data from start of TIFF header - var dataoffset = (uint)(2 + (ifd.Count * 12) + 4 + stream.Position - tiffoffset); - var currentdataoffset = dataoffset; - var absolutedataoffset = stream.Position + (2 + (ifd.Count * 12) + 4); - - var makernotewritten = false; - - // Field count - stream.Write(conv.GetBytes((ushort)ifd.Count), 0, 2); - - // Fields - while (fieldqueue.Count != 0) - { - ExifProperty field = fieldqueue.Dequeue(); - ExifInterOperability interop = field.Interoperability; - - uint fillerbytecount = 0; - - // Try to preserve the makernote data offset - if (!makernotewritten && - !_makerNoteProcessed && - _makerNoteOffset != 0 && - ifdtype == IFD.EXIF && - field.Tag != ExifTag.MakerNote && - interop.Data.Length > 4 && - currentdataoffset + interop.Data.Length > _makerNoteOffset && - ifd.ContainsKey(ExifTag.MakerNote)) - { - // Delay writing this field until we write the creator's note data - fieldqueue.Enqueue(field); - continue; - } - - if (field.Tag == ExifTag.MakerNote) - { - makernotewritten = true; - - // We may need to write filler bytes to preserve maker note offset - if (preserveMakerNote && !_makerNoteProcessed && _makerNoteOffset > currentdataoffset) - { - fillerbytecount = _makerNoteOffset - currentdataoffset; - } - else - { - fillerbytecount = 0; - } - } - - // Tag - stream.Write(conv.GetBytes(interop.TagID), 0, 2); - - // Type - stream.Write(conv.GetBytes(interop.TypeID), 0, 2); - - // Count - stream.Write(conv.GetBytes(interop.Count), 0, 4); - - // Field data - var data = interop.Data; - if (ByteOrder != BitConverterEx.SystemByteOrder && - (interop.TypeID == 3 || interop.TypeID == 4 || interop.TypeID == 9 || - interop.TypeID == 5 || interop.TypeID == 10)) - { - var vlen = 4; - if (interop.TypeID == 3) - { - vlen = 2; - } - - var n = data.Length / vlen; - - for (var i = 0; i < n; i++) - { - Array.Reverse(data, i * vlen, vlen); - } - } - - // Fields containing offsets to other IFDs - // Just store their offsets, we will write the values later on when we know the lengths of IFDs - if (ifdtype == IFD.Zeroth && interop.TagID == 0x8769) - { - _exifIfdFieldOffset = stream.Position; - } - else if (ifdtype == IFD.Zeroth && interop.TagID == 0x8825) - { - _gpsIfdFieldOffset = stream.Position; - } - else if (ifdtype == IFD.EXIF && interop.TagID == 0xa005) - { - _interopIfdFieldOffset = stream.Position; - } - else if (ifdtype == IFD.First && interop.TagID == 0x201) - { - _thumbOffsetLocation = stream.Position; - } - else if (ifdtype == IFD.First && interop.TagID == 0x202) - { - _thumbSizeLocation = stream.Position; - } - - // Write 4 byte field value or field data - if (data.Length <= 4) - { - stream.Write(data, 0, data.Length); - for (var i = data.Length; i < 4; i++) - { - stream.WriteByte(0); - } - } - else - { - // Pointer to data area relative to TIFF header - stream.Write(conv.GetBytes(currentdataoffset + fillerbytecount), 0, 4); - - // Actual data - var currentoffset = stream.Position; - stream.Seek(absolutedataoffset, SeekOrigin.Begin); - - // Write filler bytes - for (var i = 0; i < fillerbytecount; i++) - { - stream.WriteByte(0xFF); - } - - stream.Write(data, 0, data.Length); - stream.Seek(currentoffset, SeekOrigin.Begin); - - // Increment pointers - currentdataoffset += fillerbytecount + (uint)data.Length; - absolutedataoffset += fillerbytecount + data.Length; - } - } - - // Offset to 1st IFD - // We will write zeros for now. This will be filled after we write all IFDs - if (ifdtype == IFD.Zeroth) - { - _firstIfdFieldOffset = stream.Position; - } - - stream.Write(new byte[] { 0, 0, 0, 0 }, 0, 4); - - // Seek to end of IFD - stream.Seek(absolutedataoffset, SeekOrigin.Begin); - - // Write thumbnail data - if (ifdtype == IFD.First) - { - if (Thumbnail != null) - { - var ts = new MemoryStream(); - Thumbnail.Save(ts); - ts.Close(); - var thumb = ts.ToArray(); - _thumbOffsetValue = (uint)(stream.Position - tiffoffset); - _thumbSizeValue = (uint)thumb.Length; - stream.Write(thumb, 0, thumb.Length); - ts.Dispose(); - } - else - { - _thumbOffsetValue = 0; - _thumbSizeValue = 0; - } - } - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/JPEGMarker.cs b/src/Umbraco.Core/Media/Exif/JPEGMarker.cs deleted file mode 100644 index 3912d87e82..0000000000 --- a/src/Umbraco.Core/Media/Exif/JPEGMarker.cs +++ /dev/null @@ -1,95 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents a JPEG marker byte. -/// -internal enum JPEGMarker : byte -{ - // Start Of Frame markers, non-differential, Huffman coding - SOF0 = 0xc0, - SOF1 = 0xc1, - SOF2 = 0xc2, - SOF3 = 0xc3, - - // Start Of Frame markers, differential, Huffman coding - SOF5 = 0xc5, - SOF6 = 0xc6, - SOF7 = 0xc7, - - // Start Of Frame markers, non-differential, arithmetic coding - JPG = 0xc8, - SOF9 = 0xc9, - SOF10 = 0xca, - SOF11 = 0xcb, - - // Start Of Frame markers, differential, arithmetic coding - SOF13 = 0xcd, - SOF14 = 0xce, - SOF15 = 0xcf, - - // Huffman table specification - DHT = 0xc4, - - // Arithmetic coding conditioning specification - DAC = 0xcc, - - // Restart interval termination - RST0 = 0xd0, - RST1 = 0xd1, - RST2 = 0xd2, - RST3 = 0xd3, - RST4 = 0xd4, - RST5 = 0xd5, - RST6 = 0xd6, - RST7 = 0xd7, - - // Other markers - SOI = 0xd8, - EOI = 0xd9, - SOS = 0xda, - DQT = 0xdb, - DNL = 0xdc, - DRI = 0xdd, - DHP = 0xde, - EXP = 0xdf, - - // application segments - APP0 = 0xe0, - APP1 = 0xe1, - APP2 = 0xe2, - APP3 = 0xe3, - APP4 = 0xe4, - APP5 = 0xe5, - APP6 = 0xe6, - APP7 = 0xe7, - APP8 = 0xe8, - APP9 = 0xe9, - APP10 = 0xea, - APP11 = 0xeb, - APP12 = 0xec, - APP13 = 0xed, - APP14 = 0xee, - APP15 = 0xef, - - // JPEG extensions - JPG0 = 0xf0, - JPG1 = 0xf1, - JPG2 = 0xf2, - JPG3 = 0xf3, - JPG4 = 0xf4, - JPG5 = 0xf5, - JPG6 = 0xf6, - JPG7 = 0xf7, - JPG8 = 0xf8, - JPG9 = 0xf9, - JPG10 = 0xfa, - JPG11 = 0xfb, - JP1G2 = 0xfc, - JPG13 = 0xfd, - - // Comment - COM = 0xfe, - - // Temporary - TEM = 0x01, -} diff --git a/src/Umbraco.Core/Media/Exif/JPEGSection.cs b/src/Umbraco.Core/Media/Exif/JPEGSection.cs deleted file mode 100644 index 787b04b056..0000000000 --- a/src/Umbraco.Core/Media/Exif/JPEGSection.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the memory view of a JPEG section. -/// A JPEG section is the data between markers of the JPEG file. -/// -internal class JPEGSection -{ - #region Instance Methods - - /// - /// Returns a string representation of the current section. - /// - /// A System.String that represents the current section. - public override string ToString() => string.Format("{0} => Header: {1} bytes, Entropy Data: {2} bytes", Marker, Header.Length, EntropyData.Length); - - #endregion - - #region Properties - - /// - /// The marker byte representing the section. - /// - public JPEGMarker Marker { get; } - - /// - /// Section header as a byte array. This is different from the header - /// definition in JPEG specification in that it does not include the - /// two byte section length. - /// - public byte[] Header { get; set; } - - /// - /// For the SOS and RST markers, this contains the entropy coded data. - /// - public byte[] EntropyData { get; set; } - - #endregion - - #region Constructors - - /// - /// Constructs a JPEGSection represented by the marker byte and containing - /// the given data. - /// - /// The marker byte representing the section. - /// Section data. - /// Entropy coded data. - public JPEGSection(JPEGMarker marker, byte[] data, byte[] entropydata) - { - Marker = marker; - Header = data; - EntropyData = entropydata; - } - - /// - /// Constructs a JPEGSection represented by the marker byte. - /// - /// The marker byte representing the section. - public JPEGSection(JPEGMarker marker) - : this(marker, new byte[0], new byte[0]) - { - } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/MathEx.cs b/src/Umbraco.Core/Media/Exif/MathEx.cs deleted file mode 100644 index fbf5f2dbde..0000000000 --- a/src/Umbraco.Core/Media/Exif/MathEx.cs +++ /dev/null @@ -1,1329 +0,0 @@ -using System.Globalization; -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Contains extended Math functions. -/// -internal static class MathEx -{ - /// - /// Returns the greatest common divisor of two numbers. - /// - /// First number. - /// Second number. - public static uint GCD(uint a, uint b) - { - while (b != 0) - { - var rem = a % b; - a = b; - b = rem; - } - - return a; - } - - /// - /// Returns the greatest common divisor of two numbers. - /// - /// First number. - /// Second number. - public static ulong GCD(ulong a, ulong b) - { - while (b != 0) - { - var rem = a % b; - a = b; - b = rem; - } - - return a; - } - - /// - /// Represents a generic rational number represented by 32-bit signed numerator and denominator. - /// - public struct Fraction32 : IComparable, IFormattable, IComparable, IEquatable - { - #region Constants - - private const uint MaximumIterations = 10000000; - - #endregion - - #region Member Variables - - private int mNumerator; - private int mDenominator; - - #endregion - - #region Properties - - /// - /// Gets or sets the numerator. - /// - public int Numerator - { - get => (IsNegative ? -1 : 1) * mNumerator; - set - { - if (value < 0) - { - IsNegative = true; - mNumerator = -1 * value; - } - else - { - IsNegative = false; - mNumerator = value; - } - - Reduce(ref mNumerator, ref mDenominator); - } - } - - /// - /// Gets or sets the denominator. - /// - public int Denominator - { - get => mDenominator; - set - { - mDenominator = Math.Abs(value); - Reduce(ref mNumerator, ref mDenominator); - } - } - - /// - /// Gets the error term. - /// - public double Error { get; } - - /// - /// Gets or sets a value determining id the fraction is a negative value. - /// - public bool IsNegative { get; set; } - - #endregion - - #region Predefined Values - - public static readonly Fraction32 NaN = new(0, 0); - public static readonly Fraction32 NegativeInfinity = new(-1, 0); - public static readonly Fraction32 PositiveInfinity = new(1, 0); - - #endregion - - #region Static Methods - - /// - /// Returns a value indicating whether the specified number evaluates to a value - /// that is not a number. - /// - /// A fraction. - /// true if f evaluates to Fraction.NaN; otherwise, false. - public static bool IsNan(Fraction32 f) => f.Numerator == 0 && f.Denominator == 0; - - /// - /// Returns a value indicating whether the specified number evaluates to negative - /// infinity. - /// - /// A fraction. - /// true if f evaluates to Fraction.NegativeInfinity; otherwise, false. - public static bool IsNegativeInfinity(Fraction32 f) => f.Numerator < 0 && f.Denominator == 0; - - /// - /// Returns a value indicating whether the specified number evaluates to positive - /// infinity. - /// - /// A fraction. - /// true if f evaluates to Fraction.PositiveInfinity; otherwise, false. - public static bool IsPositiveInfinity(Fraction32 f) => f.Numerator > 0 && f.Denominator == 0; - - /// - /// Returns a value indicating whether the specified number evaluates to negative - /// or positive infinity. - /// - /// A fraction. - /// true if f evaluates to Fraction.NegativeInfinity or Fraction.PositiveInfinity; otherwise, false. - public static bool IsInfinity(Fraction32 f) => f.Denominator == 0; - - /// - /// Returns the multiplicative inverse of a given value. - /// - /// A fraction. - /// Multiplicative inverse of f. - public static Fraction32 Inverse(Fraction32 f) => new(f.Denominator, f.Numerator); - - /// - /// Converts the string representation of a fraction to a fraction object. - /// - /// A string formatted as numerator/denominator - /// A fraction object converted from s. - /// s is null - /// s is not in the correct format - /// - /// s represents a number less than System.UInt32.MinValue or greater than - /// System.UInt32.MaxValue. - /// - public static Fraction32 Parse(string s) => FromString(s); - - /// - /// Converts the string representation of a fraction to a fraction object. - /// A return value indicates whether the conversion succeeded. - /// - /// A string formatted as numerator/denominator - /// true if s was converted successfully; otherwise, false. - public static bool TryParse(string s, out Fraction32 f) - { - try - { - f = Parse(s); - return true; - } - catch - { - f = new Fraction32(); - return false; - } - } - - #endregion - - #region Operators - - #region Arithmetic Operators - - // Multiplication - public static Fraction32 operator *(Fraction32 f, int n) => new(f.Numerator * n, f.Denominator * Math.Abs(n)); - - public static Fraction32 operator *(int n, Fraction32 f) => f * n; - - public static Fraction32 operator *(Fraction32 f, float n) => new((float)f * n); - - public static Fraction32 operator *(float n, Fraction32 f) => f * n; - - public static Fraction32 operator *(Fraction32 f, double n) => new((double)f * n); - - public static Fraction32 operator *(double n, Fraction32 f) => f * n; - - public static Fraction32 operator *(Fraction32 f1, Fraction32 f2) => - new(f1.Numerator * f2.Numerator, f1.Denominator * f2.Denominator); - - // Division - public static Fraction32 operator /(Fraction32 f, int n) => new(f.Numerator / n, f.Denominator / Math.Abs(n)); - - public static Fraction32 operator /(Fraction32 f, float n) => new((float)f / n); - - public static Fraction32 operator /(Fraction32 f, double n) => new((double)f / n); - - public static Fraction32 operator /(Fraction32 f1, Fraction32 f2) => f1 * Inverse(f2); - - // Addition - public static Fraction32 operator +(Fraction32 f, int n) => f + new Fraction32(n, 1); - - public static Fraction32 operator +(int n, Fraction32 f) => f + n; - - public static Fraction32 operator +(Fraction32 f, float n) => new((float)f + n); - - public static Fraction32 operator +(float n, Fraction32 f) => f + n; - - public static Fraction32 operator +(Fraction32 f, double n) => new((double)f + n); - - public static Fraction32 operator +(double n, Fraction32 f) => f + n; - - public static Fraction32 operator +(Fraction32 f1, Fraction32 f2) - { - int n1 = f1.Numerator, d1 = f1.Denominator; - int n2 = f2.Numerator, d2 = f2.Denominator; - - return new Fraction32((n1 * d2) + (n2 * d1), d1 * d2); - } - - // Subtraction - public static Fraction32 operator -(Fraction32 f, int n) => f - new Fraction32(n, 1); - - public static Fraction32 operator -(int n, Fraction32 f) => new Fraction32(n, 1) - f; - - public static Fraction32 operator -(Fraction32 f, float n) => new((float)f - n); - - public static Fraction32 operator -(float n, Fraction32 f) => new Fraction32(n) - f; - - public static Fraction32 operator -(Fraction32 f, double n) => new((double)f - n); - - public static Fraction32 operator -(double n, Fraction32 f) => new Fraction32(n) - f; - - public static Fraction32 operator -(Fraction32 f1, Fraction32 f2) - { - int n1 = f1.Numerator, d1 = f1.Denominator; - int n2 = f2.Numerator, d2 = f2.Denominator; - - return new Fraction32((n1 * d2) - (n2 * d1), d1 * d2); - } - - // Increment - public static Fraction32 operator ++(Fraction32 f) => f + new Fraction32(1, 1); - - // Decrement - public static Fraction32 operator --(Fraction32 f) => f - new Fraction32(1, 1); - - #endregion - - #region Casts To Integral Types - - public static explicit operator int(Fraction32 f) => f.Numerator / f.Denominator; - - public static explicit operator float(Fraction32 f) => f.Numerator / (float)f.Denominator; - - public static explicit operator double(Fraction32 f) => f.Numerator / (double)f.Denominator; - - #endregion - - #region Comparison Operators - - public static bool operator ==(Fraction32 f1, Fraction32 f2) => - f1.Numerator == f2.Numerator && f1.Denominator == f2.Denominator; - - public static bool operator !=(Fraction32 f1, Fraction32 f2) => - f1.Numerator != f2.Numerator || f1.Denominator != f2.Denominator; - - public static bool operator <(Fraction32 f1, Fraction32 f2) => - f1.Numerator * f2.Denominator < f2.Numerator * f1.Denominator; - - public static bool operator >(Fraction32 f1, Fraction32 f2) => - f1.Numerator * f2.Denominator > f2.Numerator * f1.Denominator; - - #endregion - - #endregion - - #region Constructors - - private Fraction32(int numerator, int denominator, double error) - { - IsNegative = false; - if (numerator < 0) - { - numerator = -numerator; - IsNegative = !IsNegative; - } - - if (denominator < 0) - { - denominator = -denominator; - IsNegative = !IsNegative; - } - - mNumerator = numerator; - mDenominator = denominator; - Error = error; - - if (mDenominator != 0) - { - Reduce(ref mNumerator, ref mDenominator); - } - } - - public Fraction32(int numerator, int denominator) - : this(numerator, denominator, 0) - { - } - - public Fraction32(int numerator) - : this(numerator, 1) - { - } - - public Fraction32(Fraction32 f) - : this(f.Numerator, f.Denominator, f.Error) - { - } - - public Fraction32(float value) - : this((double)value) - { - } - - public Fraction32(double value) - : this(FromDouble(value)) - { - } - - public Fraction32(string s) - : this(FromString(s)) - { - } - - #endregion - - #region Instance Methods - - /// - /// Sets the value of this instance to the fraction represented - /// by the given numerator and denominator. - /// - /// The new numerator. - /// The new denominator. - public void Set(int numerator, int denominator) - { - IsNegative = false; - if (numerator < 0) - { - IsNegative = !IsNegative; - numerator = -numerator; - } - - if (denominator < 0) - { - IsNegative = !IsNegative; - denominator = -denominator; - } - - mNumerator = numerator; - mDenominator = denominator; - - if (mDenominator != 0) - { - Reduce(ref mNumerator, ref mDenominator); - } - } - - /// - /// Indicates whether this instance and a specified object are equal value-wise. - /// - /// Another object to compare to. - /// - /// true if obj and this instance are the same type and represent - /// the same value; otherwise, false. - /// - public override bool Equals(object? obj) - { - if (obj == null) - { - return false; - } - - if (obj is Fraction32) - { - return Equals((Fraction32)obj); - } - - return false; - } - - /// - /// Indicates whether this instance and a specified object are equal value-wise. - /// - /// Another fraction object to compare to. - /// - /// true if obj and this instance represent the same value; - /// otherwise, false. - /// - public bool Equals(Fraction32 obj) => IsNegative == obj.IsNegative && mNumerator == obj.Numerator && - mDenominator == obj.Denominator; - - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer that is the hash code for this instance. - public override int GetHashCode() => mDenominator ^ ((IsNegative ? -1 : 1) * mNumerator); - - /// - /// Returns a string representation of the fraction. - /// - /// A numeric format string. - /// - /// An System.IFormatProvider that supplies culture-specific - /// formatting information. - /// - /// - /// The string representation of the value of this instance as - /// specified by format and provider. - /// - /// - /// format is invalid or not supported. - /// - public string ToString(string? format, IFormatProvider? formatProvider) - { - var sb = new StringBuilder(); - sb.Append(((IsNegative ? -1 : 1) * mNumerator).ToString(format, formatProvider)); - sb.Append('/'); - sb.Append(mDenominator.ToString(format, formatProvider)); - return sb.ToString(); - } - - /// - /// Returns a string representation of the fraction. - /// - /// A numeric format string. - /// - /// The string representation of the value of this instance as - /// specified by format. - /// - /// - /// format is invalid or not supported. - /// - public string ToString(string format) - { - var sb = new StringBuilder(); - sb.Append(((IsNegative ? -1 : 1) * mNumerator).ToString(format)); - sb.Append('/'); - sb.Append(mDenominator.ToString(format)); - return sb.ToString(); - } - - /// - /// Returns a string representation of the fraction. - /// - /// - /// An System.IFormatProvider that supplies culture-specific - /// formatting information. - /// - /// - /// The string representation of the value of this instance as - /// specified by provider. - /// - public string ToString(IFormatProvider formatProvider) - { - var sb = new StringBuilder(); - sb.Append(((IsNegative ? -1 : 1) * mNumerator).ToString(formatProvider)); - sb.Append('/'); - sb.Append(mDenominator.ToString(formatProvider)); - return sb.ToString(); - } - - /// - /// Returns a string representation of the fraction. - /// - /// A string formatted as numerator/denominator. - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append(((IsNegative ? -1 : 1) * mNumerator).ToString()); - sb.Append('/'); - sb.Append(mDenominator.ToString()); - return sb.ToString(); - } - - /// - /// Compares this instance to a specified object and returns an indication of - /// their relative values. - /// - /// An object to compare, or null. - /// - /// A signed number indicating the relative values of this instance and value. - /// Less than zero: This instance is less than obj. - /// Zero: This instance is equal to obj. - /// Greater than zero: This instance is greater than obj or obj is null. - /// - /// obj is not a Fraction. - public int CompareTo(object? obj) - { - if (!(obj is Fraction32)) - { - throw new ArgumentException("obj must be of type Fraction", "obj"); - } - - return CompareTo((Fraction32)obj); - } - - /// - /// Compares this instance to a specified object and returns an indication of - /// their relative values. - /// - /// An fraction to compare with this instance. - /// - /// A signed number indicating the relative values of this instance and value. - /// Less than zero: This instance is less than obj. - /// Zero: This instance is equal to obj. - /// Greater than zero: This instance is greater than obj or obj is null. - /// - public int CompareTo(Fraction32 obj) - { - if (this < obj) - { - return -1; - } - - if (this > obj) - { - return 1; - } - - return 0; - } - - #endregion - - #region Private Helper Methods - - /// - /// Converts the given floating-point number to its rational representation. - /// - /// The floating-point number to be converted. - /// The rational representation of value. - private static Fraction32 FromDouble(double value) - { - if (double.IsNaN(value)) - { - return NaN; - } - - if (double.IsNegativeInfinity(value)) - { - return NegativeInfinity; - } - - if (double.IsPositiveInfinity(value)) - { - return PositiveInfinity; - } - - var isneg = value < 0; - if (isneg) - { - value = -value; - } - - var f = value; - var forg = f; - var lnum = 0; - var lden = 1; - var num = 1; - var den = 0; - var lasterr = 1.0; - var a = 0; - var currIteration = 0; - while (true) - { - if (++currIteration > MaximumIterations) - { - break; - } - - a = (int)Math.Floor(f); - f = f - a; - if (Math.Abs(f) < double.Epsilon) - { - break; - } - - f = 1.0 / f; - if (double.IsInfinity(f)) - { - break; - } - - var cnum = (num * a) + lnum; - var cden = (den * a) + lden; - if (Math.Abs((cnum / (double)cden) - forg) < double.Epsilon) - { - break; - } - - var err = ((cnum / (double)cden) - (num / (double)den)) / (num / (double)den); - - // Are we converging? - if (err >= lasterr) - { - break; - } - - lasterr = err; - lnum = num; - lden = den; - num = cnum; - den = cden; - } - - if (den > 0) - { - lasterr = value - (num / (double)den); - } - else - { - lasterr = double.PositiveInfinity; - } - - return new Fraction32((isneg ? -1 : 1) * num, den, lasterr); - } - - /// Converts the string representation of a fraction to a Fraction type. - /// The input string formatted as numerator/denominator. - /// s is null. - /// s is not formatted as numerator/denominator. - /// - /// s represents numbers less than System.Int32.MinValue or greater than - /// System.Int32.MaxValue. - /// - private static Fraction32 FromString(string s) - { - if (s == null) - { - throw new ArgumentNullException("s"); - } - - var sa = s.Split(Constants.CharArrays.ForwardSlash); - var numerator = 1; - var denominator = 1; - - if (sa.Length == 1) - { - // Try to parse as int - if (int.TryParse(sa[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out numerator)) - { - denominator = 1; - } - else - { - // Parse as double - var dval = double.Parse(sa[0]); - return FromDouble(dval); - } - } - else if (sa.Length == 2) - { - numerator = int.Parse(sa[0], CultureInfo.InvariantCulture); - denominator = int.Parse(sa[1], CultureInfo.InvariantCulture); - } - else - { - throw new FormatException("The input string must be formatted as n/d where n and d are integers"); - } - - return new Fraction32(numerator, denominator); - } - - /// - /// Reduces the given numerator and denominator by dividing with their - /// greatest common divisor. - /// - /// numerator to be reduced. - /// denominator to be reduced. - private static void Reduce(ref int numerator, ref int denominator) - { - var gcd = GCD((uint)numerator, (uint)denominator); - if (gcd == 0) - { - gcd = 1; - } - - numerator = numerator / (int)gcd; - denominator = denominator / (int)gcd; - } - - #endregion - } - - /// - /// Represents a generic rational number represented by 32-bit unsigned numerator and denominator. - /// - public struct UFraction32 : IComparable, IFormattable, IComparable, IEquatable - { - #region Constants - - private const uint MaximumIterations = 10000000; - - #endregion - - #region Member Variables - - private uint mNumerator; - private uint mDenominator; - - #endregion - - #region Properties - - /// - /// Gets or sets the numerator. - /// - public uint Numerator - { - get => mNumerator; - set - { - mNumerator = value; - Reduce(ref mNumerator, ref mDenominator); - } - } - - /// - /// Gets or sets the denominator. - /// - public uint Denominator - { - get => mDenominator; - set - { - mDenominator = value; - Reduce(ref mNumerator, ref mDenominator); - } - } - - /// - /// Gets the error term. - /// - public double Error { get; } - - #endregion - - #region Predefined Values - - public static readonly UFraction32 NaN = new(0, 0); - public static readonly UFraction32 Infinity = new(1, 0); - - #endregion - - #region Static Methods - - /// - /// Returns a value indicating whether the specified number evaluates to a value - /// that is not a number. - /// - /// A fraction. - /// true if f evaluates to Fraction.NaN; otherwise, false. - public static bool IsNan(UFraction32 f) => f.Numerator == 0 && f.Denominator == 0; - - /// - /// Returns a value indicating whether the specified number evaluates to infinity. - /// - /// A fraction. - /// true if f evaluates to Fraction.Infinity; otherwise, false. - public static bool IsInfinity(UFraction32 f) => f.Denominator == 0; - - /// - /// Converts the string representation of a fraction to a fraction object. - /// - /// A string formatted as numerator/denominator - /// A fraction object converted from s. - /// s is null - /// s is not in the correct format - /// - /// s represents a number less than System.UInt32.MinValue or greater than - /// System.UInt32.MaxValue. - /// - public static UFraction32 Parse(string s) => FromString(s); - - /// - /// Converts the string representation of a fraction to a fraction object. - /// A return value indicates whether the conversion succeeded. - /// - /// A string formatted as numerator/denominator - /// true if s was converted successfully; otherwise, false. - public static bool TryParse(string s, out UFraction32 f) - { - try - { - f = Parse(s); - return true; - } - catch - { - f = new UFraction32(); - return false; - } - } - - #endregion - - #region Operators - - #region Arithmetic Operators - - // Multiplication - public static UFraction32 operator *(UFraction32 f, uint n) => new(f.Numerator * n, f.Denominator * n); - - public static UFraction32 operator *(uint n, UFraction32 f) => f * n; - - public static UFraction32 operator *(UFraction32 f, float n) => new((float)f * n); - - public static UFraction32 operator *(float n, UFraction32 f) => f * n; - - public static UFraction32 operator *(UFraction32 f, double n) => new((double)f * n); - - public static UFraction32 operator *(double n, UFraction32 f) => f * n; - - public static UFraction32 operator *(UFraction32 f1, UFraction32 f2) => - new(f1.Numerator * f2.Numerator, f1.Denominator * f2.Denominator); - - // Division - public static UFraction32 operator /(UFraction32 f, uint n) => new(f.Numerator / n, f.Denominator / n); - - public static UFraction32 operator /(UFraction32 f, float n) => new((float)f / n); - - public static UFraction32 operator /(UFraction32 f, double n) => new((double)f / n); - - public static UFraction32 operator /(UFraction32 f1, UFraction32 f2) => f1 * Inverse(f2); - - // Addition - public static UFraction32 operator +(UFraction32 f, uint n) => f + new UFraction32(n, 1); - - public static UFraction32 operator +(uint n, UFraction32 f) => f + n; - - public static UFraction32 operator +(UFraction32 f, float n) => new((float)f + n); - - public static UFraction32 operator +(float n, UFraction32 f) => f + n; - - public static UFraction32 operator +(UFraction32 f, double n) => new((double)f + n); - - public static UFraction32 operator +(double n, UFraction32 f) => f + n; - - public static UFraction32 operator +(UFraction32 f1, UFraction32 f2) - { - uint n1 = f1.Numerator, d1 = f1.Denominator; - uint n2 = f2.Numerator, d2 = f2.Denominator; - - return new UFraction32((n1 * d2) + (n2 * d1), d1 * d2); - } - - // Subtraction - public static UFraction32 operator -(UFraction32 f, uint n) => f - new UFraction32(n, 1); - - public static UFraction32 operator -(uint n, UFraction32 f) => new UFraction32(n, 1) - f; - - public static UFraction32 operator -(UFraction32 f, float n) => new((float)f - n); - - public static UFraction32 operator -(float n, UFraction32 f) => new UFraction32(n) - f; - - public static UFraction32 operator -(UFraction32 f, double n) => new((double)f - n); - - public static UFraction32 operator -(double n, UFraction32 f) => new UFraction32(n) - f; - - public static UFraction32 operator -(UFraction32 f1, UFraction32 f2) - { - uint n1 = f1.Numerator, d1 = f1.Denominator; - uint n2 = f2.Numerator, d2 = f2.Denominator; - - return new UFraction32((n1 * d2) - (n2 * d1), d1 * d2); - } - - // Increment - public static UFraction32 operator ++(UFraction32 f) => f + new UFraction32(1, 1); - - // Decrement - public static UFraction32 operator --(UFraction32 f) => f - new UFraction32(1, 1); - - #endregion - - #region Casts To Integral Types - - public static explicit operator uint(UFraction32 f) => f.Numerator / f.Denominator; - - public static explicit operator float(UFraction32 f) => f.Numerator / (float)f.Denominator; - public static explicit operator double(UFraction32 f) => f.Numerator / (double)f.Denominator; - - #endregion - - #region Comparison Operators - - public static bool operator ==(UFraction32 f1, UFraction32 f2) => - f1.Numerator == f2.Numerator && f1.Denominator == f2.Denominator; - - public static bool operator !=(UFraction32 f1, UFraction32 f2) => - f1.Numerator != f2.Numerator || f1.Denominator != f2.Denominator; - - public static bool operator <(UFraction32 f1, UFraction32 f2) => - f1.Numerator * f2.Denominator < f2.Numerator * f1.Denominator; - - public static bool operator >(UFraction32 f1, UFraction32 f2) => - f1.Numerator * f2.Denominator > f2.Numerator * f1.Denominator; - - #endregion - - #endregion - - #region Constructors - - public UFraction32(uint numerator, uint denominator, double error) - { - mNumerator = numerator; - mDenominator = denominator; - Error = error; - - if (mDenominator != 0) - { - Reduce(ref mNumerator, ref mDenominator); - } - } - - public UFraction32(uint numerator, uint denominator) - : this(numerator, denominator, 0) - { - } - - public UFraction32(uint numerator) - : this(numerator, 1) - { - } - - public UFraction32(UFraction32 f) - : this(f.Numerator, f.Denominator, f.Error) - { - } - - public UFraction32(float value) - : this((double)value) - { - } - - public UFraction32(double value) - : this(FromDouble(value)) - { - } - - public UFraction32(string s) - : this(FromString(s)) - { - } - - #endregion - - #region Instance Methods - - /// - /// Sets the value of this instance to the fraction represented - /// by the given numerator and denominator. - /// - /// The new numerator. - /// The new denominator. - public void Set(uint numerator, uint denominator) - { - mNumerator = numerator; - mDenominator = denominator; - - if (mDenominator != 0) - { - Reduce(ref mNumerator, ref mDenominator); - } - } - - /// - /// Returns the multiplicative inverse of a given value. - /// - /// A fraction. - /// Multiplicative inverse of f. - public static UFraction32 Inverse(UFraction32 f) => new(f.Denominator, f.Numerator); - - /// - /// Indicates whether this instance and a specified object are equal value-wise. - /// - /// Another object to compare to. - /// - /// true if obj and this instance are the same type and represent - /// the same value; otherwise, false. - /// - public override bool Equals(object? obj) - { - if (obj == null) - { - return false; - } - - if (obj is UFraction32) - { - return Equals((UFraction32)obj); - } - - return false; - } - - /// - /// Indicates whether this instance and a specified object are equal value-wise. - /// - /// Another fraction object to compare to. - /// - /// true if obj and this instance represent the same value; - /// otherwise, false. - /// - public bool Equals(UFraction32 obj) => mNumerator == obj.Numerator && mDenominator == obj.Denominator; - - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer that is the hash code for this instance. - public override int GetHashCode() => (int)mDenominator ^ (int)mNumerator; - - /// - /// Returns a string representation of the fraction. - /// - /// A numeric format string. - /// - /// An System.IFormatProvider that supplies culture-specific - /// formatting information. - /// - /// - /// The string representation of the value of this instance as - /// specified by format and provider. - /// - /// - /// format is invalid or not supported. - /// - public string ToString(string? format, IFormatProvider? formatProvider) - { - var sb = new StringBuilder(); - sb.Append(mNumerator.ToString(format, formatProvider)); - sb.Append('/'); - sb.Append(mDenominator.ToString(format, formatProvider)); - return sb.ToString(); - } - - /// - /// Returns a string representation of the fraction. - /// - /// A numeric format string. - /// - /// The string representation of the value of this instance as - /// specified by format. - /// - /// - /// format is invalid or not supported. - /// - public string ToString(string format) - { - var sb = new StringBuilder(); - sb.Append(mNumerator.ToString(format)); - sb.Append('/'); - sb.Append(mDenominator.ToString(format)); - return sb.ToString(); - } - - /// - /// Returns a string representation of the fraction. - /// - /// - /// An System.IFormatProvider that supplies culture-specific - /// formatting information. - /// - /// - /// The string representation of the value of this instance as - /// specified by provider. - /// - public string ToString(IFormatProvider formatProvider) - { - var sb = new StringBuilder(); - sb.Append(mNumerator.ToString(formatProvider)); - sb.Append('/'); - sb.Append(mDenominator.ToString(formatProvider)); - return sb.ToString(); - } - - /// - /// Returns a string representation of the fraction. - /// - /// A string formatted as numerator/denominator. - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append(mNumerator.ToString()); - sb.Append('/'); - sb.Append(mDenominator.ToString()); - return sb.ToString(); - } - - /// - /// Compares this instance to a specified object and returns an indication of - /// their relative values. - /// - /// An object to compare, or null. - /// - /// A signed number indicating the relative values of this instance and value. - /// Less than zero: This instance is less than obj. - /// Zero: This instance is equal to obj. - /// Greater than zero: This instance is greater than obj or obj is null. - /// - /// obj is not a Fraction. - public int CompareTo(object? obj) - { - if (!(obj is UFraction32)) - { - throw new ArgumentException("obj must be of type UFraction32", "obj"); - } - - return CompareTo((UFraction32)obj); - } - - /// - /// Compares this instance to a specified object and returns an indication of - /// their relative values. - /// - /// An fraction to compare with this instance. - /// - /// A signed number indicating the relative values of this instance and value. - /// Less than zero: This instance is less than obj. - /// Zero: This instance is equal to obj. - /// Greater than zero: This instance is greater than obj or obj is null. - /// - public int CompareTo(UFraction32 obj) - { - if (this < obj) - { - return -1; - } - - if (this > obj) - { - return 1; - } - - return 0; - } - - #endregion - - #region Private Helper Methods - - /// - /// Converts the given floating-point number to its rational representation. - /// - /// The floating-point number to be converted. - /// The rational representation of value. - private static UFraction32 FromDouble(double value) - { - if (value < 0) - { - throw new ArgumentException("value cannot be negative.", "value"); - } - - if (double.IsNaN(value)) - { - return NaN; - } - - if (double.IsInfinity(value)) - { - return Infinity; - } - - var f = value; - var forg = f; - uint lnum = 0; - uint lden = 1; - uint num = 1; - uint den = 0; - var lasterr = 1.0; - uint a = 0; - var currIteration = 0; - while (true) - { - if (++currIteration > MaximumIterations) - { - break; - } - - a = (uint)Math.Floor(f); - f = f - a; - if (Math.Abs(f) < double.Epsilon) - { - break; - } - - f = 1.0 / f; - if (double.IsInfinity(f)) - { - break; - } - - var cnum = (num * a) + lnum; - var cden = (den * a) + lden; - if (Math.Abs((cnum / (double)cden) - forg) < double.Epsilon) - { - break; - } - - var err = ((cnum / (double)cden) - (num / (double)den)) / (num / (double)den); - - // Are we converging? - if (err >= lasterr) - { - break; - } - - lasterr = err; - lnum = num; - lden = den; - num = cnum; - den = cden; - } - - var fnum = (num * a) + lnum; - var fden = (den * a) + lden; - - if (fden > 0) - { - lasterr = value - (fnum / (double)fden); - } - else - { - lasterr = double.PositiveInfinity; - } - - return new UFraction32(fnum, fden, lasterr); - } - - /// Converts the string representation of a fraction to a Fraction type. - /// The input string formatted as numerator/denominator. - /// s is null. - /// s is not formatted as numerator/denominator. - /// - /// s represents numbers less than System.UInt32.MinValue or greater than - /// System.UInt32.MaxValue. - /// - private static UFraction32 FromString(string s) - { - if (s == null) - { - throw new ArgumentNullException("s"); - } - - var sa = s.Split(Constants.CharArrays.ForwardSlash); - uint numerator = 1; - uint denominator = 1; - - if (sa.Length == 1) - { - // Try to parse as uint - if (uint.TryParse(sa[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out numerator)) - { - denominator = 1; - } - else - { - // Parse as double - var dval = double.Parse(sa[0]); - return FromDouble(dval); - } - } - else if (sa.Length == 2) - { - numerator = uint.Parse(sa[0], CultureInfo.InvariantCulture); - denominator = uint.Parse(sa[1], CultureInfo.InvariantCulture); - } - else - { - throw new FormatException("The input string must be formatted as n/d where n and d are integers"); - } - - return new UFraction32(numerator, denominator); - } - - /// - /// Reduces the given numerator and denominator by dividing with their - /// greatest common divisor. - /// - /// numerator to be reduced. - /// denominator to be reduced. - private static void Reduce(ref uint numerator, ref uint denominator) - { - var gcd = GCD(numerator, denominator); - numerator = numerator / gcd; - denominator = denominator / gcd; - } - - #endregion - } -} diff --git a/src/Umbraco.Core/Media/Exif/SvgFile.cs b/src/Umbraco.Core/Media/Exif/SvgFile.cs deleted file mode 100644 index 08326e634c..0000000000 --- a/src/Umbraco.Core/Media/Exif/SvgFile.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Globalization; -using System.Xml.Linq; - -namespace Umbraco.Cms.Core.Media.Exif; - -internal class SvgFile : ImageFile -{ - public SvgFile(Stream fileStream) - { - fileStream.Position = 0; - - var document = - XDocument.Load(fileStream); // if it throws an exception the ugly try catch in MediaFileSystem will catch it - - var width = document.Root?.Attributes().Where(x => x.Name == "width").Select(x => x.Value).FirstOrDefault(); - var height = document.Root?.Attributes().Where(x => x.Name == "height").Select(x => x.Value).FirstOrDefault(); - - Properties.Add(new ExifSInt( - ExifTag.PixelYDimension, - height == null ? Constants.Conventions.Media.DefaultSize : int.Parse(height, CultureInfo.InvariantCulture))); - Properties.Add(new ExifSInt( - ExifTag.PixelXDimension, - width == null ? Constants.Conventions.Media.DefaultSize : int.Parse(width, CultureInfo.InvariantCulture))); - - Format = ImageFileFormat.SVG; - } - - public override void Save(Stream stream) - { - } -} diff --git a/src/Umbraco.Core/Media/Exif/TIFFFile.cs b/src/Umbraco.Core/Media/Exif/TIFFFile.cs deleted file mode 100644 index 2ae27c46dc..0000000000 --- a/src/Umbraco.Core/Media/Exif/TIFFFile.cs +++ /dev/null @@ -1,186 +0,0 @@ -using System.Text; - -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents the binary view of a TIFF file. -/// -internal class TIFFFile : ImageFile -{ - #region Constructor - - /// - /// Initializes a new instance of the class from the - /// specified data stream. - /// - /// A that contains image data. - /// The encoding to be used for text metadata when the source encoding is unknown. - protected internal TIFFFile(Stream stream, Encoding encoding) - { - Format = ImageFileFormat.TIFF; - IFDs = new List(); - Encoding = encoding; - - // Read the entire stream - var data = Utility.GetStreamBytes(stream); - - // Read the TIFF header - TIFFHeader = TIFFHeader.FromBytes(data, 0); - var nextIFDOffset = TIFFHeader.IFDOffset; - if (nextIFDOffset == 0) - { - throw new NotValidTIFFileException("The first IFD offset is zero."); - } - - // Read IFDs in order - while (nextIFDOffset != 0) - { - var ifd = ImageFileDirectory.FromBytes(data, nextIFDOffset, TIFFHeader.ByteOrder); - nextIFDOffset = ifd.NextIFDOffset; - IFDs.Add(ifd); - } - - // Process IFDs - // TODO: Add support for multiple frames - foreach (ImageFileDirectoryEntry field in IFDs[0].Fields) - { - Properties.Add(ExifPropertyFactory.Get(field.Tag, field.Type, field.Count, field.Data, BitConverterEx.SystemByteOrder, IFD.Zeroth, Encoding)); - } - } - - #endregion - - #region Properties - - /// - /// Gets the TIFF header. - /// - public TIFFHeader TIFFHeader { get; } - - #endregion - - #region Instance Methods - - /// - /// Saves the to the given stream. - /// - /// The data stream used to save the image. - public override void Save(Stream stream) - { - BitConverterEx conv = BitConverterEx.SystemEndian; - - // Write TIFF header - uint ifdoffset = 8; - - // Byte order - stream.Write( - BitConverterEx.SystemByteOrder == BitConverterEx.ByteOrder.LittleEndian - ? new byte[] { 0x49, 0x49 } - : new byte[] { 0x4D, 0x4D }, - 0, - 2); - - // TIFF ID - stream.Write(conv.GetBytes((ushort)42), 0, 2); - - // Offset to 0th IFD, will be corrected below - stream.Write(conv.GetBytes(ifdoffset), 0, 4); - - // Write IFD sections - for (var i = 0; i < IFDs.Count; i++) - { - ImageFileDirectory ifd = IFDs[i]; - - // Save the location of IFD offset - var ifdLocation = stream.Position - 4; - - // Write strips first - var stripOffsets = new byte[4 * ifd.Strips.Count]; - var stripLengths = new byte[4 * ifd.Strips.Count]; - var stripOffset = ifdoffset; - for (var j = 0; j < ifd.Strips.Count; j++) - { - var stripData = ifd.Strips[j].Data; - var oBytes = BitConverter.GetBytes(stripOffset); - var lBytes = BitConverter.GetBytes((uint)stripData.Length); - Array.Copy(oBytes, 0, stripOffsets, 4 * j, 4); - Array.Copy(lBytes, 0, stripLengths, 4 * j, 4); - stream.Write(stripData, 0, stripData.Length); - stripOffset += (uint)stripData.Length; - } - - // Remove old strip tags - for (var j = ifd.Fields.Count - 1; j > 0; j--) - { - var tag = ifd.Fields[j].Tag; - if (tag == 273 || tag == 279) - { - ifd.Fields.RemoveAt(j); - } - } - - // Write new strip tags - ifd.Fields.Add(new ImageFileDirectoryEntry(273, 4, (uint)ifd.Strips.Count, stripOffsets)); - ifd.Fields.Add(new ImageFileDirectoryEntry(279, 4, (uint)ifd.Strips.Count, stripLengths)); - - // Write fields after strips - ifdoffset = stripOffset; - - // Correct IFD offset - var currentLocation = stream.Position; - stream.Seek(ifdLocation, SeekOrigin.Begin); - stream.Write(conv.GetBytes(ifdoffset), 0, 4); - stream.Seek(currentLocation, SeekOrigin.Begin); - - // Offset to field data - var dataOffset = ifdoffset + 2 + ((uint)ifd.Fields.Count * 12) + 4; - - // Field count - stream.Write(conv.GetBytes((ushort)ifd.Fields.Count), 0, 2); - - // Fields - foreach (ImageFileDirectoryEntry field in ifd.Fields) - { - // Tag - stream.Write(conv.GetBytes(field.Tag), 0, 2); - - // Type - stream.Write(conv.GetBytes(field.Type), 0, 2); - - // Count - stream.Write(conv.GetBytes(field.Count), 0, 4); - - // Field data - var data = field.Data; - if (data.Length <= 4) - { - stream.Write(data, 0, data.Length); - for (var j = data.Length; j < 4; j++) - { - stream.WriteByte(0); - } - } - else - { - stream.Write(conv.GetBytes(dataOffset), 0, 4); - var currentOffset = stream.Position; - stream.Seek(dataOffset, SeekOrigin.Begin); - stream.Write(data, 0, data.Length); - dataOffset += (uint)data.Length; - stream.Seek(currentOffset, SeekOrigin.Begin); - } - } - - // Offset to next IFD - ifdoffset = dataOffset; - stream.Write(conv.GetBytes(i == IFDs.Count - 1 ? 0 : ifdoffset), 0, 4); - } - } - - /// - /// Gets the image file directories. - /// - public List IFDs { get; } - - #endregion -} diff --git a/src/Umbraco.Core/Media/Exif/TIFFHeader.cs b/src/Umbraco.Core/Media/Exif/TIFFHeader.cs deleted file mode 100644 index 54a79d90b4..0000000000 --- a/src/Umbraco.Core/Media/Exif/TIFFHeader.cs +++ /dev/null @@ -1,98 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents a TIFF Header. -/// -internal struct TIFFHeader -{ - /// - /// The byte order of the image file. - /// - public BitConverterEx.ByteOrder ByteOrder; - - /// - /// TIFF ID. This value should always be 42. - /// - public byte ID; - - /// - /// The offset to the first IFD section from the - /// start of the TIFF header. - /// - public uint IFDOffset; - - /// - /// The byte order of the TIFF header itself. - /// - public BitConverterEx.ByteOrder TIFFHeaderByteOrder; - - /// - /// Initializes a new instance of the struct. - /// - /// The byte order. - /// The TIFF ID. This value should always be 42. - /// - /// The offset to the first IFD section from the - /// start of the TIFF header. - /// - /// The byte order of the TIFF header itself. - public TIFFHeader(BitConverterEx.ByteOrder byteOrder, byte id, uint ifdOffset, BitConverterEx.ByteOrder headerByteOrder) - { - if (id != 42) - { - throw new NotValidTIFFHeader(); - } - - ByteOrder = byteOrder; - ID = id; - IFDOffset = ifdOffset; - TIFFHeaderByteOrder = headerByteOrder; - } - - /// - /// Returns a initialized from the given byte data. - /// - /// The data. - /// The offset into . - /// A initialized from the given byte data. - public static TIFFHeader FromBytes(byte[] data, int offset) - { - var header = default(TIFFHeader); - - // TIFF header - if (data[offset] == 0x49 && data[offset + 1] == 0x49) - { - header.ByteOrder = BitConverterEx.ByteOrder.LittleEndian; - } - else if (data[offset] == 0x4D && data[offset + 1] == 0x4D) - { - header.ByteOrder = BitConverterEx.ByteOrder.BigEndian; - } - else - { - throw new NotValidTIFFHeader(); - } - - // TIFF header may have a different byte order - if (BitConverterEx.LittleEndian.ToUInt16(data, offset + 2) == 42) - { - header.TIFFHeaderByteOrder = BitConverterEx.ByteOrder.LittleEndian; - } - else if (BitConverterEx.BigEndian.ToUInt16(data, offset + 2) == 42) - { - header.TIFFHeaderByteOrder = BitConverterEx.ByteOrder.BigEndian; - } - else - { - throw new NotValidTIFFHeader(); - } - - header.ID = 42; - - // IFD offset - header.IFDOffset = - BitConverterEx.ToUInt32(data, offset + 4, header.TIFFHeaderByteOrder, BitConverterEx.SystemByteOrder); - - return header; - } -} diff --git a/src/Umbraco.Core/Media/Exif/TIFFStrip.cs b/src/Umbraco.Core/Media/Exif/TIFFStrip.cs deleted file mode 100644 index 8bf91abde6..0000000000 --- a/src/Umbraco.Core/Media/Exif/TIFFStrip.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Represents a strip of compressed image data in a TIFF file. -/// -internal class TIFFStrip -{ - /// - /// Initializes a new instance of the class. - /// - /// The byte array to copy strip from. - /// The offset to the beginning of strip. - /// The length of strip. - public TIFFStrip(byte[] data, uint offset, uint length) - { - Data = new byte[length]; - Array.Copy(data, offset, Data, 0, length); - } - - /// - /// Compressed image data contained in this strip. - /// - public byte[] Data { get; } -} diff --git a/src/Umbraco.Core/Media/Exif/Utility.cs b/src/Umbraco.Core/Media/Exif/Utility.cs deleted file mode 100644 index 1ce1b1cdc7..0000000000 --- a/src/Umbraco.Core/Media/Exif/Utility.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Umbraco.Cms.Core.Media.Exif; - -/// -/// Contains utility functions. -/// -internal class Utility -{ - /// - /// Reads the entire stream and returns its contents as a byte array. - /// - /// The to read. - /// Contents of the as a byte array. - public static byte[] GetStreamBytes(Stream stream) - { - using (var mem = new MemoryStream()) - { - stream.Seek(0, SeekOrigin.Begin); - - var b = new byte[32768]; - int r; - while ((r = stream.Read(b, 0, b.Length)) > 0) - { - mem.Write(b, 0, r); - } - - return mem.ToArray(); - } - } -} diff --git a/src/Umbraco.Examine.Lucene/CompatibilitySuppressions.xml b/src/Umbraco.Examine.Lucene/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Examine.Lucene/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Infrastructure/CompatibilitySuppressions.xml b/src/Umbraco.Infrastructure/CompatibilitySuppressions.xml index 7baad05aa0..2095a0c798 100644 --- a/src/Umbraco.Infrastructure/CompatibilitySuppressions.xml +++ b/src/Umbraco.Infrastructure/CompatibilitySuppressions.xml @@ -1,7 +1,17 @@  - PKV006 - net6.0 + CP0006 + M:Umbraco.Cms.Core.Deploy.IGridCellValueConnector.GetValue(Umbraco.Cms.Core.Models.GridValue.GridControl,System.Collections.Generic.ICollection{Umbraco.Cms.Core.Deploy.ArtifactDependency},Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Infrastructure.dll + lib/net7.0/Umbraco.Infrastructure.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Deploy.IGridCellValueConnector.SetValue(Umbraco.Cms.Core.Models.GridValue.GridControl,Umbraco.Cms.Core.Deploy.IContextCache) + lib/net7.0/Umbraco.Infrastructure.dll + lib/net7.0/Umbraco.Infrastructure.dll + true \ No newline at end of file diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index 737cd5613b..a77b00814c 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -296,18 +296,7 @@ public static partial class UmbracoBuilderExtensions private static IUmbracoBuilder AddPreValueMigrators(this IUmbracoBuilder builder) { - builder.WithCollectionBuilder() - .Append() - .Append() - .Append() - .Append() - .Append() - .Append() - .Append() - .Append() - .Append() - .Append() - .Append(); + builder.WithCollectionBuilder(); return builder; } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index c80d70fa1f..750c65c21a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -1,25 +1,7 @@ -using System.Diagnostics.CodeAnalysis; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration; -using Umbraco.Cms.Core.Semver; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.Common; using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_0_0; using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_2_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_1; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_1_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_10_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_15_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_17_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_6_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_7_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_9_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_1_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_2_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_3_0; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_4_0; -using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade; @@ -29,10 +11,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade; /// public class UmbracoPlan : MigrationPlan { - private const string InitPrefix = "{init-"; - private const string InitSuffix = "}"; - private readonly IUmbracoVersion _umbracoVersion; - /// /// Initializes a new instance of the class. /// @@ -40,7 +18,6 @@ public class UmbracoPlan : MigrationPlan public UmbracoPlan(IUmbracoVersion umbracoVersion) : base(Constants.Conventions.Migrations.UmbracoUpgradePlanName) { - _umbracoVersion = umbracoVersion; DefinePlan(); } @@ -57,74 +34,9 @@ public class UmbracoPlan : MigrationPlan /// upgrades (from a tool old version, or going back in time, etc). /// /// - public override string InitialState - { - get - { - SemVersion currentVersion = _umbracoVersion.SemanticVersion; + public override string InitialState => "{DED98755-4059-41BB-ADBD-3FEAB12D1D7B}"; - // only from 8.0.0 and above - var minVersion = new SemVersion(8); - if (currentVersion < minVersion) - { - throw new InvalidOperationException( - $"Version {currentVersion} cannot be migrated to {_umbracoVersion.SemanticVersion}." - + $" Please upgrade first to at least {minVersion}."); - } - // Force versions between 7.14.*-7.15.* into into 7.14 initial state. Because there is no db-changes, - // and we don't want users to workaround my putting in version 7.14.0 them self. - if (minVersion <= currentVersion && currentVersion < new SemVersion(7, 16)) - { - return GetInitState(minVersion); - } - - // initial state is eg "{init-7.14.0}" - return GetInitState(currentVersion); - } - } - - /// - public override void ThrowOnUnknownInitialState(string state) - { - if (TryGetInitStateVersion(state, out var initVersion)) - { - throw new InvalidOperationException( - $"Version {_umbracoVersion.SemanticVersion} does not support migrating from {initVersion}." - + $" Please verify which versions support migrating from {initVersion}."); - } - - base.ThrowOnUnknownInitialState(state); - } - - /// - /// Gets the initial state corresponding to a version. - /// - /// The version. - /// - /// The initial state. - /// - private static string GetInitState(SemVersion version) => InitPrefix + version + InitSuffix; - - /// - /// Tries to extract a version from an initial state. - /// - /// The state. - /// The version. - /// - /// true when the state contains a version; otherwise, false.D - /// - private static bool TryGetInitStateVersion(string state, [MaybeNullWhen(false)] out string version) - { - if (state.StartsWith(InitPrefix) && state.EndsWith(InitSuffix)) - { - version = state.TrimStart(InitPrefix).TrimEnd(InitSuffix); - return true; - } - - version = null; - return false; - } /// /// Defines the plan. @@ -138,154 +50,23 @@ public class UmbracoPlan : MigrationPlan // * Creating a migration for version 8: // Append the migration to the main chain, using a new guid, before the "//FINAL" comment // - // If the new migration causes a merge conflict, because someone else also added another - // new migration, you NEED to fix the conflict by providing one default path, and paths - // out of the conflict states (see examples below). // - // * Porting from version 7: - // Append the ported migration to the main chain, using a new guid (same as above). - // Create a new special chain from the {init-...} state to the main chain. + // If the new migration causes a merge conflict, because someone else also added another + // new migration, you NEED to fix the conflict by providing one default path, and paths + // out of the conflict states, eg: + // + // .From("state-1") + // .To("state-a") + // .To("state-b") // Some might already be in this state, without having applied ChangeA + // + // .From("state-1") + // .Merge() + // .To("state-a") + // .With() + // .To("state-b") + // .As("state-2"); - // plan starts at 7.14.0 (anything before 7.14.0 is not supported) - From(GetInitState(new SemVersion(7, 14))); - - // begin migrating from v7 - remove all keys and indexes - To("{B36B9ABD-374E-465B-9C5F-26AB0D39326F}"); - - To("{7C447271-CA3F-4A6A-A913-5D77015655CB}"); - To("{CBFF58A2-7B50-4F75-8E98-249920DB0F37}"); - To("{5CB66059-45F4-48BA-BCBD-C5035D79206B}"); - To("{FB0A5429-587E-4BD0-8A67-20F0E7E62FF7}"); - To("{F0C42457-6A3B-4912-A7EA-F27ED85A2092}"); - To("{8640C9E4-A1C0-4C59-99BB-609B4E604981}"); - To("{DD1B99AF-8106-4E00-BAC7-A43003EA07F8}"); - To("{9DF05B77-11D1-475C-A00A-B656AF7E0908}"); - To("{6FE3EF34-44A0-4992-B379-B40BC4EF1C4D}"); - To("{7F59355A-0EC9-4438-8157-EB517E6D2727}"); - ToWithReplace( - "{941B2ABA-2D06-4E04-81F5-74224F1DB037}", - "{76DF5CD7-A884-41A5-8DC6-7860D95B1DF5}"); // kill AddVariationTable1 - To("{A7540C58-171D-462A-91C5-7A9AA5CB8BFD}"); - - Merge() - .To("{3E44F712-E2E3-473A-AE49-5D7F8E67CE3F}") - .With() - .To("{65D6B71C-BDD5-4A2E-8D35-8896325E9151}") - .As("{4CACE351-C6B9-4F0C-A6BA-85A02BBD39E4}"); - - To("{1350617A-4930-4D61-852F-E3AA9E692173}"); - To("{CF51B39B-9B9A-4740-BB7C-EAF606A7BFBF}"); - To("{5F4597F4-A4E0-4AFE-90B5-6D2F896830EB}"); - To("{290C18EE-B3DE-4769-84F1-1F467F3F76DA}"); - To("{6A2C7C1B-A9DB-4EA9-B6AB-78E7D5B722A7}"); - To("{8804D8E8-FE62-4E3A-B8A2-C047C2118C38}"); - To("{23275462-446E-44C7-8C2C-3B8C1127B07D}"); - To("{6B251841-3069-4AD5-8AE9-861F9523E8DA}"); - To("{EE429F1B-9B26-43CA-89F8-A86017C809A3}"); - To("{08919C4B-B431-449C-90EC-2B8445B5C6B1}"); - To("{7EB0254C-CB8B-4C75-B15B-D48C55B449EB}"); - To("{C39BF2A7-1454-4047-BBFE-89E40F66ED63}"); - To("{64EBCE53-E1F0-463A-B40B-E98EFCCA8AE2}"); - To("{0009109C-A0B8-4F3F-8FEB-C137BBDDA268}"); - To("{ED28B66A-E248-4D94-8CDB-9BDF574023F0}"); - To("{38C809D5-6C34-426B-9BEA-EFD39162595C}"); - To("{6017F044-8E70-4E10-B2A3-336949692ADD}"); - - Merge() - .To("{CDBEDEE4-9496-4903-9CF2-4104E00FF960}") - .With() - .To("{940FD19A-00A8-4D5C-B8FF-939143585726}") - .As("{0576E786-5C30-4000-B969-302B61E90CA3}"); - - To("{48AD6CCD-C7A4-4305-A8AB-38728AD23FC5}"); - To("{DF470D86-E5CA-42AC-9780-9D28070E25F9}"); - - // finish migrating from v7 - recreate all keys and indexes - To("{3F9764F5-73D0-4D45-8804-1240A66E43A2}"); - - To("{E0CBE54D-A84F-4A8F-9B13-900945FD7ED9}"); - To("{78BAF571-90D0-4D28-8175-EF96316DA789}"); - - // release-8.0.0 - - // to 8.0.1 - To("{80C0A0CB-0DD5-4573-B000-C4B7C313C70D}"); - - // release-8.0.1 - - // to 8.1.0 - To("{B69B6E8C-A769-4044-A27E-4A4E18D1645A}"); - To("{0372A42B-DECF-498D-B4D1-6379E907EB94}"); - To("{5B1E0D93-F5A3-449B-84BA-65366B84E2D4}"); - - // to 8.6.0 - To("{4759A294-9860-46BC-99F9-B4C975CAE580}"); - To("{0BC866BC-0665-487A-9913-0290BD0169AD}"); - To("{3D67D2C8-5E65-47D0-A9E1-DC2EE0779D6B}"); - To("{EE288A91-531B-4995-8179-1D62D9AA3E2E}"); - To("{2AB29964-02A1-474D-BD6B-72148D2A53A2}"); - - // to 8.7.0 - To("{a78e3369-8ea3-40ec-ad3f-5f76929d2b20}"); - - // to 8.9.0 - To("{B5838FF5-1D22-4F6C-BCEB-F83ACB14B575}"); - - // to 8.10.0 - To("{D6A8D863-38EC-44FB-91EC-ACD6A668BD18}"); - - // NOTE: we need to do a merge migration here because as of 'now', - // v9-beta* is already out and 8.15 isn't out yet - // so we need to ensure that migrations from 8.15 are included in the next - // v9*. - - // to 8.15.0 - To("{8DDDCD0B-D7D5-4C97-BD6A-6B38CA65752F}"); - To("{4695D0C9-0729-4976-985B-048D503665D8}"); - To("{5C424554-A32D-4852-8ED1-A13508187901}"); - - // to 8.17.0 - To("{153865E9-7332-4C2A-9F9D-F20AEE078EC7}"); - - // Hack to support migration from 8.18 - To("{03482BB0-CF13-475C-845E-ECB8319DBE3C}"); - - // This should be safe to execute again. We need it with a new name to ensure updates from all the following has executed this step. - // - 8.15.0 RC - Current state: {4695D0C9-0729-4976-985B-048D503665D8} - // - 8.15.0 Final - Current state: {5C424554-A32D-4852-8ED1-A13508187901} - // - 9.0.0 RC1 - Current state: {5060F3D2-88BE-4D30-8755-CF51F28EAD12} - To("{622E5172-42E1-4662-AD80-9504AF5A4E53}"); - To("{10F7BB61-C550-426B-830B-7F954F689CDF}"); - To("{5AAE6276-80DB-4ACF-B845-199BC6C37538}"); - - // to 9.0.0 RC1 - To("{22D801BA-A1FF-4539-BFCC-2139B55594F8}"); - To("{50A43237-A6F4-49E2-A7A6-5DAD65C84669}"); - To("{3D8DADEF-0FDA-4377-A5F0-B52C2110E8F2}"); - To("{1303BDCF-2295-4645-9526-2F32E8B35ABD}"); - To("{5060F3D2-88BE-4D30-8755-CF51F28EAD12}"); - To( - "{A2686B49-A082-4B22-97FD-AAB154D46A57}"); // Re-run this migration to make sure it has executed to account for migrations going out of sync between versions. - - // TO 9.0.0-rc4 - To( - "5E02F241-5253-403D-B5D3-7DB00157E20F"); // Jaddie: This GUID is missing the { }, although this likely can't be changed now as it will break installs going forwards - - // TO 9.1.0 - To("{8BAF5E6C-DCB7-41AE-824F-4215AE4F1F98}"); - - // TO 9.2.0 - To("{0571C395-8F0B-44E9-8E3F-47BDD08D817B}"); - To("{AD3D3B7F-8E74-45A4-85DB-7FFAD57F9243}"); - - // TO 9.3.0 - To("{A2F22F17-5870-4179-8A8D-2362AA4A0A5F}"); - To("{CA7A1D9D-C9D4-4914-BC0A-459E7B9C3C8C}"); - To("{0828F206-DCF7-4F73-ABBB-6792275532EB}"); - - // TO 9.4.0 - To("{DBBA1EA0-25A1-4863-90FB-5D306FB6F1E1}"); - To("{DED98755-4059-41BB-ADBD-3FEAB12D1D7B}"); + From(InitialState); // TO 10.0.0 To("{B7E0D53C-2B0E-418B-AB07-2DDE486E225F}"); diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentNuTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentNuTable.cs deleted file mode 100644 index a216abf045..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentNuTable.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; - -internal class AddContentNuTable : MigrationBase -{ - public AddContentNuTable(IMigrationContext context) - : base(context) - { - } - - protected override void Migrate() - { - IEnumerable tables = SqlSyntax.GetTablesInSchema(Context.Database); - if (tables.InvariantContains("cmsContentNu")) - { - return; - } - - Create.Table(true).Do(); - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentTypeIsElementColumn.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentTypeIsElementColumn.cs index 36f4dcb5e0..dbfcebe7c7 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentTypeIsElementColumn.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddContentTypeIsElementColumn.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddContentTypeIsElementColumn : MigrationBase { public AddContentTypeIsElementColumn(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLockObjects.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLockObjects.cs index 96937d3991..e30e09b386 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLockObjects.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLockObjects.cs @@ -4,6 +4,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddLockObjects : MigrationBase { public AddLockObjects(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLogTableColumns.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLogTableColumns.cs index 8546566999..9503c0a2c4 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLogTableColumns.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddLogTableColumns.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddLogTableColumns : MigrationBase { public AddLogTableColumns(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddPackagesSectionAccess.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddPackagesSectionAccess.cs index e147d185fe..dc469d139f 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddPackagesSectionAccess.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddPackagesSectionAccess.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Core; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddPackagesSectionAccess : MigrationBase { public AddPackagesSectionAccess(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddTypedLabels.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddTypedLabels.cs index f1369db5c3..a8e3157726 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddTypedLabels.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddTypedLabels.cs @@ -6,6 +6,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddTypedLabels : MigrationBase { public AddTypedLabels(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables1A.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables1A.cs index 118c7f8bb2..c024459b92 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables1A.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables1A.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddVariationTables1A : MigrationBase { public AddVariationTables1A(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables2.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables2.cs index 76d20b4667..14e3a31fe2 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables2.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/AddVariationTables2.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddVariationTables2 : MigrationBase { public AddVariationTables2(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ContentVariationMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ContentVariationMigration.cs index edfeb204f8..bddcc67525 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ContentVariationMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ContentVariationMigration.cs @@ -1,8 +1,9 @@ -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.Models; + using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ContentVariationMigration : MigrationBase { public ContentVariationMigration(IMigrationContext context) @@ -12,50 +13,7 @@ public class ContentVariationMigration : MigrationBase protected override void Migrate() { - static byte GetNewValue(byte oldValue) - { - switch (oldValue) - { - case 0: // Unknown - case 1: // InvariantNeutral - return 0; // Unknown - case 2: // CultureNeutral - case 3: // CultureNeutral | InvariantNeutral - return 1; // Culture - case 4: // InvariantSegment - case 5: // InvariantSegment | InvariantNeutral - return 2; // Segment - case 6: // InvariantSegment | CultureNeutral - case 7: // InvariantSegment | CultureNeutral | InvariantNeutral - case 8: // CultureSegment - case 9: // CultureSegment | InvariantNeutral - case 10: // CultureSegment | CultureNeutral - case 11: // CultureSegment | CultureNeutral | InvariantNeutral - case 12: // etc - case 13: - case 14: - case 15: - return 3; // Culture | Segment - default: - throw new NotSupportedException($"Invalid value {oldValue}."); - } - } - List? propertyTypes = - Database.Fetch(Sql().Select().From()); - foreach (PropertyTypeDto80? dto in propertyTypes) - { - dto.Variations = GetNewValue(dto.Variations); - Database.Update(dto); - } - - List? contentTypes = - Database.Fetch(Sql().Select().From()); - foreach (ContentTypeDto80? dto in contentTypes) - { - dto.Variations = GetNewValue(dto.Variations); - Database.Update(dto); - } } // we *need* to use these private DTOs here, which does *not* have extra properties, which would kill the migration diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs index 50ac54436a..14cb4816b5 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs @@ -1,15 +1,6 @@ -using System.Globalization; -using System.Runtime.Serialization; -using Newtonsoft.Json; -using NPoco; -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.Models; -using Umbraco.Cms.Infrastructure.Persistence; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Extensions; - namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ConvertRelatedLinksToMultiUrlPicker : MigrationBase { public ConvertRelatedLinksToMultiUrlPicker(IMigrationContext context) @@ -19,144 +10,7 @@ public class ConvertRelatedLinksToMultiUrlPicker : MigrationBase protected override void Migrate() { - Sql sqlDataTypes = Sql() - .Select() - .From() - .Where(x => x.EditorAlias == Constants.PropertyEditors.Legacy.Aliases.RelatedLinks - || x.EditorAlias == Constants.PropertyEditors.Legacy.Aliases.RelatedLinks2); - List? dataTypes = Database.Fetch(sqlDataTypes); - var dataTypeIds = dataTypes.Select(x => x.NodeId).ToList(); - - if (dataTypeIds.Count == 0) - { - return; - } - - foreach (DataTypeDto? dataType in dataTypes) - { - dataType.EditorAlias = Constants.PropertyEditors.Aliases.MultiUrlPicker; - Database.Update(dataType); - } - - Sql sqlPropertyTpes = Sql() - .Select() - .From() - .Where(x => dataTypeIds.Contains(x.DataTypeId)); - - var propertyTypeIds = Database.Fetch(sqlPropertyTpes).Select(x => x.Id).ToList(); - - if (propertyTypeIds.Count == 0) - { - return; - } - - Sql sqlPropertyData = Sql() - .Select() - .From() - .Where(x => propertyTypeIds.Contains(x.PropertyTypeId)); - - List? properties = Database.Fetch(sqlPropertyData); - - // Create a Multi URL Picker datatype for the converted RelatedLinks data - foreach (PropertyDataDto? property in properties) - { - var value = property.Value?.ToString(); - if (string.IsNullOrWhiteSpace(value)) - { - continue; - } - - List? relatedLinks = JsonConvert.DeserializeObject>(value); - var links = new List(); - if (relatedLinks is null) - { - return; - } - - foreach (RelatedLink relatedLink in relatedLinks) - { - GuidUdi? udi = null; - if (relatedLink.IsInternal) - { - var linkIsUdi = UdiParser.TryParse(relatedLink.Link, out udi); - if (linkIsUdi == false) - { - // oh no.. probably an integer, yikes! - if (int.TryParse(relatedLink.Link, NumberStyles.Integer, CultureInfo.InvariantCulture, - out var intId)) - { - Sql sqlNodeData = Sql() - .Select() - .From() - .Where(x => x.NodeId == intId); - - NodeDto? node = Database.Fetch(sqlNodeData).FirstOrDefault(); - if (node != null) - - // Note: RelatedLinks did not allow for picking media items, - // so if there's a value this will be a content item - hence - // the hardcoded "document" here - { - udi = new GuidUdi("document", node.UniqueId); - } - } - } - } - - var link = new LinkDto - { - Name = relatedLink.Caption, - Target = relatedLink.NewWindow ? "_blank" : null, - Udi = udi, - - // Should only have a URL if it's an external link otherwise it wil be a UDI - Url = relatedLink.IsInternal == false ? relatedLink.Link : null, - }; - - links.Add(link); - } - - var json = JsonConvert.SerializeObject(links); - - // Update existing data - property.TextValue = json; - Database.Update(property); - } } } -internal class RelatedLink -{ - public int? Id { get; internal set; } - - [JsonProperty("caption")] - public string? Caption { get; set; } - - internal bool IsDeleted { get; set; } - - [JsonProperty("link")] - public string? Link { get; set; } - - [JsonProperty("newWindow")] - public bool NewWindow { get; set; } - - [JsonProperty("isInternal")] - public bool IsInternal { get; set; } -} - -[DataContract] -internal class LinkDto -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "target")] - public string? Target { get; set; } - - [DataMember(Name = "udi")] - public GuidUdi? Udi { get; set; } - - [DataMember(Name = "url")] - public string? Url { get; set; } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypeMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypeMigration.cs index d97b7ebcb5..e52d5b5844 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypeMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypeMigration.cs @@ -10,6 +10,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DataTypeMigration : MigrationBase { private static readonly ISet _legacyAliases = new HashSet @@ -45,100 +46,6 @@ public class DataTypeMigration : MigrationBase protected override void Migrate() { - // drop and create columns - Delete.Column("pk").FromTable("cmsDataType").Do(); - // rename the table - Rename.Table("cmsDataType").To(Constants.DatabaseSchema.Tables.DataType).Do(); - - // create column - AddColumn(Constants.DatabaseSchema.Tables.DataType, "config"); - Execute.Sql(Sql().Update(u => u.Set(x => x.Configuration, string.Empty))).Do(); - - // renames - Execute.Sql(Sql() - .Update(u => u.Set(x => x.EditorAlias, "Umbraco.ColorPicker")) - .Where(x => x.EditorAlias == "Umbraco.ColorPickerAlias")).Do(); - - // from preValues to configuration... - Sql sql = Sql() - .Select() - .AndSelect(x => x.Id, x => x.Alias, x => x.SortOrder, x => x.Value) - .From() - .InnerJoin().On((left, right) => left.NodeId == right.NodeId) - .OrderBy(x => x.NodeId) - .AndBy(x => x.SortOrder); - - IEnumerable> dtos = Database.Fetch(sql).GroupBy(x => x.NodeId); - - foreach (IGrouping group in dtos) - { - DataTypeDto? dataType = Database.Fetch(Sql() - .Select() - .From() - .Where(x => x.NodeId == group.Key)).First(); - - // check for duplicate aliases - var aliases = group.Select(x => x.Alias).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); - if (aliases.Distinct().Count() != aliases.Length) - { - throw new InvalidOperationException( - $"Cannot migrate prevalues for datatype id={dataType.NodeId}, editor={dataType.EditorAlias}: duplicate alias."); - } - - // handle null/empty aliases - var index = 0; - var dictionary = group.ToDictionary(x => string.IsNullOrWhiteSpace(x.Alias) ? index++.ToString() : x.Alias); - - // migrate the preValues to configuration - IPreValueMigrator migrator = - _preValueMigrators.GetMigrator(dataType.EditorAlias) ?? new DefaultPreValueMigrator(); - var config = migrator.GetConfiguration(dataType.NodeId, dataType.EditorAlias, dictionary); - var json = _configurationEditorJsonSerializer.Serialize(config); - - // validate - and kill the migration if it fails - var newAlias = migrator.GetNewAlias(dataType.EditorAlias); - if (newAlias == null) - { - if (!_legacyAliases.Contains(dataType.EditorAlias)) - { - _logger.LogWarning( - "Skipping validation of configuration for data type {NodeId} : {EditorAlias}." - + " Please ensure that the configuration is valid. The site may fail to start and / or load data types and run.", - dataType.NodeId, dataType.EditorAlias); - } - } - else if (!_propertyEditors.TryGet(newAlias, out IDataEditor? propertyEditor)) - { - if (!_legacyAliases.Contains(newAlias)) - { - _logger.LogWarning( - "Skipping validation of configuration for data type {NodeId} : {NewEditorAlias} (was: {EditorAlias})" - + " because no property editor with that alias was found." - + " Please ensure that the configuration is valid. The site may fail to start and / or load data types and run.", - dataType.NodeId, newAlias, dataType.EditorAlias); - } - } - else - { - IConfigurationEditor configEditor = propertyEditor.GetConfigurationEditor(); - try - { - var _ = configEditor.FromDatabase(json, _configurationEditorJsonSerializer); - } - catch (Exception e) - { - _logger.LogWarning( - e, - "Failed to validate configuration for data type {NodeId} : {NewEditorAlias} (was: {EditorAlias})." - + " Please fix the configuration and ensure it is valid. The site may fail to start and / or load data types and run.", - dataType.NodeId, newAlias, dataType.EditorAlias); - } - } - - // update - dataType.Configuration = _configurationEditorJsonSerializer.Serialize(config); - Database.Update(dataType); - } } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ContentPickerPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ContentPickerPreValueMigrator.cs deleted file mode 100644 index 13c9645ffe..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ContentPickerPreValueMigrator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Umbraco.Cms.Core; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class ContentPickerPreValueMigrator : DefaultPreValueMigrator -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == Constants.PropertyEditors.Legacy.Aliases.ContentPicker2; - - public override string? GetNewAlias(string editorAlias) - => null; - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "showOpenButton" || - preValue.Alias == "ignoreUserStartNodes") - { - return preValue.Value == "1"; - } - - return base.GetPreValueValue(preValue); - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DecimalPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DecimalPreValueMigrator.cs deleted file mode 100644 index eb7744cc18..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DecimalPreValueMigrator.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Newtonsoft.Json; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class DecimalPreValueMigrator : DefaultPreValueMigrator -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == "Umbraco.Decimal"; - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "min" || - preValue.Alias == "step" || - preValue.Alias == "max") - { - return decimal.TryParse(preValue.Value, out var d) ? (decimal?)d : null; - } - - return preValue.Value?.DetectIsJson() ?? false ? JsonConvert.DeserializeObject(preValue.Value) : preValue.Value; - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DefaultPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DefaultPreValueMigrator.cs deleted file mode 100644 index 2faaca6086..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DefaultPreValueMigrator.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Newtonsoft.Json; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class DefaultPreValueMigrator : IPreValueMigrator -{ - public virtual bool CanMigrate(string editorAlias) - => true; - - public virtual string? GetNewAlias(string editorAlias) - => editorAlias; - - public object GetConfiguration(int dataTypeId, string editorAlias, Dictionary preValues) - { - var preValuesA = preValues.Values.ToList(); - var aliases = preValuesA.Select(x => x.Alias).Distinct().ToArray(); - if (aliases.Length == 1 && string.IsNullOrWhiteSpace(aliases[0])) - { - // array-based prevalues - return new Dictionary - { - ["values"] = preValuesA.OrderBy(x => x.SortOrder).Select(x => x.Value).ToArray(), - }; - } - - // assuming we don't want to fall back to array - if (aliases.Any(string.IsNullOrWhiteSpace)) - { - throw new InvalidOperationException( - $"Cannot migrate prevalues for datatype id={dataTypeId}, editor={editorAlias}: null/empty alias."); - } - - // dictionary-base prevalues - return GetPreValues(preValuesA).ToDictionary(x => x.Alias, GetPreValueValue); - } - - protected virtual IEnumerable GetPreValues(IEnumerable preValues) - => preValues; - - protected virtual object? GetPreValueValue(PreValueDto preValue) => preValue.Value?.DetectIsJson() ?? false - ? JsonConvert.DeserializeObject(preValue.Value) - : preValue.Value; -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DropDownFlexiblePreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DropDownFlexiblePreValueMigrator.cs deleted file mode 100644 index 6588676283..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/DropDownFlexiblePreValueMigrator.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class DropDownFlexiblePreValueMigrator : IPreValueMigrator -{ - public bool CanMigrate(string editorAlias) - => editorAlias == "Umbraco.DropDown.Flexible"; - - public virtual string? GetNewAlias(string editorAlias) - => null; - - public object GetConfiguration(int dataTypeId, string editorAlias, Dictionary preValues) - { - var config = new DropDownFlexibleConfiguration(); - foreach (PreValueDto preValue in preValues.Values) - { - if (preValue.Alias == "multiple") - { - config.Multiple = preValue.Value == "1"; - } - else - { - config.Items.Add(new ValueListConfiguration.ValueListItem { Id = preValue.Id, Value = preValue.Value }); - } - } - - return config; - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/IPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/IPreValueMigrator.cs index 11a126a60b..1f287b6597 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/IPreValueMigrator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/IPreValueMigrator.cs @@ -3,6 +3,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; /// /// Defines a service migrating preValues. /// +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public interface IPreValueMigrator { /// diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs deleted file mode 100644 index 7879e9c67d..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Globalization; -using Newtonsoft.Json; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class ListViewPreValueMigrator : DefaultPreValueMigrator -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == "Umbraco.ListView"; - - protected override IEnumerable GetPreValues(IEnumerable preValues) => - preValues.Where(preValue => preValue.Alias != "displayAtTabNumber"); - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "pageSize") - { - return int.TryParse(preValue.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) - ? (int?)i - : null; - } - - return preValue.Value?.DetectIsJson() ?? false ? JsonConvert.DeserializeObject(preValue.Value) : preValue.Value; - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/MarkdownEditorPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/MarkdownEditorPreValueMigrator.cs deleted file mode 100644 index eff4b82477..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/MarkdownEditorPreValueMigrator.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Umbraco.Cms.Core; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class MarkdownEditorPreValueMigrator : DefaultPreValueMigrator // PreValueMigratorBase -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == Constants.PropertyEditors.Aliases.MarkdownEditor; - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "preview") - { - return preValue.Value == "1"; - } - - return base.GetPreValueValue(preValue); - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/MediaPickerPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/MediaPickerPreValueMigrator.cs deleted file mode 100644 index c630693073..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/MediaPickerPreValueMigrator.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Umbraco.Cms.Core; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class MediaPickerPreValueMigrator : DefaultPreValueMigrator // PreValueMigratorBase -{ - private readonly string[] _editors = - { - Constants.PropertyEditors.Legacy.Aliases.MediaPicker2, Constants.PropertyEditors.Aliases.MediaPicker, - }; - - public override bool CanMigrate(string editorAlias) - => _editors.Contains(editorAlias); - - public override string GetNewAlias(string editorAlias) - => Constants.PropertyEditors.Aliases.MediaPicker; - - // you wish - but MediaPickerConfiguration lives in Umbraco.Web - /* - public override object GetConfiguration(int dataTypeId, string editorAlias, Dictionary preValues) - { - return new MediaPickerConfiguration { ... }; - } - */ - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "multiPicker" || - preValue.Alias == "onlyImages" || - preValue.Alias == "disableFolderSelect") - { - return preValue.Value == "1"; - } - - return base.GetPreValueValue(preValue); - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs deleted file mode 100644 index 72c28dc8ad..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Globalization; -using Newtonsoft.Json; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class NestedContentPreValueMigrator : DefaultPreValueMigrator // PreValueMigratorBase -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == "Umbraco.NestedContent"; - - // you wish - but NestedContentConfiguration lives in Umbraco.Web - /* - public override object GetConfiguration(int dataTypeId, string editorAlias, Dictionary preValues) - { - return new NestedContentConfiguration { ... }; - } - */ - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "confirmDeletes" || - preValue.Alias == "showIcons" || - preValue.Alias == "hideLabel") - { - return preValue.Value == "1"; - } - - if (preValue.Alias == "minItems" || - preValue.Alias == "maxItems") - { - return int.TryParse(preValue.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) - ? (int?)i - : null; - } - - return preValue.Value?.DetectIsJson() ?? false ? JsonConvert.DeserializeObject(preValue.Value) : preValue.Value; - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueDto.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueDto.cs index d3e639452e..3509ea9f19 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueDto.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueDto.cs @@ -2,6 +2,7 @@ using NPoco; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] [TableName("cmsDataTypePreValues")] [ExplicitColumns] public class PreValueDto diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorBase.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorBase.cs index df9cb27ec3..e658640054 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorBase.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public abstract class PreValueMigratorBase : IPreValueMigrator { public abstract bool CanMigrate(string editorAlias); diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs index 81a6200991..422bbc1e8c 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class PreValueMigratorCollection : BuilderCollectionBase { private readonly ILogger _logger; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollectionBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollectionBuilder.cs index ba335eef4b..b16d85af6a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollectionBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollectionBuilder.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class PreValueMigratorCollectionBuilder : OrderedCollectionBuilderBase { diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/RenamingPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/RenamingPreValueMigrator.cs deleted file mode 100644 index 273c8ae51b..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/RenamingPreValueMigrator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Exceptions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class RenamingPreValueMigrator : DefaultPreValueMigrator -{ - private readonly string[] _editors = { "Umbraco.NoEdit" }; - - public override bool CanMigrate(string editorAlias) - => _editors.Contains(editorAlias); - - public override string GetNewAlias(string editorAlias) - { - switch (editorAlias) - { - case "Umbraco.NoEdit": - return Constants.PropertyEditors.Aliases.Label; - default: - throw new PanicException($"The alias {editorAlias} is not supported"); - } - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/RichTextPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/RichTextPreValueMigrator.cs deleted file mode 100644 index 4e7c5b79f1..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/RichTextPreValueMigrator.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Newtonsoft.Json; -using Umbraco.Cms.Core; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class RichTextPreValueMigrator : DefaultPreValueMigrator -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == "Umbraco.TinyMCEv3"; - - public override string GetNewAlias(string editorAlias) - => Constants.PropertyEditors.Aliases.TinyMce; - - protected override object? GetPreValueValue(PreValueDto preValue) - { - if (preValue.Alias == "hideLabel") - { - return preValue.Value == "1"; - } - - return preValue.Value?.DetectIsJson() ?? false ? JsonConvert.DeserializeObject(preValue.Value) : preValue.Value; - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/UmbracoSliderPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/UmbracoSliderPreValueMigrator.cs deleted file mode 100644 index 7f8632dd7a..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/UmbracoSliderPreValueMigrator.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class UmbracoSliderPreValueMigrator : PreValueMigratorBase -{ - public override bool CanMigrate(string editorAlias) - => editorAlias == "Umbraco.Slider"; - - public override object GetConfiguration(int dataTypeId, string editorAlias, - Dictionary preValues) => - new SliderConfiguration - { - EnableRange = GetBoolValue(preValues, "enableRange"), - InitialValue = GetDecimalValue(preValues, "initVal1"), - InitialValue2 = GetDecimalValue(preValues, "initVal2"), - MaximumValue = GetDecimalValue(preValues, "maxVal"), - MinimumValue = GetDecimalValue(preValues, "minVal"), - StepIncrements = GetDecimalValue(preValues, "step"), - }; -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ValueListPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ValueListPreValueMigrator.cs deleted file mode 100644 index 9528cadc8b..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ValueListPreValueMigrator.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; - -internal class ValueListPreValueMigrator : IPreValueMigrator -{ - private readonly string[] _editors = - { - "Umbraco.RadioButtonList", "Umbraco.CheckBoxList", "Umbraco.DropDown", "Umbraco.DropdownlistPublishingKeys", - "Umbraco.DropDownMultiple", "Umbraco.DropdownlistMultiplePublishKeys", - }; - - public bool CanMigrate(string editorAlias) - => _editors.Contains(editorAlias); - - public virtual string? GetNewAlias(string editorAlias) - => null; - - public object GetConfiguration(int dataTypeId, string editorAlias, Dictionary preValues) - { - var config = new ValueListConfiguration(); - foreach (PreValueDto preValue in preValues.Values) - { - config.Items.Add(new ValueListConfiguration.ValueListItem { Id = preValue.Id, Value = preValue.Value }); - } - - return config; - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs index e80dd72765..e2303cf2a2 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs @@ -13,6 +13,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DropDownPropertyEditorsMigration : PropertyEditorsMigrationBase { private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropMigrationsTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropMigrationsTable.cs index 8eebd91772..dc225678f3 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropMigrationsTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropMigrationsTable.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DropMigrationsTable : MigrationBase { public DropMigrationsTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropPreValueTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropPreValueTable.cs index 64152d0cb3..ff4673b848 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropPreValueTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropPreValueTable.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DropPreValueTable : MigrationBase { public DropPreValueTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTaskTables.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTaskTables.cs index e38c0c3292..23dc153b7a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTaskTables.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTaskTables.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DropTaskTables : MigrationBase { public DropTaskTables(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTemplateDesignColumn.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTemplateDesignColumn.cs index 454644b1fb..745efdcf06 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTemplateDesignColumn.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropTemplateDesignColumn.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DropTemplateDesignColumn : MigrationBase { public DropTemplateDesignColumn(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropXmlTables.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropXmlTables.cs index 1cdb73d410..6dbd91374f 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropXmlTables.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropXmlTables.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DropXmlTables : MigrationBase { public DropXmlTables(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FallbackLanguage.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FallbackLanguage.cs index 4f3b685ef5..ee0d5157ae 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FallbackLanguage.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FallbackLanguage.cs @@ -5,6 +5,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] /// /// Adds a new, self-joined field to umbracoLanguages to hold the fall-back language for /// a given language. diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FixLanguageIsoCodeLength.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FixLanguageIsoCodeLength.cs index f1bd804c59..606348d179 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FixLanguageIsoCodeLength.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/FixLanguageIsoCodeLength.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class FixLanguageIsoCodeLength : MigrationBase { public FixLanguageIsoCodeLength(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/LanguageColumns.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/LanguageColumns.cs index a265195bc9..e883a92e00 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/LanguageColumns.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/LanguageColumns.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class LanguageColumns : MigrationBase { public LanguageColumns(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeRedirectUrlVariant.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeRedirectUrlVariant.cs index 64c8d4c8b4..2e039543f3 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeRedirectUrlVariant.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeRedirectUrlVariant.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MakeRedirectUrlVariant : MigrationBase { public MakeRedirectUrlVariant(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeTagsVariant.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeTagsVariant.cs index 630a853aa2..986ac4d3ce 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeTagsVariant.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MakeTagsVariant.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MakeTagsVariant : MigrationBase { public MakeTagsVariant(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs index f89a6d1497..dfc713f912 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs @@ -11,6 +11,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MergeDateAndDateTimePropertyEditor : MigrationBase { private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/ContentTypeDto80.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/ContentTypeDto80.cs deleted file mode 100644 index 856c81af52..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/ContentTypeDto80.cs +++ /dev/null @@ -1,63 +0,0 @@ -using NPoco; -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.Models; - -/// -/// Snapshot of the as it was at version 8.0 -/// -/// -/// This is required during migrations the schema of this table changed and running SQL against the new table would -/// result in errors -/// -[TableName(TableName)] -[PrimaryKey("pk")] -[ExplicitColumns] -internal class ContentTypeDto80 -{ - public const string TableName = Constants.DatabaseSchema.Tables.ContentType; - - [Column("pk")] - [PrimaryKeyColumn(IdentitySeed = 535)] - public int PrimaryKey { get; set; } - - [Column("nodeId")] - [ForeignKey(typeof(NodeDto))] - [Index(IndexTypes.UniqueNonClustered, Name = "IX_cmsContentType")] - public int NodeId { get; set; } - - [Column("alias")] - [NullSetting(NullSetting = NullSettings.Null)] - public string? Alias { get; set; } - - [Column("icon")] - [Index(IndexTypes.NonClustered)] - [NullSetting(NullSetting = NullSettings.Null)] - public string? Icon { get; set; } - - [Column("thumbnail")] - [Constraint(Default = "folder.png")] - public string? Thumbnail { get; set; } - - [Column("description")] - [NullSetting(NullSetting = NullSettings.Null)] - [Length(1500)] - public string? Description { get; set; } - - [Column("isContainer")] - [Constraint(Default = "0")] - public bool IsContainer { get; set; } - - [Column("allowAtRoot")] - [Constraint(Default = "0")] - public bool AllowAtRoot { get; set; } - - [Column("variations")] - [Constraint(Default = "1" /*ContentVariation.InvariantNeutral*/)] - public byte Variations { get; set; } - - [ResultColumn] - public NodeDto? NodeDto { get; set; } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/PropertyDataDto80.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/PropertyDataDto80.cs deleted file mode 100644 index 4c537472db..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/PropertyDataDto80.cs +++ /dev/null @@ -1,142 +0,0 @@ -using NPoco; -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.Models; - -/// -/// Snapshot of the as it was at version 8.0 -/// -/// -/// This is required during migrations the schema of this table changed and running SQL against the new table would -/// result in errors -/// -[TableName(TableName)] -[PrimaryKey("id")] -[ExplicitColumns] -internal class PropertyDataDto80 -{ - public const string TableName = Constants.DatabaseSchema.Tables.PropertyData; - public const int VarcharLength = 512; - public const int SegmentLength = 256; - - private decimal? _decimalValue; - - // pk, not used at the moment (never updating) - [Column("id")] [PrimaryKeyColumn] public int Id { get; set; } - - [Column("versionId")] - [ForeignKey(typeof(ContentVersionDto))] - [Index(IndexTypes.UniqueNonClustered, Name = "IX_" + TableName + "_VersionId", - ForColumns = "versionId,propertyTypeId,languageId,segment")] - public int VersionId { get; set; } - - [Column("propertyTypeId")] - [ForeignKey(typeof(PropertyTypeDto80))] - [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_PropertyTypeId")] - public int PropertyTypeId { get; set; } - - [Column("languageId")] - [ForeignKey(typeof(LanguageDto))] - [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_LanguageId")] - [NullSetting(NullSetting = NullSettings.Null)] - public int? LanguageId { get; set; } - - [Column("segment")] - [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_Segment")] - [NullSetting(NullSetting = NullSettings.Null)] - [Length(SegmentLength)] - public string? Segment { get; set; } - - [Column("intValue")] - [NullSetting(NullSetting = NullSettings.Null)] - public int? IntegerValue { get; set; } - - [Column("decimalValue")] - [NullSetting(NullSetting = NullSettings.Null)] - public decimal? DecimalValue - { - get => _decimalValue; - set => _decimalValue = value?.Normalize(); - } - - [Column("dateValue")] - [NullSetting(NullSetting = NullSettings.Null)] - public DateTime? DateValue { get; set; } - - [Column("varcharValue")] - [NullSetting(NullSetting = NullSettings.Null)] - [Length(VarcharLength)] - public string? VarcharValue { get; set; } - - [Column("textValue")] - [NullSetting(NullSetting = NullSettings.Null)] - [SpecialDbType(SpecialDbTypes.NTEXT)] - public string? TextValue { get; set; } - - [ResultColumn] - [Reference(ReferenceType.OneToOne, ColumnName = "PropertyTypeId")] - public PropertyTypeDto80? PropertyTypeDto { get; set; } - - [Ignore] - public object? Value - { - get - { - if (IntegerValue.HasValue) - { - return IntegerValue.Value; - } - - if (DecimalValue.HasValue) - { - return DecimalValue.Value; - } - - if (DateValue.HasValue) - { - return DateValue.Value; - } - - if (!string.IsNullOrEmpty(VarcharValue)) - { - return VarcharValue; - } - - if (!string.IsNullOrEmpty(TextValue)) - { - return TextValue; - } - - return null; - } - } - - public PropertyDataDto80 Clone(int versionId) => - new PropertyDataDto80 - { - VersionId = versionId, - PropertyTypeId = PropertyTypeId, - LanguageId = LanguageId, - Segment = Segment, - IntegerValue = IntegerValue, - DecimalValue = DecimalValue, - DateValue = DateValue, - VarcharValue = VarcharValue, - TextValue = TextValue, - PropertyTypeDto = PropertyTypeDto - }; - - protected bool Equals(PropertyDataDto other) => Id == other.Id; - - public override bool Equals(object? other) => - !ReferenceEquals(null, other) // other is not null - && (ReferenceEquals(this, other) // and either ref-equals, or same id - || (other is PropertyDataDto pdata && pdata.Id == Id)); - - public override int GetHashCode() => - // ReSharper disable once NonReadonlyMemberInGetHashCode - Id; -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/PropertyTypeDto80.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/PropertyTypeDto80.cs deleted file mode 100644 index a5a7f48d6d..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/Models/PropertyTypeDto80.cs +++ /dev/null @@ -1,76 +0,0 @@ -using NPoco; -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; -using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.Models; - -/// -/// Snapshot of the as it was at version 8.0 -/// -/// -/// This is required during migrations before 8.6 since the schema has changed and running SQL against the new table -/// would result in errors -/// -[TableName(Constants.DatabaseSchema.Tables.PropertyType)] -[PrimaryKey("id")] -[ExplicitColumns] -internal class PropertyTypeDto80 -{ - [Column("id")] - [PrimaryKeyColumn(IdentitySeed = 50)] - public int Id { get; set; } - - [Column("dataTypeId")] - [ForeignKey(typeof(DataTypeDto), Column = "nodeId")] - public int DataTypeId { get; set; } - - [Column("contentTypeId")] - [ForeignKey(typeof(ContentTypeDto), Column = "nodeId")] - public int ContentTypeId { get; set; } - - [Column("propertyTypeGroupId")] - [NullSetting(NullSetting = NullSettings.Null)] - [ForeignKey(typeof(PropertyTypeGroupDto))] - public int? PropertyTypeGroupId { get; set; } - - [Index(IndexTypes.NonClustered, Name = "IX_cmsPropertyTypeAlias")] - [Column("Alias")] - public string Alias { get; set; } = null!; - - [Column("Name")] - [NullSetting(NullSetting = NullSettings.Null)] - public string? Name { get; set; } - - [Column("sortOrder")] - [Constraint(Default = "0")] - public int SortOrder { get; set; } - - [Column("mandatory")] - [Constraint(Default = "0")] - public bool Mandatory { get; set; } - - [Column("validationRegExp")] - [NullSetting(NullSetting = NullSettings.Null)] - public string? ValidationRegExp { get; set; } - - [Column("Description")] - [NullSetting(NullSetting = NullSettings.Null)] - [Length(2000)] - public string? Description { get; set; } - - [Column("variations")] - [Constraint(Default = "1" /*ContentVariation.InvariantNeutral*/)] - public byte Variations { get; set; } - - [ResultColumn] - [Reference(ReferenceType.OneToOne, ColumnName = "DataTypeId")] - public DataTypeDto? DataTypeDto { get; set; } - - [Column("UniqueID")] - [NullSetting(NullSetting = NullSettings.NotNull)] - [Constraint(Default = SystemMethods.NewGuid)] - [Index(IndexTypes.UniqueNonClustered, Name = "IX_cmsPropertyTypeUniqueID")] - public Guid UniqueId { get; set; } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigration.cs index cef6eb974f..3c0f0ee560 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigration.cs @@ -4,6 +4,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class PropertyEditorsMigration : MigrationBase { public PropertyEditorsMigration(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs index febf872e34..f8f730c390 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs @@ -12,6 +12,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public abstract class PropertyEditorsMigrationBase : MigrationBase { protected PropertyEditorsMigrationBase(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs index ab9b01a3b2..d3359d09fb 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs @@ -13,6 +13,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RadioAndCheckboxPropertyEditorsMigration : PropertyEditorsMigrationBase { private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorMacroColumns.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorMacroColumns.cs index f8d731e166..00acccb0bf 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorMacroColumns.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorMacroColumns.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RefactorMacroColumns : MigrationBase { public RefactorMacroColumns(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorVariantsModel.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorVariantsModel.cs index 500db8a4bc..2f0592bd40 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorVariantsModel.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RefactorVariantsModel.cs @@ -6,6 +6,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RefactorVariantsModel : MigrationBase { public RefactorVariantsModel(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameLabelAndRichTextPropertyEditorAliases.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameLabelAndRichTextPropertyEditorAliases.cs index a638f17dc4..eda61b80c5 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameLabelAndRichTextPropertyEditorAliases.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameLabelAndRichTextPropertyEditorAliases.cs @@ -4,6 +4,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RenameLabelAndRichTextPropertyEditorAliases : MigrationBase { public RenameLabelAndRichTextPropertyEditorAliases(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameMediaVersionTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameMediaVersionTable.cs index a6fe5c895b..2948567190 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameMediaVersionTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameMediaVersionTable.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RenameMediaVersionTable : MigrationBase { public RenameMediaVersionTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameUmbracoDomainsTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameUmbracoDomainsTable.cs index 8611128458..cd65470de7 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameUmbracoDomainsTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RenameUmbracoDomainsTable.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Core; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RenameUmbracoDomainsTable : MigrationBase { public RenameUmbracoDomainsTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/SuperZero.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/SuperZero.cs index 135e562fde..7aa92aa585 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/SuperZero.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/SuperZero.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Core; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class SuperZero : MigrationBase { public SuperZero(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TablesForScheduledPublishing.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TablesForScheduledPublishing.cs index 013375352e..1db65da66d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TablesForScheduledPublishing.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TablesForScheduledPublishing.cs @@ -4,6 +4,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class TablesForScheduledPublishing : MigrationBase { public TablesForScheduledPublishing(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigration.cs index 2f2ac746ab..3ac5609533 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigration.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class TagsMigration : MigrationBase { public TagsMigration(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigrationFix.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigrationFix.cs index eaa745a780..d0c496df01 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigrationFix.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/TagsMigrationFix.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Core; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class TagsMigrationFix : MigrationBase { public TagsMigrationFix(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdateDefaultMandatoryLanguage.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdateDefaultMandatoryLanguage.cs index 557f658691..a077ffa3d7 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdateDefaultMandatoryLanguage.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdateDefaultMandatoryLanguage.cs @@ -6,6 +6,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UpdateDefaultMandatoryLanguage : MigrationBase { public UpdateDefaultMandatoryLanguage(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs index 18d55aa1e6..2af762cda0 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs @@ -9,6 +9,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UpdatePickerIntegerValuesToUdi : MigrationBase { public UpdatePickerIntegerValuesToUdi(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UserForeignKeys.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UserForeignKeys.cs index fa19ac284a..06feca0411 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UserForeignKeys.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UserForeignKeys.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] /// /// Creates/Updates non mandatory FK columns to the user table /// diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/VariantsMigration.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/VariantsMigration.cs index db41f70711..75de36ac2d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/VariantsMigration.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/VariantsMigration.cs @@ -5,6 +5,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class VariantsMigration : MigrationBase { public VariantsMigration(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_1/ChangeNuCacheJsonFormat.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_1/ChangeNuCacheJsonFormat.cs index 60e38eca29..83d97d9331 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_1/ChangeNuCacheJsonFormat.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_1/ChangeNuCacheJsonFormat.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Migrations.PostMigrations; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_1; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ChangeNuCacheJsonFormat : MigrationBase { public ChangeNuCacheJsonFormat(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_10_0/AddPropertyTypeLabelOnTopColumn.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_10_0/AddPropertyTypeLabelOnTopColumn.cs index 4e57716c4e..fd7b5b5973 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_10_0/AddPropertyTypeLabelOnTopColumn.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_10_0/AddPropertyTypeLabelOnTopColumn.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_10_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddPropertyTypeLabelOnTopColumn : MigrationBase { public AddPropertyTypeLabelOnTopColumn(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/AddCmsContentNuByteColumn.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/AddCmsContentNuByteColumn.cs index 4a9a494b76..278d5990da 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/AddCmsContentNuByteColumn.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/AddCmsContentNuByteColumn.cs @@ -5,6 +5,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_15_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddCmsContentNuByteColumn : MigrationBase { private const string TempTableName = Constants.DatabaseSchema.TableNamePrefix + "cms" + "ContentNuTEMP"; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpdateCmsPropertyGroupIdSeed.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpdateCmsPropertyGroupIdSeed.cs index 703cfc1474..d6a6a9d6e0 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpdateCmsPropertyGroupIdSeed.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpdateCmsPropertyGroupIdSeed.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_15_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UpdateCmsPropertyGroupIdSeed : MigrationBase { public UpdateCmsPropertyGroupIdSeed(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpgradedIncludeIndexes.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpgradedIncludeIndexes.cs index 114bb7becc..d97c8d9708 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpgradedIncludeIndexes.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_15_0/UpgradedIncludeIndexes.cs @@ -5,6 +5,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_15_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UpgradedIncludeIndexes : MigrationBase { public UpgradedIncludeIndexes(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_17_0/AddPropertyTypeGroupColumns.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_17_0/AddPropertyTypeGroupColumns.cs index cef69d6bd3..41289c6e4e 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_17_0/AddPropertyTypeGroupColumns.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_17_0/AddPropertyTypeGroupColumns.cs @@ -5,6 +5,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_17_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddPropertyTypeGroupColumns : MigrationBase { private readonly IShortStringHelper _shortStringHelper; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/ConvertTinyMceAndGridMediaUrlsToLocalLink.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/ConvertTinyMceAndGridMediaUrlsToLocalLink.cs index 0f7fe97663..790b5b7010 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/ConvertTinyMceAndGridMediaUrlsToLocalLink.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/ConvertTinyMceAndGridMediaUrlsToLocalLink.cs @@ -1,18 +1,8 @@ -using System.Text.RegularExpressions; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using NPoco; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Infrastructure.Migrations.PostMigrations; -using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.Models; -using Umbraco.Cms.Infrastructure.Persistence; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_1_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ConvertTinyMceAndGridMediaUrlsToLocalLink : MigrationBase { private readonly IMediaService _mediaService; @@ -22,111 +12,6 @@ public class ConvertTinyMceAndGridMediaUrlsToLocalLink : MigrationBase protected override void Migrate() { - var mediaLinkPattern = new Regex( - @"(]*href="")(\/ media[^""\?]*)([^>]*>)", - RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); - Sql sqlPropertyData = Sql() - .Select(r => r.Select(x => x.PropertyTypeDto, r1 => r1.Select(x => x!.DataTypeDto))) - .From() - .InnerJoin() - .On((left, right) => left.PropertyTypeId == right.Id) - .InnerJoin() - .On((left, right) => left.DataTypeId == right.NodeId) - .Where(x => - x.EditorAlias == Constants.PropertyEditors.Aliases.TinyMce || - x.EditorAlias == Constants.PropertyEditors.Aliases.Grid); - - List? properties = Database.Fetch(sqlPropertyData); - - var exceptions = new List(); - foreach (PropertyDataDto80? property in properties) - { - var value = property.TextValue; - if (string.IsNullOrWhiteSpace(value)) - { - continue; - } - - var propertyChanged = false; - if (property.PropertyTypeDto?.DataTypeDto?.EditorAlias == Constants.PropertyEditors.Aliases.Grid) - { - try - { - JObject? obj = JsonConvert.DeserializeObject(value); - IEnumerable? allControls = obj?.SelectTokens("$.sections..rows..areas..controls"); - - if (allControls is not null) - { - foreach (JObject control in allControls.SelectMany(c => c).OfType()) - { - JToken? controlValue = control["value"]; - if (controlValue?.Type == JTokenType.String) - { - control["value"] = UpdateMediaUrls(mediaLinkPattern, controlValue.Value()!, - out var controlChanged); - propertyChanged |= controlChanged; - } - } - } - - property.TextValue = JsonConvert.SerializeObject(obj); - } - catch (JsonException e) - { - exceptions.Add(new InvalidOperationException( - "Cannot deserialize the value as json. This can be because the property editor " + - "type is changed from another type into a grid. Old versions of the value in this " + - "property can have the structure from the old property editor type. This needs to be " + - "changed manually before updating the database.\n" + - $"Property info: Id = {property.Id}, LanguageId = {property.LanguageId}, VersionId = {property.VersionId}, Value = {property.Value}", - e)); - continue; - } - } - else - { - property.TextValue = UpdateMediaUrls(mediaLinkPattern, value, out propertyChanged); - } - - if (propertyChanged) - { - Database.Update(property); - } - } - - if (exceptions.Any()) - { - throw new AggregateException( - "One or more errors related to unexpected data in grid values occurred.", - exceptions); - } - - Context.AddPostMigration(); - } - - private string UpdateMediaUrls(Regex mediaLinkPattern, string value, out bool changed) - { - var matched = false; - - var result = mediaLinkPattern.Replace(value, match => - { - matched = true; - - // match groups: - // - 1 = from the beginning of the a tag until href attribute value begins - // - 2 = the href attribute value excluding the querystring (if present) - // - 3 = anything after group 2 until the a tag is closed - var href = match.Groups[2].Value; - - IMedia? media = _mediaService.GetMediaByPath(href); - return media == null - ? match.Value - : $"{match.Groups[1].Value}/{{localLink:{media.GetUdi()}}}{match.Groups[3].Value}"; - }); - - changed = matched; - - return result; } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/FixContentNuCascade.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/FixContentNuCascade.cs index abb4fbfea8..cd9fdc1303 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/FixContentNuCascade.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/FixContentNuCascade.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_1_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class FixContentNuCascade : MigrationBase { public FixContentNuCascade(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/RenameUserLoginDtoDateIndex.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/RenameUserLoginDtoDateIndex.cs index ac2e27b2d6..28e91c1a97 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/RenameUserLoginDtoDateIndex.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_1_0/RenameUserLoginDtoDateIndex.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_1_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class RenameUserLoginDtoDateIndex : MigrationBase { public RenameUserLoginDtoDateIndex(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddMainDomLock.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddMainDomLock.cs index bd76857ab7..1a5633213e 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddMainDomLock.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_6_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddMainDomLock : MigrationBase { public AddMainDomLock(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddNewRelationTypes.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddNewRelationTypes.cs index c2a447e778..406c02b75a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddNewRelationTypes.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddNewRelationTypes.cs @@ -6,6 +6,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_6_0; /// /// Ensures the new relation types are created /// +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddNewRelationTypes : MigrationBase { public AddNewRelationTypes(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddPropertyTypeValidationMessageColumns.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddPropertyTypeValidationMessageColumns.cs index a5aea97fc2..78807672af 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddPropertyTypeValidationMessageColumns.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/AddPropertyTypeValidationMessageColumns.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_6_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddPropertyTypeValidationMessageColumns : MigrationBase { public AddPropertyTypeValidationMessageColumns(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/MissingContentVersionsIndexes.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/MissingContentVersionsIndexes.cs index 7e7b659401..39b02bd184 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/MissingContentVersionsIndexes.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/MissingContentVersionsIndexes.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_6_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MissingContentVersionsIndexes : MigrationBase { private const string IndexName = "IX_" + ContentVersionDto.TableName + "_NodeId"; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/UpdateRelationTypeTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/UpdateRelationTypeTable.cs index 032359cfcc..a23346a55c 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/UpdateRelationTypeTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_6_0/UpdateRelationTypeTable.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Core; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_6_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UpdateRelationTypeTable : MigrationBase { public UpdateRelationTypeTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_7_0/MissingDictionaryIndex.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_7_0/MissingDictionaryIndex.cs index 1ab43c2eb7..48274438c5 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_7_0/MissingDictionaryIndex.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_7_0/MissingDictionaryIndex.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_7_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MissingDictionaryIndex : MigrationBase { public MissingDictionaryIndex(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_9_0/ExternalLoginTableUserData.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_9_0/ExternalLoginTableUserData.cs index bf21b6b928..5951b5e9b7 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_9_0/ExternalLoginTableUserData.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_9_0/ExternalLoginTableUserData.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_9_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ExternalLoginTableUserData : MigrationBase { public ExternalLoginTableUserData(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/AddPasswordConfigToMemberTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/AddPasswordConfigToMemberTable.cs index 2bf01c55bb..496b1c533f 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/AddPasswordConfigToMemberTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/AddPasswordConfigToMemberTable.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddPasswordConfigToMemberTable : MigrationBase { public AddPasswordConfigToMemberTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/DictionaryTablesIndexes.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/DictionaryTablesIndexes.cs index 3556213cd1..08016d9178 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/DictionaryTablesIndexes.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/DictionaryTablesIndexes.cs @@ -8,6 +8,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class DictionaryTablesIndexes : MigrationBase { private const string IndexedDictionaryColumn = "key"; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexes.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexes.cs index 8caa28de03..eb1b7c1b19 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexes.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexes.cs @@ -1,5 +1,6 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ExternalLoginTableIndexes : MigrationBase { public ExternalLoginTableIndexes(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs index 8c508a3d04..15175a4cc5 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs @@ -4,6 +4,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; /// Fixes up the original for post RC release to ensure that /// the correct indexes are applied. /// +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ExternalLoginTableIndexesFixup : MigrationBase { public ExternalLoginTableIndexesFixup(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTokenTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTokenTable.cs index 288dbdf23f..7e856e3a44 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTokenTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTokenTable.cs @@ -7,6 +7,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class ExternalLoginTokenTable : MigrationBase { public ExternalLoginTokenTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MemberTableColumns.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MemberTableColumns.cs index 50204e4432..32dae76da7 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MemberTableColumns.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MemberTableColumns.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MemberTableColumns : MigrationBase { public MemberTableColumns(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MigrateLogViewerQueriesFromFileToDb.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MigrateLogViewerQueriesFromFileToDb.cs index 641433cee9..b9e6123c15 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MigrateLogViewerQueriesFromFileToDb.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/MigrateLogViewerQueriesFromFileToDb.cs @@ -7,6 +7,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MigrateLogViewerQueriesFromFileToDb : MigrationBase { internal static readonly IEnumerable _defaultLogQueries = new LogViewerQueryDto[] diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/UmbracoServerColumn.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/UmbracoServerColumn.cs index c844606ab2..6ae6c0bb12 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/UmbracoServerColumn.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/UmbracoServerColumn.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UmbracoServerColumn : MigrationBase { public UmbracoServerColumn(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs deleted file mode 100644 index 7a885eca07..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_1_0; - -internal class AddContentVersionCleanupFeature : MigrationBase -{ - public AddContentVersionCleanupFeature(IMigrationContext context) - : base(context) - { - } - - /// - /// The conditionals are useful to enable the same migration to be used in multiple - /// migration paths x.x -> 8.18 and x.x -> 9.x - /// - protected override void Migrate() - { - IEnumerable tables = SqlSyntax.GetTablesInSchema(Context.Database); - if (!tables.InvariantContains(ContentVersionCleanupPolicyDto.TableName)) - { - Create.Table().Do(); - } - - IEnumerable columns = SqlSyntax.GetColumnsInSchema(Context.Database); - AddColumnIfNotExists(columns, "preventCleanup"); - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddDefaultForNotificationsToggle.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddDefaultForNotificationsToggle.cs index 9b91c0a372..2641a8304a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddDefaultForNotificationsToggle.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddDefaultForNotificationsToggle.cs @@ -4,6 +4,7 @@ using Umbraco.Cms.Infrastructure.Persistence; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_2_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddDefaultForNotificationsToggle : MigrationBase { public AddDefaultForNotificationsToggle(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddUserGroup2NodeTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddUserGroup2NodeTable.cs deleted file mode 100644 index 41abd07b23..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_2_0/AddUserGroup2NodeTable.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_2_0; - -internal class AddUserGroup2NodeTable : MigrationBase -{ - public AddUserGroup2NodeTable(IMigrationContext context) - : base(context) - { - } - - protected override void Migrate() - { - IEnumerable tables = SqlSyntax.GetTablesInSchema(Context.Database); - if (!tables.InvariantContains(UserGroup2NodeDto.TableName)) - { - Create.Table().Do(); - } - - // Insert if there exists specific permissions today. Can't do it directly in db in any nice way. - List? allData = Database.Fetch(); - UserGroup2NodeDto[] toInsert = allData - .Select(x => new UserGroup2NodeDto { NodeId = x.NodeId, UserGroupId = x.UserGroupId }).Distinct( - new DelegateEqualityComparer( - (x, y) => x?.NodeId == y?.NodeId && x?.UserGroupId == y?.UserGroupId, - x => x.NodeId.GetHashCode() + x.UserGroupId.GetHashCode())).ToArray(); - Database.InsertBulk(toInsert); - } -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/AddTwoFactorLoginTable.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/AddTwoFactorLoginTable.cs index 5e781406ae..e1d26aae73 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/AddTwoFactorLoginTable.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/AddTwoFactorLoginTable.cs @@ -3,6 +3,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_3_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class AddTwoFactorLoginTable : MigrationBase { public AddTwoFactorLoginTable(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/MovePackageXMLToDb.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/MovePackageXMLToDb.cs index a2b2b40238..4b963e7c1c 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/MovePackageXMLToDb.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/MovePackageXMLToDb.cs @@ -4,6 +4,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_3_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class MovePackageXMLToDb : MigrationBase { private readonly PackagesRepository _packagesRepository; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/UpdateExternalLoginToUseKeyInsteadOfId.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/UpdateExternalLoginToUseKeyInsteadOfId.cs index c3f42a90ab..991e201e0d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/UpdateExternalLoginToUseKeyInsteadOfId.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_3_0/UpdateExternalLoginToUseKeyInsteadOfId.cs @@ -2,6 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_3_0; +[Obsolete("This is not used anymore and will be removed in Umbraco 13")] public class UpdateExternalLoginToUseKeyInsteadOfId : MigrationBase { public UpdateExternalLoginToUseKeyInsteadOfId(IMigrationContext context) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_4_0/AddScheduledPublishingLock.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_4_0/AddScheduledPublishingLock.cs deleted file mode 100644 index 550e67879a..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_4_0/AddScheduledPublishingLock.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_4_0; - -internal class AddScheduledPublishingLock : MigrationBase -{ - public AddScheduledPublishingLock(IMigrationContext context) - : base(context) - { - } - - protected override void Migrate() => - Database.Insert(Constants.DatabaseSchema.Tables.Lock, "id", false, new LockDto { Id = Constants.Locks.ScheduledPublishing, Name = "ScheduledPublishing" }); -} diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_4_0/UpdateRelationTypesToHandleDependencies.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_4_0/UpdateRelationTypesToHandleDependencies.cs deleted file mode 100644 index 44144b93fe..0000000000 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_4_0/UpdateRelationTypesToHandleDependencies.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Umbraco.Cms.Core; -using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_4_0; - -internal class UpdateRelationTypesToHandleDependencies : MigrationBase -{ - public UpdateRelationTypesToHandleDependencies(IMigrationContext context) - : base(context) - { - } - - protected override void Migrate() - { - var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList(); - - AddColumnIfNotExists(columns, "isDependency"); - - var aliasesWithDependencies = new[] - { - Constants.Conventions.RelationTypes.RelatedDocumentAlias, - Constants.Conventions.RelationTypes.RelatedMediaAlias, - }; - - Database.Execute( - Sql() - .Update(u => u.Set(x => x.IsDependency, true)) - .WhereIn(x => x.Alias, aliasesWithDependencies)); - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs index e0140b65b3..7119dd50ff 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs @@ -29,7 +29,8 @@ namespace Umbraco.Cms.Core.PropertyEditors ValueType = ValueTypes.Json, Icon = "icon-layout", Group = Constants.PropertyEditors.Groups.RichContent, - ValueEditorIsReusable = false)] + ValueEditorIsReusable = false, + IsDeprecated = true)] public class GridPropertyEditor : DataEditor { private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs index 230c6e2b59..cf85339d48 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs @@ -21,12 +21,13 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.NestedContent, - "Nested Content", + "Nested Content (legacy)", "nestedcontent", ValueType = ValueTypes.Json, Group = Constants.PropertyEditors.Groups.Lists, Icon = "icon-thumbnail-list", - ValueEditorIsReusable = false)] + ValueEditorIsReusable = false, + IsDeprecated = true)] public class NestedContentPropertyEditor : DataEditor { public const string ContentTypeAliasPropertyKey = "ncContentTypeAlias"; diff --git a/src/Umbraco.PublishedCache.NuCache/CompatibilitySuppressions.xml b/src/Umbraco.PublishedCache.NuCache/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.PublishedCache.NuCache/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml b/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Web.Common/CompatibilitySuppressions.xml b/src/Umbraco.Web.Common/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Web.Common/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/src/Umbraco.Web.Website/CompatibilitySuppressions.xml b/src/Umbraco.Web.Website/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/src/Umbraco.Web.Website/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/tests/Umbraco.Tests.Common/CompatibilitySuppressions.xml b/tests/Umbraco.Tests.Common/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/tests/Umbraco.Tests.Common/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file diff --git a/tests/Umbraco.Tests.Integration/CompatibilitySuppressions.xml b/tests/Umbraco.Tests.Integration/CompatibilitySuppressions.xml deleted file mode 100644 index 7baad05aa0..0000000000 --- a/tests/Umbraco.Tests.Integration/CompatibilitySuppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - PKV006 - net6.0 - - \ No newline at end of file