예제 #1
0
        public static void Shutdown()
        {
            var drivers = DriverConfiguration.Drivers;

            DriverConfiguration.Drivers = new DriverConfiguration();
            DriverConfiguration.Shutdown(drivers);
        }
예제 #2
0
        public static DriverConfiguration Initialise(params string[] assemblyNames)
        {
            foreach (var asmName in assemblyNames)
            {
                AppDomain.CurrentDomain.Load(asmName);
            }

            IMonitorDriver  monitorDriver  = null;
            IWindowDriver   windowDriver   = null;
            IImageDriver    imageDriver    = null;
            IFontDriver     fontDriver     = null;
            IGraphicsDriver graphicsDriver = null;
            IAudioDriver    audioDriver    = null;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                var jwdriver = assembly.GetCustomAttribute <JankWorksDriver>();

                if (jwdriver != null)
                {
                    var driverInstance = Activator.CreateInstance(jwdriver.DriverType);

                    SetDriverApi(ref monitorDriver, driverInstance);
                    SetDriverApi(ref windowDriver, driverInstance);
                    SetDriverApi(ref imageDriver, driverInstance);
                    SetDriverApi(ref fontDriver, driverInstance);
                    SetDriverApi(ref graphicsDriver, driverInstance);
                    SetDriverApi(ref audioDriver, driverInstance);
                }
            }

            var config = new DriverConfiguration
                         (
                monitorDriver,
                windowDriver,
                imageDriver,
                fontDriver,
                graphicsDriver,
                audioDriver
                         );

            DriverConfiguration.Drivers = config;
            return(config);

            void SetDriverApi <T>(ref T api, object driver)
            {
                if (api == null && driver is T driverApi)
                {
                    api = driverApi;
                }
            }
        }
예제 #3
0
        private static void Shutdown(DriverConfiguration drivers)
        {
            MaybeDispose(drivers.monitorApi);
            MaybeDispose(drivers.windowApi);
            MaybeDispose(drivers.graphicsApi);
            MaybeDispose(drivers.imageApi);
            MaybeDispose(drivers.fontApi);
            MaybeDispose(drivers.audioApi);

            void MaybeDispose(IDriver driver)
            {
                if (driver is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }
        }
예제 #4
0
 public static IDisposable Initialise(DriverConfiguration configuration)
 {
     DriverConfiguration.Drivers = configuration;
     return(new ScopedConfiguration(configuration));
 }
예제 #5
0
 public void Dispose() => DriverConfiguration.Shutdown(config);
예제 #6
0
 public ScopedConfiguration(DriverConfiguration config)
 {
     this.config = config;
 }