public bool LogEvent(string ActionText) { TheEventLogData tSec = new TheEventLogData { EventTime = DateTimeOffset.Now, EventLevel = eMsgLevel.l4_Message, StationName = TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false), EventName = TheCommonUtils.GenerateFinalStr(MyBaseThing.FriendlyName, MyBaseThing) }; if (!string.IsNullOrEmpty(tSec.EventName)) { tSec.EventName = tSec.EventName.Replace("%OldValue%", TriggerOldValue); } tSec.EventTrigger = TheThingRegistry.GetThingByMID(TheCommonUtils.CGuid(TriggerObject))?.FriendlyName; tSec.ActionObject = ActionText; var tEng = MyBaseEngine.GetBaseThing().GetObject() as TheRulesEngine; tEng?.LogEvent(tSec); return(true); }
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(); } }
internal static bool ParseSimplex(string pScopedTopic, TSM pMessage, TheQueuedSender pQSender) //, TheSessionState pSessionState, Action<TSM> pLocalCallback) { if (pMessage == null) { return(false); } #if !JC_COMMDEBUG try { #endif if (pMessage?.TXT?.Equals("CDE_DELETEORPHAN") == true) { TheQueuedSenderRegistry.RemoveOrphan(TheCommonUtils.CGuid(pMessage.PLS)); return(false); } if (pQSender == null) { TheBaseAssets.MySYSLOG.WriteToLog(291, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", $"QSender not found! Received from ORG:{TheCommonUtils.GetDeviceIDML(pMessage?.ORG)}", eMsgLevel.l1_Error, pMessage?.PLS)); return(false); } //SECURITY-REVIEW: This cannot be permitted without extra tokens and Encryption! otherwise it can be used to change a nodes scope on the fly! //if ("CDE_UPDATESCOPE".Equals(pMessage.TXT)) //{ // pQSender.UpdateSubscriptionScope(TheBaseAssets.MyScopeManager.GetRealScopeID(pMessage.SID)); //GRSI: rare // return true; //} if (pQSender != null && pMessage.ENG?.StartsWith(eEngineName.ContentService) == true && pMessage?.TXT == "CDE_SERVICE_INFO" && pQSender.MyTargetNodeChannel?.RealScopeID == TheBaseAssets.MyScopeManager.GetRealScopeID(pMessage.SID)) { try { pQSender.SetNodeInfo(TheCommonUtils.DeserializeJSONStringToObject <TheNodeInfoClone>(pMessage?.PLS)); } catch (Exception e) { TheBaseAssets.MySYSLOG.WriteToLog(23056, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"Error decoding SystemInfo {pQSender?.MyTargetNodeChannel?.ToMLString()}", eMsgLevel.l1_Error, e.ToString())); } } if (pMessage.TXT?.Equals("CDE_SUBSCRIBE") == true || pMessage.TXT?.Equals("CDE_INITIALIZE") == true) //9-9-2012 CDEC Did not work right on CDE_INIT { TheBaseAssets.MySYSLOG.WriteToLog(292, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"Parse-Simplex Subscribe from {pQSender?.MyTargetNodeChannel?.ToMLString()} Parsed: {pMessage?.PLS}", eMsgLevel.l7_HostDebugMessage)); if (pQSender?.MyISBlock != null && !TheBaseAssets.MyServiceHostInfo.IsCloudService) { TheBaseAssets.MySYSLOG.WriteToLog(292, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", "Parse-Simplex Subscribe rejected for Custom ISBConnect", eMsgLevel.l7_HostDebugMessage)); return(true); } ParseSubscribe(pMessage.PLS, pQSender); if (pMessage.ENG.Equals("CLOUDSYNC")) { string[] tTopics = pMessage.PLS.Split(';'); foreach (string t in tTopics) { TSM.GetScrambledIDFromTopic(t, out string tEng); if (TheThingRegistry.IsEngineRegistered(tEng)) { IBaseEngine tsBase = TheThingRegistry.GetBaseEngine(tEng); tsBase?.GetBaseThing()?.FireEvent(eEngineEvents.NewSubscription, tsBase.GetBaseThing(), pQSender.MyTargetNodeChannel, true); } } return(true); } else { TheThing tBase2 = TheThingRegistry.GetBaseEngineAsThing(pMessage.ENG); if (tBase2 != null) { tBase2.FireEvent(eEngineEvents.NewSubscription, tBase2, pQSender.MyTargetNodeChannel, true); } } if (pMessage.TXT.Equals("CDE_SUBSCRIBE")) //NEW:2.06 Make sure Subscribe and Unsubscribe only go to first node { return(true); } else { return(false); } } if (pMessage.TXT?.Equals("CDE_UNSUBSCRIBE") == true) { TheBaseAssets.MySYSLOG.WriteToLog(292, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"Parse-Simplex Unsubscribe from {pQSender.MyTargetNodeChannel?.ToMLString()} Parsed: {pMessage.PLS}", eMsgLevel.l7_HostDebugMessage)); ParseUnsubscribe(pMessage.PLS, pQSender); return(true); //NEW:2.06 Make sure Subscribe and Unsubscribe only go to first node } #if !JC_COMMDEBUG } catch (Exception ee) { TheBaseAssets.MySYSLOG.WriteToLog(316, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", "Parse-Simplex", eMsgLevel.l1_Error, ee.ToString())); } #endif return(false); }