コード例 #1
0
        private static IBindableCollection <TSource> AsBindableInternal <TSource>(this IEnumerable source, IDispatcher dispatcher) where TSource : class
        {
            source.ShouldNotBeNull("source");
#if SILVERLIGHT
            dispatcher.ShouldNotBeNull("dispatcher");
#else
            if (dispatcher == null)
            {
                dispatcher = DispatcherFactory.Create();
            }
#endif

            var alreadyBindable = source as IBindableCollection <TSource>;
            if (alreadyBindable != null)
            {
                return(alreadyBindable);
            }
#if !SILVERLIGHT
            if (source is IBindingList && !(source is INotifyCollectionChanged))
            {
                return(new BindingListToBindableCollectionAdapter <TSource>(source, dispatcher));
            }
#endif
            return(new ObservableCollectionToBindableCollectionAdapter <TSource>(source, dispatcher));
        }
コード例 #2
0
        public IEnumerable <Dispatcher> Get()
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            return(instanceDispatcher.Select());
        }
コード例 #3
0
        public Dispatcher Get(int id)
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            return(instanceDispatcher.Select(id));
        }
コード例 #4
0
        private Collection <T> Read(SqlDataReader reader)
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            Collection <T> requests = new Collection <T>();

            while (reader.Read())
            {
                Request request = new Request();
                int     i       = -1;
                request.id            = reader.GetInt32(++i);
                request.state         = (RequestState)reader.GetInt32(++i);
                request.type          = (RequestType)reader.GetInt32(++i);
                request.priority      = reader.GetInt32(++i);
                request.created       = reader.GetDateTime(++i);
                request.message       = reader.GetString(++i);
                request.resultMessage = reader.IsDBNull(++i) ? null : reader.GetString(i);
                request.dispatcher    = instanceDispatcher.Select(reader.GetInt32(++i));



                requests.Add((T)request);
            }
            return(requests);
        }
コード例 #5
0
        public Dispatcher SelectDispatcherSession(string token)
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT);

            command.Parameters.AddWithValue("@token", token);
            SqlDataReader reader = db.Select(command);

            Collection <T> sessions = Read(reader);

            if (sessions.Count == 1)
            {
                if (sessions[0].type == "DISPATCHER")
                {
                    return(instanceDispatcher.Select(sessions[0].user_id));
                }
            }
            reader.Close();
            db.Close();
            return(null);
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        public Collection <T> Select()
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            XDocument      xDoc     = XDocument.Load(Configuration.XMLFILEPATH);
            Collection <T> requests = new Collection <T>();

            List <XElement> elements = xDoc.Descendants("Requests").Descendants("Request").ToList();

            foreach (var element in elements)
            {
                Request request = new Request();
                request.id            = int.Parse(element.Attribute("id").Value);
                request.state         = (RequestState)int.Parse(element.Attribute("state").Value);
                request.type          = (RequestType)int.Parse(element.Attribute("type").Value);
                request.priority      = int.Parse(element.Attribute("priority").Value);
                request.created       = DateTime.Parse(element.Attribute("created").Value);
                request.message       = element.Attribute("message").Value;
                request.resultMessage = element.Attribute("resultMessage").Value;
                request.dispatcher    = instanceDispatcher.Select(int.Parse(element.Attribute("dispatcherId").Value));

                requests.Add((T)request);
            }

            return(requests);
        }
コード例 #8
0
ファイル: MessageXMLTable.cs プロジェクト: michalfalat/VIS
        public Collection <T> Select()
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            ManagerFactory         managerFactory  = new ManagerFactory();
            ManagerTable <Manager> instanceManager = (ManagerTable <Manager>)managerFactory.GetManagerInstance();

            XDocument      xDoc     = XDocument.Load(Configuration.XMLFILEPATH);
            Collection <T> messages = new Collection <T>();

            List <XElement> elements = xDoc.Descendants("Messages").Descendants("Message").ToList();

            foreach (var element in elements)
            {
                Message message = new Message();
                message.id         = int.Parse(element.Attribute("id").Value);
                message.created    = DateTime.Parse(element.Attribute("created").Value);
                message.text       = element.Attribute("text").Value;
                message.isRead     = bool.Parse(element.Attribute("isRead").Value);
                message.dispatcher = instanceDispatcher.Select(int.Parse(element.Attribute("dispatcherId").Value));
                message.manager    = instanceManager.Select(int.Parse(element.Attribute("managerId").Value));


                messages.Add((T)message);
            }

            return(messages);
        }
コード例 #9
0
        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]");
        }
コード例 #10
0
ファイル: QueueProcessor.cs プロジェクト: xtuyaowu/xparser
 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);
 }
コード例 #11
0
        private Collection <T> Read(SqlDataReader reader)
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            ManagerFactory         managerFactory  = new ManagerFactory();
            ManagerTable <Manager> instanceManager = (ManagerTable <Manager>)managerFactory.GetManagerInstance();


            Collection <T> messages = new Collection <T>();

            while (reader.Read())
            {
                Message message = new Message();
                int     i       = -1;
                message.id         = reader.GetInt32(++i);
                message.created    = reader.GetDateTime(++i);
                message.text       = reader.GetString(++i);
                message.isRead     = reader.GetBoolean(++i);
                message.dispatcher = instanceDispatcher.Select(reader.GetInt32(++i));
                message.manager    = instanceManager.Select(reader.GetInt32(++i));



                messages.Add((T)message);
            }
            return(messages);
        }
コード例 #12
0
ファイル: QueueProcessor.cs プロジェクト: xtuyaowu/xparser
 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);
 }
コード例 #13
0
        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>();
        }
コード例 #14
0
        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>();
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        private void InstantiateDispatcher()
        {
            DispatcherFactory factory = new DispatcherFactory();

            Dispatcher = factory.InstantiateDispatcher(DispatcherAssembly);
            Dispatcher.Configuration = this;

            LogWriter.LogMessage(LogLevel.Debug, "Initializing Dispatcher");
        }
コード例 #17
0
        public void Awake()
        {
            m_Dispatcher = DispatcherFactory.GetDispatcher();

            m_ApplicationContextTarget = ApplicationContext.BindTarget(m_UIApplicationState);
            m_DebugContextTarget       = DebugOptionContext.BindTarget(m_UIDebugState);

            DispatchToken = m_Dispatcher.Register <Payload <IViewerAction> >(InvokeOnDispatch);
        }
コード例 #18
0
        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"));
        }
コード例 #19
0
ファイル: ViewService.cs プロジェクト: joekolodz/SierraHOTAS
        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);
        }
コード例 #20
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());
        }
コード例 #21
0
 public NotificationQueue(
     IServiceProvider serviceProvider,
     DispatcherFactory dispatcherFactory,
     ILogger <NotificationQueue> logger)
 {
     _serviceProvider   = serviceProvider;
     _dispatcherFactory = dispatcherFactory;
     _logger            = logger;
     _notificationQueue = new ConcurrentQueue <Func <CancellationToken, Task> >();
     _signal            = new SemaphoreSlim(0);
 }
コード例 #22
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);
        }
コード例 #23
0
ファイル: DispatcherCache.cs プロジェクト: w4x/boolangstudio
 /// <summary>
 /// Gets a dispatcher from the cache if available otherwise
 /// invokes factory to produce one and then cache it.
 /// </summary>
 /// <param name="key">the dispatcher key</param>
 /// <param name="factory">function to produce a dispatcher in case one it's not yet available</param>
 /// <returns></returns>
 public Dispatcher Get(DispatcherKey key, DispatcherFactory factory)
 {
     Dispatcher dispatcher;
     if (!_cache.TryGetValue(key, out dispatcher))
     {
         lock (_cache)
         {
             if (!_cache.TryGetValue(key, out dispatcher))
             {
                 dispatcher = factory();
                 _cache.Add(key, dispatcher);
             }
         }
     }
     return dispatcher;
 }
コード例 #24
0
ファイル: DispatcherCache.cs プロジェクト: codehaus/boo
        /// <summary>
        /// Gets a dispatcher from the cache if available otherwise
        /// invokes factory to produce one and then cache it.
        /// </summary>
        /// <param name="key">the dispatcher key</param>
        /// <param name="factory">function to produce a dispatcher in case one it's not yet available</param>
        /// <returns></returns>
        public Dispatcher Get(DispatcherKey key, DispatcherFactory factory)
        {
            Dispatcher dispatcher;

            if (!_cache.TryGetValue(key, out dispatcher))
            {
                lock (_cache)
                {
                    if (!_cache.TryGetValue(key, out dispatcher))
                    {
                        dispatcher = factory();
                        _cache.Add(key, dispatcher);
                    }
                }
            }
            return(dispatcher);
        }
コード例 #25
0
        public static IContainer UseAsyncDispatcherSingleton(this IContainer container)
        {
            Assembly assemblyWithAggregates = ApplicationServiceGenerator.Generate(typeof(UserAggregate).Assembly);

            AsyncMessageDispatcher dispatcher = DispatcherFactory.CreateAsync(configuration =>
            {
                configuration.SetServiceLocator(new StructureMapServiceProvider(container));
                configuration.AddScanRule(assemblyWithAggregates);      //scan for command handlers
                configuration.AddScanRule(typeof(Event).Assembly);      //scan for command handlers
                configuration.AddScanRule(typeof(_namespace).Assembly); //scan for event and query handlers
                configuration.EnableHandlingPriority();
                //configuration.AddInterceptor<LoggingInterceptor>();
            });

            container.Configure(expression => expression.For <AsyncMessageDispatcher>().Use(dispatcher).Singleton());
            return(container);
        }
コード例 #26
0
        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");
            }
        }
コード例 #27
0
ファイル: QueueProcessor.cs プロジェクト: xtuyaowu/xparser
 public virtual void Dispose()
 {
     this.disposing = true;
     ReportableObjectDirectory.Remove(this.queueName);
     if (this.dispatcher.Name != DispatcherFactory.DefaultDispatcher.Name)
     {
         this.dispatcherQueue.Dispose();
         this.dispatcher.Dispose();
     }
     else
     {
         this.dispatcherQueue.Dispose();
         if (DispatcherFactory.DefaultDispatcher != null && DispatcherFactory.DefaultDispatcher.DispatcherQueues.Count == 0)
         {
             this.dispatcher = null;
             DispatcherFactory.DestroyDefaultDispatcher();
         }
     }
     GC.SuppressFinalize(this);
     LoggerWrapper.Logger.Debug(string.Format("Teardown of queue {0} completed", new object[]
     {
         this.queueName
     }));
 }
コード例 #28
0
 protected virtual void Awake()
 {
     Setup(DispatcherFactory.GetDispatcher());
 }
コード例 #29
0
        public async Task InvokeAsync(HttpContext httpContext, IanvsContext ianvsContext, DispatcherFactory dispatcherFactory, Tracer tracer)
        {
            var egressSpan = tracer.StartSpan("ianvs-egress");

            // TODO: Implement Protocol Translation - e.g. REST to gRPC
            // https://github.com/onyx-ws/ianvs/issues/11

            // Get the dispatcher matching for the backend
            ianvsContext.Dispatcher = dispatcherFactory.GetDispatcher(ianvsContext.MatchedEndpoint.Protocol);
            egressSpan.AddEvent("Preparing Request");
            // Prepare backend request message
            ianvsContext.BackendMessage.Message = ianvsContext.Dispatcher.PrepareRequest(ianvsContext, egressSpan);
            egressSpan.AddEvent("Request prepared");

            Stopwatch backendTimer = new Stopwatch();

            backendTimer.Start();

            egressSpan.AddEvent("Sending backend request");

            _logger.LogInformation($"{Environment.MachineName} {ianvsContext.RequestId} Sending request to backend service {ianvsContext.MatchedOperation.OperationId} {ianvsContext.MatchedOperation.Method} {ianvsContext.MatchedEndpoint.Url} {ianvsContext.TargetServer.Url}");
            Task <object> backendResponse = ianvsContext.Dispatcher.Dispatch(ianvsContext);

            _logger.LogInformation($"{Environment.MachineName} {ianvsContext.RequestId} Waiting for backend service response");
            backendResponse.Wait();
            backendTimer.Stop();
            egressSpan.AddEvent("Backend service response received");

            ianvsContext.BackendResponse = new BackendMessage()
            {
                Message = backendResponse.Result
            };

            ianvsContext.Dispatcher.ProcessResponse(ianvsContext);
            _logger.LogInformation($"{Environment.MachineName} {ianvsContext.RequestId} Backend service response received in {backendTimer.ElapsedMilliseconds}ms {ianvsContext.StatusCode}");

            egressSpan.End();
            // Egress middleware is the last in the Ianvs processing chain
            // No further calls made to _next
        }
コード例 #30
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);
            }
        }
コード例 #31
0
 /// <summary>
 /// Converts any <see cref="IEnumerable{T}"/> into a Bindable LINQ <see cref="IBindableCollection{TElement}"/>.
 /// </summary>
 /// <typeparam name="TSource">The type of source item.</typeparam>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="source">The source Iterator.</param>
 /// <param name="dispatcher">The dispatcher.</param>
 /// <returns>
 /// An <see cref="IBindableCollection{TElement}"/> containing the items.
 /// </returns>
 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
 public static IBindableCollection <TResult> AsBindable <TSource, TResult>(this IEnumerable <TSource> source, Dispatcher dispatcher)
     where TResult : TSource
     where TSource : class
 {
     return(AsBindable <TSource, TResult>(source, DispatcherFactory.Create(dispatcher)));
 }