private static void ConfigureServices(Container container)
        {
            container.Register<ISchedulerAccessor>(new SchedulerAccessor(DispatcherScheduler.Instance, Scheduler.ThreadPool));

            var log = new ThreadSafeLoggingService(Logging.ApplicationLogName);

            container.Register<ILog>(log);
            container.Register<ILogManager>(log);

            #if DEBUG_256_DEVICE
            container.Register<IDeviceInformationService>(c => new LowEndDeviceInformationService());
            #endif

            container.Register<IPeriodicJobUpdateService>(l => new PeriodicJobUpdateService(
                l.Resolve<IJobUpdateService>(),
                l.Resolve<ISchedulerAccessor>().Background,
                l.Resolve<IScheduledActionServiceFacade>(),
                l.Resolve<IDeviceInformationService>()
                ));

            container.Register<INavigationService>(l =>
                new PhoneApplicationFrameNavigationService(l.Resolve<PhoneApplicationFrame>()));

            container.Register<ITileImageGenerator>(c => new TileImageGenerator(
                c.Resolve<IApplicationResourceFacade>()));

            container.Register<ISettingsApplier>(c => new SettingsApplier(
                c.Resolve<ILogManager>(),
                c.Resolve<IJobUpdateService>(),
                c.Resolve<IPeriodicJobUpdateService>(),
                c.Resolve<IClock>(),
                c.Resolve<IApplicationResourceFacade>(),
                c.Resolve<IPhoneApplicationServiceFacade>(),
                c.Resolve<ITileImageGenerator>(),
                c.Resolve<IIsolatedStorageFacade>(),
                c.Resolve<ILog>()));

            container.Register<Bootstrap>(l => new Bootstrap(
                l.Resolve<IApplicationSettings>(),
                l.Resolve<IClock>(),
                l.Resolve<IMessageBoxFacade>(),
                l.Resolve<IMutexService>(),
                l.Resolve<ILogManager>(),
                l.Resolve<ISettingsApplier>(),
                l.Resolve<IJobRepository>(),
                l.Resolve<IPeriodicJobUpdateService>(),
                l.Resolve<IApplicationInformation>()));

            container.Register<IThemeCssGenerator>(c => new PhoneThemeCssGenerator(
                c.Resolve<IApplicationResourceFacade>()
                ));

            container.Register<IHelpService>(c => new HelpService(
                c.Resolve<IIsolatedStorageFacade>(),
                c.Resolve<IApplicationResourceFacade>(),
                c.Resolve<IThemeCssGenerator>()
                ));

            container.Register<IApplicationMarketplaceFacade>(c => new ApplicationMarketplaceFacade(
                c.Resolve<IApplicationInformation>()
                ));

            container.Register<IShellTileService>(c => new UpdatingShellTileService());

            container.Register<IJobController>(c => new JobController(
                c.Resolve<IJobRepository>(),
                c.Resolve<IJobProviderFactory>(),
                c.Resolve<IApplicationTileService>(),
                c.Resolve<ISchedulerAccessor>(),
                c.Resolve<IMessageBoxFacade>(),
                c.Resolve<IApplicationInformation>(),
                c.Resolve<IApplicationMarketplaceFacade>()
                ));
        }
Пример #2
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            Container container = CommonDependencyConfiguration.Configure();

            // TODO: Move all this to a bootstrap

            var log = new ThreadSafeLoggingService(Logging.AgentLogName);

            container.Register<ILog>(log);
            container.Register<ILogManager>(log);

            if (!container.Resolve<IMutexService>().WaitOne(MutexNames.ForegroundApplication))
            {
            #if DEBUG
                Debug.WriteLine("Foreground process is running, aborting agent task");
            #endif
                NotifyComplete();
                return;
            }

            #if !DEBUG
            if (container.Resolve<IApplicationSettings>().LoggingEnabled)
            #endif
            {
                container.Resolve<ILogManager>().Enable();
            }

            var clock = container.Resolve<IClock>();
            var applicationSettings = container.Resolve<IApplicationSettings>();
            var jobUpdateService = container.Resolve<IJobUpdateService>();

            TimeSpan timeSpan = applicationSettings.BackgroundUpdateInterval;

            if (timeSpan == MinimumBackgroundUpdateInterval)
            {
                timeSpan = TimeSpan.Zero;
            }

            TimeSpan nextRun = PeriodicTaskHelper.GetNextRunTime(
                jobUpdateService.LastUpdateTime, timeSpan, clock.UtcNow);

            // TODO: Should this allow up to BackgroundUpdateInterval / 2 to better round out scheduling weirdness?
            if (nextRun == TimeSpan.Zero)
            {
                jobUpdateService.Complete += (s, e) =>
                {
                    log.Disable();
                    NotifyComplete();
                };

                jobUpdateService.UpdateAll(UpdateTimeout);
            }
            else
            {
                log.Write("Next background update not due for {0}. Skipping.", timeSpan.ToString());
                log.Disable();
                NotifyComplete();
            }

            #if DEBUG_AGENT
            ScheduledActionService.LaunchForTest("BuildScout.BackgroundUpdateAgent", TimeSpan.FromSeconds(10));
            #endif
        }