2019-10-28 18:02:52 +11:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Composing;
|
2019-10-29 00:25:03 +11:00
|
|
|
|
using Umbraco.ModelsBuilder.Embedded;
|
2019-10-28 18:02:52 +11:00
|
|
|
|
|
|
|
|
|
|
// will install only if configuration says it needs to be installed
|
|
|
|
|
|
[assembly: PreApplicationStartMethod(typeof(LiveModelsProviderModule), "Install")]
|
|
|
|
|
|
|
2019-10-29 00:25:03 +11:00
|
|
|
|
namespace Umbraco.ModelsBuilder.Embedded
|
2019-10-28 18:02:52 +11:00
|
|
|
|
{
|
|
|
|
|
|
// have to do this because it's the only way to subscribe to EndRequest,
|
|
|
|
|
|
// module is installed by assembly attribute at the top of this file
|
|
|
|
|
|
public class LiveModelsProviderModule : IHttpModule
|
|
|
|
|
|
{
|
|
|
|
|
|
private static LiveModelsProvider _liveModelsProvider;
|
|
|
|
|
|
|
|
|
|
|
|
public void Init(HttpApplication app)
|
|
|
|
|
|
{
|
|
|
|
|
|
app.EndRequest += App_EndRequest;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void App_EndRequest(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-10-28 19:08:42 +11:00
|
|
|
|
if (((HttpApplication)sender).Request.Url.IsClientSideRequest())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2019-10-28 18:02:52 +11:00
|
|
|
|
// here we're using "Current." since we're in a module, it is possible in a round about way to inject into a module but for now we'll just use Current
|
|
|
|
|
|
if (_liveModelsProvider == null)
|
2019-10-28 19:08:42 +11:00
|
|
|
|
_liveModelsProvider = Current.Factory.TryGetInstance<LiveModelsProvider>(); // will be null in upgrade mode
|
2019-10-28 18:02:52 +11:00
|
|
|
|
|
2019-10-28 19:08:42 +11:00
|
|
|
|
if (_liveModelsProvider?.IsEnabled ?? false)
|
2019-10-28 18:02:52 +11:00
|
|
|
|
_liveModelsProvider.GenerateModelsIfRequested(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
// nothing
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void Install()
|
|
|
|
|
|
{
|
|
|
|
|
|
// always - don't read config in PreApplicationStartMethod
|
|
|
|
|
|
HttpApplication.RegisterModule(typeof(LiveModelsProviderModule));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|