Example #1
0
        /// <summary>
        /// Indictes where to render a template section in the page template.
        /// </summary>
        /// <param name="sectionName">The name of the page template section. This must be unique in a page template.</param>
        /// <returns>PageTemplateSectionTagOutput to allow for method chaining.</returns>
        public IPageTemplateSectionTagBuilder Section(string sectionName)
        {
            var factory = IckyDependencyResolution.ResolveFromMvcContext <IPageTemplateSectionTagBuilderFactory>();
            var output  = factory.Create(HtmlHelper, Model, sectionName);

            return(output);
        }
Example #2
0
        /// <summary>
        /// Registers Cofoundry into the Owin pipeline and runs all the registered
        /// Cofoundry StartupTasks. You must install and register a Cofoundry DI Integration
        /// nuget package before calling this method (e.g. app.UseCofoundryAutoFacIntegration())
        /// </summary>
        /// <param name="app">Owin AppBuilder</param>
        /// <param name="configBuilder">Additional configuration options</param>
        public static void UseCofoundry(this IAppBuilder app, Action <CofoundryStartupConfiguration> configBuilder = null)
        {
            var configuration = new CofoundryStartupConfiguration();

            if (configBuilder != null)
            {
                configBuilder(configuration);
            }

            // We're not in a request scope here so open and close our own scope to tidy up resources
            using (var childContext = IckyDependencyResolution.CreateNewChildContextFromRoot())
            {
                // Use the fullname secondry ordering here to get predicatable task ordering
                IEnumerable <IStartupTask> startupTasks = childContext
                                                          .ResolveAll <IStartupTask>()
                                                          .OrderBy(i => i.Ordering)
                                                          .ThenBy(i => i.GetType().FullName);

                if (configuration.StartupTaskFilter != null)
                {
                    startupTasks = configuration.StartupTaskFilter(startupTasks);
                }

                foreach (var startupTask in startupTasks)
                {
                    startupTask.Run(app);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Indictes where to render a section in a custom entity details page template.
        /// </summary>
        /// <typeparam name="TModel">Custom entity display model type.</typeparam>
        /// <param name="helper">IPageTemplateHelper to extend.</param>
        /// <param name="sectionName">The name of the section. This must be unique in a page template.</param>
        /// <returns>ICustomEntityTemplateSectionTagBuilder to allow for method chaining.</returns>
        public static ICustomEntityTemplateSectionTagBuilder <TModel> CustomEntitySection <TModel>(
            this IPageTemplateHelper <ICustomEntityDetailsPageViewModel <TModel> > helper, string sectionName)
            where TModel : ICustomEntityDetailsDisplayViewModel
        {
            var factory = IckyDependencyResolution.ResolveFromMvcContext <ICustomEntityTemplateSectionTagBuilderFactory>();
            var output  = factory.Create(helper.HtmlHelper, helper.Model, sectionName);

            return(output);
        }
Example #4
0
 public CofoundryPageHelper(HtmlHelper htmlHelper)
 {
     // DI because mvc framework doesn't support injection yet
     Routing     = IckyDependencyResolution.ResolveFromMvcContext <IContentRouteLibrary>();
     Settings    = IckyDependencyResolution.ResolveFromMvcContext <ISettingsViewHelper>();
     CurrentUser = IckyDependencyResolution.ResolveFromMvcContext <ICurrentUserViewHelper>();
     Js          = IckyDependencyResolution.ResolveFromMvcContext <IJavascriptViewHelper>();;
     Sanitizer   = IckyDependencyResolution.ResolveFromMvcContext <IHtmlSanitizerHelper>();;
     Html        = IckyDependencyResolution.ResolveFromMvcContext <ICofoundryHtmlHelper>();;
     UI          = new UIViewHelper(htmlHelper);
 }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            // No constructor injection available on filters
            var optimizationSettings = IckyDependencyResolution.ResolveFromMvcContext <OptimizationSettings>();

            if (optimizationSettings.RemoveWhitespaceFromHtml)
            {
                // Only remove white space for HTML documents
                var response = filterContext.HttpContext.Response;
                if (response.ContentType == "text/html" && response.Filter != null && !filterContext.IsChildAction)
                {
                    response.Filter = new WhitespaceStream(response.Filter);
                }
            }
        }
Example #6
0
        public async override Task Invoke(IOwinContext cx)
        {
            bool runUpdate = false;

            if (_updateStatus == UpdateStatus.NotStarted)
            {
                lock (_updateStatusLock)
                {
                    if (_updateStatus == UpdateStatus.NotStarted)
                    {
                        _updateStatus = UpdateStatus.InProgress;
                        runUpdate     = true;
                    }
                }

                if (runUpdate)
                {
                    try
                    {
                        using (var cs = IckyDependencyResolution.CreateNewChildContextFromRoot())
                        {
                            var service = cs.Resolve <IAutoUpdateService>();
                            await service.UpdateAsync();
                        }
                        _updateStatus = UpdateStatus.Complete;
                    }
                    catch (Exception ex)
                    {
                        _updateStatus = UpdateStatus.NotStarted;
                        throw;
                    }
                }
            }

            if (_updateStatus == UpdateStatus.InProgress)
            {
                cx.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                await cx.Response.WriteAsync("The application is being updated. Please try again shortly.");
            }
            else
            {
                await Next.Invoke(cx);
            }
        }
Example #7
0
        private void LogException(Exception ex)
        {
            var errorLogginService = IckyDependencyResolution.ResolveFromMvcContext <IErrorLoggingService>();

            errorLogginService.Log(ex);
        }