V8: kill usercontrol support, cleanup macros (#4329)
This commit is contained in:
committed by
Sebastiaan Janssen
parent
74a1bb9123
commit
2036da5e84
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
@@ -36,9 +35,6 @@ namespace Umbraco.Core.IO
|
||||
|
||||
public static string Umbraco => IOHelper.ReturnPath("umbracoPath", "~/umbraco");
|
||||
|
||||
[Obsolete("Usercontrols are obsolete and code should be removed")]
|
||||
public static string UserControls => "~/usercontrols";
|
||||
|
||||
public static string Packages => Data + "/packages";
|
||||
|
||||
public static string Preview => Data + "/preview";
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
|
||||
//populate the new macroSource column with legacy data
|
||||
Execute.Sql($"UPDATE {Constants.DatabaseSchema.Tables.Macro} SET macroSource = macroXSLT, macroType = {(int)MacroTypes.Unknown} WHERE macroXSLT IS NOT NULL").Do();
|
||||
Execute.Sql($"UPDATE {Constants.DatabaseSchema.Tables.Macro} SET macroSource = macroScriptAssembly, macroType = {(int)MacroTypes.Unknown} WHERE macroScriptAssembly IS NOT NULL").Do();
|
||||
Execute.Sql($"UPDATE {Constants.DatabaseSchema.Tables.Macro} SET macroSource = macroScriptType, macroType = {(int)MacroTypes.UserControl} WHERE macroScriptType IS NOT NULL").Do();
|
||||
Execute.Sql($"UPDATE {Constants.DatabaseSchema.Tables.Macro} SET macroSource = macroScriptType, macroType = {(int)MacroTypes.Unknown} WHERE macroScriptType IS NOT NULL").Do();
|
||||
Execute.Sql($"UPDATE {Constants.DatabaseSchema.Tables.Macro} SET macroSource = macroPython, macroType = {(int)MacroTypes.PartialView} WHERE macroPython IS NOT NULL").Do();
|
||||
|
||||
//now apply constraints (NOT NULL) to new table
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace Umbraco.Core.Models
|
||||
[DataContract(IsReference = true)]
|
||||
public enum MacroTypes
|
||||
{
|
||||
[EnumMember]
|
||||
UserControl = 3,
|
||||
[EnumMember]
|
||||
Unknown = 4,
|
||||
[EnumMember]
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Umbraco.Tests.IO
|
||||
[TestFixture]
|
||||
public class IoHelperTests
|
||||
{
|
||||
|
||||
[TestCase("~/Scripts", "/Scripts", null)]
|
||||
[TestCase("/Scripts", "/Scripts", null)]
|
||||
[TestCase("../Scripts", "/Scripts", typeof(ArgumentException))]
|
||||
@@ -42,8 +41,7 @@ namespace Umbraco.Tests.IO
|
||||
Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Preview, true), IOHelper.MapPath(SystemDirectories.Preview, false));
|
||||
Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Root, true), IOHelper.MapPath(SystemDirectories.Root, false));
|
||||
Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Scripts, true), IOHelper.MapPath(SystemDirectories.Scripts, false));
|
||||
Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Umbraco, true), IOHelper.MapPath(SystemDirectories.Umbraco, false));
|
||||
Assert.AreEqual(IOHelper.MapPath(SystemDirectories.UserControls, true), IOHelper.MapPath(SystemDirectories.UserControls, false));
|
||||
Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Umbraco, true), IOHelper.MapPath(SystemDirectories.Umbraco, false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Macros;
|
||||
@@ -32,47 +27,7 @@ namespace Umbraco.Tests.Macros
|
||||
Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings);
|
||||
}
|
||||
|
||||
[TestCase("123", "IntProp", typeof(int))]
|
||||
[TestCase("Hello", "StringProp", typeof(string))]
|
||||
[TestCase("123456789.01", "DoubleProp", typeof(double))]
|
||||
[TestCase("1234567", "FloatProp", typeof(float))]
|
||||
[TestCase("1", "BoolProp", typeof(bool))]
|
||||
[TestCase("true", "BoolProp", typeof(bool))]
|
||||
[TestCase("0", "BoolProp", typeof(bool))]
|
||||
[TestCase("false", "BoolProp", typeof(bool))]
|
||||
[TestCase("2001-05-10", "DateProp", typeof(DateTime))]
|
||||
[TestCase("123px", "UnitProp", typeof(Unit))]
|
||||
[TestCase("456pt", "UnitProp", typeof(Unit))]
|
||||
[TestCase("CEC063D3-D73E-4B7D-93ED-7F69CA9BF2D0", "GuidProp", typeof(Guid))]
|
||||
[TestCase("CEC063D3D73E4B7D93ED7F69CA9BF2D0", "GuidProp", typeof(Guid))]
|
||||
[TestCase("", "NullDateProp", typeof(DateTime?))]
|
||||
[TestCase("2001-05-10", "NullDateProp", typeof(DateTime?))]
|
||||
[TestCase("", "NullUnitProp", typeof(Unit?))]
|
||||
[TestCase("456pt", "NullUnitProp", typeof(Unit?))]
|
||||
public void SetUserControlProperty(string val, string macroPropName, Type convertTo)
|
||||
{
|
||||
var ctrl = new UserControlTest();
|
||||
var macroModel = new MacroModel
|
||||
{
|
||||
Name = "test",
|
||||
Alias = "test",
|
||||
MacroSource = "~/usercontrols/menu.ascx"
|
||||
};
|
||||
macroModel.Properties.Add(new MacroPropertyModel(macroPropName, val));
|
||||
|
||||
UserControlMacroEngine.UpdateControlProperties(ctrl, macroModel);
|
||||
|
||||
var ctrlType = ctrl.GetType();
|
||||
var prop = ctrlType.GetProperty(macroPropName);
|
||||
var converted = val.TryConvertTo(convertTo);
|
||||
|
||||
Assert.IsTrue(converted.Success);
|
||||
Assert.NotNull(prop);
|
||||
Assert.AreEqual(converted.Result, prop.GetValue(ctrl));
|
||||
}
|
||||
|
||||
[TestCase("PartialView", true)]
|
||||
[TestCase("UserControl", true)]
|
||||
[TestCase("Unknown", false)]
|
||||
public void Macro_Is_File_Based(string macroTypeString, bool expectedNonNull)
|
||||
{
|
||||
@@ -102,19 +57,5 @@ namespace Umbraco.Tests.Macros
|
||||
{
|
||||
//var asdf = macro.GetCacheIdentifier()
|
||||
}
|
||||
|
||||
private class UserControlTest : UserControl
|
||||
{
|
||||
public int IntProp { get; set; }
|
||||
public string StringProp { get; set; }
|
||||
public double DoubleProp { get; set; }
|
||||
public float FloatProp { get; set; }
|
||||
public bool BoolProp { get; set; }
|
||||
public DateTime DateProp { get; set; }
|
||||
public Unit UnitProp { get; set; }
|
||||
public Guid GuidProp { get; set; }
|
||||
public DateTime? NullDateProp { get; set; }
|
||||
public Unit? NullUnitProp { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ function macroService() {
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.macroService#generateWebFormsSyntax
|
||||
* @name umbraco.services.macroService#generateMacroSyntax
|
||||
* @methodOf umbraco.services.macroService
|
||||
* @function
|
||||
*
|
||||
@@ -82,35 +82,6 @@ function macroService() {
|
||||
|
||||
return macroString;
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.macroService#generateWebFormsSyntax
|
||||
* @methodOf umbraco.services.macroService
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* generates the syntax for inserting a macro into a webforms templates
|
||||
*
|
||||
* @param {object} args an object containing the macro alias and it's parameter values
|
||||
*/
|
||||
generateWebFormsSyntax: function(args) {
|
||||
|
||||
var macroString = '<umbraco:Macro ';
|
||||
|
||||
if (args.macroParamsDictionary) {
|
||||
|
||||
_.each(args.macroParamsDictionary, function (val, key) {
|
||||
var keyVal = key + "=\"" + (val ? val : "") + "\" ";
|
||||
macroString += keyVal;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
macroString += "Alias=\"" + args.macroAlias + "\" runat=\"server\"></umbraco:Macro>";
|
||||
|
||||
return macroString;
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
@@ -180,10 +151,7 @@ function macroService() {
|
||||
});
|
||||
|
||||
//get the syntax based on the rendering engine
|
||||
if (renderingEngine && renderingEngine === "WebForms") {
|
||||
syntax = this.generateWebFormsSyntax({ macroAlias: macroAlias, macroParamsDictionary: paramDictionary });
|
||||
}
|
||||
else if (renderingEngine && renderingEngine === "Mvc") {
|
||||
if (renderingEngine && renderingEngine === "Mvc") {
|
||||
syntax = this.generateMvcSyntax({ macroAlias: macroAlias, macroParamsDictionary: paramDictionary });
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -108,34 +108,6 @@ describe('macro service tests', function () {
|
||||
toBe("<?UMBRACO_MACRO macroAlias=\"myMacro\" />");
|
||||
|
||||
});
|
||||
|
||||
it('can generate syntax for webforms', function () {
|
||||
|
||||
var syntax = macroService.generateWebFormsSyntax({
|
||||
macroAlias: "myMacro",
|
||||
macroParamsDictionary: {
|
||||
param1: "value1",
|
||||
param2: "value2",
|
||||
param3: "value3"
|
||||
}
|
||||
});
|
||||
|
||||
expect(syntax).
|
||||
toBe("<umbraco:Macro param1=\"value1\" param2=\"value2\" param3=\"value3\" Alias=\"myMacro\" runat=\"server\"></umbraco:Macro>");
|
||||
|
||||
});
|
||||
|
||||
it('can generate syntax for webforms with no params', function () {
|
||||
|
||||
var syntax = macroService.generateWebFormsSyntax({
|
||||
macroAlias: "myMacro",
|
||||
macroParamsDictionary: {}
|
||||
});
|
||||
|
||||
expect(syntax).
|
||||
toBe("<umbraco:Macro Alias=\"myMacro\" runat=\"server\"></umbraco:Macro>");
|
||||
|
||||
});
|
||||
|
||||
it('can generate syntax for MVC', function () {
|
||||
|
||||
@@ -167,4 +139,4 @@ describe('macro service tests', function () {
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -544,7 +544,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Please fill both alias and name on the new property type!</key>
|
||||
<key alias="filePermissionsError">There is a problem with read/write access to a specific file or folder</key>
|
||||
<key alias="macroErrorLoadingPartialView">Error loading Partial View script (file: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Error loading userControl '%0%'</key>
|
||||
<key alias="missingTitle">Please enter a title</key>
|
||||
<key alias="missingType">Please choose a type</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">You're about to make the picture larger than the original size. Are you sure that you want to proceed?</key>
|
||||
|
||||
@@ -548,7 +548,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Please fill both alias and name on the new property type!</key>
|
||||
<key alias="filePermissionsError">There is a problem with read/write access to a specific file or folder</key>
|
||||
<key alias="macroErrorLoadingPartialView">Error loading Partial View script (file: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Error loading userControl '%0%'</key>
|
||||
<key alias="missingTitle">Please enter a title</key>
|
||||
<key alias="missingType">Please choose a type</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">You're about to make the picture larger than the original size. Are you sure that you want to proceed?</key>
|
||||
|
||||
@@ -451,7 +451,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Debes rellenar el alias y el nombre en el tipo de propiedad</key>
|
||||
<key alias="filePermissionsError">Hay un problema de lectura y escritura al acceder a un archivo o carpeta</key>
|
||||
<key alias="macroErrorLoadingPartialView">Error cargando Vista Parcial (archivo: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Error cargando userControl '%0%'</key>
|
||||
<key alias="missingTitle"><![CDATA[Por favor, introduzca un título
|
||||
]]></key>
|
||||
<key alias="missingType">Por favor, elige un tipo </key>
|
||||
|
||||
@@ -464,7 +464,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Veuillez remplir l'alias et le nom de la nouvelle propriété!</key>
|
||||
<key alias="filePermissionsError">Il y a un problème de droits en lecture/écriture sur un fichier ou dossier spécifique</key>
|
||||
<key alias="macroErrorLoadingPartialView">Erreur de chargement du script d'une Partial View (fichier : %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Erreur de chargement du userControl '%0%'</key>
|
||||
<key alias="missingTitle">Veuillez entrer un titre</key>
|
||||
<key alias="missingType">Veuillez choisir un type</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">Vous allez définir une taille d'image supérieure à sa taille d'origine. Êtes-vous certain(e) de vouloir continuer?</key>
|
||||
|
||||
@@ -344,7 +344,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">新しいプロパティ型のエイリアスと名前の両方を設定してください!</key>
|
||||
<key alias="filePermissionsError">特定のファイルまたはフォルタの読み込み/書き込みアクセスに問題があります</key>
|
||||
<key alias="macroErrorLoadingPartialView">Partial View スクリプトの読み込みエラー (ファイル: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">userControl の読み込みエラー '%0%'</key>
|
||||
<key alias="missingTitle">タイトルを入力してください</key>
|
||||
<key alias="missingType">型を選択してください</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">元画像より大きくしようとしていますが、本当によろしいのですか?</key>
|
||||
|
||||
@@ -376,7 +376,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Zowel de alias als de naam van het nieuwe eigenschappentype moeten worden ingevuld!</key>
|
||||
<key alias="filePermissionsError">Er is een probleem met de lees/schrijfrechten op een bestand of map</key>
|
||||
<key alias="macroErrorLoadingPartialView">Error bij het laden van Partial View script (file: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Error bij het laden van userControl '%0%'</key>
|
||||
<key alias="missingTitle">Vul een titel in</key>
|
||||
<key alias="missingType">Selecteer een type</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">U wilt een afbeelding groter maken dan de originele afmetingen. Weet je zeker dat je wilt doorgaan?</key>
|
||||
|
||||
@@ -446,7 +446,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Proszę uzupełnij zarówno alias, jak i nazwę dla nowego typu właściwości</key>
|
||||
<key alias="filePermissionsError">Wystąpił problem podczas zapisu/odczytu wymaganego pliku lub folderu</key>
|
||||
<key alias="macroErrorLoadingPartialView">Wystąpił błąd podczas ładowania skryptu Częściowego Widoku (plik: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Wystąpił błąd podczas ładowania userControl '%0%'</key>
|
||||
<key alias="missingTitle">Proszę podać tytuł</key>
|
||||
<key alias="missingType">Proszę wybrać typ</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">Chcesz utworzyć obraz większy niż rozmiar oryginalny. Czy na pewno chcesz kontynuować?</key>
|
||||
|
||||
@@ -483,7 +483,6 @@
|
||||
<key alias="dissallowedMediaType">Использование данного типа файлов на сайте запрещено администратором</key>
|
||||
<key alias="filePermissionsError">Ошибка доступа к указанному файлу или папке</key>
|
||||
<key alias="macroErrorLoadingPartialView">Ошибка загрузки кода в частичном представлении (файл: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Ошибка загрузки пользовательского элемента управления '%0%'</key>
|
||||
<key alias="missingTitle">Укажите заголовок</key>
|
||||
<key alias="missingType">Выберите тип</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">Вы пытаетесь увеличить изображение по сравнению с его исходным размером. Уверены, что хотите сделать это?</key>
|
||||
|
||||
@@ -286,7 +286,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">Yeni özellik tipine takma adını ve hem de doldurunuz!</key>
|
||||
<key alias="filePermissionsError">Belirli bir dosya veya klasör için okuma / yazma erişimi olan bir sorun var</key>
|
||||
<key alias="macroErrorLoadingPartialView">Error loading Partial View script (Dosya: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">Error loading userControl '%0%'</key>
|
||||
<key alias="missingTitle">Lütfen bir başlık girin</key>
|
||||
<key alias="missingType">Lütfen bir tür seçin</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">Orijinal boyutundan daha resmi büyütmek üzereyiz. Devam etmek istediğinizden emin misiniz?</key>
|
||||
|
||||
@@ -364,7 +364,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">请为新的属性类型填写名称和别名!</key>
|
||||
<key alias="filePermissionsError">权限有问题,访问指定文件或文件夹失败!</key>
|
||||
<key alias="macroErrorLoadingPartialView">加载Partial视图脚本时出错(文件: %0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">加载 userControl 时出错 '%0%'</key>
|
||||
<key alias="missingTitle">请输入标题</key>
|
||||
<key alias="missingType">请选择类型</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">图片尺寸大于原始尺寸不会提高图片质量,您确定要把图片尺寸变大吗?</key>
|
||||
|
||||
@@ -357,7 +357,6 @@
|
||||
<key alias="contentTypeAliasAndNameNotNull">請為新的屬性類型填寫名稱和別名!</key>
|
||||
<key alias="filePermissionsError">許可權有問題,訪問指定文檔或資料夾失敗!</key>
|
||||
<key alias="macroErrorLoadingPartialView">讀取片段視圖腳本錯誤(檔案:%0%)</key>
|
||||
<key alias="macroErrorLoadingUsercontrol">讀取使用者控制項 %0% 錯誤</key>
|
||||
<key alias="missingTitle">請輸入標題</key>
|
||||
<key alias="missingType">請選擇類型</key>
|
||||
<key alias="pictureResizeBiggerThanOrg">圖片尺寸大於原始尺寸不會提高圖片品質,您確定要把圖片尺寸變大嗎?</key>
|
||||
|
||||
@@ -68,7 +68,6 @@ namespace Umbraco.Web.HealthCheck.Checks.Permissions
|
||||
{ SystemDirectories.Media, PermissionCheckRequirement.Optional },
|
||||
{ SystemDirectories.Scripts, PermissionCheckRequirement.Optional },
|
||||
{ SystemDirectories.Umbraco, PermissionCheckRequirement.Optional },
|
||||
{ SystemDirectories.UserControls, PermissionCheckRequirement.Optional },
|
||||
{ SystemDirectories.MvcViews, PermissionCheckRequirement.Optional }
|
||||
};
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace Umbraco.Web.Install
|
||||
internal class FilePermissionHelper
|
||||
{
|
||||
// ensure that these directories exist and Umbraco can write to them
|
||||
private static readonly string[] PermissionDirs = { SystemDirectories.Css, SystemDirectories.Config, SystemDirectories.Data, SystemDirectories.Media, SystemDirectories.UserControls, SystemDirectories.Preview };
|
||||
private static readonly string[] PackagesPermissionsDirs = { SystemDirectories.Bin, SystemDirectories.Umbraco, SystemDirectories.UserControls, SystemDirectories.Packages };
|
||||
private static readonly string[] PermissionDirs = { SystemDirectories.Css, SystemDirectories.Config, SystemDirectories.Data, SystemDirectories.Media, SystemDirectories.Preview };
|
||||
private static readonly string[] PackagesPermissionsDirs = { SystemDirectories.Bin, SystemDirectories.Umbraco, SystemDirectories.Packages };
|
||||
|
||||
// ensure Umbraco can write to these files (the directories must exist)
|
||||
private static readonly string[] PermissionFiles = { };
|
||||
|
||||
@@ -11,7 +11,6 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
@@ -171,8 +170,7 @@ namespace Umbraco.Web.Macros
|
||||
switch (model.MacroType)
|
||||
{
|
||||
case MacroTypes.PartialView:
|
||||
case MacroTypes.UserControl:
|
||||
filename = model.MacroSource; //user controls & partial views are saved with their full virtual path
|
||||
filename = model.MacroSource; // partial views are saved with their full virtual path
|
||||
break;
|
||||
default:
|
||||
// not file-based, or not supported
|
||||
@@ -363,14 +361,6 @@ namespace Umbraco.Web.Macros
|
||||
() => ExecutePartialView(model),
|
||||
() => textService.Localize("errors/macroErrorLoadingPartialView", new[] { model.MacroSource }));
|
||||
|
||||
case MacroTypes.UserControl:
|
||||
return ExecuteMacroWithErrorWrapper(model,
|
||||
$"Loading UserControl: MacroSource=\"{model.MacroSource}\".",
|
||||
"Loaded UserControl.",
|
||||
() => ExecuteUserControl(model),
|
||||
() => textService.Localize("errors/macroErrorLoadingUsercontrol", new[] { model.MacroSource }));
|
||||
|
||||
//case MacroTypes.Script:
|
||||
default:
|
||||
return ExecuteMacroWithErrorWrapper(model,
|
||||
$"Execute macro with unsupported type \"{model.MacroType}\".",
|
||||
@@ -411,17 +401,6 @@ namespace Umbraco.Web.Macros
|
||||
return engine.Execute(macro, content);
|
||||
}
|
||||
|
||||
public static MacroContent ExecuteUserControl(MacroModel macro)
|
||||
{
|
||||
// add tilde for v4 defined macros
|
||||
if (string.IsNullOrEmpty(macro.MacroSource) == false
|
||||
&& macro.MacroSource.StartsWith("~") == false)
|
||||
macro.MacroSource = "~/" + macro.MacroSource;
|
||||
|
||||
var engine = new UserControlMacroEngine();
|
||||
return engine.Execute(macro);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Execution helpers
|
||||
|
||||
@@ -162,8 +162,6 @@ namespace Umbraco.Web.Macros
|
||||
while (!stop)
|
||||
{
|
||||
var tagIndex = fieldResult.ToString().ToLower().IndexOf("<?umbraco");
|
||||
if (tagIndex < 0)
|
||||
tagIndex = fieldResult.ToString().ToLower().IndexOf("<umbraco:macro");
|
||||
if (tagIndex > -1)
|
||||
{
|
||||
var tempElementContent = "";
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace Umbraco.Web.Macros
|
||||
{
|
||||
class UserControlMacroEngine
|
||||
{
|
||||
public MacroContent Execute(MacroModel model)
|
||||
{
|
||||
var filename = model.MacroSource;
|
||||
|
||||
// ensure the file exists
|
||||
var path = IOHelper.FindFile(filename);
|
||||
if (File.Exists(IOHelper.MapPath(path)) == false)
|
||||
throw new Exception($"Failed to load control, file {filename} does not exist.");
|
||||
|
||||
// load the control
|
||||
var control = (UserControl)new UserControl().LoadControl(path);
|
||||
control.ID = string.IsNullOrEmpty(model.MacroControlIdentifier)
|
||||
? GetControlUniqueId(filename)
|
||||
: model.MacroControlIdentifier;
|
||||
|
||||
// initialize the control
|
||||
// note: we are not setting the 'CurrentNode' property on the control anymore,
|
||||
// as that was an INode which is gone in v8. Use UmbracoContext to access the
|
||||
// current content.
|
||||
Current.Logger.Info<UserControlMacroEngine>("Loaded control '{UserControlFile}' with ID '{UserControlId}'", filename, control.ID);
|
||||
UpdateControlProperties(control, model);
|
||||
|
||||
return new MacroContent { Control = control };
|
||||
}
|
||||
|
||||
private static string GetControlUniqueId(string filename)
|
||||
{
|
||||
const string key = "MacroControlUniqueId";
|
||||
|
||||
var x = 0;
|
||||
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
if (HttpContext.Current.Items.Contains(key))
|
||||
x = (int)HttpContext.Current.Items[key];
|
||||
x += 1;
|
||||
HttpContext.Current.Items[key] = x;
|
||||
}
|
||||
|
||||
return $"{Path.GetFileNameWithoutExtension(filename)}_{x}";
|
||||
}
|
||||
|
||||
// set the control properties according to the model properties ie parameters
|
||||
internal static void UpdateControlProperties(Control control, MacroModel model)
|
||||
{
|
||||
var type = control.GetType();
|
||||
|
||||
foreach (var modelProperty in model.Properties)
|
||||
{
|
||||
var controlProperty = type.GetProperty(modelProperty.Key);
|
||||
if (controlProperty == null)
|
||||
{
|
||||
Current.Logger.Warn<UserControlMacroEngine>("Control property '{UserControlProperty}' doesn't exist or isn't accessible, skip.", modelProperty.Key);
|
||||
continue;
|
||||
}
|
||||
|
||||
var tryConvert = modelProperty.Value.TryConvertTo(controlProperty.PropertyType);
|
||||
if (tryConvert.Success)
|
||||
{
|
||||
try
|
||||
{
|
||||
controlProperty.SetValue(control, tryConvert.Result, null);
|
||||
Current.Logger.Debug<UserControlMacroEngine>("Set property '{UserControlProperty}' value '{UserControlPropertyValue}'", modelProperty.Key, modelProperty.Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Current.Logger.Warn<UserControlMacroEngine>(e, "Failed to set property '{UserControlProperty}' value '{UserControlPropertyValue}'", modelProperty.Key, modelProperty.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Current.Logger.Warn<UserControlMacroEngine>("Failed to set property '{UserControlProperty}' value '{UserControlPropertyValue}'", modelProperty.Key, modelProperty.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -386,11 +386,8 @@ namespace Umbraco.Web.Mvc
|
||||
|
||||
var handler = GetHandlerOnMissingTemplate(request);
|
||||
|
||||
// if it's not null it can be either the PublishedContentNotFoundHandler (no document was
|
||||
// found to handle 404, or document with no template was found) or the WebForms handler
|
||||
// (a document was found and its template is WebForms)
|
||||
|
||||
// if it's null it means that a document was found and its template is Mvc
|
||||
// if it's not null it's the PublishedContentNotFoundHandler (no document was found to handle 404, or document with no template was found)
|
||||
// if it's null it means that a document was found
|
||||
|
||||
// if we have a handler, return now
|
||||
if (handler != null)
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
@@ -80,27 +78,6 @@ namespace Umbraco.Web.Mvc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When POSTing to MVC but rendering in WebForms we need to do some trickery, we'll create a dummy viewcontext with all of the
|
||||
/// current model state, tempdata, viewdata so that if we're rendering partial view macros within the webforms view, they will
|
||||
/// get all of this merged into them.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
private static void EnsureViewContextForWebForms(ControllerContext context)
|
||||
{
|
||||
var tempDataDictionary = new TempDataDictionary();
|
||||
tempDataDictionary.Save(context, new SessionStateTempDataProvider());
|
||||
var viewCtx = new ViewContext(context, new DummyView(), new ViewDataDictionary(), tempDataDictionary, new StringWriter());
|
||||
|
||||
viewCtx.ViewData.ModelState.Merge(new ModelStateDictionary(context.Controller.ViewData.ModelState));
|
||||
|
||||
foreach (var d in context.Controller.ViewData)
|
||||
viewCtx.ViewData[d.Key] = d.Value;
|
||||
|
||||
//now we need to add it to the special route tokens so it's picked up later
|
||||
context.HttpContext.Request.RequestContext.RouteData.DataTokens[Constants.DataTokenCurrentViewContext] = viewCtx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure ModelState, ViewData and TempData is copied across
|
||||
/// </summary>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
@@ -10,7 +9,6 @@ using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Macros;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
@@ -21,7 +19,7 @@ namespace Umbraco.Web.Templates
|
||||
/// This is used purely for the RenderTemplate functionality in Umbraco
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This allows you to render either an MVC or Webforms template based purely off of a node id and an optional alttemplate id as string output.
|
||||
/// This allows you to render an MVC template based purely off of a node id and an optional alttemplate id as string output.
|
||||
/// </remarks>
|
||||
internal class TemplateRenderer
|
||||
{
|
||||
|
||||
@@ -341,7 +341,6 @@
|
||||
<Compile Include="HealthCheck\HealthCheckController.cs" />
|
||||
<Compile Include="Macros\MacroPropertyModel.cs" />
|
||||
<Compile Include="Macros\MacroRenderer.cs" />
|
||||
<Compile Include="Macros\UserControlMacroEngine.cs" />
|
||||
<Compile Include="HealthCheck\HealthCheckGroup.cs" />
|
||||
<Compile Include="HealthCheck\HealthCheck.cs" />
|
||||
<Compile Include="HealthCheck\HealthCheckStatus.cs" />
|
||||
|
||||
Reference in New Issue
Block a user