void sinkUpdateUX(cdeP pProp) { int i = MyBaseThing.StatusLevel; //Optimizing that GetProperty is not called 3 times SummaryForm?.SetUXProperty(Guid.Empty, string.Format("Background={0}", TheNMIEngine.GetStatusColor(i))); MyBaseEngine.ProcessMessage(new TheProcessMessage(new TSM(MyBaseEngine.GetEngineName(), "UPDATE_VALUE"))); }
private void ShowKPI(int pFldOrder, string pLabel, string pUpdName, int MaxVal = 100, int AveVal = 50, string pUnits = "bytes") { TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.TileGroup, pFldOrder, 0, 0, null, null, new nmiCtrlTileGroup { ParentFld = 300, TileWidth = 6 }); TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.SmartLabel, pFldOrder + 1, 0, 0, null, null, new nmiCtrlSmartLabel { ParentFld = pFldOrder, Text = pLabel, NoTE = true, TileFactorY = 2, TileHeight = 1, TileWidth = 5, ClassName = "cdeTileGroupHeaderSmall" }); var tBut = TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.TileButton, pFldOrder + 2, 2, 0, "V-Tise", null, new nmiCtrlTileButton { ParentFld = pFldOrder, NoTE = true, TileFactorY = 2, TileHeight = 1, TileWidth = 1, ClassName = "cdeGlassButton" }); tBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, $"But{pUpdName}", (sender, para) => { TheThing tT = TheThingRegistry.GetThingByID(MyBaseEngine.GetEngineName(), $"ISO{MyBaseThing.cdeMID}:{pUpdName}"); if (tT == null) { TheKPIReport tRep = new TheKPIReport(null, MyPlugin); TheThing.SetSafePropertyGuid(tRep, "RealSensorThing", MyBaseThing.cdeMID); tRep.GetBaseThing().ID = $"ISO{MyBaseThing.cdeMID}:{pUpdName}"; MyBaseThing.GetProperty(pUpdName, true); TheThing.SetSafePropertyString(tRep, "RealSensorProperty", pUpdName); TheThing.SetSafePropertyNumber(tRep, "StateSensorMaxValue", MaxVal); TheThing.SetSafePropertyNumber(tRep, "StateSensorAverage", AveVal); TheThing.SetSafePropertyNumber(tRep, "StateSensorSteps", MaxVal / 15); TheThing.SetSafePropertyString(tRep, "StateSensorValueName", pLabel); TheThing.SetSafePropertyString(tRep, "StateSensorUnit", pUnits); TheThing.SetSafePropertyString(tRep, "FriendlyName", MyBaseThing.FriendlyName); TheThing.SetSafePropertyString(tRep, "ReportName", $"ISO-KPI: {MyBaseThing.FriendlyName} - {pLabel}"); TheThing.SetSafePropertyString(tRep, "ReportCategory", "ISO KPI Reports"); ThePluginInfo tI = MyPlugin.GetBaseEngine().GetPluginInfo(); if (tI != null) { TheThing.SetSafePropertyString(tRep, "SerialNumber", TheCommonUtils.CStr(tI.CurrentVersion)); TheThing.SetSafePropertyString(tRep, "VendorName", TheCommonUtils.CStr(tI.Developer)); TheThing.SetSafePropertyString(tRep, "ProductName", TheCommonUtils.CStr(tI.ServiceDescription)); TheThing.SetSafePropertyString(tRep, "ProductText", TheCommonUtils.CStr(tI.LongDescription)); TheThing.SetSafePropertyString(tRep, "VendorText", TheCommonUtils.CStr(tI.DeveloperUrl)); TheThing.SetSafePropertyString(tRep, "ProductID", TheCommonUtils.CStr(tI.cdeMID)); } TheThingRegistry.RegisterThing(tRep); MyBaseEngine.ProcessMessage(new TheProcessMessage(new TSM(MyBaseEngine.GetEngineName(), "REFRESH_DASH"))); } else { TheCommCore.PublishToOriginator((para as TheProcessMessage).Message, new TSM(eEngineName.NMIService, "NMI_TTS", tT.cdeMID.ToString())); } }); TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.SmartLabel, pFldOrder + 3, 0, 0, null, pUpdName, new nmiCtrlSingleEnded { ParentFld = pFldOrder, TileWidth = 2 }); TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.BarChart, pFldOrder + 4, 0, 0, null, pUpdName, new nmiCtrlBarChart() { ParentFld = pFldOrder, MaxValue = MaxVal, TileWidth = 4, NoTE = true, Foreground = "blue" }); }
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(); } }
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(); } }
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); }