예제 #1
0
 //https://docs.microsoft.com/en-us/xamarin/ios/watchos/platform/background-tasks
 public static void Init(IShinyStartup startup = null, Action <IServiceCollection> platformBuild = null)
 => InitPlatform(startup, services =>
 {
     services.TryAddSingleton <IEnvironment, EnvironmentImpl>();
     services.TryAddSingleton <IConnectivity, SharedConnectivityImpl>();
     services.TryAddSingleton <IPowerManager, PowerManagerImpl>();
     //services.TryAddSingleton<IJobManager, JobManager>();
     services.TryAddSingleton <IFileSystem, FileSystemImpl>();
     services.TryAddSingleton <ISettings, SettingsImpl>();
     platformBuild?.Invoke(services);
 });
예제 #2
0
 public static void Init(IShinyStartup startup = null, Action <IServiceCollection> platformBuild = null)
 {
     InitPlatform(startup, services =>
     {
         services.AddSingleton <IJobManager, TestJobManager>();
         services.AddSingleton <IConnectivity, TestConnectivity>();
         services.AddSingleton <IPowerManager, TestPowerManager>();
         services.AddSingleton <IFileSystem, FileSystemImpl>();
         services.AddSingleton <ISettings, TestSettings>();
         services.AddSingleton <IEnvironment, TestEnvironment>();
         platformBuild?.Invoke(services);
     });
 }
예제 #3
0
        protected static void InitPlatform(IShinyStartup startup = null, Action <IServiceCollection> platformBuild = null)
        {
            var services = new ShinyServiceCollection();

            startup?.ConfigureServices(services);
            platformBuild?.Invoke(services);

            services.TryAddSingleton <IMessageBus, MessageBus>();
            services.TryAddSingleton <IRepository, FileSystemRepositoryImpl>();
            services.TryAddSingleton <ISerializer, JsonNetSerializer>();

            Services = services;

            container = startup?.CreateServiceProvider(services) ?? services.BuildServiceProvider(ValidateScopes);
            services.RunPostBuildActions(container);
            startup?.ConfigureApp(container);
        }
예제 #4
0
        public static void Init(IShinyStartup startup = null, Action <IServiceCollection> platformBuild = null)
        => InitPlatform(startup, services =>
        {
            services.TryAddSingleton <IEnvironment, EnvironmentImpl>();
            services.TryAddSingleton <IConnectivity, ConnectivityImpl>();
            services.TryAddSingleton <IPowerManager, PowerManagerImpl>();
            services.TryAddSingleton <IFileSystem, FileSystemImpl>();
            services.TryAddSingleton <ISettings, SettingsImpl>();

            //if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            //{
            //    services.TryAddSingleton<IJobManager, BgTasksJobManager>();
            //}
            //else
            //{
            services.TryAddSingleton <IJobManager, JobManager>();
            //}
            platformBuild?.Invoke(services);
        });
예제 #5
0
        public static void Init(IShinyStartup startup = null, IShinyModule platformModule = null)
        => InitPlatform(startup, services =>
        {
            services.TryAddSingleton <IEnvironment, EnvironmentImpl>();
            services.TryAddSingleton <IConnectivity, ConnectivityImpl>();
            services.TryAddSingleton <IPowerManager, PowerManagerImpl>();
            services.TryAddSingleton <IFileSystem, FileSystemImpl>();
            services.TryAddSingleton <ISettings, SettingsImpl>();
            services.TryAddSingleton <UwpContext>();

            services.TryAddSingleton <IJobManager, JobManager>();
            services.TryAddSingleton <IBackgroundTaskProcessor, JobBackgroundTaskProcessor>();

            if (platformModule != null)
            {
                services.RegisterModule(platformModule);
            }

            Dehydrate(STARTUP_KEY, startup);
            Dehydrate(MODULE_KEY, platformModule);
        });
예제 #6
0
        public static void Init(Application androidApp,
                                IShinyStartup startup = null,
                                Action <IServiceCollection> platformBuild = null)
        {
            InitPlatform(
                startup,
                services =>
            {
                services.AddSingleton(androidApp);
                services.TryAddSingleton <AndroidContext>();
                services.TryAddSingleton <ITopActivity, ShinyTopActivity>();

                services.TryAddSingleton <IEnvironment, EnvironmentImpl>();
                services.TryAddSingleton <IConnectivity, ConnectivityImpl>();
                services.TryAddSingleton <IPowerManager, PowerManagerImpl>();
                services.TryAddSingleton <IJobManager, JobManager>();
                services.TryAddSingleton <IFileSystem, FileSystemImpl>();
                services.TryAddSingleton <ISettings, SettingsImpl>();
                platformBuild?.Invoke(services);
            }
                );
        }
예제 #7
0
 public static void ShinyInit <TBgTask>(this Windows.UI.Xaml.Application app, IShinyStartup startup) where TBgTask : IBackgroundTask
 {
     UwpPlatform.SetBackgroundTask(typeof(TBgTask));
     ShinyHost.Init(new UwpPlatform(app), startup);
 }
예제 #8
0
 public static void ShinyRunBackgroundTask(this IBackgroundTask task, IBackgroundTaskInstance taskInstance, IShinyStartup startup)
 => UwpPlatform.RunBackgroundTask(task, taskInstance, startup);
예제 #9
0
 public static void UseAppCenterLogging(this IShinyStartup startup,
                                        string?appSecret = null,
                                        bool crashes     = true,
                                        bool events      = false)
 => UseAppCenterLogging(appSecret, crashes, events);
예제 #10
0
        public static void RunBackgroundTask(IBackgroundTask task, IBackgroundTaskInstance taskInstance, IShinyStartup startup)
        {
            if (!ShinyHost.IsInitialized)
            {
                UwpPlatform.SetBackgroundTask(task.GetType());
                ShinyHost.Init(new UwpPlatform(null), startup);
            }

            var services = ShinyHost.ServiceProvider;

            if (taskInstance.Task.Name.StartsWith("JOB-"))
            {
                services
                .Resolve <JobManager>(true) !
                .Process(taskInstance);
            }
            else
            {
                var targetType = Type.GetType(taskInstance.Task.Name);
                var processor  = ActivatorUtilities.GetServiceOrCreateInstance(services, targetType) as IBackgroundTaskProcessor;
                processor?.Process(taskInstance);
            }
        }