Пример #1
0
        internal static TheFormInfo GenerateForm(Guid FormId, TheClientInfo pClientInfo)
        {
            if (TheCDEngines.MyNMIService == null)
            {
                return(null);
            }
            TheFormInfo tDef = TheNMIEngine.GetFormById(FormId);

            if (tDef == null)
            {
                return(null);
            }

            TheFormInfo tToSend = tDef.Clone(pClientInfo.WebPlatform);

            TheNMIEngine.CheckAddButtonPermission(pClientInfo, tToSend);
            tToSend.AssociatedClassName = FormId.ToString();
            var tso = GetScreenOptions(FormId, pClientInfo, tDef);

            if (tso != null && tso.TileWidth > 0)
            {
                tToSend.TileWidth = tso.TileWidth;
            }

            tToSend.FormFields = GetPermittedFields(FormId, pClientInfo, tso, true);
            return(tToSend);
        }
Пример #2
0
        public static TheFieldInfo Add4x2Edit(TT MyBaseThing, TheFormInfo pForm, eFieldType pType, int StartFld, int ParentFld, int flg, string pLabel, string pUpdateName, ThePropertyBag pBag = null)
        {
            NMI.AddSmartControl(MyBaseThing, pForm, eFieldType.TileGroup, StartFld, 0, 0, null, null, new nmiCtrlTileGroup {
                ParentFld = ParentFld, TileWidth = 6
            });
            NMI.AddSmartControl(MyBaseThing, pForm, eFieldType.SmartLabel, StartFld + 1, 0, 0, null, null, new nmiCtrlSmartLabel {
                Style = "width:80%; font-size:20px; text-align:left; padding:20px;", NoTE = true, Text = pLabel, ParentFld = StartFld, TileWidth = 4
            });
            var fld = NMI.AddSmartControl(MyBaseThing, pForm, pType, StartFld + 2, flg, 0, null, pUpdateName, new nmiCtrlNumber {
                ParentFld = StartFld, TileWidth = 2
            });

            if (pBag != null)
            {
                fld.PropertyBag = pBag;
            }
            return(fld);
        }
Пример #3
0
        public static TheFieldInfo AddSpeedGauge(TT MyBaseThing, TheFormInfo tMyForm, int pFldNumber, int pParentFld, string Label, string Units, string UpdateName, int MinVal, int MaxVal, int errLevel, int Wid = 4, bool invertRange = false)
        {
            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\" }}]";
            }

            return(NMI.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, pFldNumber, 0, 0, null, UpdateName, new ThePropertyBag()
            {
                "ControlType=Speed Gauge", "NoTE=true", $"ParentFld={pParentFld}",
                $"TileWidth={Wid}", $"TileHeight={Wid}",
                $"MinValue={MinVal}",
                $"MaxValue={MaxVal}",
                $"SubTitle={Units}",
                Plotband,
                $"SetSeries={{ \"name\": \"{Label}\",\"data\": [{TT.GetSafePropertyNumber(MyBaseThing,UpdateName)}],\"tooltip\": {{ \"valueSuffix\": \" {Units}\"}}}}",
                $"Value={TT.GetSafePropertyNumber(MyBaseThing,UpdateName)}"
            }));
        }
Пример #4
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));
                        });
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Creates the basic NMI User Interface
        /// </summary>
        /// <returns></returns>
        public override bool CreateUX()
        {
            if (mIsUXInitCalled)
            {
                return(false);
            }

            mIsUXInitCalled = true;
            if (!MyBaseEngine.GetEngineState().IsService)
            {
                mIsUXInitialized = true;
                return(true);
            }

            UserPrefID = new Guid("{E15AE1F2-69F3-42DC-97E8-B0CC2A8526A6}").ToString().ToLower();
            UserManID  = TheThing.GetSafeThingGuid(MyBaseThing, "USEMAN").ToString().ToLower();
            AddDashboard(MyBaseThing, new TheDashboardInfo(eNMIPortalDashboard, "-HIDE")
            {
                FldOrder = 99999, PropertyBag = { "Category=NMI" }
            });                                                                                                                                   //Main Portal of Relay
            TheDashboardInfo tDash = AddDashboard(MyBaseThing, new TheDashboardInfo(eNMIDashboard, "NMI Admin Portal")
            {
                cdeA = 0x0, FldOrder = 9090, PropertyBag = new nmiDashboard()
                {
                    Category = "NMI", ForceLoad = true, Thumbnail = "FA5:f06c", Caption = "###NMI Admin###"
                }
            });

            if (!TheBaseAssets.MyServiceHostInfo.IsIsolated)
            {
                TheFormInfo tInf = new TheFormInfo(new Guid("{6EE8AC31-7395-4A80-B01C-D49BE174CFC0}"), eEngineName.NMIService, "###Service Overview###", "HostEngineStates")
                {
                    IsNotAutoLoading = true, PropertyBag = new nmiCtrlTableView {
                        ShowFilterField = true
                    }
                };
                AddFormToThingUX(tDash, MyBaseThing, tInf, "CMyTable", "###Service Overview###", 1, 0x0F, 128, "###NMI Administration###", null, new ThePropertyBag {
                    "TileThumbnail=FA5:f05a"
                });

                var tDisButName = "DISPLUG";
                var tDisBut     = AddSmartControl(MyBaseThing, tInf, eFieldType.TileButton, 1, 0x42, 0x80, null, "DisableText", new nmiCtrlTileButton()
                {
                    MID = new Guid("{7C67925E-7C2D-4460-9E61-6166494E9328}"), TableHeader = "###Is Enabled###", TileHeight = 1, TileWidth = 1, FldWidth = 1, ClassName = "cdeTableButton"
                });
                tDisBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, tDisButName, (sender, para) =>
                {
                    if (para is TheProcessMessage pMsg && pMsg.Message != null)
                    {
                        var tCmd = pMsg.Message.PLS?.Split(':');
                        if (tCmd != null && tCmd.Length > 2)
                        {
                            if (tCmd[1] != tDisButName)
                            {
                                return;
                            }
                            var estate = TheCDEngines.MyServiceStates.GetEntryByID(tCmd[2]);
                            if (estate != null)
                            {
                                var tBase = TheThingRegistry.GetBaseEngine(estate.ClassName);
                                if (tBase != null)
                                {
                                    if (tBase.HasCapability(eThingCaps.Internal))
                                    {
                                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", TheNMIEngine.LocNMI(pMsg, "###Not allowed on internal engines###")));
                                        return;
                                    }
                                    if (tBase.HasCapability(eThingCaps.MustBePresent))
                                    {
                                        TheCommCore.PublishToOriginator(pMsg.Message, new TSM(eEngineName.NMIService, "NMI_TOAST", TheNMIEngine.LocNMI(pMsg, "###Not allowed on engines that must be present###")));
                                        return;
                                    }
                                }
                                estate.IsDisabled = !estate.IsDisabled;
                                estate.IsUnloaded = estate.IsDisabled;
                                SetUXProperty(Guid.Empty, tDisBut.cdeMID, $"Caption={estate.DisableText}", pMsg.Message.PLS.Split(':')[2]);
                                TheBaseAssets.RecordServices();
                            }
                        }
                    }
                });