Inheritance: INotificationService, INotifierContext
Ejemplo n.º 1
0
        public override IContext CreateContext()
        {
            IContext ctx = base.CreateContext();

            _log.Debug( "LAUNCHING" );
            _log.Debug( String.Format( "Launching {0} > Distribution : {1} > Version : {2}, GUID : {3}", CKApp.CurrentParameters.AppName, CKApp.CurrentParameters.DistribName, AppVersion, ApplicationGUID ) );

            _notificationMngr = new NotificationManager();

            // Discover available plugins.
            string pluginPath = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Plugins" );
            if( Directory.Exists( pluginPath ) ) ctx.PluginRunner.Discoverer.Discover( new DirectoryInfo( pluginPath ), true );

            RequirementLayer hostRequirements = new RequirementLayer( "CivikeyStandardHost" );
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{2ed1562f-2416-45cb-9fc8-eef941e3edbc}" ), RunningRequirement.MustExistAndRun ); //KeyboardContext
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{1DB78D66-B5EC-43AC-828C-CCAB91FA6210}" ), RunningRequirement.MustExistAndRun ); //HelpService
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{0F740086-85AC-46EB-87ED-12A4CA2D12D9}" ), RunningRequirement.MustExistAndRun ); //SendString

            //Making sure that these services are started regardless of the keyboard being opened at launch.
            //This way, even keyboards created by a user can use the differents key protocols.
            //We'll be able to remove that once the editor has the capacity to update the edited keyboard's RequirementLayer.
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{04B1B7F5-6CD8-4691-B5FD-2C4401C3AC0C}" ), RunningRequirement.MustExistAndRun ); //IChangeKeyboardCommandHandlerService
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{4EDBED5A-C38E-4A94-AD34-18720B09F3B7}" ), RunningRequirement.MustExistAndRun ); //IClicCommandHandlerService
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{4A3F1565-E127-473c-B169-0022A3EDB58D}" ), RunningRequirement.MustExistAndRun ); //IModeCommandHandlerService
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{B2EC4D13-7A4F-4F9E-A713-D5F8DDD161EF}" ), RunningRequirement.MustExistAndRun ); //IMoveMouseCommandHandler

            ctx.PluginRunner.Add( hostRequirements );

            // Load or initialize the ctx.
            LoadResult res = Instance.LoadContext( Assembly.GetExecutingAssembly(), "Host.Resources.Contexts.ContextCiviKey.xml" );
            // Initializes Services.
            {
                ctx.ServiceContainer.Add<IHostInformation>( this );
                ctx.ServiceContainer.Add<IHostHelp>( this );
                // inject specific xaml serializers.
                ctx.ServiceContainer.Add<IStructuredSerializer<Size>>( new XamlSerializer<Size>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<Color>>( new XamlSerializer<Color>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<LinearGradientBrush>>( new XamlSerializer<LinearGradientBrush>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<TextDecorationCollection>>( new XamlSerializer<TextDecorationCollection>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<FontWeight>>( new XamlSerializer<FontWeight>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<FontStyle>>( new XamlSerializer<FontStyle>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<Image>>( new XamlSerializer<Image>() );
                //ctx.ServiceContainer.Add<INotificationService>( _notificationMngr );
            }

            Context.PluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone );

            _firstApplySucceed = Context.PluginRunner.Apply();

            ctx.ConfigManager.SystemConfiguration.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler( OnSystemConfigurationPropertyChanged );
            ctx.ConfigManager.UserConfiguration.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler( OnUserConfigurationPropertyChanged );

            return ctx;
        }
Ejemplo n.º 2
0
        public override IContext CreateContext()
        {
            //WARNING : DO NOT get information from the system configuration or the user configuration before discovering.
            //Getting info from these conf will trigger the LoadSystemConf or LoadUserConf, which will parse configurations set in the corresponding files.
            //If a system conf is found and loaded at this point, plugin will be set as disabled (because the plugins are not yet discovered). If there is a userconf, the requirements will be parsed again later, and everything will work fine.
            //The problem occurs when there is no user conf. (this happens when CiviKey is launched for the first time)

            IContext ctx = base.CreateContext();

            _log.Debug( "LAUNCHING" );

            _notificationMngr = new NotificationManager();

            // Discover available plugins.
            string pluginPath = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Plugins" );
            _log.Debug( "Discovering plugins..." );
            if( Directory.Exists( pluginPath ) ) ctx.PluginRunner.Discoverer.Discover( new DirectoryInfo( pluginPath ), true );
            _log.Debug( "Plugins discovered" );
            _log.Debug( String.Format( "Launching {0} > Distribution : {1} > Version : {2}, GUID : {3}", CKApp.CurrentParameters.AppName, CKApp.CurrentParameters.DistribName, AppVersion, ApplicationUniqueId.UniqueId ) );

            var hostRequirements = new RequirementLayer( "CivikeyStandardHost" );
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{2ed1562f-2416-45cb-9fc8-eef941e3edbc}" ), RunningRequirement.MustExistAndRun );//KeyboardContext
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{0F740086-85AC-46EB-87ED-12A4CA2D12D9}" ), RunningRequirement.MustExistAndRun );//SendInput
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{B91D6A8D-2294-4BAA-AD31-AC1F296D82C4}" ), RunningRequirement.MustExistAndRun );//Window Executor
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{D173E013-2491-4491-BF3E-CA2F8552B5EB}" ), RunningRequirement.MustExistAndRun );//KeyboardDisplayer

            //Command handlers. These plugins register their protocols onto the keyboard editor.
            //Therefor, we need them started in order to be able to create any type of Key Command.
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{664AF22C-8C0A-4112-B6AD-FB03CDDF1603}" ), RunningRequirement.MustExistAndRun );//FileLauncherCommandHandler
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{418F670B-46E8-4BE2-AF37-95F43040EEA6}" ), RunningRequirement.MustExistAndRun );//KeySequenceCommandHandler
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{78D84978-7A59-4211-BE04-DD25B5E2FDC1}" ), RunningRequirement.MustExistAndRun );//TextTemplateCommandHandler
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{4EDBED5A-C38E-4A94-AD34-18720B09F3B7}" ), RunningRequirement.MustExistAndRun );//ClicCommandHandler
            hostRequirements.PluginRequirements.AddOrSet( new Guid( "{B2EC4D13-7A4F-4F9E-A713-D5F8DDD161EF}" ), RunningRequirement.MustExistAndRun );//MoveMouseCommandHandler

            // ToDoJL
            //hostRequirements.PluginRequirements.AddOrSet( new Guid( "{DC7F6FC8-EA12-4FDF-8239-03B0B64C4EDE}" ), RunningRequirement.MustExistAndRun );//HelpUpdater
            hostRequirements.ServiceRequirements.AddOrSet( "Help.Services.IHelpViewerService", RunningRequirement.MustExistAndRun );
            //hostRequirements.ServiceRequirements.AddOrSet( "Help.Services.IHelpUpdaterService", RunningRequirement.MustExistAndRun );

            ctx.PluginRunner.Add( hostRequirements );

            // Load or initialize the ctx.
            LoadResult res = Instance.LoadContext( Assembly.GetExecutingAssembly(), "Host.Resources.Contexts.ContextCiviKey.xml" );
            _log.Debug( "Context loaded successfully." );

            // Initializes Services.
            {
                ctx.ServiceContainer.Add<IHostInformation>( this );
                ctx.ServiceContainer.Add<IHostHelp>( this );
                ctx.ServiceContainer.Add<IContextSaver>( this );
                // inject specific xaml serializers.
                ctx.ServiceContainer.Add<IStructuredSerializer<Size>>( new XamlSerializer<Size>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<Color>>( new XamlSerializer<Color>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<LinearGradientBrush>>( new XamlSerializer<LinearGradientBrush>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<TextDecorationCollection>>( new XamlSerializer<TextDecorationCollection>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<FontWeight>>( new XamlSerializer<FontWeight>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<FontStyle>>( new XamlSerializer<FontStyle>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<Image>>( new XamlSerializer<Image>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<BitmapSource>>( new BitmapSourceSerializer<BitmapSource>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<InteropBitmap>>( new BitmapSourceSerializer<InteropBitmap>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<CachedBitmap>>( new BitmapSourceSerializer<CachedBitmap>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<BitmapFrame>>( new BitmapSourceSerializer<BitmapFrame>() );
                ctx.ServiceContainer.Add<IStructuredSerializer<BitmapImage>>( new BitmapSourceSerializer<BitmapImage>() );
                //ctx.ServiceContainer.Add<INotificationService>( _notificationMngr );
            }

            Context.PluginRunner.ApplyDone += OnApplyDone;

            _log.Debug( "Starting Apply..." );
            _firstApplySucceed = Context.PluginRunner.Apply();

            ctx.ConfigManager.SystemConfiguration.PropertyChanged += OnSystemConfigurationPropertyChanged;
            ctx.ConfigManager.UserConfiguration.PropertyChanged += OnUserConfigurationPropertyChanged;

            return ctx;
        }