diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/TypeModelHasher.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/TypeModelHasher.cs index 2f14bec875..ecc0f80331 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/TypeModelHasher.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/TypeModelHasher.cs @@ -1,5 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; +using System.Text; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -7,38 +10,53 @@ namespace Umbraco.ModelsBuilder.Embedded.Building { public static string Hash(IEnumerable typeModels) { - var hash = new HashCombiner(); + var builder = new StringBuilder(); // see Umbraco.ModelsBuilder.Umbraco.Application for what's important to hash // ie what comes from Umbraco (not computed by ModelsBuilder) and makes a difference foreach (var typeModel in typeModels.OrderBy(x => x.Alias)) { - hash.Add("--- CONTENT TYPE MODEL ---"); - hash.Add(typeModel.Id); - hash.Add(typeModel.Alias); - hash.Add(typeModel.ClrName); - hash.Add(typeModel.ParentId); - hash.Add(typeModel.Name); - hash.Add(typeModel.Description); - hash.Add(typeModel.ItemType.ToString()); - hash.Add("MIXINS:" + string.Join(",", typeModel.MixinTypes.OrderBy(x => x.Id).Select(x => x.Id))); + builder.Append("--- CONTENT TYPE MODEL ---"); + builder.Append(typeModel.Id); + builder.Append(typeModel.Alias); + builder.Append(typeModel.ClrName); + builder.Append(typeModel.ParentId); + builder.Append(typeModel.Name); + builder.Append(typeModel.Description); + builder.Append(typeModel.ItemType.ToString()); + builder.Append("MIXINS:" + string.Join(",", typeModel.MixinTypes.OrderBy(x => x.Id).Select(x => x.Id))); foreach (var prop in typeModel.Properties.OrderBy(x => x.Alias)) { - hash.Add("--- PROPERTY ---"); - hash.Add(prop.Alias); - hash.Add(prop.ClrName); - hash.Add(prop.Name); - hash.Add(prop.Description); - hash.Add(prop.ModelClrType.ToString()); // see ModelType tests, want ToString() not FullName + builder.Append("--- PROPERTY ---"); + builder.Append(prop.Alias); + builder.Append(prop.ClrName); + builder.Append(prop.Name); + builder.Append(prop.Description); + builder.Append(prop.ModelClrType.ToString()); // see ModelType tests, want ToString() not FullName } } // Include the MB version in the hash so that if the MB version changes, models are rebuilt - hash.Add(ApiVersion.Current.Version.ToString()); + builder.Append(ApiVersion.Current.Version.ToString()); - return hash.GetCombinedHashCode(); + return GenerateHash(builder.ToString()); + } + + private static string GenerateHash(string input) + { + using (var md5 = MD5.Create()) + { + var hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(input)); + var builder = new StringBuilder(); + foreach(var b in hashBytes) + { + builder.Append(b.ToString("X")); + } + + return builder.ToString(); + } } } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index f3f754e675..7e3431baf4 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -397,6 +397,7 @@ namespace Umbraco.ModelsBuilder.Embedded // directory, and then we end up referencing a dll which is *not* in that // directory, and BuildManager fails to instantiate views ("the view found // at ... was not created"). + // TODO: Since we use Roslyn Compiler now, instead of BuildManager this shouldn't matter anymore?? // if (File.Exists(dllPathFile)) { @@ -405,7 +406,7 @@ namespace Umbraco.ModelsBuilder.Embedded _logger.Debug($"Cached models dll at {dllPath}."); - if (File.Exists(dllPath) && !File.Exists(dllPath + ".delete") && dllPath.StartsWith(codegen)) + if (File.Exists(dllPath) && !File.Exists(dllPath + ".delete") /*&& dllPath.StartsWith(codegen)*/) { assembly = Assembly.LoadFile(dllPath); var attr = assembly.GetCustomAttribute();