Пример #1
0
        private static IServiceCollection AddCdePubSubServices(this IServiceCollection collection)
        {
            collection.AddSingleton(sp =>
            {
                sp.UseCde();
                var engines = TheThingRegistry.GetBaseEngines(false);
                var engine  = engines.FirstOrDefault(e => e.GetEngineName() == InfrastructureEngine);
                if (engine != null)
                {
                    return(engine.GetBaseThing());
                }

                if (!TheCDEngines.RegisterNewMiniRelay(InfrastructureEngine))
                {
                    throw new InvalidOperationException("Failed to register CDE infrastructure engine");
                }

                engine = TheThingRegistry.GetBaseEngine(InfrastructureEngine, false);
                return(engine.GetBaseThing());
            });

            collection.AddSingleton(sp => new Publisher(Operator.GetLine(sp.GetRequiredService <TheThing>())).ConnectAsync().Result as Publisher)
            .AddSingleton(sp => sp.GetRequiredService <Publisher>() as IPublisher);
            collection.AddSingleton(sp => new Subscriber(Operator.GetLine(sp.GetRequiredService <TheThing>()), sp.GetRequiredService <Publisher>()))
            .AddSingleton(sp => sp.GetRequiredService <Subscriber>() as ISubscriber);

            return(collection);
        }
Пример #2
0
        public override void Disconnect(TheProcessMessage pMsg)
        {
            IsConnected             = false;
            MyBaseThing.StatusLevel = 0;
            var tList = TheThingRegistry.GetBaseEngines(true);

            foreach (var tEng in tList)
            {
                tEng.GetBaseThing()?.UnregisterStatusChanged(sinkSTChange);
                tEng.GetBaseThing()?.GetProperty("LastMessage", true).UnregisterEvent(eThingEvents.PropertyChanged, sinkLMChange);
            }
            MyBaseThing.LastMessage = $"Disconnected from Logger at {DateTimeOffset.Now}";
        }