Exemplo n.º 1
0
        public void AddConnectionWizard()
        {
            var flds = TheNMIEngine.AddNewWizard <TheModbusWiz>(new Guid("{824858DA-061A-4A70-92E3-A31B2D8C7800}"), Guid.Empty, TheNMIEngine.GetEngineDashBoardByThing(MyBaseThing).cdeMID, "Welcome to the Modbus Connection Wizard",
                                                                new nmiCtrlWizard {
                PanelTitle = "<i class='fa faIcon fa-5x'>&#xf0d0;</i></br>New Modbus Connection", SideBarTitle = "New Modbus Connection Wizard", SideBarIconFA = "&#xf545;", TileThumbnail = "FA5:f545"
            },
                                                                (myClass, pClientInfo) =>
            {
                myClass.cdeMID   = Guid.Empty;
                TheThing tMemTag = null;
                if (myClass.DeviceType == "RTU")
                {
                    var tReq = new TheThingRegistry.MsgCreateThingRequestV1()
                    {
                        EngineName   = MyBaseEngine.GetEngineName(),
                        DeviceType   = eModbusType.ModbusRTUDevice,
                        FriendlyName = myClass.ClientName,
                        OwnerAddress = MyBaseThing,
                        InstanceId   = Guid.NewGuid().ToString(),
                        Address      = myClass.Address,
                        Properties   = new Dictionary <string, object> {
                            { "Baudrate", myClass.Baudrate },
                            { "BitFormat", myClass.BitFormat },
                            { "AutoConnect", myClass.AutoConnect },
                            { "SlaveAddress", myClass.SlaveAddress },
                        },
                        CreateIfNotExist = true
                    };
                    tMemTag = TheThingRegistry.CreateOwnedThingAsync(tReq).Result;
                }
                else
                {
                    var tReq = new TheThingRegistry.MsgCreateThingRequestV1()
                    {
                        EngineName   = MyBaseEngine.GetEngineName(),
                        DeviceType   = eModbusType.ModbusTCPDevice,
                        FriendlyName = myClass.ClientName,
                        OwnerAddress = MyBaseThing,
                        InstanceId   = Guid.NewGuid().ToString(),
                        Address      = myClass.Address,
                        Properties   = new Dictionary <string, object> {
                            { "IpPort", myClass.Port },
                            { "AutoConnect", myClass.AutoConnect },
                            { "SlaveAddress", myClass.SlaveAddress },
                        },
                        CreateIfNotExist = true
                    };
                    tMemTag = TheThingRegistry.CreateOwnedThingAsync(tReq).Result;
                }
                tTargetButton.SetUXProperty(pClientInfo.NodeID, $"OnClick=TTS:{tMemTag.GetBaseThing().cdeMID}");
            });
            var tMyForm2 = flds["Form"] as TheFormInfo;

            tMyForm2.RegisterEvent2(eUXEvents.OnShow, (para, obj) =>
            {
                var pMsg = para as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
            });

            var tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 0, 1, 2, null /*"Name and Address"*/, "3:'<%DeviceType%>'=='RTU'");

            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleEnded, 1, 1, 2, 0, "Connection Name", "ClientName", new TheNMIBaseControl {
                Explainer = "1. Enter name for the new Modbus connection.",
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.ComboBox, 1, 2, 2, 0, "Modbus Type", "DeviceType", new nmiCtrlComboBox {
                Options = "RTU;TCP", Explainer = "2. Select the Type of Modbus Connection.",
            });

            tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 1, 2, 0, null /*"Name and Address"*/);
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleEnded, 2, 1, 2, 0, "IP Address or DNS", "Address", new TheNMIBaseControl {
                Explainer = "1. Enter IP Address or DNS name of Server.",
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.Number, 2, 2, 2, 0, "Port", "Port", new TheNMIBaseControl {
                DefaultValue = "502", Explainer = "2. Enter port of the modbus server.",
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.Number, 2, 3, 2, 0, "Slave Address", "SlaveAddress", new nmiCtrlNumber()
            {
                DefaultValue = "1", TileWidth = 3, ParentFld = 200, MaxValue = 255, MinValue = 0
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleCheck, 2, 4, 2, 0, "Auto-Connect", "AutoConnect", new nmiCtrlSingleCheck {
                DefaultValue = "true", Explainer = "3. If selected the connection will auto-connect.",
            });

            tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 1, 3, 0, null /*"Name and Address"*/);
            var ComSelect = TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.ComboBox, 3, 1, 2, 0, "Select COM Port", "Address", new TheNMIBaseControl {
                Explainer = "1. Select the COM port connected to your Server.",
            });

            try
            {
                var    sports = SerialPort.GetPortNames();
                string tp     = TheCommonUtils.CListToString(sports, ";");
                ComSelect.PropertyBag = new nmiCtrlComboBox {
                    Options = tp
                };
            }
            catch (Exception eee)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(10000, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseThing.EngineName, $"GetPortNames failed : {eee}", eMsgLevel.l1_Error));
            }

            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.ComboBox, 3, 2, 2, 0, "Baud", "Baudrate", new nmiCtrlComboBox()
            {
                TileWidth = 3, ParentFld = 200, Options = "2400;4800;9600;19200;38400;57600"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.ComboBox, 3, 3, 2, 0, "Bit Format", "BitFormat", new nmiCtrlComboBox()
            {
                TileWidth = 3, ParentFld = 200, Options = "8,N,1:0;8,E,1:1;8,O,1:2"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.Number, 3, 4, 2, 0, "Slave Address", "SlaveAddress", new nmiCtrlNumber()
            {
                DefaultValue = "1", TileWidth = 3, ParentFld = 200, MaxValue = 255, MinValue = 0
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleCheck, 3, 5, 2, 0, "Auto-Connect", "AutoConnect", new nmiCtrlSingleCheck {
                DefaultValue = "true", Explainer = "2. If selected the connection will auto-connect.",
            });

            TheNMIEngine.AddWizardFinishPage(MyBaseThing, tMyForm2, 5);
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SmartLabel, 5, 1, 0, 0, null, null, new nmiCtrlSmartLabel {
                NoTE = true, TileWidth = 7, Text = "Done...what do you want to do next?", TileHeight = 2
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileGroup, 5, 2, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 1, TileHeight = 2, TileFactorX = 2
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileButton, 5, 3, 2, 0, "Go to Modbus Dashboard", null, new nmiCtrlTileButton {
                NoTE = true, TileHeight = 2, TileWidth = 3, OnClick = $"TTS:{mMyDashboard.cdeMID}", ClassName = "cdeTransitButton"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileGroup, 5, 4, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 1, TileHeight = 2
            });
            tTargetButton = TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileButton, 5, 5, 2, 0, "Go to New Connection", null, new nmiCtrlTileButton {
                NoTE = true, TileHeight = 2, TileWidth = 3, ClassName = "cdeTransitButton"
            });
        }
Exemplo n.º 2
0
        public void AddVSensorWizard()
        {
            var flds = TheNMIEngine.AddNewWizard <TheVSensWiz>(new Guid("{4B536A76-8618-45A9-A6F5-B9AC1743EBA3}"), Guid.Empty, TheNMIEngine.GetEngineDashBoardByThing(MyBaseThing).cdeMID, "Welcome to the V-Things Wizard",
                                                               new nmiCtrlWizard {
                PanelTitle = "<i class='fa faIcon fa-5x'>&#xf0d0;</i></br>Add a new Sensor Dashboard", SideBarTitle = "New Sensor Dashboard Wizard", SideBarIconFA = "&#xf545;", TileThumbnail = "FA5:f545"
            },
                                                               (myClass, pClientInfo) =>
            {
                myClass.cdeMID = Guid.Empty;
                myClass.Error  = "";

                var tReq = new TheThingRegistry.MsgCreateThingRequestV1()
                {
                    EngineName   = MyBaseEngine.GetEngineName(),
                    DeviceType   = eVThings.eVirtualSensor,
                    FriendlyName = myClass.ClientName,
                    InstanceId   = Guid.NewGuid().ToString(),
                    Properties   = new Dictionary <string, object> {
                        { "RealSensorThing", myClass.SelectedSensor },
                        { "RealSensorProperty", myClass.SelectedProp },
                    },
                    CreateIfNotExist = true
                };
                var tMemTag = TheThingRegistry.CreateOwnedThingAsync(tReq).Result;
                mResultInfo?.SetUXProperty(pClientInfo.NodeID, $"Text=Success!");
                mInstanceButton?.SetUXProperty(pClientInfo.NodeID, $"OnClick=TTS:{tMemTag.GetBaseThing().cdeMID}");
            });
            var tMyForm2 = flds["Form"] as TheFormInfo;

            var tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 0, 1, 0, "Sensor Selector");

            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleEnded, 1, 1, 2, 0, "Dashboard Name", "ClientName", new TheNMIBaseControl {
                Explainer = "1. Enter name for the new Dashboard.",
            });
            var tf = TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.ThingPicker, 1, 2, 2, 0, "Select Sensor Thing", "SelectedSensor", new nmiCtrlThingPicker()
            {
                IncludeEngines = true, Explainer = "2. Select a thing to show in Dashboard"
            });

            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.PropertyPicker, 1, 3, 2, 0, "Select Property", "SelectedProp", new nmiCtrlPropertyPicker()
            {
                ThingFld = tf.FldOrder, Explainer = "3. Select a property of the Thing"
            });

            TheNMIEngine.AddWizardFinishPage(MyBaseThing, tMyForm2, 2);
            mResultInfo = TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SmartLabel, 2, 1, 0, 0, null, "Error", new nmiCtrlSmartLabel {
                FontSize = 24, NoTE = true, TileWidth = 7
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SmartLabel, 2, 2, 0, 0, null, null, new nmiCtrlSmartLabel {
                NoTE = true, TileWidth = 7, Text = "What do you want to do next?", TileHeight = 2
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileGroup, 2, 3, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 1, TileHeight = 2, TileFactorX = 2
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileButton, 2, 4, 2, 0, "Run another Wizard", null, new nmiCtrlTileButton {
                NoTE = true, TileHeight = 1, TileWidth = 3, OnClick = $"TTS:{MyDashboard.cdeMID}", ClassName = "cdeTransitButton"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileGroup, 2, 5, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 1, TileHeight = 2
            });
            mInstanceButton = TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileButton, 2, 6, 2, 0, "Go to Sensor Dashboard", null, new nmiCtrlTileButton {
                NoTE = true, TileHeight = 1, TileWidth = 3, ClassName = "cdeTransitButton"
            });
        }
Exemplo n.º 3
0
        public void CreateOPCWizard()
        {
            TheFieldInfo tTargetButton = null;
            var          flds          = TheNMIEngine.AddNewWizard <TheOPCSetClass>(new Guid("{56565656-6AD1-45AE-BE61-96AF02329614}"), Guid.Empty, TheNMIEngine.GetEngineDashBoardByThing(MyBaseThing).cdeMID, "Welcome to the OPC Wizard",
                                                                                    new nmiCtrlWizard {
                PanelTitle = "<i class='fa faIcon fa-3x'>&#xf0d0;</i></br>New OPC Client", SideBarTitle = "New OPC Client Wizard", SideBarIconFA = "&#xf545;", TileThumbnail = "FA5:f545"
            },
                                                                                    (myClass, pClientInfo) =>
            {
                myClass.cdeMID   = Guid.Empty;
                TheThing tMemTag = null;
                if (myClass.CreateMemoryTag)
                {
                    var tReq = new TheThingRegistry.MsgCreateThingRequestV1()
                    {
                        EngineName       = "CDMyVThings.TheVThings",
                        DeviceType       = "Memory Tag",
                        FriendlyName     = myClass.ClientName,
                        OwnerAddress     = MyBaseThing,
                        InstanceId       = Guid.NewGuid().ToString(),
                        CreateIfNotExist = true
                    };
                    tMemTag = TheThingRegistry.CreateOwnedThingAsync(tReq).Result;
                }

                var tOPCReq = new TheThingRegistry.MsgCreateThingRequestV1()
                {
                    EngineName       = "CDMyOPCUAClient.cdeOPCUaClient",
                    DeviceType       = "OPC-UA Remote Server",
                    FriendlyName     = myClass.ClientName,
                    Address          = myClass.OPCAddress,
                    OwnerAddress     = MyBaseThing,
                    InstanceId       = Guid.NewGuid().ToString(),
                    CreateIfNotExist = true
                };
                tOPCReq.Properties = new Dictionary <string, object>();
                //tOPCReq.Properties["ID"] = Guid.NewGuid().ToString();
                tOPCReq.Properties["AutoConnect"]     = myClass.AutoConnect;
                tOPCReq.Properties["SendOpcDataType"] = true;
                if (!myClass.DisableSecurity)
                {
                    tOPCReq.Properties["DisableSecurity"]            = true;
                    tOPCReq.Properties["AcceptUntrustedCertificate"] = true;
                    tOPCReq.Properties["DisableDomainCheck"]         = true;
                    tOPCReq.Properties["AcceptInvalidCertificate"]   = true;
                    tOPCReq.Properties["Anonymous"] = true;
                }
                if (tMemTag != null)
                {
                    tOPCReq.Properties["TagHostThingForSubscribeAll"] = tMemTag.cdeMID;
                }
                var tOPCServer = TheThingRegistry.CreateOwnedThingAsync(tOPCReq).Result;
                try
                {
                    if (tOPCServer != null && myClass.Prop2Tag && myClass.AutoConnect)
                    {
                        var response = TheCommRequestResponse.PublishRequestJSonAsync <MsgOPCUAConnect, MsgOPCUAConnectResponse>(MyBaseThing, tOPCServer, new MsgOPCUAConnect {
                            LogEssentialOnly = true, WaitUntilConnected = true
                        }).Result;
                        if (response != null && string.IsNullOrEmpty(response.Error))
                        {
                            var tBrowseResponse = TheCommRequestResponse.PublishRequestJSonAsync <MsgOPCUABrowse, MsgOPCUABrowseResponse>(MyBaseThing, tOPCServer, new MsgOPCUABrowse()).Result;
                            if (string.IsNullOrEmpty(tBrowseResponse.Error))
                            {
                                TheCommCore.PublishToNode(pClientInfo.NodeID, new TSM(eEngineName.NMIService, "NMI_TOAST", $"OPC UA Client browse error: {tBrowseResponse.Error}"));
                                return;
                            }
                            else
                            {
                                List <MsgOPCUACreateTags.TagInfo> tTagList = tBrowseResponse.Tags;
                                if (tTagList != null && tTagList.Count > 0)
                                {
                                    var tres = TheCommRequestResponse.PublishRequestJSonAsync <MsgOPCUACreateTags, MsgOPCUACreateTagsResponse>(MyBaseThing, tOPCServer, new MsgOPCUACreateTags {
                                        Tags = tTagList, BulkApply = true
                                    }).Result;
                                    if (tres != null && string.IsNullOrEmpty(tres.Error))
                                    {
                                        TheCommCore.PublishToNode(pClientInfo.NodeID, new TSM(eEngineName.NMIService, "NMI_TOAST", "OPC UA Client Created and memory tag ready"));
                                    }
                                }
                            }
                        }
                    }
                    TheCommCore.PublishToNode(pClientInfo.NodeID, new TSM(eEngineName.NMIService, "NMI_TOAST", "OPC UA Client Created and ready"));
                }
                catch (Exception)
                {
                    TheCommCore.PublishToNode(pClientInfo.NodeID, new TSM(eEngineName.NMIService, "NMI_TOAST", "Something went wrong! Check the OPC and Memory Tag settings"));
                }
                tTargetButton.SetUXProperty(pClientInfo.NodeID, $"OnClick=TTS:{tOPCServer.GetBaseThing().cdeMID}");
                TheCommonUtils.SleepOneEye(2000, 100);
            });

            var tMyForm2 = flds["Form"] as TheFormInfo;

            var tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 0, 1, 2, null /*"Name and Address"*/);

            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleEnded, 1, 1, 2, 0, "Connection Name", "ClientName", new TheNMIBaseControl {
                Explainer = "1. Enter name for the new OPC connection.",
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleEnded, 1, 2, 2, 0, "OPC Server Address", "OPCAddress", new TheNMIBaseControl {
                Explainer = "1. Enter address of the OPC server.",
            });

            tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 1, 2, 3, null /* "Settings"*/);
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleCheck, 2, 1, 2, 0, "OPC Server requires Security", "DisableSecurity", new nmiCtrlSingleCheck {
                Explainer = "Check if the OPC Server requires security"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleCheck, 2, 2, 2, 0, "Create a Memory Tag", "CreateMemoryTag", new nmiCtrlSingleCheck {
                TileWidth = 3, Explainer = "Check to create a Memory Tag and check to subscribes all Tags into it"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleCheck, 2, 3, 2, 0, "All Tags in Memory Tag", "Prop2Tag", new nmiCtrlSingleCheck {
                TileWidth = 3
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SingleCheck, 2, 4, 2, 0, "Auto Connect to Server", "AutoConnect", new nmiCtrlSingleCheck {
                TileWidth = 3, Explainer = "Don't select this if your server requires security settings"
            });

            tFlds = TheNMIEngine.AddNewWizardPage(MyBaseThing, tMyForm2, 2, 3, 0, null /*"Final Settings"*/);
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SmartLabel, 3, 2, 0, 0, null, null, new nmiCtrlSmartLabel {
                Text = "Once you click finish, the Wizard will create the items you requested. It will notify you with a toast when its done", TileHeight = 5, TileWidth = 7, NoTE = true
            });
            //HELP SECTION final step help section

            TheNMIEngine.AddWizardProcessPage(MyBaseThing, tMyForm2, 4);
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SmartLabel, 4, 1, 0, 0, null, null, new nmiCtrlSmartLabel {
                NoTE = true, TileWidth = 7, Text = "Creating the new instance..please wait", TileHeight = 2
            });

            TheNMIEngine.AddWizardFinishPage(MyBaseThing, tMyForm2, 5);
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.SmartLabel, 5, 1, 0, 0, null, null, new nmiCtrlSmartLabel {
                NoTE = true, TileWidth = 7, Text = "Done...what do you want to do next?", TileHeight = 2
            });

            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileGroup, 5, 2, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 1, TileHeight = 2, TileFactorX = 2
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileButton, 5, 3, 2, 0, "Go to Dashboard", null, new nmiCtrlTileButton {
                NoTE = true, TileHeight = 2, TileWidth = 3, OnClick = $"TTS:{mMyDashboard.cdeMID}", ClassName = "cdeTransitButton"
            });
            TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileGroup, 5, 4, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 1, TileHeight = 2
            });
            tTargetButton = TheNMIEngine.AddWizardControl(MyBaseThing, tMyForm2, eFieldType.TileButton, 5, 5, 2, 0, "Go to New OPC Client", null, new nmiCtrlTileButton {
                NoTE = true, TileHeight = 2, TileWidth = 3, ClassName = "cdeTransitButton"
            });
        }