コード例 #1
0
        public RconServer(
            IDependencyContainer container)
            : base(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        {
            _container      = container;
            _commandHandler = container.Resolve <ICommandHandler>();
            _logger         = container.Resolve <ILogger>();
            _runtime        = container.Resolve <IRuntime>();
            _host           = container.Resolve <IHost>();
            container.TryResolve(null, out _scheduler);

            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());

            IPAddress = ipHostInfo.AddressList.First(o => o.AddressFamily == AddressFamily.InterNetwork);
        }
コード例 #2
0
        public void DependencyInTextScope()
        {
            IDependencyContainer root = CreateContainer();

            root.Definitions
            .AddTransient <IHelloService, HiService>()
            .AddScoped <IMessageFormatter, StringMessageFormatter>("S1");

            IHelloService helloService;

            TryCatchUnResolvable <IHelloService>(root);

            using (IDependencyProvider s1 = root.Scope("S1"))
            {
                TryCatchUnResolvable <IHelloService>(root);

                helloService = s1.Resolve <IHelloService>();
                Assert.IsTrue(s1.TryResolve <IHelloService>(out helloService));
            }

            TryCatchUnResolvable <IHelloService>(root);
            Assert.IsFalse(root.TryResolve <IHelloService>(out helloService));
        }
コード例 #3
0
ファイル: EventManager.cs プロジェクト: lovenets/Rocket
        public void Emit(IEventEmitter sender, IEvent @event, EventExecutedCallback callback = null)
        {
            if (!sender.IsAlive)
            {
                return;
            }

            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            string eventNameString = "[" + string.Join(", ", @event.Names.ToArray()) + "]" + " by \"" + sender.Name + "\"";
            string primaryName     = @event.Names.First();

            logger?.LogTrace(eventNameString + ": Emitting.");

            inProgress.Add(@event);

            List <EventAction> actions =
                eventListeners
                .Where(c => c.TargetEventType?.IsInstanceOfType(@event)
                       ?? @event.Names.Any(d => c.TargetEventNames.Any(e => d.Equals(e, StringComparison.OrdinalIgnoreCase))) &&
                       c.Owner.IsAlive)
                .ToList();

            actions.Sort((a, b) => ServicePriorityComparer.Compare(a.Handler.Priority, b.Handler.Priority));

            List <EventAction> targetActions =
                (from info in actions
                 /* ignore cancelled events */
                 where !(@event is ICancellableEvent) ||
                 !((ICancellableEvent)@event).IsCancelled ||
                 info.Handler.IgnoreCancelled
                 where CheckEmitter(info, sender.Name, @event.IsGlobal)
                 where CheckEvent(info, @event.Names)
                 select info)
                .ToList();

            void FinishEvent()
            {
                logger?.LogTrace(eventNameString + ": Finished.");
                inProgress.Remove(@event);
                callback?.Invoke(@event);
            }

            if (targetActions.Count == 0)
            {
                logger?.LogTrace(eventNameString + ": No listeners found.");
                FinishEvent();
                return;
            }

            container.TryResolve(null, out ITaskScheduler scheduler);
            if (scheduler == null && @event.ExecutionTarget != EventExecutionTargetContext.Sync)
            {
                FinishEvent();
                return;
            }

            int executionCount = 0;

            foreach (EventAction info in targetActions)
            {
                ILifecycleObject pl = info.Owner;

                if (scheduler == null)
                {
                    info.Action.Invoke(sender, @event);
                    continue;
                }

                scheduler.ScheduleUpdate(pl, () =>
                {
                    executionCount++;
                    info.Action.Invoke(sender, @event);

                    //all actions called; run OnEventExecuted
                    if (executionCount == targetActions.Count)
                    {
                        FinishEvent();
                    }
                }, primaryName + "EmitTask", (ExecutionTargetContext)@event.ExecutionTarget);
            }

            if (scheduler == null)
            {
                FinishEvent();
            }
        }
コード例 #4
0
ファイル: EventManager.cs プロジェクト: lovenets/Rocket
 public EventManager(IDependencyContainer container)
 {
     this.container = container;
     container.TryResolve(null, out logger);
 }