示例#1
0
 public virtual bool Init(bool declareInit)
 {
     if (mIsInitCalled)
     {
         return(false);
     }
     mIsInitCalled           = true;
     IsConnected             = false;
     MyBaseThing.StatusLevel = 0;
     MyBaseThing.LastMessage = "Service is ready";
     MyBaseThing.RegisterStatusChanged(sinkUpdateUX);
     MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
     if (string.IsNullOrEmpty(MyBaseThing.ID))
     {
         MyBaseThing.ID = Guid.NewGuid().ToString();
         TheThing.SetSafePropertyBool(MyBaseThing, "IsStateSensor", true);
         TheThing.SetSafePropertyString(MyBaseThing, "StateSensorType", "analog");
         TheThing.SetSafePropertyString(MyBaseThing, "StateSensorUnit", "ms");
         TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue", 100);
         TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorAverage", 50);
         TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMinValue", 0);
         //TheThing.SetSafePropertyString(MyBaseThing, "StateSensorName", MyBaseThing.FriendlyName);
         TheRulesFactory.CreateOrUpdateRule(new TheThingRule(Guid.NewGuid(), "NetService:" + MyBaseThing.FriendlyName + " Failed", MyBaseThing, "StatusLevel", eRuleTrigger.Larger, "1", true, true));
     }
     if (declareInit)
     {
         mIsInitialized = true;
     }
     return(true);
 }
示例#2
0
        public override bool Init()
        {
            if (mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            MyBaseThing.RegisterStatusChanged(sinkStatChanged);
            MyBaseThing.StatusLevel = 4;
            MyBaseThing.Value       = "0";
            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
            MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted);
            MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, OnThingRegisterd);

            if (!TheBaseAssets.MyServiceHostInfo.IsCloudService && !TheThing.GetSafePropertyBool(MyBaseThing, "RanBefore"))
            {
                TheThing.SetSafePropertyBool(MyBaseThing, "RanBefore", true);
                string tAutoPing = TheBaseAssets.MySettings.GetSetting("AutoPing");
                if (!string.IsNullOrEmpty(tAutoPing))
                {
                    TheThing tThing = new TheThing();
                    tThing.EngineName   = MyBaseEngine.GetEngineName();
                    tThing.DeviceType   = eNetworkServiceTypes.PingService;
                    tThing.Address      = tAutoPing;
                    tThing.FriendlyName = tAutoPing;
                    TheThing.SetSafePropertyBool(tThing, "AllowRTT", true);
                    TheThing.SetSafePropertyBool(tThing, "AutoConnect", true);
                    TheThingRegistry.RegisterThing(tThing);
                }
            }

            if (MyBaseEngine.GetEngineState().IsService)
            {
                TheCommonUtils.cdeRunAsync("Init Networkers", true, (o) =>
                {
                    InitNetworkServices();
                    mIsInitialized = true;
                    FireEvent(eThingEvents.Initialized, this, true, true);
                    MyBaseEngine.ProcessInitialized();
                });
            }
            return(false);
        }