CK.WordPredictor.TextualContextService.Start C# (CSharp) Method

Start() public method

public Start ( ) : void
return void
        public void Start()
        {
            if( PredictionTextAreaService != null && PredictionTextAreaService.Service != null )
            {
                PredictionTextAreaService.Service.PredictionAreaTextSent += OnPredictionAreaContentSent;
                PredictionTextAreaService.Service.PredictionAreaContentChanged += OnPredictionAreaServicePropertyChanged;
            }
            PredictionTextAreaService.ServiceStatusChanged += OnPredictionAreaServiceStatusChanged;

            if( CommandTextualContextService != null && CommandTextualContextService.Service != null )
            {
                CommandTextualContextService.Service.TextualContextClear += OnTextualContextClear;
            }
            CommandTextualContextService.ServiceStatusChanged += OnCommandTextualContextServiceStatusChanged;

            if( SendKeyService != null && SendKeyService.Service != null )
            {
                SendKeyService.Service.KeySent += OnOldKeySent;
            }
            SendKeyService.ServiceStatusChanged += OnSendKeyServiceStatusChanged;

            if( SendStringService != null && SendStringService.Service != null )
            {
                SendStringService.Service.KeySent += OnKeySent;
                SendStringService.Service.StringSent += OnStringSent;
            }
            SendStringService.ServiceStatusChanged += OnSendStringServiceStatusChanged;
        }

Usage Example

        public void When_A_Word_Is_Predicted_It_Must_Appears_In_Prediction_Zone()
        {
            // Texual service plugin usage
            var textualService = new TextualContextService()
            {
                //SendKeyService = ServiceHelper.MockServiceWrapper<ISendKeyCommandHandlerService>(),
                //SendStringService = ServiceHelper.MockServiceWrapper<ISendStringService>()
            };
            // Predictor service plugin usage

            SybilleWordPredictorService.PluginDirectoryPath = TestHelper.SybilleResourceFullPath;
            var predictorService = new SybilleWordPredictorService()
            {
                Feature = TestHelper.MockFeature( 10 ).Object,
                TextualContextService = textualService,
            };

            // Mocking of IKeyboardContext
            var mKbContext = TestHelper.MockKeyboardContext( TestHelper.CompatibilityKeyboardName, TestHelper.PredictionZoneName );

            // The Plugin Under Test.
            var pluginSut = new InKeyboardWordPredictor()
            {
                Feature = TestHelper.MockFeature( 10 ).Object,
                WordPredictorService = predictorService.MockServiceWrapper<IWordPredictorService>(),
                Context = mKbContext.Object
            };

            // Start all depending plugins
            textualService.Start();
            predictorService.Setup( null );
            predictorService.Start();
            pluginSut.Start();
            Task.WaitAll( predictorService.AsyncEngineContinuation );
            // Start test. When a token is inserted into the textual service, it will triggers the predictor service to make a prediction.
            textualService.SetRawText( "J" );
            Assert.That( predictorService.Words.Count > 0 );

            // We need to assert that the SUT correctly creates Keys into the Prediction Zone, according to its specs.

            // Test
            var keys = pluginSut.Context.Keyboards[TestHelper.CompatibilityKeyboardName].Zones[ TestHelper.PredictionZoneName].Keys;
            Assert.That( keys.Select( e => e.CurrentLayout.Current.Visible == true ).Count() == predictorService.Words.Count );

            mKbContext.VerifyAll();
        }