public void AddSpeedGauge(TheFormInfo tMyForm, int pFldNumber = 25000, int pParentFld = TheDefaultSensor.SensorGaugeGroup, bool IsHighGood = false)
        {
            string Plotband = "";

            if (IsHighGood)
            {
                Plotband = $"PlotBand=[{{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMinValue")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"color\": \"#FF000088\" }}, {{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue")}, \"color\": \"#00FF0044\" }}]";
            }
            else
            {
                Plotband = $"PlotBand=[{{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMinValue")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"color\": \"#00FF0088\" }}, {{ \"from\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorAverage")}, \"to\": {TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue")}, \"color\": \"#FF000044\" }}]";
            }

            GaugeFld = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, pFldNumber, 0, 0, null, "QValue", new ThePropertyBag()
            {
                "ControlType=Speed Gauge", "NoTE=true", $"ParentFld={pParentFld}",
                "TileWidth=6", "TileHeight=3",
                $"MinValue={TheThing.GetSafePropertyNumber(MyBaseThing,"StateSensorMinValue")}",
                $"MaxValue={TheThing.GetSafePropertyNumber(MyBaseThing,"StateSensorMaxValue")}",
                $"SubTitle={TheThing.GetSafePropertyString(MyBaseThing, "StateSensorUnit")}",
                Plotband,
                $"SetSeries={{ \"name\": \"{TheThing.GetSafePropertyString(MyBaseThing, "StateSensorValueName")}\",\"data\": [{TheThing.GetSafePropertyNumber(MyBaseThing,"QValue")}],\"tooltip\": {{ \"valueSuffix\": \" {TheThing.GetSafePropertyString(MyBaseThing, "StateSensorUnit")}\"}}}}",
                $"Value={MyBaseThing.Value}"
            });
        }
Exemple #2
0
        private static Image DrawStripHeader(DateTimeOffset now, TheFieldInfo pInfo)
        {
            bool drawRightToLeft = (TheCommonUtils.CBool(pInfo?.PropBagGetValue("DrawRightToLeft")));
            int  pixelWidth      = 78 * TheCommonUtils.CInt(pInfo?.PropBagGetValue("TileWidth"));

            if (pixelWidth == 0)
            {
                pixelWidth = 78;
            }
            int Hours = TheCommonUtils.CInt(pInfo?.PropBagGetValue("Hours"));

            if (Hours == 0)
            {
                Hours = 1;
            }
            int    pixelHeight = 39;
            Bitmap bmp         = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb);

            DateTimeOffset start = now.Subtract(new TimeSpan(drawRightToLeft ? Hours : 0, now.Minute, now.Second));
            TimeSpan       step  = new TimeSpan(0, Hours * 5, 0);

            double scaling = (float)pixelWidth / (Hours * 60 * 60);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                Font           drawFont    = new Font("Arial", 10);
                SolidBrush     drawBrush   = new SolidBrush(Color.Black); // Color.FromArgb(179, 255, 255, 255));
                DateTimeOffset currentTime = start;
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                for (int i = 0; i <= 12; i++)
                {
                    string pattern = CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern;
                    pattern = pattern.Replace("MMMM", "MMM");
                    string timeValue = currentTime.DateTime.ToString(pattern) + "\n";

                    timeValue += currentTime.DateTime.ToShortTimeString();
                    SizeF  size = g.MeasureString(timeValue, drawFont);
                    double x    = now.Subtract(currentTime).TotalSeconds *scaling - size.Width / 2;
                    if (drawRightToLeft)
                    {
                        x = pixelWidth - x;
                    }
                    if (x >= -3 && x <= pixelWidth - size.Width + 3)
                    {
                        g.DrawString(timeValue, drawFont, drawBrush, new PointF((float)x, pixelHeight - size.Height - 5));
                    }
                    if (drawRightToLeft)
                    {
                        currentTime = currentTime.Add(step);
                    }
                    else
                    {
                        currentTime = currentTime.Subtract(step);
                    }
                }
            }
            return(bmp);
        }
Exemple #3
0
        public override bool DoCreateUX()
        {
            return(true); //TODO: Make much better UX here...Remove Controls first then create (see OPC DA Plugin)

#pragma warning disable CS0162
            MyStatusForm = TheNMIEngine.AddForm(new TheFormInfo(MyBaseThing)
            {
                FormTitle = MyBaseThing.FriendlyName, DefaultView = eDefaultView.Form
            });
            SummaryForm = TheNMIEngine.AddFormToThingUX(MyBaseThing, MyStatusForm, "CMyForm", MyBaseThing.FriendlyName, 3, 1, 0x0, "OPC UA Methods", "FriendlyName", new ThePropertyBag()
            {
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleEnded, 1, 0, MyBaseThing.cdeA, "OPC UA Method Name", "FriendlyName");

            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 2, 0x82, 0, "Call", false, "", null, new ThePropertyBag()
            {
                "PreventDefault", "TileWidth=2", "TileHeight=1", "Style=background-image:url('GlasButton.png');"
            });
            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (m_Method == null || m_Method.MyOPCServer == null || !m_Method.MyOPCServer.IsConnected)
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Server not connected - please connect first"));
                    return;
                }
                HandleMessage(this, new TheProcessMessage(new TSM(MyBaseThing.EngineName, "CALL_METHOD:" + TheCommonUtils.cdeGuidToString(Guid.NewGuid()))));
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TextArea, 3, 0, 0xC0, "Last MSG", false, "LastMessage", null, new ThePropertyBag()
            {
                "TileWidth=6", "TileHeight=3"
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SmartLabel, 100, 0, MyBaseThing.cdeA, "", false, null, null, new ThePropertyBag()
            {
                "Format=Input Arguments", "Style=font-size:20px;text-align: left;float:none;clear:left;background-color:black;color:white;"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SmartLabel, 200, 0, MyBaseThing.cdeA, "", false, null, null, new ThePropertyBag()
            {
                "Format=Output Arguments", "Style=font-size:20px;text-align: left;float:none;clear:left;background-color:black;color:white;"
            });

            CreateDynUX(false);
            return(true);

#pragma warning restore CS0162
        }
        public override bool CreateUX()
        {
            if (mIsUXInitialized)
            {
                return(true);                  //No processing if Storage is not active
            }
            mIsUXInitialized = true;
            TheDashboardInfo tDash = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "Storage Service: MS-SQL")
            {
                cdeA        = 0xC0,
                FldOrder    = 11,
                PropertyBag = new nmiDashboardTile()
                {
                    Category = "Services", Caption = "<i class='fa faIcon fa-5x'>&#xf1c0;</i></br>Storage Service: MS-SQL"
                }
            });

            if (TheCDEngines.MyIStorageService != null)
            {
                var tF = TheNMIEngine.AddStandardForm(MyBaseThing, "SQL Storage Settings", 20, TheThing.GetSafeThingGuid(MyBaseThing, "SQLStorageSettings").ToString(), null, 0xF0);
                var tMyUserSettingsForm = tF["Form"] as TheFormInfo;
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyUserSettingsForm, eFieldType.CollapsibleGroup, 30, 2, 0, "Storage Options", null, new nmiCtrlCollapsibleGroup()
                {
                    ParentFld = 1, DoClose = false, IsSmall = true, TileWidth = 6
                });
                TheFieldInfo thingRegistryBtn = TheNMIEngine.AddSmartControl(MyBaseThing, tMyUserSettingsForm, eFieldType.SingleCheck, 40, 2, 0, "Store Thing Registry", "StoreThingRegistry", new nmiCtrlSingleCheck()
                {
                    HelpText = "You have to restart the relay in order for this setting to get in effect", ParentFld = 30, DefaultValue = "False"
                });
                thingRegistryBtn.RegisterPropertyChanged(SinkUpdateStorage);
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyUserSettingsForm, eFieldType.SingleCheck, 50, 2, 0, "Don't Log Queue Updates", "DontLogQueue", new nmiCtrlSingleCheck()
                {
                    TileWidth = 3, ParentFld = 30
                });
            }

            //var tList=TheCDEngines.EnumerateStorageMirror().FirstOrDefault(s=>s.Value.Contains("TheFieldInfo"));
            ////if (tList != null)
            //{
            //    TheChartDefinition pChart = new TheChartDefinition(new Guid("{F7468BC6-03F7-4BF7-A0B7-A5A7B2A55645}"), tList.Value, 100, tList.Key, true, "", "", "");
            //    TheNMIEngine.AddChartScreen(MyBaseThing, pChart, 3, "Sensor Chart", 3, 0, "Charts", false, new ThePropertyBag() { ".NoTE=true", ".TileWidth=12", ".TileHeight=6", "Header=All Sensor Data" });
            //}
            TheNMIEngine.AddAboutButton(MyBaseThing, null, TheNMIEngine.GetNodeForCategory());

            return(true);
        }
Exemple #5
0
        public static TheFieldInfo UpdateSpeedGauge(TheFieldInfo pInfo, int MinVal, int MaxVal, int errLevel, bool invertRange = false)
        {
            if (pInfo == null)
            {
                return(null);
            }
            string Plotband = $"PlotBand=[{{ \"from\": {MinVal}, \"to\": {errLevel}, \"color\": \"#FF000088\" }}, {{ \"from\": {errLevel}, \"to\": {MaxVal}, \"color\": \"#00FF0044\" }}]";

            if (invertRange)
            {
                Plotband = $"PlotBand=[{{ \"from\": {MinVal}, \"to\": {errLevel}, \"color\": \"#00FF0044\" }}, {{ \"from\": {errLevel}, \"to\": {MaxVal}, \"color\": \"#FF000088\" }}]";
            }

            pInfo.PropertyBag = new ThePropertyBag()
            {
                $"MinValue={MinVal}",
                $"MaxValue={MaxVal}",
                Plotband
            };
            return(pInfo);
        }
Exemple #6
0
        public virtual void InitUX()
        {
            var tHead = TheNMIEngine.AddStandardForm(MyBaseThing, MyBaseThing.FriendlyName, null, 0x0, new nmiStandardForm {
                MaxTileWidth = 12, IconUpdateName = "StatusLevel", UseMargin = true
            });

            MyStatusForm            = tHead["Form"] as TheFormInfo; // TheNMIEngine.AddForm(new TheFormInfo(MyBaseThing) { FormTitle = MyBaseThing.DeviceType, DefaultView = eDefaultView.Form, PropertyBag = new ThePropertyBag { "MaxTileWidth=6" } });
            SummaryForm             = tHead["DashIcon"] as TheDashPanelInfo;
            MyCollapsHead           = tHead["Header"] as TheFieldInfo;
            SummaryForm.PropertyBag = new nmiDashboardTile {
                Format = $"{MyBaseThing.FriendlyName}<br>Status Level: {{0}}", LabelForeground = "white", ClassName = "cdeLiveTile cdeLiveTileBar"
            };
            var tBlock = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 2);

            tBlock["Group"].SetParent(1);
            tBlock["Group"].Flags = 0;
            tBlock["Group"].cdeA  = 0;
            tBlock["Value"].cdeA  = 0;
            tBlock = TheNMIEngine.AddConnectivityBlock(MyBaseThing, MyStatusForm, 120, sinkConnect);
            tBlock["Group"].SetParent(1);
            sinkUpdateUX(null);
        }
Exemple #7
0
        public static bool RegisterEvents(TheThing pBaseThing, TheFieldInfo pFldInfo)
        {
            pFldInfo.RegisterPropertyChanged((tQRField, pP) =>
            {
                SendStripChart(tQRField, pBaseThing.cdeMID, Guid.Empty);
            });
            ThePropertyBag.PropBagUpdateValue(pFldInfo.PropertyBag, "OnLoaded", "=", "y");
            TheCDEngines.MyNMIService.RegisterEvent($"{eNMIEvents.FieldLoaded}:{pFldInfo.cdeMID}", (pThing, pIncoming) =>
            {
                TheProcessMessage pMsg = pIncoming as TheProcessMessage;
                if (pMsg == null)
                {
                    return;
                }

                string[] cmd      = pMsg.Message.TXT.Split(':');
                TheFieldInfo tFld = TheNMIEngine.GetFieldById(TheCommonUtils.CGuid(cmd[1]));
                if (tFld != null)
                {
                    string[] tDI = pFldInfo.DataItem.Split('.');
                    string mDI   = pFldInfo.DataItem;
                    if (tDI.Length > 2 && tDI[0] == "MyPropertyBag")
                    {
                        mDI = tDI[1];
                        if (tDI.Length > 3)
                        {
                            for (int i = 2; i < tDI.Length - 1; i++)
                            {
                                mDI += "." + tDI[i];
                            }
                        }
                    }
                    SendStripChart(tFld, pBaseThing.cdeMID, pMsg.Message.GetOriginator());
                }
            });
            return(true);
        }
Exemple #8
0
        private static void SendStripChart(TheFieldInfo tQRField, Guid pThingGuid, Guid pOrg)
        {
            List <TheDrawingObject> tSendLIst = new List <TheDrawingObject>();
            DateTimeOffset          now       = DateTimeOffset.Now;

            byte[] TargetBytes;
            using (MemoryStream memstream = new MemoryStream())
            {
                DrawStripHeader(now, tQRField).Save(memstream, ImageFormat.Png);
                TargetBytes = memstream.ToArray();
            }
            //StripHeaderImage = TargetBytes;
            cdeP tP = new cdeP("HeaderImage", null);

            tP.cdeT  = 4;
            tP.Value = TargetBytes;

            TheNMIEngine.SetUXProperty(pOrg, tQRField.cdeMID, $"HeaderImage={tP}");

            Image tImg = DrawStrip(pThingGuid, now, tQRField);

            if (tImg != null)
            {
                using (MemoryStream memstream = new MemoryStream())
                {
                    tImg.Save(memstream, ImageFormat.Png);
                    TargetBytes = memstream.ToArray();
                }
                //StripImage = TargetBytes;
                cdeP tP2 = new cdeP("StripImage", null);
                tP2.cdeT  = 4;
                tP2.Value = TargetBytes;

                TheNMIEngine.SetUXProperty(pOrg, tQRField.cdeMID, $"StripImage={tP2}");
            }
        }
        public virtual bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;

            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, null, 12, null, "Value");

            MyStatusForm            = tFlds["Form"] as TheFormInfo;
            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = new ThePropertyBag()
            {
                string.Format("Format={0}<br>{{0}} Properties", MyBaseThing.FriendlyName), "TileWidth=2"
            };
            SummaryForm.RegisterPropertyChanged(sinkStatChanged);

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 10);

            ts["Group"].SetParent(1);

            var tc = TheNMIEngine.AddStartingBlock(MyBaseThing, MyStatusForm, 20, (pMsg, DoStart) =>
            {
                if (DoStart)
                {
                    OnChangeTimer(null);
                }
                else
                {
                    StopGenerator();
                }
            });

            tc["Group"].SetParent(1);
            ts["Group"].Header = "Settings...";

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 51, 2, 0x0, "###CDMyVThings.TheVThings#NumberProperties187329#Number Properties###", nameof(Gen_Config_NumberOfActiveProperties), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            CountBar = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 52, 2, 0x0, "###CDMyVThings.TheVThings#Frequencyms741318#Frequency###", nameof(Gen_Config_PropertyUpdateInterval), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 53, 0, 0x0, "###CDMyVThings.TheVThings#PropertiesperSecond546134#Properties per Second###", nameof(Gen_Stats_PropertiesPerSecond), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 54, 0, 0x0, "###CDMyVThings.TheVThings#Propertycount904939#Property Counter###", nameof(Gen_Stats_PropertyCounter), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 60, 2, 0, "###CDMyVThings.TheVThings#ResetCounter741318#Reset Counter###", false, "", null, new nmiCtrlTileButton()
            {
                TileWidth = 3, ParentFld = 20, ClassName = "cdeGoodActionButton", NoTE = true
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                TheProcessMessage pMsg = pPara as TheProcessMessage;
                if (pMsg == null || pMsg.Message == null)
                {
                    return;
                }
                this.Gen_Stats_PropertyCounter     = 0;
                this.Gen_Stats_PropertiesPerSecond = 0;
                sinkStatChanged(null, null);
            });

            //PropTable = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Table, 100, 0xA2, 0x80, "###CDMyVThings.TheVThings#AllProperties100123#All Properties###", "mypropertybag;1", new TheNMIBaseControl() { TileWidth = 12, TileHeight = 6, ParentFld = 1 });
            PropTable = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Table, 100, 0xA2, 0x80, "###CDMyVThings.TheVThings#AllProperties100123#All Properties###", "mypropertybag;0", new TheNMIBaseControl()
            {
                NoTE = true, TileWidth = 12, TileHeight = 6, ParentFld = 1
            });
            mIsUXInitialized = true;
            return(true);
        }
        public virtual bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;

            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, null, 12, null, "Value");

            MyStatusForm            = tFlds["Form"] as TheFormInfo;
            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = new ThePropertyBag()
            {
                string.Format("Format={0}<br>{{0}} Properties", MyBaseThing.FriendlyName), "TileWidth=2"
            };

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 10);

            ts["Group"].SetParent(1);

            var tc = TheNMIEngine.AddStartingBlock(MyBaseThing, MyStatusForm, 20, (pMsg, DoStart) =>
            {
                if (DoStart)
                {
                    StartVerifier();
                }
                else
                {
                    StopVerifier();
                }
            });

            tc["Group"].SetParent(1);
            ts["Group"].Header = "Settings...";

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 41, 2, 0x0, "###CDMyVThings.TheVThings#NumberProperties295308#Number Properties###", "Gen_Config_NumberOfActiveProperties", new nmiCtrlNumber()
            {
                ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.ThingPicker, 42, 2, 0xC0, "###CDMyVThings.TheVThings#ThingforPropertySubs849298#Thing for Property Subs###", "ThingToVerify", new nmiCtrlThingPicker()
            {
                IncludeEngines = true, ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 43, 0, 0x0, "###CDMyVThings.TheVThings#PropertiesperSecond849298#Properties per Second###", "Gen_Stats_PropertiesPerSecond", new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 44, 0, 0x0, "###CDMyVThings.TheVThings#Propertycounter208103#Property Counter###", "Gen_Stats_PropertyCounter", new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 45, 2, 0x0, "###CDMyVThings.TheVThings#MinimumLatencyms44483#Minimum Latency (ms)###", "Gen_MinLatency", new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 46, 2, 0x0, "###CDMyVThings.TheVThings#MaximumLatencyms44483#Maximum Latency (ms)###", "Gen_MaxLatency", new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 20
            });
            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 60, 2, 0, "###CDMyVThings.TheVThings#ResetCounter741318#Reset Counter###", false, "", null, new nmiCtrlTileButton()
            {
                TileWidth = 3, ParentFld = 20, ClassName = "cdeGoodActionButton", NoTE = true
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                TheProcessMessage pMsg = pPara as TheProcessMessage;
                if (pMsg == null || pMsg.Message == null)
                {
                    return;
                }
                this.Stats_PropertyCounter     = 0;
                this.Stats_PropertiesPerSecond = 0;
                count       = 0;
                _maxLatency = 0;
                _minLatency = long.MaxValue;

                // sinkStatChanged(null, null);
            });

            PropTable = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Table, 120, 0xA2, 0x80, "All Properties", "mypropertybag;0", new ThePropertyBag()
            {
                "ParentFld=1", "TileWidth=12", "TileHeight=6"
            });

            mIsUXInitialized = true;
            return(true);
        }
        /// <summary>
        /// NMI of the Live Tag that can be overritten
        /// </summary>
        /// <returns></returns>
        public virtual bool DoCreateUX()
        {
            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, "FACEPLATE", 12, null, "Value");

            MyStatusForm            = tFlds["Form"] as TheFormInfo;
            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = new nmiDashboardTile()
            {
                Category = "A-NONE", Caption = "-HIDE", RenderTarget = "HomeCenterScreen"
            };

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 10);

            ts["Group"].SetParent(1);
            ts["FriendlyName"].Type   = eFieldType.TextArea;
            ts["FriendlyName"].Header = "###Friendly Name###";

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 500, 2, 0x80, "Default Properties", null, new nmiCtrlCollapsibleGroup {
                DoClose = true, IsSmall = true, TileWidth = 6, ParentFld = 1
            });
            TheNMIEngine.AddFields(MyStatusForm, new List <TheFieldInfo>
            {
                { new TheFieldInfo()
                  {
                      FldOrder = 20, DataItem = "cdeMID", Flags = 0, Type = eFieldType.SmartLabel, Header = "MID/Owner", PropertyBag = new TheNMIBaseControl {
                          ParentFld = 10, TileFactorY = 2
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 21, DataItem = "cdeO", Flags = 0, Type = eFieldType.SmartLabel, Header = "", PropertyBag = new TheNMIBaseControl {
                          ParentFld = 10, TileFactorY = 2
                      }
                  } },

                { new TheFieldInfo()
                  {
                      FldOrder = 513, DataItem = "MyPropertyBag.EngineName.Value", Flags = 0, Type = eFieldType.TextArea, Header = "Engine Name", PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 514, DataItem = "MyPropertyBag.DeviceType.Value", Flags = 0, Type = eFieldType.SingleEnded, Header = "DeviceType", PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 515, DataItem = "MyPropertyBag.ID.Value", Flags = 0, Type = eFieldType.TextArea, Header = "ID", PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 516, DataItem = "MyPropertyBag.Address.Value", Flags = 0, Type = eFieldType.TextArea, Header = "Address", PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },

                { new TheFieldInfo()
                  {
                      FldOrder = 518, DataItem = "MyPropertyBag.cdeStartupTime.Value", Flags = 0, Type = eFieldType.Number, Header = "Startup Time", TileWidth = 3, PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 520, DataItem = "HasLiveObject", Flags = 0, Type = eFieldType.SingleCheck, Header = "Is Alive", TileWidth = 3, PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 521, DataItem = "IsInitialized", Flags = 0, Type = eFieldType.SingleCheck, Header = "Is Init", TileWidth = 3, PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 522, DataItem = "IsUXInitialized", Flags = 0, Type = eFieldType.SingleCheck, Header = "UX Init", TileWidth = 3, PropertyBag = new TheNMIBaseControl {
                          ParentFld = 500
                      }
                  } },
            });
            TheFieldInfo tDl = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 2000, 2, 0x0, "", null, new nmiCtrlTileButton()
            {
                Thumbnail = "FA3:f019", TileWidth = 1, TileHeight = 1, ParentFld = 1
            });

            tDl.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "DOWNLOAD", OnDownloadClick);

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 1000, 2, 0x80, "All Properties", null, new nmiCtrlCollapsibleGroup {
                DoClose = true, IsSmall = true, MaxTileWidth = 12, ParentFld = 1
            });
            TheNMIEngine.AddField(MyStatusForm, new TheFieldInfo()
            {
                FldOrder = 1010, DataItem = "mypropertybag", Flags = 8, Type = eFieldType.Table, TileWidth = 12, TileHeight = 7, PropertyBag = new ThePropertyBag()
                {
                    "NoTE=true", "ParentFld=1000"
                }
            });

            return(true);
        }
Exemple #12
0
        private void CreateLogTable(int StartFld, int pParentFld)
        {
            TheFormInfo tBackup = TheNMIEngine.AddForm(new TheFormInfo(TheThing.GetSafeThingGuid(MyBaseThing, "BKUPFORM"), eEngineName.NMIService, "Log Files", MyLogFilesTableName)
            {
                GetFromServiceOnly = true, TileWidth = -1, OrderBy = "BackupTime desc", TileHeight = 4
            });

            TheNMIEngine.AddFields(tBackup, new List <TheFieldInfo>
            {
                { new TheFieldInfo()
                  {
                      FldOrder = 11, DataItem = "BackupTime", Flags = 0, Type = eFieldType.DateTime, Header = "Log Create Date", FldWidth = 2
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 12, DataItem = "Title", Flags = 0, Type = eFieldType.SingleEnded, Header = "Log Name", FldWidth = 7
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 13, DataItem = "BackupSize", Flags = 0, Type = eFieldType.SingleEnded, Header = "Log Size", FldWidth = 2
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 100, DataItem = "CDE_DELETE", Flags = 2, cdeA = 0x80, Type = eFieldType.TileButton, TileWidth = 1, TileHeight = 1
                  } },
            });
            TheFieldInfo btnDownload = TheNMIEngine.AddSmartControl(MyBaseThing, tBackup, eFieldType.TileButton, 1, 2, 0x0, "<i class='fa fa-3x'>&#xf019;</i>", "", new nmiCtrlTileButton()
            {
                ClassName = "cdeTableButton", TileHeight = 1, TileWidth = 1
            });

            btnDownload.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "DOWNLOAD", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }

                string[] pCmds = pMsg.Message.PLS.Split(':');
                if (pCmds.Length > 2)
                {
                    TheBackupDefinition tFile = MyLogFiles.GetEntryByID(TheCommonUtils.CGuid(pCmds[2]));
                    if (tFile != null)
                    {
                        TSM tFilePush = new TSM(eEngineName.ContentService, string.Format("CDE_FILE:{0}.txt:text/text", tFile.Title));
                        try
                        {
                            using (FileStream fr = new FileStream(tFile.FileName, FileMode.Open))
                            {
                                using (BinaryReader br = new BinaryReader(fr))
                                {
                                    tFilePush.PLB = br.ReadBytes((int)fr.Length);
                                }
                            }
                        }
                        catch (Exception)
                        { }
                        if (tFilePush.PLB == null)
                        {
                            TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Log cannot be downloaded..."));
                        }
                        else
                        {
                            TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Log is downloading. Please wait"));
                            tFilePush.SID = pMsg.Message.SID;
                            tFilePush.PLS = "bin";
                            TheCommCore.PublishToOriginator(pMsg.Message, tFilePush);
                        }
                    }
                }
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, StartFld, 2, 0x0, "Logs on Node...", null, new nmiCtrlCollapsibleGroup {
                TileWidth = 12, IsSmall = true, DoClose = true, ParentFld = pParentFld, AllowHorizontalExpand = true, MaxTileWidth = 12
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Table, StartFld + 1, 0, 0, null, tBackup.cdeMID.ToString(), new nmiCtrlTableView {
                TileWidth = -1, IsDivOnly = true, ParentFld = StartFld, NoTE = true, TileHeight = -1, MID = TheThing.GetSafeThingGuid(MyBaseThing, "LOGMID"), MainClassName = "cdeInFormTable"
            });
        }
        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);
        }
Exemple #14
0
        internal static List <TheFieldInfo> GetPermittedFields(Guid FormId, TheClientInfo pClientInfo, TheFOR tso, bool UpdateSubs)
        {
            List <TheFieldInfo> tReturnLst = new List <TheFieldInfo>();

            try
            {
                Func <TheFieldInfo, bool> pSelector = (s => TheUserManager.HasUserAccess(pClientInfo.UserID, s.cdeA) &&
                                                       ((s.Flags & 4) == 0 || !pClientInfo.IsMobile) &&
                                                       ((s.Flags & 128) == 0 || pClientInfo.IsFirstNode || pClientInfo.IsUserTrusted));                  //NEW3.105: Only Show from First node is set

                IEnumerable <TheFieldInfo> FormFields = TheNMIEngine.GetFieldsByFunc(s => s.FormID == FormId).Where(pSelector).OrderBy(s => s.FldOrder); //NMI-REDO: this is the main bottleneck Function
                if (FormFields != null)
                {
                    foreach (var tField in FormFields)
                    {
                        if (CheckHidePersmission(tField.PlatBag, pClientInfo))
                        {
                            TheFieldInfo tFld = tField.Clone();
                            if (tFld.PlatBag.ContainsKey(eWebPlatform.Any))
                            {
                                tFld.PropertyBag.MergeBag(tFld.PlatBag[eWebPlatform.Any], true, false);
                            }
                            if (tFld.PlatBag.ContainsKey(pClientInfo.WebPlatform))
                            {
                                tFld.PropertyBag.MergeBag(tFld.PlatBag[pClientInfo.WebPlatform], true, false);
                            }
                            bool DeleteFld = false;
                            if (tso != null)
                            {
                                var tfo = tso.Flds.Where(s => s.FldOrder == tFld.FldOrder);
                                if (tfo != null && tfo.Count() > 0)
                                {
                                    foreach (TheFLDOR tF in tfo)
                                    {
                                        if (tF.PO != null)
                                        {
                                            tFld.PropertyBag = tF.PO;
                                        }
                                        if (tF.NewFldOrder > 0)
                                        {
                                            tFld.FldOrder = tF.NewFldOrder;
                                        }
                                        else if (tF.NewFldOrder < 0)
                                        {
                                            DeleteFld = true;
                                        }
                                    }
                                }
                            }
                            if (!DeleteFld)
                            {
                                tReturnLst.Add(tFld);
                                //NEW in 4.1: All subscriptiosn here
                                if (UpdateSubs)
                                {
                                    var tThing = RegisterNMISubscription(pClientInfo, tFld.DataItem, tFld);
                                    if (tThing != null && (tFld.Type == eFieldType.FacePlate || tFld.Type == eFieldType.TileButton))
                                    {
                                        var tsuc = TheNMIEngine.ParseFacePlateUrlInternal(tThing, ThePropertyBag.PropBagGetValue(tFld.PropertyBag, "HTMLUrl", "="), false, pClientInfo.NodeID);
                                        if (!tsuc)
                                        {
                                            TheNMIEngine.ParseFacePlateInternal(tThing, ThePropertyBag.PropBagGetValue(tFld.PropertyBag, "HTML", "="), pClientInfo.NodeID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(777, new TSM(eEngineName.NMIService, "Get Permitted fields failed", eMsgLevel.l1_Error, e.ToString()));
            }

            return(tReturnLst);
        }
Exemple #15
0
        private void CreateConfigurationSection(int writeEnableFlag, TheFormInfo tMyForm, int pStartFld, int pParentFld)
        {
            UseTree = TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("UseTreeView"));

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, pStartFld, 2, 0xc0, "Tag Management...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                DoClose = !UseTree, IsSmall = true, ParentFld = pParentFld, TileWidth = UseTree ? 18 : 6
            }));

            if (!UseTree)
            {
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, pStartFld + 1, writeEnableFlag, 0xC0, "Browse Branch", "BrowseBranch", new nmiCtrlSingleEnded()
                {
                    ParentFld = pStartFld
                });
            }
#if USE_WEBIX
            else
            {
                var stringCols = TheCommonUtils.SerializeObjectToJSONString(new List <TheWXColumn> {
                    { new TheWXColumn()
                      {
                          TileWidth = 6, Header = "Node Name", ID = "DisplayName", FilterType = "textFilter", Template = "{common.treetable()}{common.treecheckbox()}&nbsp;<strong>#DisplayName#</strong>"
                      } },
                    //{ new TheWXColumn() { TileWidth = 2, Header = "Host Property", ID = "HostPropertyNameOverride", SortType = "string", Flags=2 } },
                    { new TheWXColumn()
                      {
                          TileWidth = 1, Header = "Sample-Rate", ID = "SampleRate", SortType = "int", Flags = 2
                      } },
                    { new TheWXColumn()
                      {
                          TileWidth = 1, Header = "Deadband-Filter", ID = "DeadbandFilterValue", SortType = "int", Flags = 2
                      } },
                    { new TheWXColumn()
                      {
                          TileWidth = 1, Header = "Trigger", ID = "ChangeTrigger", SortType = "int", Flags = 2
                      } },
                    { new TheWXColumn()
                      {
                          TileWidth = 6, Header = "Node ID", ID = "NodeIdName", FilterType = "textFilter", SortType = "int"
                      } }
                });

                OpcTagTree = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, pStartFld + 6, 2, 0, "Sample Tree", "SelectedIs", new nmiCtrlWXTreeTable()
                {
                    ParentFld       = pStartFld,
                    TileWidth       = 12,
                    TileHeight      = 12,
                    NoTE            = true,
                    RootNode        = "Objects",
                    TreeNode        = "Parent",
                    NameNode        = "DisplayName",
                    SelectNode      = "HasActiveHostThing",
                    LeftSplit       = 1,
                    OpenAllBranches = false,
                    SplitCharacter  = ".",
                    Columns         = stringCols
                });
                OpcTagTree.RegisterEvent2("NMI_FIELD_EVENT", (pMSG, para) => {
                    var tUpdate = TheCommonUtils.DeserializeJSONStringToObject <TheWXFieldEvent>(pMSG.Message.PLS);
                    if (tUpdate != null)
                    {
                        var MyTag = MyTags.MyMirrorCache.GetEntryByID(tUpdate.cdeMID);
                        if (MyTag != null)
                        {
                            switch (tUpdate.Name)
                            {
                            case "SampleRate":
                                MyTag.SampleRate = TheCommonUtils.CInt(tUpdate.Value);
                                break;

                            case "DeadbandFilterValue":
                                MyTag.DeadbandFilterValue = TheCommonUtils.CDbl(tUpdate.Value);
                                break;

                            case "ChangeTrigger":
                                MyTag.ChangeTrigger = TheCommonUtils.CInt(tUpdate.Value);
                                break;
                            }
                        }
                    }
                });
            }
#endif

            // BROWSE Button
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, pStartFld + 2, writeEnableFlag, 0xC0, "Browse", null, new nmiCtrlTileButton()
            {
                ParentFld = pStartFld, ClassName = "cdeGoodActionButton", TileWidth = 3, NoTE = true
            })
            .RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "BROWSE", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (pMsg == null || pMsg.Message == null)
                {
                    return;
                }
                if (ConnectionState != ConnectionStateEnum.Connected)
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Server not connected - please connect first"));
                }
                else
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Browsing..."));
                    LastMessage   = "Browsing Started at " + DateTimeOffset.Now.ToString();
                    BrowsedTagCnt = 0;
                    Browser(currentRoot, currentRoot.ToString(), true, false, null);


                    var dataModelJson = TheCommonUtils.SerializeObjectToJSONString(
                        MyTags.MyMirrorCache.TheValues
                        .Where(t => t.HostPropertyNameOverride?.Contains("].[") != true)     // Filter out any DataValue sub-properties (i.e. engineering units), as the tree view doesn't seem to handle nodes under leaf-nodes (or inner nodes with data) yet
                        .ToList());
                    OpcTagTree?.SetUXProperty(pMsg.Message.GetOriginator(), $"DataModel={dataModelJson}", true);
                    LastMessage += " - Browsing done at " + DateTimeOffset.Now.ToString();
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", LastMessage));
                }
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.Number, pStartFld + 3, 0, 0x0, "Browsed Tags:", "BrowsedTagCnt", new nmiCtrlNumber()
            {
                ParentFld = pStartFld, TileWidth = 3
            });


            ///Browsed TAGS Form
            {
                var tDataSource = "TheOPCTags";
                if (MyTags != null)
                {
                    tDataSource = MyTags.StoreMID.ToString();
                }
                var tOPCTagForm = new TheFormInfo(TheThing.GetSafeThingGuid(MyBaseThing, "TAGLIST_ID"), eEngineName.NMIService, "OPC-UA Server Tags", $"{tDataSource};:;1000")
                {
                    IsNotAutoLoading = true, AddButtonText = "Add new Tag", PropertyBag = new nmiCtrlTableView {
                        ShowFilterField = true
                    }
                };
                TheNMIEngine.AddFormToThingUX(MyBaseThing, tOPCTagForm, "CMyTable", "Tag List", 1, 3, 0xF0, null, null, new ThePropertyBag()
                {
                    "Visibility=false"
                });
                TheNMIEngine.AddFields(tOPCTagForm, new List <TheFieldInfo> {
                    // 1: Thing subscription
                    { new TheFieldInfo()
                      {
                          FldOrder = 3, DataItem = "IsSubscribedAsThing", Flags = 0, Type = eFieldType.SingleCheck, Header = "Has Tag Thing", FldWidth = 1
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 11, DataItem = "Parent", Flags = 0, Type = eFieldType.SingleEnded, Header = "Parent", FldWidth = 4
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 12, DataItem = "DisplayName", Flags = 0, Type = eFieldType.SingleEnded, Header = "Name", FldWidth = 3
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 13, DataItem = nameof(TheOPCTag.HostPropertyNameOverride), Flags = writeEnableFlag, Type = eFieldType.SingleEnded, Header = "Host Property Name", FldWidth = 3
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 14, DataItem = "HostThingMID", Flags = writeEnableFlag, Type = eFieldType.ThingPicker, Header = "Host Thing", FldWidth = 3
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 15, DataItem = nameof(TheOPCTag.ChangeTrigger), Flags = writeEnableFlag, Type = eFieldType.ComboBox, Header = "Change Trigger", FldWidth = 1, PropertyBag = new nmiCtrlComboBox {
                              Options = "Status:0;Value:1;Value & Timestamp:2"
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 16, DataItem = nameof(TheOPCTag.SampleRate), Flags = writeEnableFlag, Type = eFieldType.Number, Header = "Sample Rate (ms)", FldWidth = 1
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 17, DataItem = nameof(TheOPCTag.DeadbandFilterValue), Flags = writeEnableFlag, Type = eFieldType.Number, Header = "Deadband", FldWidth = 1
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 18, DataItem = "NodeIdName", Flags = 2, Type = eFieldType.SingleEnded, Header = "NodeId", FldWidth = 6
                      } },
                    // 30: Property subscription
                    { new TheFieldInfo()
                      {
                          FldOrder = 19, DataItem = nameof(TheOPCTag.HistoryStartTime), Flags = writeEnableFlag, Type = eFieldType.SingleEnded, Header = "History Start", FldWidth = 3
                      } },
                    //{  new TheFieldInfo() { FldOrder=13,DataItem="PropAttr.7.Value.Value",Flags=0,Type=eFieldType.SingleEnded,Header="Value",FldWidth=5 }},
                    //{  new TheFieldInfo() { FldOrder=14,DataItem="PropAttr.7.DataType",Flags=0,Type=eFieldType.SingleEnded,Header="Type",FldWidth=5 }},
                });
                TheNMIEngine.AddTableButtons(tOPCTagForm, false, 100, 0);

                // Button Subscribe as Thing
                TheNMIEngine.AddSmartControl(MyBaseThing, tOPCTagForm, eFieldType.TileButton, 1, writeEnableFlag, 0xC0, "Create Tag Thing", null, new nmiCtrlTileButton()
                {
                    ClassName = "cdeGoodActionButton", TileHeight = 1
                })
                .RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "SUBSCRIBE", (tThing, pMsg) => SubscribeAsThing(tThing, pMsg, MyTags));

                // Button: Subscribe property into host thing
                TheNMIEngine.AddSmartControl(MyBaseThing, tOPCTagForm, eFieldType.TileButton, 5, writeEnableFlag, 0xC0, "Monitor as Property", null, new nmiCtrlTileButton()
                {
                    ClassName = "cdeGoodActionButton", TileHeight = 1
                })
                .RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "SUBSCRIBEPROP", (tThing, pMsg) => SubscribeAsProperty(tThing, pMsg, MyTags));

                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, pStartFld + 4, writeEnableFlag, 0xF0, "Show Tag List", null, new nmiCtrlTileButton()
                {
                    OnClick = $"TTS:{tOPCTagForm.cdeMID}", ParentFld = pStartFld, ClassName = "cdeTransitButton", TileWidth = 3, NoTE = true
                });
            }

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.Number, pStartFld + 5, writeEnableFlag, 0xC0, "Default Sample Rate", nameof(DefSampleRate), new nmiCtrlNumber()
            {
                ParentFld = pStartFld, TileWidth = 3
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.ThingPicker, pStartFld + 6, writeEnableFlag, 0xC0, "Thing for Property Subs", "TagHostThingForSubscribeAll", new nmiCtrlThingPicker()
            {
                NoTE = true, ParentFld = pStartFld, TileWidth = 4
            });

            // SUBSCRIBE all tags as Properties
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, pStartFld + 7, writeEnableFlag, 0xC0, $"Subscribe {(UseTree ? "selected" : "all")} in properties", null, new nmiCtrlTileButton()
            {
                ParentFld = pStartFld, ClassName = "cdeGoodActionButton", TileWidth = 2, NoTE = true
            })
            .RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "ALLTAGS", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (pMsg == null || pMsg.Message == null)
                {
                    return;
                }
                if (ConnectionState != ConnectionStateEnum.Connected)
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Server not connected - please connect first"));
                }
                else
                {
                    var tHostThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(this.TagHostThingForSubscribeAll));
                    if (tHostThing == null)
                    {
                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Host Thing not specified or invalid"));
                        return;
                    }
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Subscribing..."));

                    if (MyTags.MyMirrorCache.Count == 0 && !UseTree)
                    {
                        // Clear all previous subscription in either MyTags (tag as thing) oder HostThing (tag as property)
                        MyTags.MyMirrorCache.Reset();

                        // TODO Figure out how to clean up subscribed things in properties.
                        // - Can't just delete as a customer may have hand picked certain properties via browse paths etc.
                        // - Allow customer to use multiple host things?
                        //var tThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(TagHostThing));
                        //if (tThing != null)
                        //{
                        //    foreach (var prop in tThing.GetPropertiesMetaStartingWith("OPCUA:"))
                        //    {
                        //        tThing.RemoveProperty(prop.Name);
                        //    }
                        //}

                        LastMessage = "Subscribing started at " + DateTimeOffset.Now.ToString();

                        BrowsedTagCnt = 0;

                        Browser(currentRoot, currentRoot.ToString(), true, true, tHostThing, CreateIDFilter());

                        LastMessage += " - Subscribing done at " + DateTimeOffset.Now.ToString();
                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", LastMessage));
                    }
                    else
                    {
                        // Previously browsed: use those tags to do the subscriptions
                        LastMessage = "Subscribing started at " + DateTimeOffset.Now.ToString();

                        var subscription = GetOrCreateSubscription(0);
                        var pFilterIDs   = CreateIDFilter();
                        int count        = 0;
                        //var results = new List<Opc.Ua.Client.MonitoredItem>();//CM: removed as Nothing is done with "results"

                        foreach (var tag in MyTags.TheValues)
                        {
                            string tagNameForFilter;
                            if (tag.DisplayName == "EngineeringUnits" || tag.DisplayName == "EURange")
                            {
                                tagNameForFilter = tag.Parent;
                            }
                            else
                            {
                                tagNameForFilter = $"{tag.Parent}.{tag.DisplayName}";
                            }

                            if (pFilterIDs != null && pFilterIDs.Contains(tagNameForFilter))
                            {
                                tag.HostThingMID = TheCommonUtils.cdeGuidToString(tHostThing.cdeMID);
                                var childTags    = tag.GetChildTags();
                                if (childTags?.Any() == true)
                                {
                                    foreach (var childTag in childTags)
                                    {
                                        childTag.HostThingMID = tag.HostThingMID;
                                    }
                                }
                                if (!RegisterAndMonitorTagInHostThing(subscription, tag, out string error, false, true, false) || !string.IsNullOrEmpty(error))
                                {
                                    // error
                                }
Exemple #16
0
        public virtual bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;

            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, null, 12, null, "Value");

            MyStatusForm            = tFlds["Form"] as TheFormInfo;
            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = new ThePropertyBag()
            {
                string.Format("Format={0}<br>{{0}} Properties", MyBaseThing.FriendlyName), "TileWidth=2"
            };
            SummaryForm.RegisterPropertyChanged(sinkStatChanged);

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 10);

            ts["Group"].SetParent(1);

            var tc = TheNMIEngine.AddStartingBlock(MyBaseThing, MyStatusForm, 200, async(pMsg, DoStart) =>
            {
                if (DoStart)
                {
                    await StartPlaybackAsync(false);
                }
                else
                {
                    await StopPlaybackAsync(null);
                }
            });

            tc["Group"].SetParent(49);
            //ts["Group"].Header = "Settings...";

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 49, 2, 0x0, "###CDMyVThings.TheVThings#Settings#Settings...###", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 1, DoClose = true, IsSmall = true
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 50, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackSpeedFactor#Speed Factor###", nameof(PlaybackSpeedFactor), new nmiCtrlNumber()
            {
                DefaultValue = "1", TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 60, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackMaxItemDelay#Maximum Delay###", nameof(MaxItemDelay), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 70, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackItemDelay#Item Delay###", nameof(PlaybackItemDelay), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 75, 2, 0x0, "###CDMyVThings.TheVThings#AutoStartDelay#Auto Start Delay###", nameof(AutoStartDelay), new nmiCtrlSingleCheck()
            {
                TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 80, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackRestart#Restart###", nameof(RestartPlayback), new nmiCtrlSingleCheck()
            {
                TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 85, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackAdjustTimestamps#Adjust times###", nameof(AdjustTimestamps), new nmiCtrlSingleCheck()
            {
                TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 87, 2, 0x0, "###CDMyVThings.TheVThings#ReplayCount#Replay Count###", nameof(ReplayCount), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 49, DefaultValue = "1"
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleEnded, 90, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackInputFileName#Input File###", nameof(InputFileName), new nmiCtrlSingleEnded()
            {
                ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 86, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackNumberThings#Number Things###", nameof(ParallelPlaybackCount), new nmiCtrlNumber()
            {
                TileWidth = 3, ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleEnded, 110, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackEngineName#Engine Name###", nameof(PlaybackEngineName), new nmiCtrlSingleEnded()
            {
                ParentFld = 49
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleEnded, 115, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackDeviceType#Device Type###", nameof(PlaybackDeviceType), new nmiCtrlSingleEnded()
            {
                ParentFld = 49
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 120, 2, 0x0, "###CDMyVThings.TheVThings#Settings#Upload file...###", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 49, DoClose = true, IsSmall = true
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.DropUploader, 125, 2, 0x0, "###CDMyVThings.TheVThings#PlaybackInputFileDropper#Drop Input File here###", null,
                                         new nmiCtrlDropUploader {
                TileHeight = 6, NoTE = true, TileWidth = 6, EngineName = MyBaseEngine.GetEngineName(), MaxFileSize = 100000000, ParentFld = 120
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 20, 2, 0x0, "###CDMyVThings.TheVThings#KPIs#KPIs...###", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 1, TileWidth = 6, IsSmall = true
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 135, 0, 0x0, "###CDMyVThings.TheVThings#PropertiesperSecond546134#Properties per Second###", nameof(Gen_Stats_PropertiesPerSecond), new nmiCtrlNumber()
            {
                ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 140, 0, 0x0, "###CDMyVThings.TheVThings#Propertycount904939#Property count###", nameof(Gen_Stats_PropertyCounter), new nmiCtrlNumber()
            {
                ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.DateTime, 150, 0, 0x0, "###CDMyVThings.TheVThings#PlaybackUpdateTime#Update time###", nameof(Gen_StatsLastUpdateTime), new nmiCtrlDateTime()
            {
                ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TimeSpan, 160, 0, 0x0, "###CDMyVThings.TheVThings#PlaybackLoadDuration#Load duration###", nameof(LoadDuration), new nmiCtrlDateTime()
            {
                ParentFld = 20
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TimeSpan, 170, 0, 0x0, "###CDMyVThings.TheVThings#PlaybackDuration#Playback duration###", nameof(PlaybackDuration), new nmiCtrlDateTime()
            {
                ParentFld = 20
            });


            TheFieldInfo mResetCounterButton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 180, 2, 0, "###CDMyVThings.TheVThings#ResetCounter741318#Reset Counter###", false, "", null, new nmiCtrlTileButton()
            {
                ParentFld = 130, ClassName = "cdeGoodActionButton"
            });

            mResetCounterButton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                if (!(pPara is TheProcessMessage pMsg) || pMsg.Message == null)
                {
                    return;
                }
                this.Gen_Stats_PropertyCounter = 0;
                Interlocked.Exchange(ref _propertyCounter, 0);
                sinkStatChanged(null, null);
            });
Exemple #17
0
        private static Image DrawStrip(Guid pThingGuid, DateTimeOffset now, TheFieldInfo pInfo)
        {
            int pixelWidth = 78 * TheCommonUtils.CInt(pInfo?.PropBagGetValue("TileWidth"));

            if (pixelWidth == 0)
            {
                pixelWidth = 78;
            }
            int Hours = TheCommonUtils.CInt(pInfo?.PropBagGetValue("Hours"));

            if (Hours == 0)
            {
                Hours = 1;
            }
            int    pixelHeight = 1;
            Bitmap bmp         = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb);

            int    st           = 0;
            string tColorString = pInfo?.PropBagGetValue("ChartColors");

            string[] htmlColors = null;
            if (string.IsNullOrEmpty(tColorString))
            {
                htmlColors = TheBaseAssets.MyServiceHostInfo.StatusColors.Split(';');
            }
            else
            {
                htmlColors = tColorString.Split(';');
            }
            Dictionary <int, SolidBrush> stateColorMapping = htmlColors.ToDictionary(x => st++, y => new SolidBrush(ColorTranslator.FromHtml(y)));

            TheThing tThing = TheThingRegistry.GetThingByMID("*", pThingGuid);

            if (tThing == null)
            {
                return(null);
            }
            cdeP pMSH = ((ICDEThing)tThing.GetObject())?.GetProperty("MachineStorageHistory", false);

            if (pMSH == null)
            {
                return(null);
            }
            List <TheMachineStateHistory> tList = TheCommonUtils.DeserializeJSONStringToObject <List <TheMachineStateHistory> >(pMSH.ToString());

            if (tList == null)
            {
                return(null);
            }
            tList = tList.Where(s => now.Subtract(s.StateChangeTime).TotalHours < Hours).OrderBy(s => s.StateChangeTime).ToList();

            cdeP LastDeletedEntry            = tThing.GetProperty("LastDeletedEntry", false);
            TheMachineStateHistory lastState = null;

            if (LastDeletedEntry != null)
            {
                TheMachineStateHistory tHis = TheCommonUtils.DeserializeJSONStringToObject <TheMachineStateHistory>(LastDeletedEntry.ToString());
                lastState = new TheMachineStateHistory()
                {
                    State = tHis.State, StateChangeTime = now.Subtract(new TimeSpan(Hours, 0, 0))
                };
            }

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.ScaleTransform((float)pixelWidth / (Hours * 60 * 60), 1.0f);
                List <KeyValuePair <int, RectangleF> > rectangles = new List <KeyValuePair <int, RectangleF> >();
                foreach (var t in tList)
                {
                    if (lastState != null && t.State != lastState.State)
                    {
                        float start = (float)now.Subtract(t.StateChangeTime).TotalSeconds;
                        float size  = (float)t.StateChangeTime.Subtract(lastState.StateChangeTime).TotalSeconds;
                        rectangles.Add(new KeyValuePair <int, RectangleF>(lastState.State, new RectangleF(new PointF(start, 0), new SizeF(size, pixelHeight))));
                        lastState = t;
                    }
                    if (lastState == null)
                    {
                        lastState = t;
                    }
                }
                if (lastState != null)
                {
                    float size = (float)now.Subtract(lastState.StateChangeTime).TotalSeconds;
                    rectangles.Add(new KeyValuePair <int, RectangleF>(lastState.State, new RectangleF(new PointF(0, 0), new SizeF(size, pixelHeight))));
                }
                if (rectangles.Count > 0)
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    // g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    for (int state = 0; state <= rectangles.Max(x => x.Key); state++)
                    {
                        if (stateColorMapping.ContainsKey(state))
                        {
                            IEnumerable <RectangleF> rects = rectangles.Where(x => x.Key == state).Select(x => x.Value);
                            var rectangleFs = rects as RectangleF[] ?? rects.ToArray();
                            if (rectangleFs.Any())
                            {
                                if (state > stateColorMapping.Count)
                                {
                                    g.FillRectangles(new SolidBrush(Color.Pink), rectangleFs.ToArray());
                                }
                                else
                                {
                                    g.FillRectangles(stateColorMapping[state], rectangleFs.ToArray());
                                }
                            }
                        }
                    }
                }
            }
            if (TheCommonUtils.CBool(pInfo?.PropBagGetValue("DrawRightToLeft")))
            {
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipX); //draw right to left
            }
            return(bmp);
        }
        public virtual void DoCreateUX(TheFormInfo tMyForm, ThePropertyBag pChartControlBag = null)
        {
            var tQVN = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorValueName");
            //var tQV = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorValue");
            var tQU = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorUnit");

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileGroup, 12460, 0, 0, null, null, new nmiCtrlTileGroup {
                ParentFld = 12011, TileWidth = 6, TileHeight = 3
            });
            ValueField = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SmartLabel, 12461, 0, 0, $"{tQVN}", "QValue", new nmiCtrlSmartLabel {
                ParentFld = 12460, TileWidth = 6, TileFactorY = 2, TileHeight = 3, FontSize = 96
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SmartLabel, 12462, 0, 0, $"{tQU}", "StateSensorUnit", new nmiCtrlSmartLabel {
                ParentFld = 12460, NoTE = true, TileWidth = 6, TileFactorY = 2, TileHeight = 1, FontSize = 18, HorizontalAlignment = "right", VerticalAlignment = "top"
            });

            var tG = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileGroup, 12000, 0, 0, null, null, new nmiCtrlTileGroup()
            {
                TileWidth = 18
            });

            tG.AddOrUpdatePlatformBag(eWebPlatform.Mobile, new nmiPlatBag {
                MaxTileWidth = 6
            });
            tG.AddOrUpdatePlatformBag(eWebPlatform.HoloLens, new nmiPlatBag {
                MaxTileWidth = 12
            });
            tG.AddOrUpdatePlatformBag(eWebPlatform.TeslaXS, new nmiPlatBag {
                MaxTileWidth = 12
            });

            string pSensorPicSource = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorLogo");

            if (string.IsNullOrEmpty(pSensorPicSource))
            {
                pSensorPicSource = "SENSORS/Images/SensorLogo_156x78.png";
            }
            TheSensorNMI.CreatePerformanceHeader(MyBaseThing, tMyForm, 12010, 12000, pSensorPicSource);

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 12030, 2, 0, $"Live Chart", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 12000, TileWidth = 6, NoTE = true, Background = "transparent", Foreground = "black", FontSize = 10, IsSmall = true, HorizontalAlignment = "left"
            });                                                                                                                                                                                                                                                                                                               //LabelClassName = "cdeTileGroupHeaderSmall SensorGroupLabel", LabelForeground = "white",
            LiveChartFld = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, 12031, 2, 0, $"{tQVN} Chart", "QValue", new ThePropertyBag()
            {
                "ControlType=Live Chart",
                "ParentFld=12030", "NoTE=true", $"Title={tQVN}",
                "SeriesNames=[{ \"name\":\"Current Temp\", \"lineColor\":\"rgba(0,255,0,0.39)\"}, { \"name\":\"Max Temp\", \"lineColor\":\"rgba(0,0,255,0.64)\"}]", "TileWidth=6", "TileHeight=4", "Speed=500", $"MaxValue={TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue")}", "Delay=0", "Background=rgba(0,0,0,0.01)"
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 12040, 2, 0, "Distribution Curve", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 12000, TileWidth = 6, NoTE = true, Background = "transparent", Foreground = "black", FontSize = 10, IsSmall = true, HorizontalAlignment = "left"
            });                                                                                                                                                                                                                                                                                                                      //LabelClassName = "cdeTileGroupHeaderSmall SensorGroupLabel", LabelForeground = "white",
            BucketChartFld = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, 12041, 0, 0, $"{tQVN} Chart", "BucketChart", new ThePropertyBag()
            {
                "NoTE=true", "ParentFld=12040", $"SubTitle={tQVN}", $"SetSeries={{\"name\": \"{tQVN}\"}}",
                "TileWidth=6", "TileHeight=4", "ControlType=Stack Chart",
                $"XAxis={{ \"categories\": {mBucket?.GetBuckets()} }}", $"iValue={mBucket?.GetBucketArray()}"
            });

            TheSensorNMI.CreateDeviceDetails(MyBaseThing, tMyForm, 12060, 12000, null); // new List<string> { $"{tQVN},{tQV}" });

            if (pChartControlBag == null)
            {
                pChartControlBag = new ThePropertyBag {
                    "DoClose=true"
                }
            }
            ;
            else
            {
                ThePropertyBag.PropBagUpdateValue(pChartControlBag, "DoClose", "=", "true");
            }
            var tt = MyHistorian?.CreateHistoryTrendUX(tMyForm, 12300, 12000, $"{tQVN} Trend", $"{tQVN} Trend", TheThing.GetSafePropertyString(MyBaseThing, "HistoryFields"), false, false, pChartControlBag);
        }
        public override bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;

            //NUI Definition for All clients
            mMyDashboard = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "OPC UA Client")
            {
                PropertyBag = new nmiDashboardTile()
                {
                    Category = " Connectivity", Thumbnail = "opcLarge.png;1;cdeLargeIcon", TileWidth = 3, TileHeight = 4, ClassName = "cdeLiveTile cdeLargeTile"
                }
            });

            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, "OPC General Settings", "OPCD", 0, new nmiStandardForm {
                MaxTileWidth = 12, UseMargin = true, Category = TheNMIEngine.GetNodeForCategory()
            });
            TheFormInfo tMyForm = tFlds["Form"] as TheFormInfo;

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 5, 2, 0xc0, "GLS Discovery Service", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                DoClose = false, IsSmall = true, TileWidth = 6, ParentFld = 1
            }));
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 10, 2, 0, "GLS Address", "Address", new nmiCtrlSingleEnded()
            {
                ParentFld = 5
            });
            TheFieldInfo tBut = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, 11, 2, 0, "Scan for Servers", null, new nmiCtrlTileButton()
            {
                ParentFld = 5, ClassName = "cdeGoodActionButton"
            });

            tBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "SCAN", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (pMsg != null)
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Scanning..."));
                    GetEndpoints();
                    mMyDashboard.Reload(pMsg, false);
                }
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 15, 2, 0xc0, "Tracing (all clients)...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                DoClose = false, TileWidth = 6, IsSmall = true, ParentFld = 1
            }));

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleCheck, 16, 2, 0, "OPC Client File Tracing", nameof(EnableTracing), new nmiCtrlSingleCheck {
                TileWidth = 3, ParentFld = 15
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleCheck, 17, 2, 0, "OPC Client Trace to Log", nameof(EnableTracingToLog), new nmiCtrlSingleCheck {
                TileWidth = 3, ParentFld = 15
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.Number, 18, 2, 0, "OPC Client Trace Mask", nameof(OPCTraceMask), new nmiCtrlNumber {
                TileWidth = 6, ParentFld = 15, HelpText = "1=Err,2=Info,4=Stk,8=Svc,16=SvcDtl,32=Op,64=OpDtl,128=Start,256=Ext,512=Sec"
            });



            TheFormInfo tAllOPCUASrvs = new TheFormInfo(MyBaseEngine)
            {
                cdeMID = TheThing.GetSafeThingGuid(MyBaseThing, "OPCS"), defDataSource = string.Format("TheThing;:;0;:;True;:;DeviceType={1};EngineName={0}", MyBaseEngine.GetEngineName(), eOPCDeviceTypes.OPCRemoteServer), FormTitle = "Discovered OPC-UA Servers", AddButtonText = "Add a Server"
            };

            TheNMIEngine.AddFormToThingUX(MyBaseThing, tAllOPCUASrvs, "CMyTable", "All OPC-UA Remote Servers", 1, 0x0F, 0xC0, TheNMIEngine.GetNodeForCategory(), null, new ThePropertyBag()
            {
                "Thumbnail=OPCLogo.png;1.0"
            });
            var tOpcs = TheNMIEngine.AddCommonTableColumns(MyBaseThing, tAllOPCUASrvs);

            tOpcs["Address"].Header      = "Server URL";
            tOpcs["Address"].PropertyBag = new nmiCtrlSingleEnded {
                TileWidth = 4, FldWidth = 4
            };

            TheNMIEngine.AddField(tAllOPCUASrvs, new TheFieldInfo()
            {
                FldOrder = 5, cdeA = 0xC0, Flags = 2, Type = eFieldType.SingleCheck, Header = "Auto-Connect", DataItem = "MyPropertyBag.AutoConnect.Value"
            });
            TheNMIEngine.AddField(tAllOPCUASrvs, new TheFieldInfo()
            {
                FldOrder = 6, cdeA = 0xC0, Flags = 2, Type = eFieldType.SingleCheck, Header = "Connected", DataItem = "MyPropertyBag.IsConnected.Value", PropertyBag = new nmiCtrlSingleCheck {
                    AreYouSure = "Are you sure you want to connect/disconnect?"
                }
            });
            //            TheNMIEngine.AddField(tAllOPCUASrvs, new TheFieldInfo() { FldOrder = 13, Flags = 2, cdeA = 0xFF, Type = eFieldType.SingleEnded, Header = "Friendly Name", DataItem = "MyPropertyBag.FriendlyName.Value", PropertyBag = new ThePropertyBag() { "FldWidth=3" } });
            //TheNMIEngine.AddField(tAllOPCUASrvs, new TheFieldInfo() { FldOrder = 14, Flags = 2, cdeA = 0xC0, Type = eFieldType.SingleEnded, Header = "Server URL", DataItem = "MyPropertyBag.Address.Value", PropertyBag = new ThePropertyBag() { "FldWidth=5" } });
            TheNMIEngine.AddField(tAllOPCUASrvs, new TheFieldInfo()
            {
                FldOrder = 50, cdeA = 0xFF, Type = eFieldType.DateTime, Header = "Last Update", DataItem = "MyPropertyBag.LastUpdate.Value", PropertyBag = new ThePropertyBag()
                {
                    "FldWidth=3"
                }
            });
            TheNMIEngine.AddField(tAllOPCUASrvs, new TheFieldInfo()
            {
                FldOrder = 55, cdeA = 0xFF, Type = eFieldType.DateTime, Header = "Last Receive", DataItem = "MyPropertyBag.LastDataReceivedTime.Value", PropertyBag = new ThePropertyBag()
                {
                    "FldWidth=3"
                }
            });
            //TheNMIEngine.AddTableButtons(tAllOPCUASrvs);

            TheThingRegistry.UpdateEngineUX(MyBaseEngine.GetEngineName());

            TheNMIEngine.AddLiveTagTable(MyBaseThing, eOPCDeviceTypes.OPCLiveTag, "UA Live Tags", TheNMIEngine.GetNodeForCategory());
            TheNMIEngine.AddLiveTagTable(MyBaseThing, eOPCDeviceTypes.OPCMethod, "UA Methods", TheNMIEngine.GetNodeForCategory());

            TheNMIEngine.AddTileBreak(MyBaseThing, mMyDashboard, "..A");

            TheNMIEngine.AddAboutButton(MyBaseThing, true, "REFRESH_DASH", 0xc0);
            TheNMIEngine.RegisterEngine(MyBaseEngine);

            CreateOPCWizard();

            mIsUXInitialized = true;
            return(true);
        }
Exemple #20
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"
            });
        }
Exemple #21
0
        public override bool CreateUX()
        {
            if (!mIsUXInitStarted)
            {
                mIsUXInitStarted = true;

                // Creates a "portal" for each rule. This is how we create
                // a tile for each rule on the rules engine's main page.
                mThisFormFields = TheNMIEngine.AddStandardForm(MyBaseThing, MyBaseThing.FriendlyName, 18);

                // Update our status.
                TheFormInfo tFormGuid = mThisFormFields["Form"] as TheFormInfo;
                tFormGuid.RegisterEvent2(eUXEvents.OnShow, (pMSG, para) => {
                    UpdateStatus();
                });

                // Create "Rule Status" settings group
                // Field Order = 10
                // Parent = 1 (main form)
                // Get standard Status Block.
                var tstFlds = TheNMIEngine.AddStatusBlock(MyBaseThing, tFormGuid, idGroupStatus);
                tstFlds["Group"].SetParent(idForm);
                tstFlds["Group"].Header = "Rule Status";
                // tstFlds["Group"].PropertyBag = new ThePropertyBag { "DoClose=true" };
                tstFlds["FriendlyName"].Header = "Rule Name";

                // When the Friendly Name changes, propogate to the other UI elements that use it.
                tstFlds["FriendlyName"].RegisterUXEvent(MyBaseThing, eUXEvents.OniValueChanged, null, (psender, pPara) =>
                {
                    (mThisFormFields["Header"] as TheFieldInfo).SetUXProperty(Guid.Empty, $"Title={MyBaseThing.FriendlyName}");
                    (mThisFormFields["DashIcon"] as TheDashPanelInfo).SetUXProperty(Guid.Empty, $"Caption={MyBaseThing.FriendlyName}");
                });

                // Add fields to Status Block that are specific to this plugin.
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.SingleCheck, 60, 2, 0, "Activate Rule", "IsRuleActive", new nmiCtrlSingleCheck {
                    ParentFld = idGroupStatus, TileWidth = 3
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.SingleCheck, 70, 2, 0, "Log Action", "IsRuleLogged", new nmiCtrlSingleCheck {
                    ParentFld = idGroupStatus, TileWidth = 3
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.SingleCheck, 75, 2, 0, "Log Action to Eventlog", "IsEVTLogged", new nmiCtrlSingleCheck {
                    ParentFld = idGroupStatus, TileWidth = 3
                });
                TheFieldInfo tTriggerBut = TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.TileButton, 65, 2, 0xC0, "Trigger Now", null, new nmiCtrlTileButton {
                    ParentFld = idGroupStatus, ClassName = "cdeGoodActionButton", NoTE = true, TileWidth = 3
                });
                tTriggerBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "TriggerNow", (psender, pPara) =>
                {
                    TheProcessMessage pMSG = pPara as TheProcessMessage;
                    if (pMSG == null || pMSG.Message == null)
                    {
                        return;
                    }

                    string[] cmd = pMSG.Message.PLS.Split(':');
                    if (cmd.Length > 2)
                    {
                        TheThing tThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(cmd[2]));
                        if (tThing == null)
                        {
                            return;
                        }
                        TheRule tRule = tThing.GetObject() as TheRule;
                        if (tRule != null)
                        {
                            //FireAction(tRule, true);
                            tRule.FireAction(true);
                            MyBaseEngine.ProcessMessage(new TheProcessMessage(new TSM(MyBaseEngine.GetEngineName(), "FIRE_RULE", MyBaseThing.cdeMID.ToString())));
                            TheCommCore.PublishToOriginator(pMSG.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", string.Format("Rule {0} triggered", tRule.GetBaseThing().FriendlyName)));
                        }
                    }
                });

                // Create "Trigger Object" settings group (Field Order = idGroupTriggerObject (100), Parent = 1)
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.CollapsibleGroup, idGroupTriggerObject, 2, 0, "Trigger Object", null, new nmiCtrlCollapsibleGroup {
                    ParentFld = idForm, TileWidth = 6, IsSmall = true
                });

                // Create "Action Settings" settings group (Field Order = idGroupActionSettings (500), Parent = 1)
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.CollapsibleGroup, idGroupActionSettings, 2, 0, "Action Settings", null, new nmiCtrlCollapsibleGroup {
                    ParentFld = idForm, TileWidth = 6, IsSmall = true
                });

                // Create "Thing Property Action" settings group (Field Order = idGroupThingPropAction (550), Parent = 500)
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.CollapsibleGroup, idGroupThingPropAction, 2, 0, "Thing/Property Action", null, new nmiCtrlCollapsibleGroup {
                    ParentFld = idGroupActionSettings, TileWidth = 6, IsSmall = true
                });

                // Create "TSM Action" settings group (Field Order = idGroupTSMAction (600), Parent = 500)
                TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.CollapsibleGroup, idGroupTSMAction, 2, 0, "TSM Action", null, new nmiCtrlCollapsibleGroup {
                    ParentFld = idGroupActionSettings, TileWidth = 6, IsSmall = true, DoClose = true
                });

                // Create all other (non-group header) fields.
                TheNMIEngine.AddFields(tFormGuid, new List <TheFieldInfo>
                {
                    /* Trigger Object Group */
                    { new TheFieldInfo()
                      {
                          FldOrder = 140, DataItem = "MyPropertyBag.TriggerObject.Value", Flags = 2, Type = eFieldType.ThingPicker, Header = "Trigger Object", PropertyBag = new nmiCtrlThingPicker()
                          {
                              ParentFld = idGroupTriggerObject, HelpText = "If this objects...", IncludeEngines = true
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 150, DataItem = "MyPropertyBag.TriggerProperty.Value", Flags = 2, Type = eFieldType.PropertyPicker, Header = "Trigger Property", DefaultValue = "Value", PropertyBag = new nmiCtrlPropertyPicker()
                          {
                              ParentFld = idGroupTriggerObject, HelpText = "...property is...", ThingFld = 140
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 160, DataItem = "MyPropertyBag.TriggerCondition.Value", Flags = 2, Type = eFieldType.ComboBox, Header = "Trigger Condition", DefaultValue = "2", PropertyBag = new nmiCtrlComboBox()
                          {
                              ParentFld = idGroupTriggerObject, HelpText = "... then this value, this rule will fire...", DefaultValue = "2", Options = "Fire:0;State:1;Equals:2;Larger:3;Smaller:4;Not:5;Contains:6;Set:7;StartsWith:8;EndsWith:9;Flank:10"
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 170, DataItem = "MyPropertyBag.TriggerValue.Value", Flags = 2, Type = eFieldType.SingleEnded, Header = "Trigger Value", PropertyBag = new ThePropertyBag()
                          {
                              "ParentFld=100", "HelpText=...this objects..."
                          }
                      } },

                    /* Action Settings Group */
                    { new TheFieldInfo()
                      {
                          FldOrder = 505, DataItem = "MyPropertyBag.ActionObjectType.Value", Flags = 2, Type = eFieldType.ComboBox, Header = "Action Object Type", PropertyBag = new nmiCtrlComboBox()
                          {
                              ParentFld = idGroupActionSettings, Options = "Set Property on a Thing:CDE_THING;Publish Central:CDE_PUBLISHCENTRAL;Publish to Service:CDE_PUBLISH2SERVICE", DefaultValue = "CDE_THING"
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 506, DataItem = "MyPropertyBag.ActionDelay.Value", Flags = 2, Type = eFieldType.Number, Header = "Delay", DefaultValue = "0", PropertyBag = new ThePropertyBag()
                          {
                              "ParentFld=500", "HelpText=...after a delay of these seconds..."
                          }
                      } },

                    /* Thing / Property Action Sub-Group */
                    { new TheFieldInfo()
                      {
                          FldOrder = 560, DataItem = "MyPropertyBag.ActionObject.Value", Flags = 2, Type = eFieldType.ThingPicker, Header = "Action Object", PropertyBag = new nmiCtrlThingPicker()
                          {
                              ParentFld = 550, HelpText = "...this objects...", IncludeEngines = true
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 562, DataItem = "MyPropertyBag.ActionProperty.Value", Flags = 2, Type = eFieldType.PropertyPicker, Header = "Action Property", DefaultValue = "Value", PropertyBag = new nmiCtrlPropertyPicker()
                          {
                              ParentFld = idGroupThingPropAction, HelpText = "...property will change to...", ThingFld = 560
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 563, DataItem = "MyPropertyBag.ActionValue.Value", Flags = 2, Type = eFieldType.SingleEnded, Header = "Action Value", PropertyBag = new nmiCtrlSingleEnded {
                              ParentFld = idGroupThingPropAction, HelpText = "...this value", Style = "text-overflow:ellipsis;overflow:hidden; max-width:400px"
                          }
                      } },

                    /* TSM Action Sub-Group */
                    { new TheFieldInfo()
                      {
                          FldOrder = 630, DataItem = "MyPropertyBag.TSMEngine.Value", Flags = 2, Type = eFieldType.ThingPicker, Header = "TSM Engine", PropertyBag = new nmiCtrlThingPicker()
                          {
                              ParentFld = 600, ValueProperty = "EngineName", IncludeEngines = true, Filter = "DeviceType=IBaseEngine"
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 631, DataItem = "MyPropertyBag.TSMText.Value", Flags = 2, Type = eFieldType.SingleEnded, Header = "TSM Text", PropertyBag = new ThePropertyBag()
                          {
                              "ParentFld=600", "HelpText=Command of the TSM"
                          }
                      } },
                    { new TheFieldInfo()
                      {
                          FldOrder = 632, DataItem = "MyPropertyBag.TSMPayload.Value", Flags = 2, Type = eFieldType.TextArea, Header = "TSM Payload", PropertyBag = new nmiCtrlTextArea()
                          {
                              ParentFld = idGroupTSMAction, TileHeight = 2, HelpText = "Body of the TSM"
                          }
                      } },
                });

                mIsUXInitCompleted = true;
            }
            return(true);
        }
        public override bool CreateUX()
        {
            if (TheBaseAssets.MyServiceHostInfo.IsCloudService)
            {
                mIsUXInitialized = true;
                return(true);
            }
            if (!TheNMIEngine.IsInitialized())
            {
                return(false);
            }
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;

            MyDash = TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "Rules Engine")
            {
                FldOrder = 5000, cdeA = 0xC0, PropertyBag = new ThePropertyBag {
                    "Caption=Rules Engine", "Thumbnail=FA5:f546", "Category=Services"
                }
            });

            TheFormInfo tFormGuid = new TheFormInfo(new Guid("{6C34871C-D49B-4D7A-84E0-35E25B1F18B0}") /*TheThing.GetSafeThingGuid(MyBaseThing, "RULESREG")*/, eEngineName.NMIService, "The Rules Registry", $"TheThing;:;0;:;True;:;DeviceType={eKnownDeviceTypes.TheThingRule};EngineName={MyBaseEngine.GetEngineName()}")
            {
                GetFromFirstNodeOnly = true, IsNotAutoLoading = true, AddButtonText = "Add Rule", AddTemplateType = "44444444-6AD1-45AE-BE61-96AF02329613"
            };

            //TheNMIEngine.AddForm(tFormGuid);
            TheNMIEngine.AddFormToThingUX(MyDash, MyBaseThing, tFormGuid, "CMyTable", "Rules Registry", 5, 9, 128, TheNMIEngine.GetNodeForCategory(), null, new ThePropertyBag {
                "Thumbnail=FA5:f07b"
            });
            TheNMIEngine.AddFields(tFormGuid, new List <TheFieldInfo>
            {
                { new TheFieldInfo()
                  {
                      FldOrder = 10, DataItem = "MyPropertyBag.IsRuleActive.Value", Flags = 2, Type = eFieldType.SingleCheck, Header = "Active", FldWidth = 1, TileLeft = 2, TileTop = 6, TileWidth = 4, TileHeight = 1
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 20, DataItem = "MyPropertyBag.IsRuleLogged.Value", Flags = 2, Type = eFieldType.SingleCheck, Header = "Logged", FldWidth = 1, TileLeft = 6, TileTop = 6, TileWidth = 4, TileHeight = 1
                  } },

                { new TheFieldInfo()
                  {
                      FldOrder = 30, DataItem = "MyPropertyBag.FriendlyName.Value", Flags = 2, Type = eFieldType.SingleEnded, Header = "Rule Name", FldWidth = 3, TileLeft = 0, TileTop = 1, TileWidth = 11, TileHeight = 1, PropertyBag = new nmiCtrlSingleEnded()
                      {
                          HelpText = "Give this rule a friendly name"
                      }
                  } },
                { new TheFieldInfo()
                  {
                      FldOrder = 137, DataItem = "cdeO", Flags = 16, Type = eFieldType.SingleEnded, Header = "Status", FldWidth = 3, Format = "<span style='font-size:xx-small'>Running:%MyPropertyBag.IsRuleRunning.Value%<br>TrigerAlive:%MyPropertyBag.IsTriggerObjectAlive.Value%</span>"
                  } },
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.StatusLight, 35, 0x40, 0x0, "Status", "StatusLevel", new TheNMIBaseControl()
            {
                FldWidth = 1
            });


            TheNMIEngine.AddTableButtons(tFormGuid, true, 1000, 0xA2);

            TheFieldInfo tTriggerBut = TheNMIEngine.AddSmartControl(MyBaseThing, tFormGuid, eFieldType.TileButton, 5, 2, 0xC0, "Trigger Now", null, new nmiCtrlTileButton {
                ClassName = "cdeGoodActionButton", TileLeft = 1, TileTop = 6, TileWidth = 1, TileHeight = 1, NoTE = true
            });

            tTriggerBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "TriggerNow", (psender, pPara) =>
            {
                TheProcessMessage pMSG = pPara as TheProcessMessage;
                if (pMSG == null || pMSG.Message == null)
                {
                    return;
                }

                string[] cmd = pMSG.Message.PLS.Split(':');
                if (cmd.Length > 2)
                {
                    TheThing tThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(cmd[2]));
                    if (tThing == null)
                    {
                        return;
                    }
                    TheRule tRule = tThing.GetObject() as TheRule;
                    if (tRule != null)
                    {
                        tRule.FireAction(true);
                        TheCommCore.PublishToOriginator(pMSG.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", string.Format("Rule {0} triggered", tRule.FriendlyName)));
                    }
                }
            });

            TheNMIEngine.AddAboutButton4(MyBaseThing, MyDash, null, true, false, "REFRESH_DASH");

            AddRulesWizard();

            mIsUXInitialized = true;
            return(true);
        }
Exemple #23
0
        public override bool DoCreateUX()
        {
            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, null, 12, null, "Value");

            MyStatusForm            = tFlds["Form"] as TheFormInfo;
            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = new ThePropertyBag()
            {
                string.Format("Format={0}<br>{{0}}", MyBaseThing.FriendlyName)
            };

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 10);

            ts["Group"].SetParent(1);

            // loading spinner
            //var tDash = TheThingRegistry.IsEngineRegistered("CDMyNMIControls.TheNMIctrls")
            var tDash = new nmiDashboardTile {
                ClassName = "cdeDashPlate", Format = "Loading... <i class='fa fa-spinner fa-pulse'></i>", TileWidth = 2, TileHeight = 2, HTML = "<div><p><%C20:FriendlyName%></p><div id='COUNTD%cdeMID%'></div></div>", Style = "background-image:url('GlasButton.png');color:white;background-color:gray", RSB = true
            };

            //: new ThePropertyBag { $"Format={MyBaseThing.FriendlyName}<br>{{0}}", "Foreground=white" };

            SummaryForm.PropertyBag = tDash;
            SummaryForm.RegisterPropertyChanged(SinkStatChanged);

            var tControl = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(MyBaseThing, "ControlType"));
            var tBag     = ThePropertyBag.CreateUXBagFromProperties(MyBaseThing);

            tBag.Add("ParentFld=1");

            CountBar = tControl > 0
             ? TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, (eFieldType)tControl, 21, 2, 0, "Current Value", "Value", tBag)
             : TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.BarChart, 21, 2, 0, "Current Value", "Value", new nmiCtrlBarChart {
                ParentFld = 1
            });

            //if (TheThingRegistry.IsEngineRegistered("CDMyNMIControls.TheNMIctrls"))
            {
                //MyGauge=TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.UserControl, 4000, 2, 0, "Countdown", "Value", new ThePropertyBag { "TileWidth=2", "NoTE=true", "EngineName=CDMyNMIControls.TheNMIctrls", "RenderTarget=COUNTD%cdeMID%", "ControlType=cdeNMI.ctrlCircularGauge", "LabelForeground=#00b9ff", "Foreground=#FFFFFF" });
                MyGauge = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CircularGauge, 4000, 2, 0, "Countdown", "Value", new ThePropertyBag {
                    "TileWidth=2", "NoTE=true", "RenderTarget=COUNTD%cdeMID%", "LabelForeground=#00b9ff", "Foreground=#FFFFFF"
                });
            }

            var mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 120, 2, 0x80, "Trigger", false, "", null, new nmiCtrlTileButton {
                NoTE = true, TileWidth = 3, ParentFld = 10, ClassName = "cdeGoodActionButton"
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                if (_mTimer != null)
                {
                    _mTimer.Dispose();
                    _mTimer = null;
                }
                SinkTriggered(GetProperty("StartValue", false));
            });
            var mSP = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 130, 2, 0x80, "Stop", false, "", null, new nmiCtrlTileButton {
                NoTE = true, TileWidth = 3, ParentFld = 10, ClassName = "cdeBadActionButton"
            });

            mSP.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                if (_mTimer != null)
                {
                    _mTimer.Dispose();
                    _mTimer = null;
                }
            });
            // Settings Controls & User Input
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 151, 2, 0x80, "Settings...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup {
                ParentFld = 1, TileWidth = 6, IsSmall = true, DoClose = true
            }));
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 153, 2, 0x80, "Tick time in ms", nameof(Frequency), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 151
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 156, 2, 0x80, "Step", nameof(Step), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 151
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 157, 2, 0x80, "Amplitude", nameof(Amplitude), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 151
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 158, 2, 0x80, "Shift", nameof(Shift), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 151
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 180, 2, 0x80, "Autostart", nameof(AutoStart), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 151
            });

            return(true);
        }
        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"
            });
        }
Exemple #25
0
        public virtual bool DoCreateUX()
        {
            MyEditorForm = new TheFormInfo(MyBaseThing)
            {
                DefaultView = eDefaultView.Form, PropertyBag = new ThePropertyBag {
                    "MaxTileWidth=6", "HideCaption=true", "AllowDrag=true"
                }
            };
            MyEditorForm.ModelID = "NMIEditor";

            TheDashboardInfo tDash = TheNMIEngine.GetDashboardById(TheNMIHtml5RT.eNMIDashboard);

            MyEditorDashIcon = TheNMIEngine.AddFormToThingUX(tDash, MyBaseThing, MyEditorForm, "CMyForm", "NMI Control Editor", 1, 0x89, 0x80, "NMI", null, new ThePropertyBag()
            {
                "RenderTarget=cdeInSideBarRight", "NeverHide=true"
            });                                                                                                                                                                                                                           //"mAllowDrag=true", "nVisibility=false",

            MySampleControl = TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.SingleEnded, 3, 2, MyBaseThing.cdeA, "CurrentValue", "Value", null);


            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileGroup, 9, 0, 0, null, null, new nmiCtrlTileGroup {
                TileWidth = 7, TileHeight = 1, TileFactorY = 2
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 10, 2, 0, "Basic", null, new nmiCtrlTileButton {
                ParentFld = 9, OnClick = "GRP:NMIP:Basic", TileWidth = 1, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 20, 2, 0, "Screen", null, new nmiCtrlTileButton {
                ParentFld = 9, OnClick = "GRP:NMIP:Screen", TileWidth = 1, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 30, 2, 0, "All", null, new nmiCtrlTileButton {
                ParentFld = 9, OnClick = "GRP:NMIP:All", TileWidth = 1, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 40, 2, 0, "Source", null, new nmiCtrlTileButton {
                ParentFld = 9, OnClick = "GRP:NMIP:Source", TileWidth = 1, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton"
            });
            //TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 50, 2, 0, "Compounds", null, new nmiCtrlTileButton { OnClick = "GRP:Cate:5", TileWidth = 2, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton" });
            //TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 60, 2, 0, "Gauges", null, new nmiCtrlTileButton {  OnClick = "GRP:Cate:6", TileWidth = 2, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton" });
            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 70, 2, 0x80, "Reload", false, "", null, new nmiCtrlTileButton()
            {
                ParentFld = 9, TileWidth = 2, NoTE = true, TileFactorY = 2, ClassName = "cdeGoodActionButton"
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                TheProcessMessage pMsg = pPara as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
                UpdateUx(pThing.GetBaseThing());
                MyEditorForm.Reload(pMsg, tDash.cdeMID, true);
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileGroup, 1000, 2, 0x80, null, null, new nmiCtrlTileGroup()
            {
                Group = "NMIP:Basic"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.ComboBox, 1010, 2, 0x80, "Control Type", "ControlType", new ThePropertyBag()
            {
                "Options=%RegisteredControlTypes%", "ParentFld=1000"
            });
            GetProperty("ControlType", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                UpdateUx(MyBaseThing);
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.Number, 1020, 2, 0, "Tile Width", "TileWidth", new nmiCtrlNumber()
            {
                ParentFld = 1000, TileHeight = 1, TileFactorY = 1, DefaultValue = "6", TileWidth = 3
            });
            GetProperty("TileWidth", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "TileWidth= " + p.ToString());
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.Number, 1030, 2, 0, "Tile Height", "TileHeight", new nmiCtrlNumber()
            {
                ParentFld = 1000, TileHeight = 1, TileFactorY = 1, DefaultValue = "1", TileWidth = 3
            });
            GetProperty("TileHeight", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "TileHeight= " + p.ToString());
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.ComboBox, 1040, 2, 0, "Horizontal Alignment", "HorizontalAlignment", new nmiCtrlComboBox()
            {
                ParentFld = 1000, Options = ";left;center;right"
            });
            GetProperty("HorizontalAlignment", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "HorizontalAlignment= " + p.ToString());
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.ComboBox, 1050, 2, 0, "Class Name", "ClassName", new nmiCtrlComboBox()
            {
                ParentFld = 1000, Options = ";BlueWhite;GreenYellow;RedWhite"
            });
            GetProperty("ClassName", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "ClassName= " + p.ToString());
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.SingleEnded, 1060, 2, 0, "HelpText", "HelpText", new nmiCtrlSingleEnded()
            {
                ParentFld = 1000
            });
            GetProperty("HelpText", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "HelpText= " + p.ToString());
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.ComboBox, 1070, 2, 0, "Opacity", "Opacity", new nmiCtrlComboBox()
            {
                ParentFld = 1000, Options = ";0.1;0.3;0.5;0.7;0.9;1.0"
            });
            GetProperty("Opacity", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "Opacity= " + p.ToString());
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.SingleCheck, 1080, 2, 0, "No TE", "NoTE", new nmiCtrlSingleCheck()
            {
                ParentFld = 1000
            });
            GetProperty("NoTE", true).RegisterEvent(eThingEvents.PropertyChanged, (p) =>
            {
                MySampleControl.SetUXProperty(Guid.Empty, "NoTE= " + p.ToString());
            });


            //Screen Properties
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileGroup, 3000, 2, 0x80, null, null, new nmiCtrlTileGroup()
            {
                Group = "NMIP:Screen", Visibility = false
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.ComboOption, 3010, 2, 0x80, "NMI Screen", "FormName", new ThePropertyBag()
            {
                "Options=%GetLiveScreens%", "TileWidth=6", "TileHeight=1", "ParentFld=3000"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.CheckField, 3020, 2, 0x80, "Flags", "Flags", new ThePropertyBag()
            {
                "Bits=6", "TileHeight=6", "TileFactorY=2",
                "ImageList=<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf21b;</i><i class='fa fa-stack-2x'>&#x2003;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf044;</i><i class='fa fa-stack-2x'>&#x2003;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf10b;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf0ce;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf0f6;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf15c;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>", "ParentFld=3000"
            }).FldWidth = 1;

            //ALL Properties
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileGroup, 2000, 2, 0x80, null, null, new nmiCtrlTileGroup()
            {
                TileWidth = 6, Group = "NMIP:All", Visibility = false
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.Table, 2010, 0xA2, 0x80, "All Properties", "mypropertybag;1", new ThePropertyBag()
            {
                "NoTE=true", "TileHeight=4", "TileLeft=9", "TileTop=3", "TileWidth=6", "FldWidth=6", "ParentFld=2000"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.SingleEnded, 2020, 0x0A, 0, "New Property Name", "ScratchName", new nmiCtrlSingleEnded()
            {
                ParentFld = 2000
            });
            TheFieldInfo tBut = TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 2040, 0x0A, 0, "Add Property", false, null, null, new nmiCtrlTileButton()
            {
                ParentFld = 2000, NoTE = true, ClassName = "cdeGoodActionButton"
            });

            tBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "AddProp", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
                string[] parts = pMsg.Message.PLS.Split(':');
                TheThing tOrg  = pThing.GetBaseThing(); // TheThingRegistry.GetThingByMID(MyBaseEngine.GetEngineName(), TheCommonUtils.CGuid(parts[2]));
                //if (tOrg == null) return;

                string tNewPropName = TheThing.GetSafePropertyString(tOrg, "ScratchName");
                if (string.IsNullOrEmpty(tNewPropName))
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Please specify a new property name"));
                }
                else
                {
                    if (tOrg.GetProperty(tNewPropName) != null)
                    {
                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Property already exists"));
                    }
                    else
                    {
                        tOrg.DeclareNMIProperty(tNewPropName, ePropertyTypes.TString);
                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Property Added"));
                        MyEditorForm.Reload(pMsg, false);
                    }
                    tOrg.SetProperty("ScratchName", "");
                }
            });

            //THING Connector
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileGroup, 5000, 2, 0x80, null, null, new nmiCtrlTileGroup()
            {
                TileWidth = 6, Group = "NMIP:Source", Visibility = false
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.ThingPicker, 5010, 2, 0x80, "Source Thing", "Address", new nmiCtrlThingPicker()
            {
                ParentFld = 5000, IncludeEngines = true
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.PropertyPicker, 5020, 2, 0x80, "Source Property", "SourceProp", new nmiCtrlPropertyPicker()
            {
                ParentFld = 5000, ThingFld = 5010
            });

            TheFieldInfo mSendbutton2 = TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 5050, 2, 0x80, "Engage", false, "", null, new nmiCtrlTileButton()
            {
                NoTE = true, TileWidth = 6, ClassName = "cdeGoodActionButton", ParentFld = 5000
            });

            mSendbutton2.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                TheProcessMessage pMsg = pPara as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
                UpdateUx(pThing.GetBaseThing());
            });
            UpdateUx(MyBaseThing);
            return(true);
        }
Exemple #26
0
        public override bool DoCreateUX()
        {
            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, null, null, 0, new nmiStandardForm {
                IconUpdateName = "Value", MaxTileWidth = 12, UseMargin = true
            });

            MyStatusForm         = tFlds["Form"] as TheFormInfo;
            MyStatusForm.ModelID = "CountdownForm";

            ThePropertyBag tDash = new nmiDashboardTile()
            {
                ClassName    = "cdeDashPlate",
                Caption      = "Loading... <i class='fa fa-spinner fa-pulse'></i>",
                TileWidth    = 2,
                TileHeight   = 2,
                HTML         = "<div><div id='COUNTD%cdeMID%'></div><p><%C20:FriendlyName%></p></div>", //TODO:SETP Move to Generate Screen for all HTML blocks!
                Style        = "background-image:none;color:white;background-color:gray",
                RSB          = true,
                RenderTarget = "HomeCenterStage"
            };

            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = tDash;
            SummaryForm.RegisterPropertyChanged(sinkStatChanged);

            tGauge = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CircularGauge, 4000, 2, 0, "Countdown", "Value", new ThePropertyBag()
            {
                "TileWidth=2", "NoTE=true", "RenderTarget=COUNTD%cdeMID%", "LabelForeground=#00b9ff", "Foreground=#FFFFFF"
            });

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 10);

            ts["Group"].SetParent(1);

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 150, 2, 128, "###CDMyVThings.TheVThings#Settings796959#Settings...###", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                DoClose = true, TileWidth = 6, IsSmall = true, ParentFld = 1
            }));

            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 151, 2, 0, "###CDMyVThings.TheVThings#Trigger796959#Trigger###", false, "", null, new nmiCtrlTileButton()
            {
                NoTE = true, ParentFld = 150, ClassName = "cdeGoodActionButton"
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                if (mTimer != null)
                {
                    mTimer.Dispose();
                    mTimer = null;
                }
                sinkTriggered(this.GetProperty(nameof(StartValue), false));
                //UpdateUx();
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 152, 2, MyBaseThing.cdeA, "###CDMyVThings.TheVThings#StartValue633339#Start Value###", nameof(StartValue), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 150
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Number, 153, 2, MyBaseThing.cdeA, "###CDMyVThings.TheVThings#Ticktimeinms633339#Tick time in ms###", nameof(Frequency), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 150
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 154, 2, MyBaseThing.cdeA, "###CDMyVThings.TheVThings#ContinueonRestart992144#Continue on Restart###", nameof(AutoStart), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 150
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 155, 2, MyBaseThing.cdeA, "###CDMyVThings.TheVThings#StartOverwhenzero992144#Start Over when zero###", nameof(Restart), new nmiCtrlNumber {
                TileWidth = 3, TileHeight = 1, ParentFld = 150
            });

            int            tControl = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(MyBaseThing, "ControlType"));
            ThePropertyBag tBag     = ThePropertyBag.CreateUXBagFromProperties(MyBaseThing);

            tBag.Add("ParentFld=1");
            if (tControl > 0)
            {
                CountBar = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, (eFieldType)tControl, 100, 2, MyBaseThing.cdeA, "CurrentValue", "Value", tBag);
            }
            else
            {
                TheThing.SetSafePropertyString(MyBaseThing, "ControlType", "34");
                TheThing.SetSafePropertyString(MyBaseThing, "NoTE", "true");
                TheThing.SetSafePropertyString(MyBaseThing, "TileWidth", "6");
                TheThing.SetSafePropertyString(MyBaseThing, "TileHeight", "1");
                CountBar = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.BarChart, 100, 2, MyBaseThing.cdeA, "CurrentValue", "Value", new nmiCtrlBarChart()
                {
                    NoTE = true, TileWidth = 6, TileHeight = 1, ParentFld = 10
                });
            }
            return(true);
        }
Exemple #27
0
        internal static TheScreenInfo GenerateLiveScreen(Guid pScreenId, TheClientInfo tClientInfo) // Guid pUserGuid, int lcid, int pFlag)
        {
            if (TheCDEngines.MyNMIService == null)
            {
                return(null);
            }

            TheScreenInfo tInfo = new TheScreenInfo
            {
                cdeMID          = pScreenId,
                MyDashboard     = null,
                MyStorageInfo   = new List <TheFormInfo>(),
                MyStorageMeta   = new cdeConcurrentDictionary <string, TheFormInfo>(),
                MyStorageMirror = new List <object>(),
                MyDashPanels    = new List <TheDashPanelInfo>()
            };

            TheThing tLiveForm = TheThingRegistry.GetThingByMID("*", pScreenId);

            if (tLiveForm == null || !TheUserManager.HasUserAccess(tClientInfo.UserID, tLiveForm.cdeA))
            {
                return(null); //V3.1: BUG 126 - could lead to racing condition. TODO: Revisit later
                //TheFormInfo tI = new TheFormInfo(tLiveForm) { FormTitle = (tLiveForm == null ? "Form not Found!" : "Access Denied!") };
                //tI.TargetElement = pScreenId.ToString();
                //tI.AssociatedClassName = pScreenId.ToString();
                //tInfo.MyStorageInfo.Add(tI);
                //tI.FormFields = new List<TheFieldInfo>();
                //TheFieldInfo tFldInfo = new TheFieldInfo(null, null, 10, 0, 0);
                //tFldInfo.Type = eFieldType.SmartLabel;
                //tFldInfo.Header = (tLiveForm == null ? "This Form was defined but has not Meta-Data associated with it." : "You do not have the required access permissions!");
                //tI.FormFields.Add(tFldInfo);
                //return tInfo;
            }
            string          tFormName = TheThing.GetSafePropertyString(tLiveForm, "FriendlyName");
            List <TheThing> tFields   = TheThingRegistry.GetThingsByFunc("*", s => s.cdeO == TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID && TheThing.GetSafePropertyString(s, "FormName") == tFormName && TheThing.GetSafePropertyBool(s, "IsLiveTag") && (s.UID == Guid.Empty || s.UID == tClientInfo.UserID));

            if (tFields != null && tFields.Any())
            {
                string tFormTitle = TheThing.GetSafePropertyString(tLiveForm, "FormTitle");
                if (string.IsNullOrEmpty(tFormTitle))
                {
                    tFormTitle = tFormName;
                }
                TheFormInfo tI = new TheFormInfo(tLiveForm)
                {
                    FormTitle           = tFormTitle,
                    TargetElement       = pScreenId.ToString(),
                    DefaultView         = eDefaultView.Form,
                    TileWidth           = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(tLiveForm, "TileWidth")),
                    TileHeight          = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(tLiveForm, "TileHeight")),
                    IsUsingAbsolute     = TheThing.GetSafePropertyBool(tLiveForm, "IsAbsolute"),
                    AssociatedClassName = pScreenId.ToString()
                };
                tInfo.MyStorageInfo.Add(tI);
                tI.FormFields = new List <TheFieldInfo>();
                int fldNo = 10;
                foreach (TheThing tTh in tFields)
                {
                    int tfldNo = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(tTh, "FldOrder"));
                    if (tfldNo == 0)
                    {
                        tfldNo = fldNo;
                    }
                    int          tFlags   = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(tTh, "Flags"));
                    cdeP         ValProp  = tTh.GetProperty("Value");
                    bool         IsNewFld = true;
                    TheFieldInfo tFldInfo = TheNMIEngine.GetFieldById(TheThing.GetSafePropertyGuid(tTh, "FldID"));
                    if (tFldInfo == null)
                    {
                        tFldInfo = new TheFieldInfo(tTh, "Value", tfldNo, tFlags & 0xFFBF, tTh.GetBaseThing().cdeA);
                    }
                    else
                    {
                        tFldInfo.FldOrder = tfldNo;
                        tFldInfo.Flags    = tFlags;
                        IsNewFld          = false;
                    }
                    if (tFldInfo.PropertyBag == null)
                    {
                        tFldInfo.PropertyBag = new ThePropertyBag();
                    }
                    ThePropertyBag.PropBagUpdateValue(tFldInfo.PropertyBag, "IsOnTheFly", "=", "True");
                    ThePropertyBag.PropBagUpdateValue(tFldInfo.PropertyBag, "UXID", "=", $"{tTh.cdeMID}");
                    tFldInfo.Header = tTh.FriendlyName;
                    RegisterNMISubscription(tClientInfo, "Value", tFldInfo);

                    string tControlType = TheThing.GetSafePropertyString(tTh, "ControlType");
                    if (TheCommonUtils.CInt(tControlType) == 0 && !TheCommonUtils.IsNullOrWhiteSpace(tControlType))
                    {
                        tFldInfo.Type = eFieldType.UserControl;
                        RegisterFieldEvents(tTh, ValProp, IsNewFld, tFldInfo, tControlType);
                    }
                    else
                    {
                        tFldInfo.Type = (eFieldType)TheCommonUtils.CInt(tControlType);
                    }
                    tFldInfo.DefaultValue = ValProp?.ToString();
                    tFldInfo.TileWidth    = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(tTh, "TileWidth"));
                    tFldInfo.TileHeight   = TheCommonUtils.CInt(TheThing.GetSafePropertyNumber(tTh, "TileHeight"));

                    foreach (cdeP prop in tTh.GetNMIProperties())
                    {
                        ThePropertyBag.PropBagUpdateValue(tFldInfo.PropertyBag, prop.Name, "=", prop.ToString());
                    }
                    if (tFldInfo.Type == eFieldType.TileButton)
                    {
                        tTh.DeclareNMIProperty("IsDown", ePropertyTypes.TBoolean);
                        ThePropertyBag.PropBagUpdateValue(tFldInfo.PropertyBag, "EnableTap", "=", "True");
                        tFldInfo.RegisterUXEvent(tTh, eUXEvents.OnPropertyChanged, "IsDown", (pThing, pObj) =>
                        {
                            if (!(pObj is TheProcessMessage pMsg) || pMsg.Message == null)
                            {
                                return;
                            }
                            TheThing.SetSafePropertyBool(pThing, "IsDown", TheCommonUtils.CBool(pMsg.Message.PLS));
                        });
        public override bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            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:f0e0"
            };

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

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



            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.SmartLabel, 20, 0, 0xC0, "Server Info", true, null, null, new ThePropertyBag() { "Style=font-size:20px;text-align: left;float:none;clear:left;width:100%", "ParentFld=6" });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 121, (int)eFlag.IsReadWrite, 0xC0, "Servername", "Address", new ThePropertyBag()
            {
                "TileHeight=1", "TileWidth=6", "ParentFld=100"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleCheck, 122, 2, 0xC0, "UseSsl", "UseSsl", new ThePropertyBag()
            {
                "TileHeight=1", "TileWidth=3", "ParentFld=100"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.Number, 123, 2, 0xC0, "Port", "Port", new ThePropertyBag()
            {
                "TileHeight=1", "TileWidth=3", "ParentFld=100", "DefaultValue=25"
            });
            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"
            });

            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileButton, 132, 2, 0, "Send Email", false, "", null, new nmiCtrlTileButton()
            {
                NoTE = true, ParentFld = 100, ClassName = "cdeGoodActionButton"
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                SendEmail(null);
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TextArea, 155, 0, 0, "Sent Result", "ResultText", new ThePropertyBag()
            {
                "TileHeight=2", "TileWidth=6", "Rows=2", "ParentFld=100"
            });
            mIsUXInitialized = true;
            return(true);
        }
Exemple #29
0
        public override bool DoCreateUX()
        {
            MyBaseThing.RegisterProperty("ClickState");
            var tFlds = TheNMIEngine.AddStandardForm(MyBaseThing, null, 24, null, "Value");

            MyStatusForm = tFlds["Form"] as TheFormInfo;
            //MyStatusForm.PropertyBag = new ThePropertyBag { "TileWidth=6" };
            MyStatusForm.RegisterEvent2(eUXEvents.OnShow, (pmse, sen) => { UpdateUx(); });
            SummaryForm             = tFlds["DashIcon"] as TheDashPanelInfo;
            SummaryForm.PropertyBag = new nmiDashboardTile()
            {
                Format = $"{MyBaseThing.FriendlyName}<br>{{0}}", Caption = MyBaseThing.FriendlyName
            };

            CountBar             = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleEnded, 5, 2, MyBaseThing.cdeA, "CurrentValue", "Value", null);
            ChangeTimestampField = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.DateTime, 6, 0, MyBaseThing.cdeA, "Last Change", nameof(ValueChangeTimestamp), new nmiCtrlDateTime {
                ParentFld = 1, Visibility = ShowChangeTimestamp
            });
            TimestampField = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.DateTime, 7, 0, MyBaseThing.cdeA, "Timestamp", nameof(ValueTimestamp), new nmiCtrlDateTime {
                ParentFld = 1, Visibility = ShowChangeTimestamp
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 800, 2, 0x80, "Configuration...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 1, DoClose = true, IsSmall = true
            }));

            var ts = TheNMIEngine.AddStatusBlock(MyBaseThing, MyStatusForm, 810);

            ts["Group"].SetParent(800);
            ts["Group"].PropertyBag = new nmiCtrlCollapsibleGroup {
                DoClose = true
            };



            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 1000, 2, 0x80, "NMI Settings...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 800, DoClose = true, IsSmall = true, TileWidth = 6
            }));
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 3000, 2, 0x80, "Advanced NMI Settings...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 1000, DoClose = true, IsSmall = true, TileWidth = 6
            }));
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.ComboOption, 3010, 2, 0x80, "NMI Screen", "FormName", new ThePropertyBag()
            {
                "Options=%GetLiveScreens%", "TileWidth=6", "TileHeight=1", "ParentFld=3000"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CheckField, 3020, 2, 0x80, "Flags", "Flags", new ThePropertyBag()
            {
                "Bits=6", "TileHeight=6", "TileFactorY=2",
                "ImageList=<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf21b;</i><i class='fa fa-stack-2x'>&#x2003;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf044;</i><i class='fa fa-stack-2x'>&#x2003;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf10b;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf0ce;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf0f6;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>," +
                "<span class='fa-stack'><i class='fa fa-stack-1x'>&#xf15c;</i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'>&#xf05e;</i></span>", "ParentFld=3000"
            }).FldWidth = 1;

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.ComboBox, 1500, 2, 0x80, "Control Type", "ControlType", new ThePropertyBag()
            {
                "Options=%RegisteredControlTypes%", "ParentFld=1000"
            });

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 2000, 2, 0x80, "All Properties...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                NoTE = true, ParentFld = 1000, DoClose = true, IsSmall = true, TileWidth = 6
            }));

            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.Table, 2010, 0xA2, 0x80, "All Properties", "mypropertybag;1", new ThePropertyBag()
            {
                "NoTE=true", "TileHeight=4", "TileLeft=9", "TileTop=3", "TileWidth=6", "FldWidth=6", "ParentFld=2000"
            });
            TheNMIEngine.AddFields(MyStatusForm, new List <TheFieldInfo> {
                { new TheFieldInfo()
                  {
                      FldOrder = 2020, DataItem = "MyPropertyBag.ScratchName.Value", Flags = 0x0A, Type = eFieldType.SingleEnded, Header = "New Property Name", TileWidth = 6, TileHeight = 1, PropertyBag = new ThePropertyBag()
                      {
                          "ParentFld=2000"
                      }
                  } },
            });

            TheFieldInfo tBut = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 2040, 0x0A, 0, "Add Property", false, null, null, new nmiCtrlTileButton()
            {
                ParentFld = 2000, NoTE = true, ClassName = "cdeGoodActionButton"
            });

            tBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "AddProp", (pThing, pObj) =>
            {
                TheProcessMessage pMsg = pObj as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
                string[] parts = pMsg.Message.PLS.Split(':');
                TheThing tOrg  = TheThingRegistry.GetThingByMID(MyBaseEngine.GetEngineName(), TheCommonUtils.CGuid(parts[2]));
                if (tOrg == null)
                {
                    return;
                }

                string tNewPropName = TheThing.GetSafePropertyString(tOrg, "ScratchName");
                if (string.IsNullOrEmpty(tNewPropName))
                {
                    TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Please specify a new property name"));
                }
                else
                {
                    if (tOrg.GetProperty(tNewPropName) != null)
                    {
                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Property already exists"));
                        tOrg.SetProperty("ScratchName", "");
                    }
                    else
                    {
                        tOrg.DeclareNMIProperty(tNewPropName, ePropertyTypes.TString);
                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", "Property Added"));
                        tOrg.SetProperty("ScratchName", "");
                        MyStatusForm.Reload(pMsg, false);
                    }
                }
            });
            TheFieldInfo mSendbutton = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 1550, 2, 0x80, "Reload", false, "", null, new nmiCtrlTileButton()
            {
                TileWidth = 6, NoTE = true, ClassName = "cdeGoodActionButton", ParentFld = 1000
            });

            mSendbutton.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                TheProcessMessage pMsg = pPara as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
                UpdateUx();
                MyStatusForm.Reload(pMsg, true);
                //TheNMIEngine.GetEngineDashBoardByThing(MyBaseEngine.GetBaseThing()).Reload(pMsg, true);
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.CollapsibleGroup, 5000, 2, 0x80, "Source...", null, ThePropertyBag.Create(new nmiCtrlCollapsibleGroup()
            {
                DoClose = true, IsSmall = true, ParentFld = 800, TileWidth = 6
            }));
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.ThingPicker, 5010, 2, 0x80, "Source Thing", "Address", new nmiCtrlThingPicker()
            {
                ParentFld = 5000, IncludeEngines = true, IncludeRemotes = true
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.PropertyPicker, 5020, 2, 0x80, "Source Property", "SourceProp", new nmiCtrlPropertyPicker()
            {
                ParentFld = 5000, ThingFld = 5010
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 5030, 2, 0x80, "Show Timestamp", nameof(ShowTimestamp), new nmiCtrlSingleCheck {
                ParentFld = 5000, TileWidth = 3
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.SingleCheck, 5040, 2, 0x80, "Show Change Time", nameof(ShowChangeTimestamp), new nmiCtrlSingleCheck {
                ParentFld = 5000, TileWidth = 3
            });
            TheFieldInfo mSendbutton2 = TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 5050, 2, 0x80, "Engage", false, "", null, new nmiCtrlTileButton()
            {
                NoTE = true, TileWidth = 6, ClassName = "cdeGoodActionButton", ParentFld = 5000
            });

            mSendbutton2.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "", (pThing, pPara) =>
            {
                TheProcessMessage pMsg = pPara as TheProcessMessage;
                if (pMsg?.Message == null)
                {
                    return;
                }
                UpdateUx();
            });

            UpdateUx();
            return(true);
        }
        public bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }
            mIsUXInitCalled = true;

            //NUI Definition for All clients
            TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "Visitor Log")
            {
                PropertyBag = new nmiDashboard {
                    Category = "Diagnostics", Caption = "<i class='fa faIcon fa-5x'>&#xf0c0;</i></br>Visitor Log"
                }
            });

            TheFormInfo tMyForm = TheNMIEngine.AddForm(new TheFormInfo(MyBaseThing)
            {
                FormTitle = "Visitor Log of " + TheBaseAssets.MyServiceHostInfo.MyStationName, DefaultView = eDefaultView.Form, TileWidth = 10
            });

            TheNMIEngine.AddFormToThingUX(MyBaseThing, tMyForm, "CMyForm", "My Visitor Log</br><span style='font-size:xx-small'>" + TheBaseAssets.MyServiceHostInfo.MyStationName + "</span>", 3, 3, 0, TheNMIEngine.GetNodeForCategory(), null, null);
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 2, 0, 0, "Visitor Count Since Startup", "VisitorCount", new ThePropertyBag()
            {
                "TileWidth=3"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 3, 0, 0, "Connected Browser", "BrowserCount", new ThePropertyBag()
            {
                "TileWidth=3"
            });

            #region GoogleMaps
            string gKey = null;
            if (TheBaseAssets.MyCmdArgs.ContainsKey("GoogleMapsKey"))
            {
                gKey = TheBaseAssets.MyCmdArgs["GoogleMapsKey"];
            }
            if (TheNMIEngine.IsControlTypeRegistered("cdeNMI.ctrlGoogleMaps") && !string.IsNullOrEmpty(gKey))
            {
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 420, 2, 0, "Google Maps", null, new nmiCtrlCollapsibleGroup()
                {
                    TileWidth = 12, IsSmall = true
                });
                var myGoogleMap = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, 421, 0, 0, null, "MapCoords", new ThePropertyBag()
                {
                    "NoTE=true", "ParentFld=420", "Zoom=4", "Tilt=45", "Lat=48", "Lng=-122", $"GoogleKey={gKey}", //TODO: Make configuration setting
                    "TileWidth=10", "TileHeight=10", "ControlType=cdeNMI.ctrlGoogleMaps", "Markers=[{ \"Description\": \"Home\",\"latitude\": 48,\"longitude\": -122 }]"
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 422, 2, 0, "Coordinates", "Lat", new nmiCtrlSingleEnded()
                {
                    TileWidth = 3, ParentFld = 420
                });
                TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SingleEnded, 423, 2, 0, "", "Lng", new nmiCtrlSingleEnded()
                {
                    NoTE = true, TileWidth = 1, ParentFld = 420
                });
                GetProperty("Lat", true).RegisterEvent(eThingEvents.PropertyChangedByUX, (p) => {
                    myGoogleMap?.SetUXProperty(Guid.Empty, $"Lat={p.ToString()}");
                });
                GetProperty("Lng", true).RegisterEvent(eThingEvents.PropertyChangedByUX, (p) => {
                    myGoogleMap?.SetUXProperty(Guid.Empty, $"Lng={p.ToString()}");
                });

                TheFieldInfo tBarZOOM = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.BarChart, 427, 2, 0, "Zoom", "ZoomVal", new ThePropertyBag()
                {
                    "NoTE=true", "TileHeight=1", "TileWidth=6", "IsVertical=false", "ParentFld=420", "MaxValue=20"
                });
                tBarZOOM.RegisterUXEvent(MyBaseThing, eUXEvents.OnPropertyChanged, "Value", (sender, para) =>
                {
                    TheProcessMessage tP = para as TheProcessMessage;
                    if (tP != null && tP.Message != null)
                    {
                        myGoogleMap?.SetUXProperty(tP.Message.GetOriginator(), $"Zoom={tP.Message.PLS}");
                    }
                });

                tMyForm.RegisterEvent2(eUXEvents.OnShow, (pMsg, arg) => {
                    var tVisits = MyVisitorLog.GetAllVisitors();
                    if (tVisits?.Count > 0)
                    {
                        myGoogleMap?.SetUXProperty(pMsg.Message.GetOriginator(), $"Markers={TheCommonUtils.SerializeObjectToJSONString(tVisits)}");
                    }
                });
            }
            #endregion


            TheFormInfo tConns = new TheFormInfo(TheThing.GetSafeThingGuid(MyBaseThing, "FootPrints"), eEngineName.NMIService, "Node Footprints", MyNodePrintsName, "Add Footprint", null)
            {
                IsNotAutoLoading = true
            };
            TheNMIEngine.AddFormToThingUX(MyBaseThing, tConns, "CMyTable", "Node Footprints", 1, 9, 0x80, "Node Type Definitions", null, new ThePropertyBag()
            {
                "Visibility=true"
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tConns, eFieldType.Number, 10, 0, 0x0, "Counter", "Counter", new nmiCtrlNumber()
            {
                TileWidth = 1, FldWidth = 1
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tConns, eFieldType.SingleEnded, 20, 2, 0x0, "Node Type", "NodeType", new nmiCtrlNumber()
            {
                TileWidth = 3, FldWidth = 3
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tConns, eFieldType.Number, 25, 2, 0x0, "Plugin Count", "ExactCount", new nmiCtrlNumber()
            {
                TileWidth = 1, FldWidth = 1
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tConns, eFieldType.TextArea, 30, 2, 0xC0, "Plugin Footprint", "Footprint", new nmiCtrlTextArea()
            {
                TileWidth = 10, TileHeight = 2, FldWidth = 10
            });
            TheNMIEngine.AddTableButtons(tConns, false, 100);

            TheNMIEngine.AddAboutButton(MyBaseThing);
            mIsUXInitialized = true;
            return(true);
        }