public void ShouldDispatch()
        {
            var root       = new Root();
            var dispatcher = DispatcherFactory.CreateDispatcher(root, _endpoint.Object, false);

            dispatcher.Execute("BooleanValue/Value", new Dictionary <string, string>()).Result.ShouldBe("False");
            dispatcher.Execute("BooleanValue/UpdateValue", new Dictionary <string, string> {
                { "value", "True" }
            });
            root.BooleanValue.Value.ShouldBe(true);

            dispatcher.Execute("IntValue/Value", new Dictionary <string, string>()).Result.ShouldBe("0");
            dispatcher.Execute("IntValue/UpdateValue", new Dictionary <string, string> {
                { "value", "3" }
            });
            root.IntValue.Value.ShouldBe(3);

            dispatcher.Execute("StringValue/Value", new Dictionary <string, string>()).Result.ShouldBe(string.Empty);
            dispatcher.Execute("StringValue/UpdateValue", new Dictionary <string, string> {
                { "value", "3" }
            });
            root.StringValue.Value.ShouldBe("3");

            dispatcher.Execute("Combine", new Dictionary <string, string> {
                { "delimiter", "___" }
            }).Result.ShouldBe("3___3");

            _endpoint.Setup(x => x.RegisterInstance(It.IsAny <object>())).Returns("i1");
            dispatcher.Execute("CreateContainer", new Dictionary <string, string> {
                { "initialValue", "a" }
            }).Result.ShouldBe("i1");
        }
        public void ShouldResolveAmbiguityByDiscardingGenericMethods()
        {
            var service    = new GenericInterfaceImpl(new[] { "a", "b", "c" });
            var dispatcher = DispatcherFactory.CreateDispatcher(service, null, false);

            dispatcher.Execute("GetItems", new Dictionary <string, string>()).Result.ShouldBe("[a,b,c]");
        }
Ejemplo n.º 3
0
 public QueueProcessor(string queueName, int threadCount, TaskExecutionSchedulingPolicy taskExecutionSchedulingPolicy, Priority priority, double schedulingRate, int activateItems)
 {
     this.queueName     = queueName;
     this.activateItems = activateItems;
     if (threadCount > 0)
     {
         ThreadPriority threadPriority = this.ConvertThreadPriority(priority);
         this.dispatcher = DispatcherFactory.CreateDispatcher(threadCount, threadPriority, this.queueName);
     }
     else
     {
         this.dispatcher = DispatcherFactory.DefaultDispatcher;
     }
     if (schedulingRate > 0.0)
     {
         TaskExecutionPolicy taskExecutionPolicy = this.ConvertTaskExecutionPolicy(taskExecutionSchedulingPolicy);
         this.dispatcherQueue = new DispatcherQueue(this.queueName, this.dispatcher, taskExecutionPolicy, schedulingRate);
     }
     else
     {
         this.dispatcherQueue = new DispatcherQueue(this.queueName, this.dispatcher);
     }
     this.upperBound   = 0;
     this.port         = new Port <T>();
     this.teardownPort = new Port <EmptyValue>();
     ReportableObjectDirectory.Add(this.queueName, this);
 }
Ejemplo n.º 4
0
 private QueueProcessor(string queueName, int threadCount, TaskExecutionPolicy taskExecutionPolicy, ThreadPriority threadPriority, int maximumQueueDepth, double schedulingRate)
 {
     this.queueName = queueName;
     if (threadCount > 0)
     {
         this.dispatcher = DispatcherFactory.CreateDispatcher(threadCount, this.queueName);
     }
     else
     {
         this.dispatcher = DispatcherFactory.DefaultDispatcher;
     }
     if (maximumQueueDepth > 0)
     {
         this.dispatcherQueue = new DispatcherQueue(this.queueName, this.dispatcher, taskExecutionPolicy, maximumQueueDepth);
     }
     else
     {
         if (schedulingRate > 0.0)
         {
             this.dispatcherQueue = new DispatcherQueue(this.queueName, this.dispatcher, taskExecutionPolicy, schedulingRate);
         }
         else
         {
             this.dispatcherQueue = new DispatcherQueue(this.queueName, this.dispatcher);
         }
     }
     this.upperBound   = maximumQueueDepth;
     this.port         = new Port <T>();
     this.teardownPort = new Port <EmptyValue>();
     ReportableObjectDirectory.Add(this.queueName, this);
 }
        public void ShouldFailTaskOnExceptionInDispatchedCode()
        {
            var root       = new Root();
            var dispatcher = DispatcherFactory.CreateDispatcher(root, null, false);

            var task = dispatcher.Execute("Throw", new Dictionary <string, string>());

            new Action(() => { task.Wait(); }).ShouldThrow <Exception>();
        }
        public void ShouldThrowOnInvalidPath()
        {
            var root       = new Root();
            var dispatcher = DispatcherFactory.CreateDispatcher(root, null, false);

            var task = dispatcher.Execute("IntValue/InvalidPath", new Dictionary <string, string>());

            new Action(() => { task.Wait(); }).ShouldThrow <Exception>();
        }
        public void ShouldDetachInstanceOnCorrepondingCommand()
        {
            var root       = new Root();
            var dispatcher = DispatcherFactory.CreateDispatcher(root, _endpoint.Object, false);

            _endpoint.Setup(x => x.RegisterInstance(root)).Returns("instance");
            dispatcher.Execute("~detach", new Dictionary <string, string>()).Result.ShouldBe("instance");
            _endpoint.Verify(x => x.RegisterInstance(root));
        }
Ejemplo n.º 8
0
        public ViewService(Window mainWindow, IEventAggregator eventAggregator, DispatcherFactory dispatcherFactory)
        {
            _mainWindow      = mainWindow;
            _eventAggregator = eventAggregator;
            _appDispatcher   = dispatcherFactory.CreateDispatcher();

            _eventAggregator.Subscribe <ShowMessageWindowEvent>(ShowMessageWindow);
            _eventAggregator.Subscribe <ShowModeProfileConfigWindowEvent>(ShowModeProfileConfigWindow);
            _eventAggregator.Subscribe <ShowInputGraphWindowEvent>(ShowInputGraphWindow);
        }
Ejemplo n.º 9
0
        public string RegisterInstance(object instance)
        {
            if (_session == null)
            {
                _session = new Session(new SimpleTimer(_tickInterval), _cleanupInterval);
                _server  = new TinyHttpServer(_prefix, _session);
            }

            return(new ObjectAddress(_prefix, _session.RegisterInstance(DispatcherFactory.CreateDispatcher(instance, this, _useThreadDispatcher))).Encode());
        }
        public void ShouldResolveAmbiguityByDiscardingMethodsWithIncompatibleParameters()
        {
            var service    = new Mock <IAmbiguousMethodsService>();
            var dispatcher = DispatcherFactory.CreateDispatcher(service.Object, null, false);

            dispatcher.Execute("Execute", new Dictionary <string, string> {
                { "arg", "value" }
            });
            service.Verify(x => x.Execute("value"));
        }
Ejemplo n.º 11
0
        private AxisMapViewModel CreateAxisMapViewModel(out IFileSystem subFileSystem, out IMediaPlayer subMediaPlayer, out HOTASAxis map)
        {
            subFileSystem = Substitute.For <IFileSystem>();
            var subDispatcherFactory  = new DispatcherFactory();
            var subMediaPlayerFactory = Substitute.For <MediaPlayerFactory>();

            map            = new HOTASAxis();
            subMediaPlayer = Substitute.For <IMediaPlayer>();
            subMediaPlayerFactory.CreateMediaPlayer().Returns(subMediaPlayer);

            var mapVm = new AxisMapViewModel(subDispatcherFactory.CreateDispatcher(), subMediaPlayerFactory, subFileSystem, map);

            return(mapVm);
        }
        public void ShouldDispatchOnDispatcherThreadForDispatcherObjects()
        {
            using (var dt = new DispatcherThread())
            {
                var root       = dt.Invoke(() => new DispatcherRoot());
                var dispatcher = DispatcherFactory.CreateDispatcher(root, _endpoint.Object, false);

                dispatcher.Execute("GetIntValue", new Dictionary <string, string>()).Result.ShouldBe("1");
                dispatcher.Execute("GetIntValueAsync", new Dictionary <string, string>()).Result.ShouldBe("1");

                dispatcher.Execute("Invoke", new Dictionary <string, string>()).Result.ShouldBe("");
                dispatcher.Execute("InvokeAsync", new Dictionary <string, string>()).Result.ShouldBe("");

                _endpoint.Setup(x => x.RegisterInstance(It.IsAny <object>())).Returns("i1");
                dispatcher.Execute("Clone", new Dictionary <string, string>()).Result.ShouldBe("i1");
                dispatcher.Execute("CloneAsync", new Dictionary <string, string>()).Result.ShouldBe("i1");
            }
        }
Ejemplo n.º 13
0
        public Endpoint(string prefix, object rootInstance, bool useThreadDispatcher, TimeSpan cleanupInterval, TimeSpan executionTimeout)
        {
            _prefix = prefix;
            _useThreadDispatcher = useThreadDispatcher;
            _cleanupInterval     = cleanupInterval;
            _tickInterval        = TimeSpan.FromMinutes(1);
            _executionTimeout    = executionTimeout;
            if (_tickInterval > _cleanupInterval)
            {
                _tickInterval = _cleanupInterval;
            }

            if (rootInstance != null)
            {
                _session = new Session(new SimpleTimer(_tickInterval), _cleanupInterval, DispatcherFactory.CreateDispatcher(rootInstance, this, useThreadDispatcher));
                _server  = new TinyHttpServer(prefix, _session);
            }
        }