public bool Init()
        {
            if (!mIsInitStarted)
            {
                mIsInitStarted = true;
                MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);

                /// Note: Where this sample is interesting is when one (or both)
                /// of the following flags are defined on the command line of
                /// the application host:
                /// -- CDMyWebToMeshSample_EnableREST=true -- Enable REST Server Support.
                /// -- CDMyWebToMeshSample_EnableMeshDataQuery -- Whether to send TSM messages out for data query.

                g_EnableRESTServer       = utils.CheckCommandLineFlag("CDMyWebToMeshSample_EnableREST");
                g_EnableMeshDataQuery    = utils.CheckCommandLineFlag("CDMyWebToMeshSample_EnableMeshDataQuery");
                g_EnableMeshDataResponse = utils.CheckCommandLineFlag("CDMyWebToMeshSample_EnableMeshDataResponse");

                // Initialize http handler for REST handling.
                if (g_EnableRESTServer)
                {
                    RegisterHttpInterceptor();
                }

                MyBaseThing.StatusLevel = 1;
                MyBaseThing.LastMessage = "Mile Record Holder service has started.";
                mIsInitCompleted        = true;
                MyBaseEngine.ProcessInitialized();
            }
            return(true);
        }
 public bool Init()
 {
     if (!mIsInitStarted)
     {
         mIsInitStarted          = true;
         MyBaseThing.StatusLevel = 1;
         MyBaseThing.LastMessage = "Service has started";
         MyBaseEngine.ProcessInitialized();
         mIsInitCompleted = true;
     }
     return(true);
 }
Example #3
0
        public bool Init()
        {
            if (!mIsInitStarted)
            {
                mIsInitStarted          = true;
                MyBaseThing.StatusLevel = 4;
                MyBaseThing.LastMessage = "Service has started";

                InitServices();
                mIsInitCompleted = true;           // For future IsInit() calls
                MyBaseEngine.ProcessInitialized(); //Set the status of the Base Engine according to the status of the Things it manages
            }
            return(false);
        }
Example #4
0
 //List<ScriptSnapshot> MyScriptTableList;
 //Dictionary<string, Guid> SnapShotGuids;
 public bool Init()
 {
     if (!mIsInitStarted)
     {
         mIsInitStarted = true;
         MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
         mIsInitCompleted = true;
         MyBaseEngine.ProcessInitialized();
         MyBaseThing.SetStatus(4, "Waiting for other services before running scripts");
         TheBaseEngine.WaitForEnginesStarted(OnEnginesStarted);
         SetupStorageMirror();
     }
     return(true);
 }
Example #5
0
        public bool Init()
        {
            if (!mIsInitStarted)
            {
                mIsInitStarted = true;
                MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);

                // Initialize http interceptor for REST handling.
                RegisterHttpInterceptor();

                MyBaseThing.StatusLevel = 1;
                MyBaseThing.LastMessage = "Mile Record Holder service has started.";
                mIsInitCompleted        = true;
                MyBaseEngine.ProcessInitialized();
            }
            return(true);
        }
Example #6
0
        public bool Init()
        {
            if (!mIsInitStarted)
            {
                mIsInitStarted = true;
                MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
                // Additional initialization processing goes here

                // Initialize handler for /ThingAPI REST handling.
                RegisterHttpInterceptor();

                MyBaseThing.StatusLevel = 1;
                MyBaseThing.LastMessage = "Hello World service has started.";
                mIsInitCompleted        = true;
                MyBaseEngine.ProcessInitialized();
            }
            return(true);
        }
        public bool Init()
        {
            if (mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
            if (TheThing.GetSafePropertyString(MyBaseThing, "VisitorCount") == "")
            {
                VisitorCount = 0;
            }
            MyNodePrintsName = $"NodePrints{TheThing.GetSafeThingGuid(MyBaseThing, "NodePrints")}";
            TheBaseEngine.WaitForStorageReadiness(OnStorageReady, true);
            MyBaseThing.SetPublishThrottle(15000);
            TheCommCore.RegisterRelayEvents(null, null, sinkNewConnection);

            if (MyVisitorLog == null)
            {
                MyVisitorLog = new TheVisitorLog(MyBaseThing);
            }
            TheQueuedSenderRegistry.RegisterHealthTimer(GetSystemInfo);
            TheCDEngines.MyNMIService.RegisterEvent("NMI_MY_LOCATION", (sender2, para) =>
            {
                var t = para as TheNMILocationInfo;
                if (t != null)
                {
                    var NewEntry = new TheVisitorLogData {
                        cdeN = t.cdeN, latitude = t.Latitude, longitude = t.Longitude, ip = t.ClientInfo?.UserID.ToString(), LastVisit = DateTimeOffset.Now, Description = t.ClientInfo != null && t.ClientInfo.UserID != Guid.Empty ? TheUserManager.GetUserFullName(t.ClientInfo.UserID) : "Unknown user"
                    };
                    MyVisitorLog.LogVisitor(NewEntry);
                    myGoogleMap?.SetUXProperty(Guid.Empty, $"AddMarker={TheCommonUtils.SerializeObjectToJSONString(NewEntry)}");
                }
            });
            TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/cdemeshinfo.aspx", sinkRequestMeshInfo);
            MyBaseEngine.ProcessInitialized();
            MyBaseEngine.SetEngineReadiness(true, null);
            MyBaseEngine.SetStatusLevel(1);
            mIsInitialized = true;
            return(true);
        }
        public bool Init()
        {
            if (mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
            MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnDeletedThing);
            MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, OnThingRegistered);
            MyBaseEngine.RegisterEvent(eEngineEvents.ShutdownEvent, OnShutdown);
            TheCommonUtils.cdeRunAsync("Init Mesh Receiver Connections", false, (state) =>
            {
                // Migrate instances from previous versions
                List <TheThing> tLegacyDeviceList = TheThingRegistry.GetThingsOfEngine("CDMyCloudServices.cdeMyCloudService");
                foreach (var tLegacyDevice in tLegacyDeviceList)
                {
                    if (!tLegacyDevice.HasLiveObject)
                    {
                        switch (tLegacyDevice.DeviceType)
                        {
                        case "Mesh Receiver":
                            tLegacyDevice.EngineName = MyBaseThing.EngineName;
                            tLegacyDevice.DeviceType = MeshDeviceTypes.MeshReceiver;
                            TheThingRegistry.UpdateThing(tLegacyDevice, false);
                            break;
                        }
                    }
                }

                //await System.Threading.Tasks.Task.Delay(30000);
                InitServers();
                mIsInitialized = true;
                FireEvent(eThingEvents.Initialized, this, true, true);
                MyBaseEngine.ProcessInitialized();
            }, null);

            return(false);
        }
Example #9
0
        public bool Init()
        {
            if (!mIsInitStarted)
            {
                mIsInitStarted = true;
                MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
                // Additional initialization processing goes here

                // Registering an Http Interceptor that just returns a hello message.
                TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/HelloHTTPInterceptor", sinkHelloHttpInterceptor);

                // Registering an Http Interceptor that returns a dynamic web page.
                TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/relay.html", sinkRelay);

                //// Injecting scripts into C-DEngine context.
                //TheCommCore.MyHttpService.RegisterGlobalScriptInterceptor("/MyStuff.js", (o) =>
                //{
                //});

                //TheRequestData p = new TheRequestData();
                //string strOut = TheCommCore.MyHttpService.CreateHttpHeader(p);
                //List<string> pGlobalScripts = TheCommCore.MyHttpService.GetGlobalScripts();

                //// Providing status info to C-DEngine status page.
                //// Request to append status details to the /CDESTATUS.ASPX page for ?ALL or ?DIAG
                //TheCommCore.MyHttpService.RegisterStatusRequest((o) =>
                //{
                //});

                MyBaseThing.StatusLevel = 1;
                MyBaseThing.LastMessage = "Hello HTTP Interceptor Service has started.";
                mIsInitCompleted        = true;
                MyBaseEngine.ProcessInitialized();
            }
            return(true);
        }
Example #10
0
        public override bool CreateUX()
        {
            if (!mIsUXInitCalled)
            {
                mIsUXInitCalled = true;

                var tFlds   = TheNMIEngine.AddStandardForm(MyBaseThing, null, 12);
                var tMyForm = tFlds["Form"] as TheFormInfo;
                (tFlds["DashIcon"] as TheDashPanelInfo).PropertyBag = new ThePropertyBag()
                {
                    "Format={0}", "Thumbnail=FA5:f7cd"
                };

                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 1, 0, 0, "Message Header", false, null, null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
                {
                    ParentFld = 1, IsSmall = true, MaxTileWidth = 12
                }));
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 2, 2, 0, "From Address", "FromAddress", new ThePropertyBag()
                {
                    "TileHeight=1", "TileWidth=6", "ParentFld=1"
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 3, 2, 0, "Enter a Recipient", "Recipient", new ThePropertyBag()
                {
                    "TileHeight=1", "TileWidth=6", "ParentFld=1"
                });

                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 4, 2, 0, "Subject", "SubjectText", new ThePropertyBag()
                {
                    "TileHeight=1", "TileWidth=6", "ParentFld=1"
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TextArea, 5, 2, 0, "Enter a message", "MessageText", new ThePropertyBag()
                {
                    "TileHeight=3", "TileWidth=6", "Rows=3", "ParentFld=1"
                });

                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 100, 2, 0, "Additional Settings...", null, new nmiCtrlCollapsibleGroup()
                {
                    DoClose = true, IsSmall = true, MaxTileWidth = 12, ParentFld = 1
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 124, 2, 0xC0, "Username", "UserName", new ThePropertyBag()
                {
                    "TileHeight=1", "TileWidth=6", "ParentFld=100"
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.Password, 125, 3, 0xC0, "Password", "Password", new ThePropertyBag()
                {
                    "TileHeight=1", "TileWidth=6", "ParentFld=100", "HideMTL=true"
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.ComboBox, 27, 2, 0xC0, "Carrier", "Carrier", new nmiCtrlComboBox {
                    ParentFld = 100, Options = String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12};{13}", "", "AT&T", "Boost Mobile", "T-Mobile", "Virgin Mobile", "Cingular", "Sprint", "Verizon", "Nextel", "US Cellular", "Suncom", "Powertel", "Alltel", "Metro PCS")
                });

                TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, 32, 2, 0, "Send SMS", false, "", null, new nmiCtrlTileButton()
                {
                    NoTE = true, ParentFld = 100, ClassName = "cdeGoodActionButton"
                });
                mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
                {
                    SendSMS(null);
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TextArea, 55, 0, 0, "Sent Result", "ResultText", new ThePropertyBag()
                {
                    "TileHeight=2", "TileWidth=6", "Rows=2", "ParentFld=6"
                });
                MyBaseEngine.ProcessInitialized();
                mIsUXInitialized = true;
            }
            return(true);
        }