Пример #1
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);
                }
            }
        }
Пример #2
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);
            }
        }