public StrategyBridge( DispatcherTimer timer, Func<ICKReadOnlyList<IHighlightableElement>> getElements, IPluginConfigAccessor config )
        {
            Implementations = new Dictionary<string, IScrollingStrategy>();

            foreach( Type t in GetStrategyTypes() )
            {
                //Ignore some types
                if( t == typeof( IScrollingStrategy ) || t == typeof( StrategyBridge ) || t == typeof( ScrollingStrategyBase ) )
                    continue;

                IScrollingStrategy instance = (IScrollingStrategy)Activator.CreateInstance( t );
                instance.Setup( timer, getElements, config );

                if( Implementations.ContainsKey( instance.Name ) )
                    throw new InvalidOperationException( "Cannot register the duplicate strategy name : " + instance.Name );

                Implementations[instance.Name] = instance;
            }

            _current = Implementations.Values.FirstOrDefault();
            if( _current == null )
                throw new InvalidOperationException( "One scrolling strategy at least must be available" );
        }
Beispiel #2
0
        public void Start()
        {
            Configuration.ConfigChanged += ( o, e ) =>
            {
                if( e.MultiPluginId.Any( u => u.UniqueId == KeyScrollerPlugin.PluginId.UniqueId ) )
                {
                    if( e.Key == "Strategy" )
                    {
                        _scrollingStrategy.Stop();
                        _scrollingStrategy = GetStrategyByName( e.Value.ToString() );
                        _scrollingStrategy.Start();
                    }
                }
            };

            ExternalInput.Service.Triggered += OnExternalInputTriggered;
        }
        /// <summary>
        /// Switch to the specified strategy
        /// </summary>
        /// <param name="strategyName">The name of the strategy to switch to</param>
        public void SwitchTo( string strategyName )
        {
            if( !Implementations.ContainsKey( strategyName ) )
            {
                strategyName = ZoneScrollingStrategy.StrategyName;
                if( !Implementations.ContainsKey( strategyName ) ) throw new InvalidOperationException( "trying to switch ot an unknown strategy (" + strategyName + "). Fallbacking failed (there are no implementations available)" );

                //A previous version of CiviKey has strategies that don't exist anymore. Loosening the process by implementing a fallback.
                //throw new InvalidOperationException( "Cannot switch to the unknown strategy : " + strategyName );
            }

            _current.Stop();
            _current = Implementations[strategyName];
            _current.Start();
        }
Beispiel #4
0
        public bool Setup( IPluginSetupInfo info )
        {
            _timer = new DispatcherTimer();
            int timerSpeed = Configuration.User.GetOrSet( "Speed", 1000 );
            _timer.Interval = new TimeSpan( 0, 0, 0, 0, timerSpeed );

            _registeredElements = new List<IHighlightableElement>();
            _strategies = new Dictionary<string, IScrollingStrategy>();

            foreach( string name in AvailableStrategies )
            {
                _strategies.Add( name, GetStrategyByName( name ) );
            }
            _scrollingStrategy = GetStrategyByName( Configuration.User.GetOrSet( "Strategy", "BasicScrollingStrategy" ) );

            return true;
        }