Esempio n. 1
0
        static void sinkReady()
        {
            Debug.WriteLine("Registering events for engine... ");

            TheCDEngines.MyContentEngine.RegisterEvent(eEngineEvents.IncomingMessage, sinkIncoming);
            if (TheCDEngines.MyNMIService != null)
            {
                TheCDEngines.MyNMIService.RegisterEvent(eEngineEvents.IncomingMessage, sinkIncoming);
                //TheCDEngines.MyContentEngine.RegisterEvent(eEngineEvents.ChannelConnected, sinkEstablished);
            }
            TheCommonUtils.cdeRunAsync("LoopDiDoop", true, (o) =>
            {
                TheThing tTimer    = null;
                TheThing GoogleDNS = null;
                TheThing ThingBar  = null;
                while (TheBaseAssets.MasterSwitch)
                {
                    TheCommonUtils.SleepOneEye(5000, 100);

                    if (ThingBar == null)
                    {
                        ThingBar = TheThingRegistry.GetThingByProperty("*", Guid.Empty, "FriendlyName", "ThingBar");
                        if (ThingBar != null)
                        {
                            TheThingRegistry.RegisterEventOfThing(ThingBar, eThingEvents.ValueChanged, (sender, para) =>
                            {
                                TSM tTSM2 = new TSM(eEngineName.ContentService, "UNITY:GAUGE", para.ToString());
                                TheCommCore.PublishCentral(tTSM2);
                            });
                        }
                    }
                    if (tTimer == null)
                    {
                        tTimer = TheThingRegistry.GetThingByProperty("*", Guid.Empty, "DeviceType", "Timer");
                        if (tTimer != null)
                        {
                            TheThingRegistry.RegisterEventOfThing(tTimer, eThingEvents.ValueChanged, (sender, para) =>
                            {
                                TSM tTSM2 = new TSM(eEngineName.ContentService, "UNITY:TIMER", para.ToString());
                                TheCommCore.PublishCentral(tTSM2);
                            });
                        }
                    }
                    if (GoogleDNS == null)
                    {
                        GoogleDNS = TheThingRegistry.GetThingByProperty("*", Guid.Empty, "FriendlyName", "Google DNS");
                        if (GoogleDNS != null)
                        {
                            TheThingRegistry.RegisterEventOfThing(GoogleDNS, eThingEvents.PropertyChanged, (sender, para) =>
                            {
                                cdeP tP = para as cdeP;
                                if (tP != null && tP.Name == "RoundTripTime")
                                {
                                    TSM tTSM2 = new TSM(eEngineName.ContentService, "UNITY:HEART", para.ToString());
                                    TheCommCore.PublishCentral(tTSM2);
                                }
                            });
                        }
                    }
                    if (GoogleDNS != null && tTimer != null && ThingBar != null)
                    {
                        break;
                    }
                }
            });
        }