Пример #1
0
        private void CreateRule(string pFriendlyName, TheThing pTriggerThing, string pTriggerProperty, eRuleTrigger pTriggerCondition, string pTriggerValue, bool pDoLogRule, bool bIsRuleActive)
        {
            TriggerStartTime = DateTimeOffset.MinValue;
            TriggerEndTime   = DateTimeOffset.MaxValue;

            //TriggerObjectType = "CDE_THING";
            TriggerObject = pTriggerThing.cdeMID.ToString();
            if (!TheCommonUtils.IsNullOrWhiteSpace(pTriggerProperty))
            {
                TriggerProperty = pTriggerProperty;
            }
            else
            {
                pTriggerProperty = "Value";
            }
            TriggerCondition = pTriggerCondition;
            TriggerValue     = pTriggerValue;


            FriendlyName = pFriendlyName;
            IsRuleLogged = pDoLogRule;
            IsRuleActive = bIsRuleActive;

            if (string.IsNullOrEmpty(MyBaseThing.EngineName))
            {
                MyBaseThing.EngineName = eEngineName.ThingService;
            }
            MyBaseThing.DeviceType = eKnownDeviceTypes.TheThingRule;
            MyBaseThing.ID         = MyBaseThing.cdeMID.ToString();
            RegisterEvent("RuleFired", null);
            MyBaseThing.SetIThingObject(this);
        }
Пример #2
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));
                        });
Пример #3
0
        void SendSMS(string pText)
        {
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient(MyBaseThing.Address);

                mail.From = new MailAddress(FromAddress);
                string receipt     = Recipient;
                string credentials = Credentials;
                if (TheCommonUtils.IsNullOrWhiteSpace(receipt))
                {
                    receipt = "*****@*****.**";
                }
                string carrier = Carrier;

                // Code to handle carrier
                //TODO: Set Server name and SSL/Server and Port per Carrier
                #region Handle Carrier
                switch (carrier.ToLower())
                {
                case "t-mobile":
                    receipt += "@tmomail.net";
                    break;

                case "at&t":
                    receipt += "@txt.att.net";
                    break;

                case "sprint":
                    receipt += "@messaging.sprintpcs.com";
                    break;

                case "verizon":
                    receipt += "@vtext.com";
                    break;

                case "virgin mobile":
                    receipt += "@vmobl.com";
                    break;

                case "metro pcs":
                    receipt += "@MyMetroPcs";
                    break;

                case "alltel":
                    receipt += "@message.alltel.com";
                    break;

                case "powertel":
                    receipt += "@ptel.net";
                    break;

                case "suncom":
                    receipt += "@tms.suncom.com";
                    break;

                case "nextel":
                    receipt += "@messaging.nextel.com";
                    break;

                case "us cellular":
                    receipt += "@email.uscc.net";
                    break;

                case "boost mobile":
                    receipt += "@myboostmobile.com";
                    break;

                case "cingular":
                    receipt += "@cingularme.com";
                    break;
                }
                #endregion

                mail.To.Add(receipt);
                if (string.IsNullOrEmpty(SubjectText))
                {
                    mail.Subject = TheBaseAssets.MyServiceHostInfo.ApplicationName + " Message";
                }
                else
                {
                    mail.Subject = SubjectText;
                }
                if (!TheCommonUtils.IsNullOrWhiteSpace(pText))
                {
                    mail.Body = pText;
                }
                else
                {
                    mail.Body = MessageText;
                }

                if (credentials.Equals("Admin"))
                {
                    string AdminUsername = MyBaseEngine.GetBaseThing().GetProperty("AdminUsername", false).ToString();
                    string AdminServer   = MyBaseEngine.GetBaseThing().GetProperty("AdminServer", false).ToString();
                    string AdminPassword = MyBaseEngine.GetBaseThing().GetProperty("AdminPassword", false).GetValue().ToString();
                    int    AdminPort     = int.Parse(MyBaseEngine.GetBaseThing().GetProperty("AdminPort", false).ToString());
                    SmtpServer.Credentials = new System.Net.NetworkCredential(AdminUsername, AdminPassword);
                    SmtpServer.Host        = AdminServer;
                    SmtpServer.Port        = AdminPort;
                    string AdminSsl = MyBaseEngine.GetBaseThing().GetProperty("AdminSsl", false).ToString();
                    if (AdminSsl.Equals("True"))
                    {
                        SmtpServer.EnableSsl = true;
                    }
                }
                else
                {
                    SmtpServer.Credentials = new System.Net.NetworkCredential(UserName, Password);
                    SmtpServer.Port        = Port;
                    if (UseSsl)
                    {
                        SmtpServer.EnableSsl = true;
                    }
                }
                SmtpServer.Send(mail);
                ResultText = "SMS Sent to " + Recipient;

                TSM tTSM = new TSM(MyBaseEngine.GetEngineName(), "SET_LAST_MSG", string.Format("SMS: Subject:{2} Body:{3} From {0} at {1}", TheBaseAssets.MyServiceHostInfo.MyStationName, DateTimeOffset.Now, SubjectText, mail.Body));
                MyBaseEngine.ProcessMessage(new TheProcessMessage(tTSM));
                TheCommCore.PublishCentral(tTSM);
            }
            catch (Exception ex)
            {
                ResultText = ex.ToString();
            }
        }
Пример #4
0
        void SendEmail(string pText)
        {
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient(MyBaseThing.Address);

                mail.From = new MailAddress(FromAddress);
                string receipt     = Recipient;
                string credentials = Credentials;
                if (TheCommonUtils.IsNullOrWhiteSpace(receipt))
                {
                    receipt = "*****@*****.**";
                }
                mail.To.Add(receipt);
                if (string.IsNullOrEmpty(SubjectText))
                {
                    mail.Subject = TheBaseAssets.MyServiceHostInfo.ApplicationName + " Message";
                }
                else
                {
                    mail.Subject = SubjectText;
                }
                if (!TheCommonUtils.IsNullOrWhiteSpace(pText))
                {
                    mail.Body = pText;
                }
                else
                {
                    mail.Body = MessageText;
                }
                if (credentials.Equals("Admin"))
                {
                    string AdminUsername = MyBaseEngine.GetBaseThing().GetProperty("AdminUsername", false).ToString();
                    string AdminServer   = MyBaseEngine.GetBaseThing().GetProperty("AdminServer", false).ToString();
                    string AdminPassword = MyBaseEngine.GetBaseThing().GetProperty("AdminPassword", false).GetValue().ToString();
                    int    AdminPort     = int.Parse(MyBaseEngine.GetBaseThing().GetProperty("AdminPort", false).ToString());
                    SmtpServer.Credentials = new System.Net.NetworkCredential(AdminUsername, AdminPassword);
                    SmtpServer.Host        = AdminServer;
                    SmtpServer.Port        = AdminPort;
                    string AdminSsl = MyBaseEngine.GetBaseThing().GetProperty("AdminSsl", false).ToString();
                    if (AdminSsl.Equals("True"))
                    {
                        SmtpServer.EnableSsl = true;
                    }
                }
                else
                {
                    SmtpServer.Port        = Port;
                    SmtpServer.Credentials = new System.Net.NetworkCredential(UserName, Password);
                    if (UseSsl)
                    {
                        SmtpServer.EnableSsl = true;
                    }
                }

                SmtpServer.Send(mail);
                ResultText = "Mail Sent to " + Recipient;

                TSM tTSM = new TSM(MyBaseEngine.GetEngineName(), "SET_LAST_MSG", string.Format("eMail: Subject:{2} Body:{3} From {0} at {1}", TheBaseAssets.MyServiceHostInfo.MyStationName, DateTimeOffset.Now, SubjectText, mail.Body));
                MyBaseEngine.ProcessMessage(new TheProcessMessage(tTSM));
                TheCommCore.PublishCentral(tTSM);
            }
            catch (Exception ex)
            {
                ResultText = ex.ToString();
            }
        }
Пример #5
0
        internal void RuleTrigger(string tVal, bool bForce = false)
        {
            MyBaseThing.Value = tVal;
            switch (TriggerCondition)
            {
            case eRuleTrigger.Not:
                if (!TriggerValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Larger:
                if (TheCommonUtils.CDbl(TriggerValue) < TheCommonUtils.CDbl(tVal) && TheCommonUtils.CDbl(TriggerValue) >= TheCommonUtils.CDbl(TriggerOldValue))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Smaller:
                if (TheCommonUtils.CDbl(TriggerValue) > TheCommonUtils.CDbl(tVal) && TheCommonUtils.CDbl(TriggerValue) <= TheCommonUtils.CDbl(TriggerOldValue))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Contains:
                if (tVal.ToLower().Contains(TriggerValue.ToLower()))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.StartsWith:
                if (tVal.StartsWith(TriggerValue, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.EndsWith:
                if (tVal.EndsWith(TriggerValue, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Set:
                if (!string.IsNullOrEmpty(TriggerValue))
                {
                    string expression = tVal + TriggerValue;
                    ActionValue = Evaluate(expression).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    ActionValue = tVal;
                }
                FireAction(bForce);
                break;

            case eRuleTrigger.Equals:
                if (TriggerValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Fire:
                FireAction(bForce);
                break;

            case eRuleTrigger.Flank:
                if (TheCommonUtils.IsNullOrWhiteSpace(TriggerValue))
                {
                    if (!TriggerOldValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                    {
                        FireAction(bForce);
                    }
                    break;
                }
                string[] tTrigs = TriggerValue.Split(',');
                if (tTrigs.Length == 1)
                {
                    if (Math.Abs(TheCommonUtils.CDbl(TriggerValue) - TheCommonUtils.CDbl(tVal)) < double.Epsilon && Math.Abs(TheCommonUtils.CDbl(TriggerOldValue) - TheCommonUtils.CDbl(tVal)) > double.Epsilon)
                    {
                        FireAction(false);
                    }
                }
                else
                {
                    if (Math.Abs(TheCommonUtils.CDbl(tVal) - TheCommonUtils.CDbl(TriggerOldValue)) > Double.Epsilon &&
                        Math.Abs(TheCommonUtils.CDbl(TriggerOldValue) - TheCommonUtils.CDbl(tTrigs[0])) < double.Epsilon &&
                        Math.Abs(TheCommonUtils.CDbl(tVal) - TheCommonUtils.CDbl(tTrigs[1])) < Double.Epsilon)
                    {
                        FireAction(bForce);
                    }
                }
                break;

            case eRuleTrigger.State:
                if (TriggerOldValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;
            }
            TriggerOldValue = tVal;
        }
        internal TheUserDetails CloneToUser(Guid pUserID)
        {
            TheUserDetails tMinUser = TheUserManager.GetUserByID(pUserID);

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

            Guid pSessionID = tMinUser.CurrentSessionID;

            TheUserDetails tU = new TheUserDetails
            {
                ApplicationName   = ApplicationName,
                AssignedEasyScope = AssignedEasyScope,  //OK
                cdeAVA            = cdeAVA,
                cdeCTIM           = cdeCTIM,
                cdeMID            = cdeMID,
                cdePRI            = cdePRI,
                cdeO                = cdeO,
                EMail               = EMail,
                Name                = Name,
                AccessMask          = -1,
                HomeScreen          = HomeScreen,
                IsReadOnly          = IsReadOnly,
                LoginGesture        = LoginGesture,
                HomeNode            = TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID,
                PrimaryDeviceID     = PrimaryDeviceID,
                PrimaryRole         = PrimaryRole,
                ThemeName           = ThemeName,
                UserName            = UserName,
                TeTo                = TeTo,
                LCID                = LCID,
                ShowClassic         = ShowClassic,
                ShowToolTipsInTable = ShowToolTipsInTable,
                SpeakToasts         = SpeakToasts,
                HomeNodeName        = HomeNodeName
            };

            if (string.IsNullOrEmpty(NodeScope) || NodeScope.ToUpper() == "THIS")
            {
                NodeScope = TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID.ToString();
            }
            tU.NodeScope = NodeScope;
            if (string.IsNullOrEmpty(HomeNodeName))
            {
                HomeNodeName = TheBaseAssets.MyServiceHostInfo.MyStationName;
            }

            if (!string.IsNullOrEmpty(SecToken))
            {
                string[] tSec = TheCommonUtils.cdeSplit(TheCommonUtils.cdeRSADecrypt(pSessionID, SecToken), ";:;", false, false);
                if ("CDE!" == tSec[0])
                {
                    for (int i = 1; i < tSec.Length; i++)
                    {
                        int tPos = tSec[i].IndexOf('=');
                        if (tPos < 0)
                        {
                            continue;
                        }
                        int    tFldNo = TheCommonUtils.CInt(tSec[i].Substring(0, tPos));
                        string tPara  = tSec[i].Substring(tPos + 1);
                        if (TheCommonUtils.IsNullOrWhiteSpace(tPara) || tPara == "null")
                        {
                            continue;
                        }
                        switch (tFldNo)
                        {
                        case 40:
                            tU.EMail = tPara;
                            break;

                        case 20:                                 //Name of User
                            tU.Name = tPara;
                            break;

                        case 50:                                                             //Password
                            tU.Password = TheBaseAssets.MySecrets.CreatePasswordHash(tPara); //PW-SECURITY-REVIEW: Create Hash Here
                            break;

                        case 56:     //Pin
                            if (string.IsNullOrEmpty(tU.TeTo))
                            {
                                tU.TeTo = TheBaseAssets.MyScopeManager.GenerateCode(8);
                            }
                            tU.PinHash = TheBaseAssets.MySecrets.CreatePasswordHash($"{tU.TeTo.ToUpper()}@@{tPara}");
                            break;

                        case 120:                             //HomeScreen
                            if (tU.PrimaryRole != "NMIADMIN") //not allowed to set a HomeScreen for NMIAdmin
                            {
                                tU.HomeScreen = tPara;
                            }
                            break;

                        case 110:                                 //Language ID
                            tU.LCID = TheCommonUtils.CInt(tPara);
                            break;

                        case 6:                                 //Node Scope
                            tU.NodeScope = tPara;
                            break;

                        case 70:                                 //AccessMask
                            tU.AccessMask = TheCommonUtils.CInt(tPara);
                            break;
                        }
                    }
                }
                else
                {
                    //Should no come here
                    //tU.Password = tSec[0]; //PW-SECURITY-REVIEW: should contain hash
                    //               if (tSec.Length > 1)
                    //	tU.AssignedEasyScope = tSec[1]; //ok - not used at this point
                    //if (tSec.Length > 2)
                    //	tU.AccessMask = TheCommonUtils.CInt(tSec[2]);
                }
            }
            else
            {
                tU.Password   = TheBaseAssets.MySecrets.CreatePasswordHash(Password);               //PW-SECURITY-REVIEW: should contain hash
                tU.AccessMask = AccessMask;
            }
            tU.SecToken = TheCommonUtils.cdeEncrypt(tU.Password + ";:;" + tU.AssignedEasyScope + ";:;" + tU.AccessMask, TheBaseAssets.MySecrets.GetAI());              //AES OK ; PW Should be Hash
            return(tU);
        }