Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private NotifyObject GetNotifyObject(AlarmObject alarmObject, string popupMessage, NotifyPopupAddress notifyPopupAddress)
        {
            string alertTime = "", location = "", temperatureReading = "", notificationData = "";
            /*Initialize NotifyObject*/
            NotifyObject notifyObject = new NotifyObject();

            /*Notification settings*/
            NotificationStyle notificationStyle = new NotificationStyle();

            /*Alert Time*/
            alertTime = alarmObject.AlarmTime.ToLocalTime().ToString();
            //Common.LocalTimeToUTC(alarmObject.AlarmTime, Common.TZ_OFFSET).ToStr();
            alertTime = (alertTime == string.Empty ? DateTime.Now.ToStr() : alertTime);

            /*Location*/
            location = alarmObject.ProbeName.ToStr() + (alarmObject.GroupName.ToStr() != string.Empty ? ("(" + alarmObject.GroupName + ")") : "");

            /*HOT COLD*/
            //Check for contact sensor
            if (AlarmHelper.IsContactSensor(alarmObject.SensorType))
            {
                temperatureReading = (alarmObject.Value == 0) ? "CLOSED" : "OPEN";
            }
            else
            {
                temperatureReading = (alarmObject.Value < alarmObject.AlarmMinValue) ? "LOW" : "HIGH";
            }

            /*Building the alert message data*/
            notificationData = "<alert><msg>" + HtmlEncode(popupMessage) + "</msg>" +
                               "<time_local>" + HtmlEncode(alertTime) + "</time_local>"
                               + "<time_gmt>" + HtmlEncode(alarmObject.AlarmTime.ToStr()) + "</time_gmt>"
                               + "<loc>" + HtmlEncode((alarmObject.GroupName.ToStr())) + "</loc>"
                               + "<name>" + HtmlEncode((alarmObject.ProbeName.ToStr())) + "</name>"
                               + "<type>" + HtmlEncode((alarmObject.SensorType.ToStr())) + "</type>"
                               + "<class>" + HtmlEncode((alarmObject.SensorClass.ToStr())) + "</class>"
                               + "<alertType>" + HtmlEncode((temperatureReading)) + "</alertType>"
                               + "</alert>";

            string temp      = "00000000";
            int    strLength = temp.Length - notificationData.Length.ToString().Length;

            notificationData = temp.Substring(0, strLength) + notificationData.Length + notificationData;
            /*Assign values to Notification settings*/
            Hashtable notificationSettings = new Hashtable();

            /*Remote Port*/
            notificationSettings.Add("RemotePort", ConfigurationManager.AppSettings["PortNumber"]);

            /*Remote Host*/
            notificationSettings.Add("RemoteHost", notifyPopupAddress.NetSendTo);

            /*Name that was configured in temp trak application*/
            notificationSettings.Add("Name", notifyPopupAddress.Name);

            /*Notification ID*/
            notificationSettings.Add("NotificationID", alarmObject.NotificationID);

            /*Notification settings*/
            notifyObject.NotifierSettings = notificationSettings;

            /*Pop up message*/
            notifyObject.NotificationData = notificationData;

            /*Set Notification Type*/
            notifyObject.NotificationType = (alarmObject.IsServerPopup) ? "ServerPopup" : "RemotePopup";

            return(notifyObject);
        }
Exemplo n.º 2
0
        public DiscordEmbedNotification GenerateGymMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, GymDetailsData oldGym, string city)
        {
            var alertType  = AlertMessageType.Gyms;
            var alert      = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client.Guilds[guildId], whConfig, city, oldGym);
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = Team == PokemonTeam.Mystic ? DiscordColor.Blue :
                               Team == PokemonTeam.Valor ? DiscordColor.Red :
                               Team == PokemonTeam.Instinct ? DiscordColor.Yellow :
                               DiscordColor.LightGray,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generate a Discord embed Raid message
        /// </summary>
        /// <param name="guildId">Guild the notification is for</param>
        /// <param name="client">Discord client</param>
        /// <param name="whConfig">Webhook config</param>
        /// <param name="alarm">Webhook alarm</param>
        /// <param name="city">City the Raid was found in</param>
        /// <returns>DiscordEmbedNotification object to send</returns>
        public DiscordEmbedNotification GenerateRaidMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            var server       = whConfig.Servers[guildId];
            var alertType    = PokemonId > 0 ? AlertMessageType.Raids : AlertMessageType.Eggs;
            var alert        = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var raidImageUrl = IsEgg ?
                               IconFetcher.Instance.GetRaidEggIcon(server.IconStyle, Convert.ToInt32(Level), false, IsExEligible) :
                               IconFetcher.Instance.GetPokemonIcon(server.IconStyle, PokemonId, Form, Evolution, Gender, Costume, false);
            var properties = GetProperties(client.Guilds[guildId], whConfig, city, raidImageUrl);
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = (IsExEligible ? 0 /*ex*/ : int.Parse(Level)).BuildRaidColor(MasterFile.Instance.DiscordEmbedColors),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text, properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
Exemplo n.º 4
0
 private void OnQuestAlarmTriggered(QuestData quest, AlarmObject alarm, ulong guildId)
 {
     QuestAlarmTriggered?.Invoke(this, new AlarmEventTriggeredEventArgs <QuestData>(quest, alarm, guildId));
 }
Exemplo n.º 5
0
        public DiscordEmbedNotification GenerateWeatherMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            var server          = whConfig.Servers[guildId];
            var alertType       = AlertMessageType.Weather;
            var alert           = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var weatherImageUrl = IconFetcher.Instance.GetWeatherIcon(server.IconStyle, GameplayCondition);
            var properties      = GetProperties(client.Guilds[guildId], whConfig, city, weatherImageUrl);
            var eb = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = GameplayCondition.BuildWeatherColor(),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
Exemplo n.º 6
0
 private void OnPokestopAlarmTriggered(PokestopData pokestop, AlarmObject alarm, ulong guildId)
 {
     PokestopAlarmTriggered?.Invoke(this, new AlarmEventTriggeredEventArgs <PokestopData>(pokestop, alarm, guildId));
 }
Exemplo n.º 7
0
 private void OnPokemonAlarmTriggered(PokemonData pkmn, AlarmObject alarm, ulong guildId)
 {
     PokemonAlarmTriggered?.Invoke(this, new AlarmEventTriggeredEventArgs <PokemonData>(pkmn, alarm, guildId));
 }
Exemplo n.º 8
0
        public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            var server     = whConfig.Servers[guildId];
            var alertType  = HasInvasion ? AlertMessageType.Invasions : HasLure ? AlertMessageType.Lures : AlertMessageType.Pokestops;
            var alert      = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client.Guilds[guildId], whConfig, city);
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = HasInvasion ? DiscordColor.Red : HasLure ?
                               (LureType == PokestopLureType.Normal ? DiscordColor.HotPink
                    : LureType == PokestopLureType.Glacial ? DiscordColor.CornflowerBlue
                    : LureType == PokestopLureType.Mossy ? DiscordColor.SapGreen
                    : LureType == PokestopLureType.Magnetic ? DiscordColor.Gray
                    : DiscordColor.CornflowerBlue) : DiscordColor.CornflowerBlue,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
Exemplo n.º 9
0
        private List <INotifyObject> PreapreMessage(AlarmObject alarmObject, string message, ref List <INotifyObject> notifyList)
        {
            //to store the message board id,if single message board
            int messageBoardID = 0;

            //instantiate notify list object


            //Get the Message board ID using NotifyProfileID
            messageBoardID = GetMessageBoardID(alarmObject.NotifyProfileID, alarmObject.NotificationID);

            //check whether notification has to be sent to single message board, or multiple message boards
            //messageBoardID will be less than 0 if we have multiple message boards
            if (messageBoardID >= 0 && alarmObject.SetServerTime == false)
            {
                //get message board configurations from GenNotifyMsgBoard table using the message board id
                MessageBoardConfigList messageBoardList = new MessageBoardConfigList();
                messageBoardList.Load(new Criteria()
                {
                    ID = messageBoardID
                });

                if (messageBoardList.Count == 0)
                {
                    //if no message board found for the above message board id
                    LogBook.Write("No message board exists with the message board id: " + messageBoardID.ToString());
                }
                else if (messageBoardList.Count == 1)//single message board
                {
                    LogBook.Write("Single message board");
                    //build the notification object with message board settings
                    Hashtable notificationSettings = GetNotificationSettings(messageBoardList[0]);
                    notificationSettings.Add("SensorAlarmID", alarmObject.SensorAlarmID);
                    notificationSettings.Add("IsDynamicNotificationCleared", alarmObject.IsDynamicNotificationCleared);
                    notificationSettings.Add("SensorFactoryID", alarmObject.FactoryID);
                    notificationSettings.Add("NotificationID", alarmObject.NotificationID);
                    notificationSettings.Add("ClearMessage", alarmObject.IsDynamicNotificationCleared);

                    if (alarmObject.IsDynamicNotificationCleared)
                    {
                        if (CurrentClearedBoards.Contains(messageBoardList[0].IpAddress + alarmObject.SensorAlarmID + ","))
                        {
                            return(notifyList);
                        }
                        CurrentClearedBoards += messageBoardList[0].IpAddress + alarmObject.SensorAlarmID + ",";
                    }


                    //create the notification object to be sent to Notification Engine
                    notifyList.Add(new NotifyObject()
                    {
                        NotificationData = message,
                        NotificationType = "MESSAGEBOARD",
                        NotifierSettings = notificationSettings
                    });
                }
            }
            else
            {
                LogBook.Write("Message board group");
                //get message board configurations from GenNotifyMsgBoard table using the message board id
                MessageBoardConfigList messageBoardList = new MessageBoardConfigList();


                /*To reset all message boards at service start*/
                if (alarmObject.SetServerTime)
                {
                    messageBoardList.Load(new Criteria()
                    {
                        ID = null
                    });
                }
                else
                {
                    messageBoardList.Load(new Criteria()
                    {
                        ID = messageBoardID
                    });
                }
                LogBook.Write("Message board count: " + messageBoardList.Count.ToString());
                //create the notification object list to be sent to Notification Engine
                foreach (MessageBoardConfig msgBrdConfig in messageBoardList)
                {
                    NotifyObject notifyObject = new NotifyObject();
                    notifyObject.NotificationData = message;
                    notifyObject.NotificationType = "MESSAGEBOARD";
                    notifyObject.NotifierSettings = GetNotificationSettings(msgBrdConfig);
                    notifyObject.NotifierSettings.Add("SensorAlarmID", alarmObject.SensorAlarmID);
                    notifyObject.NotifierSettings.Add("IsDynamicNotificationCleared", alarmObject.IsDynamicNotificationCleared);
                    notifyObject.NotifierSettings.Add("SensorFactoryID", alarmObject.FactoryID);
                    notifyObject.NotifierSettings.Add("NotificationID", alarmObject.NotificationID);
                    notifyObject.NotifierSettings.Add("SetServerTime", alarmObject.SetServerTime);

                    if (alarmObject.IsDynamicNotificationCleared)
                    {
                        if (CurrentClearedBoards.Contains(msgBrdConfig.IpAddress + alarmObject.SensorAlarmID + ","))
                        {
                            continue;
                        }
                        CurrentClearedBoards += msgBrdConfig.IpAddress + alarmObject.SensorAlarmID + ",";
                    }

                    notifyList.Add(notifyObject);
                }
            }

            return(notifyList);
        }
Exemplo n.º 10
0
        public DiscordEmbed GenerateGymMessage(DiscordClient client, WhConfig whConfig, AlarmObject alarm, GymDetailsData oldGym, string city)
        {
            var alertType  = AlertMessageType.Gyms;
            var alert      = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client, whConfig, city, oldGym);
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = Team == PokemonTeam.Mystic ? DiscordColor.Blue :
                               Team == PokemonTeam.Valor ? DiscordColor.Red :
                               Team == PokemonTeam.Instinct ? DiscordColor.Yellow :
                               DiscordColor.LightGray,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = $"{(client.Guilds.ContainsKey(whConfig.Discord.GuildId) ? client.Guilds[whConfig.Discord.GuildId]?.Name : Strings.Creator)} | {DateTime.Now}",
                    IconUrl = client.Guilds.ContainsKey(whConfig.Discord.GuildId) ? client.Guilds[whConfig.Discord.GuildId]?.IconUrl : string.Empty
                }
            };

            return(eb.Build());
        }
 public AlarmEventTriggeredEventArgs(T data, AlarmObject alarm)
 {
     Data  = data;
     Alarm = alarm;
 }
Exemplo n.º 12
0
        public DiscordEmbedNotification GenerateQuestMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            var alertType  = AlertMessageType.Quests;
            var alert      = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client.Guilds[guildId], whConfig, city, this.GetQuestIcon(whConfig, whConfig.Servers[guildId].IconStyle));
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = DiscordColor.Orange,
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get Popup notification list
        /// </summary>
        /// <param name="notifyEmailAddressList"></param>
        /// <returns></returns>
        private List <INotifyObject> GetNotificationList(NotifyPopupAddressList notificationPopupAddressList, AlarmObject alarmObject, string popupMessage)
        {
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            foreach (NotifyPopupAddress notifyPopupAddress in notificationPopupAddressList)
            {
                /*Check for Notification Popup Address and exit the sending process, if NotificationEmailAddress object is NULL*/
                if (notifyPopupAddress != null)
                {
                    /*Get Notification Object*/
                    INotifyObject notifyObject = GetNotifyObject(alarmObject, popupMessage, notifyPopupAddress);

                    //Add notification object to array list
                    notifyList.Add(notifyObject);
                }
                else
                {
                    /*Record notification if Popup Address parameters are not supplied properly*/
                    notificationStyle.RecordNotification("", alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.POPUP);
                }
            }
            return(notifyList);
        }
Exemplo n.º 14
0
        public INotifyObject[] Compose(AlarmObject alarmObject)
        {
            NotifyPopupAddressList notificationPopupAddressList = null;

            string popupMessage = "";

            /*Notify List*/
            List <INotifyObject> notifyList = new List <INotifyObject>();

            /*Initialize NotifySettings*/
            NotificationStyle notificationStyle = new NotificationStyle();

            if (alarmObject.IsMissCommNotification)
            {
                _logContent = "Missed Communication";
            }
            else
            {
                _logContent = "SensorID: " + alarmObject.UTID.ToStr() + " SensorAlarmID: " + alarmObject.SensorAlarmID.ToStr();
            }

            /*Check whether server popup or remote popup*/
            if (alarmObject.IsServerPopup)
            {
                /*Write Log:
                 * Started Server popup Notification
                 * Reached Server popup Notification Composer*/
                LogBook.Write("*** Started Composing Server popup Notification for " + _logContent + "***");

                /*Get custom message for missed communication*/
                if (alarmObject.IsMissCommNotification)
                {
                    popupMessage = "Missed Communication" + " [" + alarmObject.MissedCommSensorCount + "] sensors";
                }
                else
                {
                    /*Get popup message*/
                    popupMessage = notificationStyle.GetFormatString(alarmObject, 1, "Popup");

                    /*Substitute message parameters*/
                    popupMessage = notificationStyle.SubstituteFormatString(popupMessage, alarmObject);
                }

                /*Server popup*/
                NotifyPopupAddress notifyPopupAddress = new NotifyPopupAddress();
                notifyPopupAddress.NetSendTo = ConfigurationManager.AppSettings.Get("NetSendTo").ToStr();
                notifyPopupAddress.Name      = ConfigurationManager.AppSettings.Get("NetSendFromName").ToStr();

                /*Get Notification Object*/
                INotifyObject notifyObject = GetNotifyObject(alarmObject, popupMessage, notifyPopupAddress);

                if (notifyList.Count > 0)
                {
                    /*Write Log
                     * Sending Server Popup notification data to Notification Engine*/
                    LogBook.Write(_logContent + " Sending notification data to Server Popup  Notification Engine.");
                }

                notifyList.Add(notifyObject);
            }
            else
            {
                /*Write Log:
                 * Started Server popup Notification
                 * Reached Server popup Notification Composer*/
                LogBook.Write("*** Started Composing Remote popup Notification for " + _logContent + "***");

                /*Get custom message for missed communication*/
                if (alarmObject.IsMissCommNotification)
                {
                    popupMessage = "Missed Communication" + " [" + alarmObject.MissedCommSensorCount + "] sensors";
                }
                else
                {
                    /*Get NetSend message*/
                    popupMessage = notificationStyle.GetFormatString(alarmObject, 1, "NetSend");

                    /*Notification Tree*/
                    string notifyTree = notificationStyle.GetFormatString(alarmObject, 1, "NotifyTree");

                    /*Format Subject*/
                    string netSendMsg = notificationStyle.SubstituteFormatString(popupMessage, alarmObject);

                    popupMessage = netSendMsg;

                    /*Format Notify Tree*/
                    string netTreeMsg = notificationStyle.SubstituteFormatString(notifyTree, alarmObject);

                    notifyTree = netTreeMsg;

                    if (notifyTree != string.Empty)
                    {
                        popupMessage = popupMessage + "%%NOTIFYTREE%%" + notifyTree;
                    }
                }

                /*Get Notification Popup Address List*/
                notificationPopupAddressList = GetNotifyPopupAddressList(alarmObject);

                if (notificationPopupAddressList.Count != 0)
                {
                    /*Get Popup Notification list*/
                    notifyList = GetNotificationList(notificationPopupAddressList, alarmObject, popupMessage);
                }
                else
                {
                    /*Log when we don't have Popup address to notify*/
                    LogBook.Write(_logContent + " Error: Missing entry in NotifyEmails/Groups");
                }

                if (notifyList.Count > 0)
                {
                    /*Write Log
                     * Sending Remote Popup notification data to Notification Engine*/
                    LogBook.Write(_logContent + " Sending notification data to Remote Popup  Notification Engine.");
                }
            }
            return(notifyList.ToArray());
        }
        public INotifyObject[] Compose(AlarmObject alarmObject)
        {
            GenStoreInfo         genStoreInfo      = null;
            NotifyMobileList     notifyMobileList  = null;
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            LogBook.Write("Executing Compose method");


            /*Get GenStore Information*/
            genStoreInfo = GenStoreInfo.GetInstance();

            try
            {
                //If there's no record in the database, Execute method will return null
                if (genStoreInfo != null)
                {
                    /*Record notification if SMTP settings are not supplied properly*/
                    //if (genStoreInfo.SmtpServer.ToStr() != string.Empty && genStoreInfo.SmtpSendMethod != 0)
                    //if ((genStoreInfo.ToPhoneNumber == string.Empty && genStoreInfo.SmtpAuthDomain == string.Empty) && genStoreInfo.SmtpSendMethod == 0)
                    //{
                    //    /*SMTP server not defined*/
                    //    LogBook.Write("Error: No SMTP Server has been defined");

                    //    /*Record notification if SMTP parameters are not supplied properly*/
                    //    notificationStyle.RecordNotification(ErrorMessages.SmsComposer_SMTPParmsNotSupplied, _alarmObject.NotificationID, NotifyStatus.FAIL, NotifyTypes.SMS);

                    //}
                    //else
                    //{
                    LogBook.Write("Fetching notify Mobiles List");
                    /*Get all the sms addresses that are configured for notification*/
                    notifyMobileList = GetNotifyMoibilesList(alarmObject.NotifyProfileID);
                    LogBook.Write("Notify Mobile List Count: " + notifyMobileList.Count.ToString());
                    if (notifyMobileList.Count != 0)
                    {
                        LogBook.Write("Constructing notify list objects");
                        /*Construct a notification object for each sms number and add to the notification list*/
                        notifyList = GetNotificationList(notifyMobileList, alarmObject, genStoreInfo);


                        for (int index = notifyList.Count - 1; index >= 0; index--)
                        {
                            INotifyObject notifyObject = notifyList[index];
                            SmsHelper.SmsQueue.Add(notifyObject);
                            notifyList.Remove(notifyObject);
                            new NotificationStyle().RecordNotification("Sms queued: " + notifyObject.NotifierSettings["ToPhoneNumber"].ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.STATUS, NotifyTypes.SMS);
                        }


                        LogBook.Write("Notify list objects count: " + notifyList.Count);
                    }
                    else
                    {
                        /*Log when we don't have sms address to notify*/
                        LogBook.Write("Error: Missing entry in NotifySms/Groups");
                    }
                    //}
                }
                else
                {
                    /*Record notification if genStore parameters are not supplied properly.*/
                    notificationStyle.RecordNotification(ErrorMessages.SMSComposer_InvalidSettings, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.SMS);

                    /*Log if genStore information is empty*/
                    LogBook.Write("Error:  Missing GenStores table record");
                }
            }
            catch (Exception ex)
            {
                /*Write exception log*/
                LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.SmsNotificationComposer");
            }

            /*Send notification list to notification engine*/
            return(notifyList.ToArray());
        }
Exemplo n.º 16
0
        public INotifyObject[] Compose(AlarmObject alarmObject)
        {
            List <INotifyObject> notifyList = null;

            try
            {
                notifyList = new List <INotifyObject>();
                LogBook.Write("Executing compose method");

                //if the dynamic notification is already cleared , no need to send to Notify objects list to notify engine
                if (alarmObject.IsDynamicNotificationClearProcessStarted == true)
                {
                    return(new List <INotifyObject>().ToArray());
                }
                //if IsDynamicNotificationCleared is true we need to set the below flag in order skip notifications
                //received from any escalations while the clear process is going on
                if (alarmObject.IsDynamicNotificationCleared)
                {
                    alarmObject.IsDynamicNotificationClearProcessStarted = true;
                }

                //to store the message
                string message = string.Empty;



                LogBook.Write("Formatting the message");
                //create instance of notification style to generate format strings, parse it
                NotificationStyle notificationStyle = new NotificationStyle();

                //get the message from the alarm object
                message = alarmObject.Value == null ? string.Empty : alarmObject.Value.ToString();

                //if message length is greater than zero, get the format string for the message
                if (message.Length > 0)
                {
                    message = notificationStyle.GetFormatString(alarmObject, 1, "MessageBoard");
                }

                //replace line breaks with spaces
                message = message.Replace("\\n", " ");

                //substitute actual values for the format strings using the alarm object
                message = notificationStyle.SubstituteFormatString(message, alarmObject);

                LogBook.Write("Completed message formatting");

                //to format the message for missed communications
                if (alarmObject.IsMissCommNotification == true)
                {
                    LogBook.Write("Constructing missed comm message");
                    message = "Missed Communication" + " [" + alarmObject.MissedCommSensorCount + "] sensors";
                }

                if (alarmObject.IsDynamicNotificationCleared)
                {
                    var prvNotificationList = from info in PreviousNotificationsList
                                              where info.SensorAlarmID == alarmObject.SensorAlarmID
                                              select info;
                    CurrentClearedBoards = string.Empty;
                    for (int index = prvNotificationList.Count() - 1; index >= 0; index--)
                    {
                        PreviousNotifications info = prvNotificationList.ToList <PreviousNotifications>()[index];
                        alarmObject.NotificationID  = info.NotificationID;
                        alarmObject.NotifyProfileID = info.NotifyProfileID;

                        PreapreMessage(alarmObject, message, ref notifyList);
                        PreviousNotificationsList.Remove(info);
                    }
                }
                else
                {
                    if (!alarmObject.SetServerTime)
                    {
                        AddNotificationToList(alarmObject);
                    }
                    PreapreMessage(alarmObject, message, ref notifyList);
                }
            }
            catch (Exception ex)
            {
                LogBook.Write(ex, " CooperAtkins.NotificationClient.NotificationComposer.MsgBrdNotificationComposer");
            }

            return(notifyList.ToArray());
        }
Exemplo n.º 17
0
 private void OnGymDetailsAlarmTriggered(GymDetailsData gymDetails, AlarmObject alarm, ulong guildId)
 {
     GymDetailsAlarmTriggered?.Invoke(this, new AlarmEventTriggeredEventArgs <GymDetailsData>(gymDetails, alarm, guildId));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Get Email notification list
        /// </summary>
        /// <param name="notifyEmailAddressList"></param>
        /// <returns></returns>
        private List <INotifyObject> GetNotificationList(NotifyEmailAddressList notifyEmailAddressList, AlarmObject alarmObject, GenStoreInfo genStoreInfo)
        {
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            foreach (NotifyEmailAddress notifyEmailAddress in notifyEmailAddressList)
            {
                /*Check for Notification Email Address and exit the sending process, if NotificationEmailAddress object is NULL*/
                if (notifyEmailAddress != null)
                {
                    /*Get Notification Object*/
                    INotifyObject notifyObject = GetNotifyObject(alarmObject, genStoreInfo, notifyEmailAddress);

                    if (notifyObject.NotifierSettings["FromAddress"].ToStr() == string.Empty || notifyObject.NotifierSettings["ToAddress"].ToStr() == string.Empty)
                    {
                        /*Record notification if Email (To/From) Address parameters are not supplied properly*/
                        notificationStyle.RecordNotification(ErrorMessages.EmailComposer_InvalidEmailAddress, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL);
                    }
                    else
                    {
                        //Add notification object to array list
                        notifyList.Add(notifyObject);
                    }
                }
                else
                {
                    /*Record notification if Email Address parameters are not supplied properly*/
                    notificationStyle.RecordNotification(ErrorMessages.EmailComposer_EmailParamsNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL);
                }
            }
            return(notifyList);
        }
Exemplo n.º 19
0
 private void OnWeatherAlarmTriggered(WeatherData weather, AlarmObject alarm, ulong guildId)
 {
     WeatherAlarmTriggered?.Invoke(this, new AlarmEventTriggeredEventArgs <WeatherData>(weather, alarm, guildId));
 }
Exemplo n.º 20
0
        public INotifyObject[] Compose(AlarmObject alarmObject)
        {
            GenStoreInfo           genStoreInfo           = null;
            NotifyEmailAddressList notifyEmailAddressList = null;
            List <INotifyObject>   notifyList             = new List <INotifyObject>();
            NotificationStyle      notificationStyle      = new NotificationStyle();


            /*Get GenStore Information*/
            genStoreInfo = GenStoreInfo.GetInstance();


            if (alarmObject.IsMissCommNotification)
            {
                _logContent = "Missed Communication";
            }
            else
            {
                _logContent = "SensorID: " + alarmObject.UTID.ToStr() + " SensorAlarmID: " + alarmObject.SensorAlarmID.ToStr();
            }

            /*Write Log:
             * Started Email Notification
             * Reached Email Notification Composer*/
            LogBook.Write("*** Started Composing E-Mail Notification for " + _logContent + "***");

            try
            {
                //If there's no record in the database, Execute method will return null
                if (genStoreInfo != null)
                {
                    /*Record notification if SMTP settings are not supplied properly*/
                    if ((genStoreInfo.SmtpServer.ToStr() == string.Empty && genStoreInfo.SmtpAuthDomain == string.Empty) && genStoreInfo.SmtpSendMethod == 0)
                    {
                        /*SMTP server not defined*/
                        LogBook.Write(_logContent + " Error: No SMTP Server has been defined.");

                        /*Record notification if SMTP parameters are not supplied properly*/
                        notificationStyle.RecordNotification(ErrorMessages.EmailComposer_SMTPParmsNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL);
                    }
                    else
                    {
                        /*Get all the email addresses that are configured for notification*/
                        notifyEmailAddressList = GetNotifyEmailAddressList(alarmObject);

                        if (notifyEmailAddressList.Count != 0)
                        {
                            /*Construct a notification object for each email address and add to the notification list*/
                            notifyList = GetNotificationList(notifyEmailAddressList, alarmObject, genStoreInfo);
                            LogBook.Write("Email Notification count: " + notifyList.Count.ToString());
                        }
                        else
                        {
                            /*Log when we don't have Email address to notify*/
                            LogBook.Write(_logContent + " Error: Missing entry in NotifyEmails/Groups.");
                        }
                    }
                }
                else
                {
                    /*Record notification if genStore parameters are not supplied properly.*/
                    notificationStyle.RecordNotification(ErrorMessages.EmailComposer_GenStoreInvalid, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL);

                    /*Log if genStore information is empty*/
                    LogBook.Write(_logContent + " Error:  Missing GenStores table record.");
                }
            }
            catch (Exception ex)
            {
                /*Write exception log*/
                //LogBook.Write(_logContent + " " + ex);
                LogBook.Write(_logContent + " Error: ", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer");
                //, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer");
            }

            //if (notifyList.Count > 0)

            /*Write Log
             * Sending Email notification data to Notification Engine*/
            LogBook.Write(_logContent + " Sending notification data to Email  Notification Engine.");

            /*Send notification list to notification engine*/
            return(notifyList.ToArray());
        }
Exemplo n.º 21
0
 private void OnRaidAlarmTriggered(RaidData raid, AlarmObject alarm, ulong guildId)
 {
     RaidAlarmTriggered?.Invoke(this, new AlarmEventTriggeredEventArgs <RaidData>(raid, alarm, guildId));
 }
Exemplo n.º 22
0
        //public bool IsUnderLevel(int targetLevel)
        //{
        //    return int.TryParse(Level, out var level) && level < targetLevel;
        //}

        //public bool IsAboveLevel(int targetLevel)
        //{
        //    return int.TryParse(Level, out var level) && level >= targetLevel;
        //}

        public async Task <DiscordEmbed> GeneratePokemonMessage(DiscordClient client, WhConfig whConfig, PokemonData pkmn, AlarmObject alarm, string city, string pokemonImageUrl)
        {
            //If IV has value then use alarmText if not null otherwise use default. If no stats use default missing stats alarmText
            var alertMessageType = pkmn.IsMissingStats ? AlertMessageType.PokemonMissingStats : AlertMessageType.Pokemon;
            var alertMessage     = alarm?.Alerts[alertMessageType] ?? AlertMessage.Defaults[alertMessageType];
            var properties       = await GetProperties(client, whConfig, city);

            var eb = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alertMessage.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alertMessage.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alertMessage.ImageUrl, properties),
                ThumbnailUrl = pokemonImageUrl,
                Description  = DynamicReplacementEngine.ReplaceText(alertMessage.Content, properties),
                Color        = pkmn.IV.BuildColor(),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = $"{(client.Guilds.ContainsKey(whConfig.Discord.GuildId) ? client.Guilds[whConfig.Discord.GuildId]?.Name : Strings.Creator)} | {DateTime.Now}",
                    IconUrl = client.Guilds.ContainsKey(whConfig.Discord.GuildId) ? client.Guilds[whConfig.Discord.GuildId]?.IconUrl : string.Empty
                }
            };

            return(await Task.FromResult(eb.Build()));
        }
Exemplo n.º 23
0
        public DiscordEmbed GenerateRaidMessage(DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city, string raidImageUrl)
        {
            var alertType  = PokemonId > 0 ? AlertMessageType.Raids : AlertMessageType.Eggs;
            var alert      = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client, whConfig, city);
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = raidImageUrl,//DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = Level.BuildRaidColor(),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = $"{(client.Guilds.ContainsKey(whConfig.Discord.GuildId) ? client.Guilds[whConfig.Discord.GuildId]?.Name : Strings.Creator)} | {DateTime.Now}",
                    IconUrl = client.Guilds.ContainsKey(whConfig.Discord.GuildId) ? client.Guilds[whConfig.Discord.GuildId]?.IconUrl : string.Empty
                }
            };

            return(eb.Build());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Generate a Discord embed Pokemon message
        /// </summary>
        /// <param name="guildId">Guild the notification is for</param>
        /// <param name="client">Discord client</param>
        /// <param name="whConfig">Webhook config</param>
        /// <param name="alarm">Webhook alarm</param>
        /// <param name="city">City the Pokemon was found in</param>
        /// <returns>DiscordEmbedNotification object to send</returns>
        public async Task <DiscordEmbedNotification> GeneratePokemonMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            // If IV has value then use alarmText if not null otherwise use default. If no stats use default missing stats alarmText
            var alertType       = IsMissingStats ? AlertMessageType.PokemonMissingStats : AlertMessageType.Pokemon;
            var alert           = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType];
            var server          = whConfig.Servers[guildId];
            var pokemonImageUrl = Id.GetPokemonIcon(FormId, Costume, whConfig, server.IconStyle);
            var properties      = await GetProperties(client.Guilds[guildId], whConfig, city, pokemonImageUrl);

            var eb = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = IV.BuildColor(),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            })));
        }
Exemplo n.º 25
0
 /// <summary>
 /// Mark the notification process alarm object as completed.
 /// </summary>
 /// <param name="alarmObject"></param>
 public static void MarkAsCompleted(AlarmObject alarmObject, string msg)
 {
     LogBook.Write(AlarmHelper.BasicAlarmInformation(alarmObject) + "," + msg + " marking alarm to complete process, object will be removed from current alarm process queue.");
     alarmObject.IsProcessCompleted = true;
 }
        /// <summary>
        /// Returns true if the current operation succeeded.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="settings"></param>
        /// <param name="notificationID"></param>
        /// <returns></returns>
        ///



        public static bool Send(string data, Hashtable settings, int notificationID, int ivrID, int alarmID, AlarmObject alarmObject)
        {
            bool   retValue      = false;
            bool   callConnected = false;
            string response      = string.Empty;
            string succeeded     = string.Empty;
            string error         = string.Empty;
            Int16  dailAttempts  = 1;
            string DigitsPressed = string.Empty;

            long QueueID = -1;

            int    TryCount                 = -1;
            bool   CallAnswered             = false;
            bool   Answered                 = false;
            bool   CallComplete             = false;
            string MachineDetection         = string.Empty;
            int    Duration                 = -1;
            string IVRServiceResponseText   = string.Empty;
            int    TTIVRNotifications_RecID = -1;


            NotifyObject      notifyObject      = new NotifyObject();
            NotifyComResponse notifyResponse    = new NotifyComResponse();
            NotifyComResponse notifyComResponse = new NotifyComResponse();

            notifyObject.NotificationType = "Voice";
            notifyObject.NotificationData = data;     //voice message to be played
            notifyObject.NotifierSettings = settings; //hash table of keys and values


            NotificationEndPointElement element;
            string vcElement1;
            string vcElement2;
            string vcElement3;
            string vcElement4;

            /* get end point for voice composer*/


            string method = NotificationClient.GetInstance().WhoAmI("Voice", out element);

            string arguments = null;

            LogBook.Write("Sending voice alert....");
            switch (method.ToLower())
            {
            case "cooperatkins.notificationclient.notifyengine.ivrnotificationcom":


                System.Diagnostics.Process process = new System.Diagnostics.Process();
                if (element == null)
                {
                    arguments = @"-m ""<notification ack='true'><notificationData><![CDATA[" + data + @"]]></notificationData><notificationType><![CDATA[Voice]]></notificationType><notificationSettings><PhoneNo><![CDATA[" + settings["PhoneNo"].ToStr() + @"]]></PhoneNo></notificationSettings></notification>"" ";
                }
                else
                {
                    arguments = @"-c " + element.EndpointAddress + @" -m ""<notification ack='true'><notificationData><![CDATA[" + data + @"]]></notificationData><notificationType><![CDATA[Voice]]></notificationType><notificationSettings><PhoneNo><![CDATA[" + settings["PhoneNo"].ToStr() + @"]]></PhoneNo></notificationSettings></notification>"" ";
                }

                while (!callConnected)
                {
                    IvrAlarmStatus ivrAlarmStatus = new IvrAlarmStatus();
                    try
                    {
                        LogBook.Write("Checking whether alarm is cleared or not");
                        ivrAlarmStatus.AlarmID        = alarmID;
                        ivrAlarmStatus.NotificationID = notificationID;
                        ivrAlarmStatus.StoreID        = GenStoreInfo.GetInstance().StoreID;
                        ivrAlarmStatus.Execute();
                    }
                    catch (Exception ex)
                    {
                        LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.IvrClientHelper", ErrorSeverity.High);
                    }
                    finally
                    {
                        ivrAlarmStatus.Dispose();
                    }

                    if (ivrAlarmStatus.IsAlarmClearedOrBackInRange)
                    {
                        break;
                    }

                    /*       analog modem use  */

                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    //process.StartInfo.RedirectStandardError = true;
                    process.StartInfo.CreateNoWindow = true;
                    process.StartInfo.FileName       = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Utility.exe";
                    //process.StartInfo.FileName = @"F:\DEV\CooperAtkins\CooperAtkins.NotificationEngine.Utility\bin\Debug\Utility.exe";
                    process.StartInfo.Arguments = arguments;
                    // process.StartInfo.WorkingDirectory = ;
                    process.Start();

                    process.WaitForExit();


                    response = process.StandardOutput.ReadToEnd();

                    callConnected = true;
                    if (response.ToLower().Contains("device initialization failed") || response.ToLower().Contains("invalid_device_id") || response.ToLower().Contains("dll_not_found") || response.ToLower().Contains("exception from hresult"))
                    {
                        callConnected = false;
                    }
                    /*     end  analog modem use  */
                }
                break;


            case "cooperatkins.notificationclient.notificationcomposer.cdyneivrnotificationcomposer":
                long     TransactionID = -1;
                DateTime StartTime;
                DateTime EndTime;
                long     AlarmID = -1;


                string CDYNE_ID      = GenStoreInfo.GetInstance().CDYNE_ACCOUNT;//NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneID", out vcElement1);
                string CDYNE_RETRIES = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneRetries", out vcElement2);
                string CDYNE_VOICEID = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneVoiceID", out vcElement3);
                string CDYNE_VOLUME  = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneVolume", out vcElement4);

                notifyObject.NotifierSettings["CDYNE_ID"]      = CDYNE_ID;
                notifyObject.NotifierSettings["CDYNE_RETRIES"] = CDYNE_RETRIES;
                notifyObject.NotifierSettings["CDYNE_VOICEID"] = CDYNE_VOICEID;
                notifyObject.NotifierSettings["CDYNE_VOLUME"]  = CDYNE_VOLUME;
                NotificationStyle  notificationStyle        = new NotificationStyle();
                TTIvrNotifications tTIvrNotificationsObject = new TTIvrNotifications();
                callConnected = false;

                while (!callConnected)
                {
                    notifyComResponse.IsInProcess = true;
                    int QueryCall = 0;
                    int UnivError = 0;

                    //if (!alarmObject.IsFailsafeEscalationNotification)
                    //{
                    //IvrAlarmStatus ivrAlarmStatus = new IvrAlarmStatus();
                    //try
                    //{
                    //    LogBook.Write("Checking whether alarm is cleared or not");
                    //    ivrAlarmStatus.AlarmID = alarmID;
                    //    ivrAlarmStatus.NotificationID = notificationID;
                    //    ivrAlarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID;
                    //    ivrAlarmStatus.Execute();
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.CDYNEIvrClientHelper", ErrorSeverity.High);
                    //}
                    //finally
                    //{
                    //    ivrAlarmStatus.Dispose();
                    //}

                    //12/9/15 comment start
                    //AlarmStatus alarmStatus = new AlarmStatus();
                    //try
                    //{
                    //    LogBook.Write("IVR Checking whether alarm [" + alarmObject.NotificationID + "] is cleared or not");
                    //    alarmStatus.NotificationID = alarmObject.NotificationID;
                    //    alarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID;
                    //    alarmStatus.Execute();
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogBook.Write(ex, "CooperAtkins.NotificationClient.Alarm.AlarmInitializer", ErrorSeverity.High);
                    //}
                    //finally
                    //{
                    //    alarmStatus.Dispose();
                    //12/9/15 comment end }

                    int threadID = notifyObject.NotifierSettings["ThreadID"].ToInt();

                    //12/9/15 comment start
                    //if (alarmStatus.IsAlarmClearedOrBackInRange)
                    //{
                    //    Answered = false;
                    //    callConnected = false;
                    //    notifyComResponse.IsSucceeded = false;
                    //    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " SUSPENDED (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                    //    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nALARM WAS CLEARED OR BACK IN RANGE";

                    //    LogBook.Write("CALL SUSPENDED To " + notifyObject.NotifierSettings["PhoneNo"] + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "] ALARM WAS CLEARED OR SENSOR IS BACK IN RANGE");

                    //    notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.FAIL, NotifyTypes.VOICE);
                    //    UpdateIVRNotification(ivrID, false, false, dailAttempts, TransactionID, threadID);

                    //    break;

                    //12/9/15 comment end }


                    int totalCallAttempts = notifyObject.NotifierSettings["Attempts"].ToInt();

                    if ((totalCallAttempts + dailAttempts) > (CDYNE_RETRIES.ToInt() + 1))
                    //also if a notficicationId is in an alert progress state from another thread,
                    //fall into this code to break out OR if cleared or inprogress check to be sure
                    //we made contatc through our maximum attempts value
                    {
                        notifyComResponse.IsInProcess = false;
                        UpdateIVRNotification(ivrID, false, notifyComResponse.IsInProcess, dailAttempts, TransactionID, threadID);
                        break;
                    }
                    //}


                    UpdateIVRNotification(ivrID, false, true, (totalCallAttempts + dailAttempts), TransactionID, threadID);

                    try{
                        IVRProcessor maketheIVRCall = new IVRProcessor();
                        notifyResponse = maketheIVRCall.Invoke(notifyObject);
                        //  notifyComResponse = new NotifyComResponse();
                        TransactionID = notifyResponse.TransactionIDReturned;
                        //query for call result

                        Answered = false;
                        PhoneNotify pn2 = new PhoneNotify();
                        while (!Answered)
                        {
                            if (QueryCall == 0)        //on first call, wait 1 minute for call to complete before getting call results
                            {
                                System.Threading.Thread.Sleep(1 * 60 * 1000);
                            }
                            else
                            {
                                System.Threading.Thread.Sleep(5 * 1000);
                            }
                            NotifyReturn nr2 = pn2.GetQueueIDStatus(TransactionID);
                            MachineDetection       = nr2.MachineDetection;
                            DigitsPressed          = nr2.DigitsPressed;
                            CallAnswered           = nr2.CallAnswered;
                            CallComplete           = nr2.CallComplete;
                            IVRServiceResponseText = nr2.ResponseText;
                            Duration  = nr2.Duration;
                            StartTime = nr2.StartTime;
                            EndTime   = nr2.EndTime;
                            if (CallAnswered == true && DigitsPressed.Contains("*"))
                            {
                                Answered      = true;
                                callConnected = true;
                                notifyComResponse.IsSucceeded = true;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nAcknowledgement received, " + "'" + DigitsPressed + "' pressed.";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nCall Complete >";

                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered and Digits: " + DigitsPressed + " were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                break;
                            }
                            else if (CallAnswered == true && !DigitsPressed.Contains("*") && MachineDetection == "HUMAN" && CallComplete)
                            {
                                Answered = true;
                                notifyComResponse.IsSucceeded = false;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nNo Acknowledgement received, Digits Pressed: " + DigitsPressed + ">";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered but no digits were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                break;
                            }
                            else if (CallAnswered == true && DigitsPressed == "" && MachineDetection == "HUMAN" && !CallComplete)
                            {
                                notifyComResponse.IsSucceeded = false;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nNo Acknowledgement received >";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered but no digits were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                QueryCall += 1;
                            }
                            else if (CallAnswered == true && DigitsPressed == "" && MachineDetection == "MACHINE")
                            {
                                Answered = false;
                                notifyComResponse.IsSucceeded = false;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] +"["+ notifyObject.NotifierSettings["CallerName"]+"]"+ " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nAnswering Machine Detected >";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered by MACHINE: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                break;
                            }
                            else if (IVRServiceResponseText == "In Call/Ringing" || IVRServiceResponseText == "Queued" || IVRServiceResponseText == "Universal Error")
                            {
                                notifyComResponse.IsSucceeded = false;
                                notifyComResponse.IsError     = true;
                                //if (notifyComResponse.ResponseContent != null)
                                //{
                                //    if ((!notifyComResponse.ResponseContent.ToString().Contains("Call/Ringing (Attempt # " + dailAttempts)) &&
                                //        (!notifyComResponse.ResponseContent.ToString().Contains("Queued (Attempt # " + dailAttempts)) &&
                                //        (!notifyComResponse.ResponseContent.ToString().Contains("Universal Error  (Attempt # " + dailAttempts)))  //only add line if it has not already been logged for this dial attempt
                                //    {
                                //        notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "] " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                //    }
                                //}
                                //else
                                //{
                                //    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "] " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                //}
                                //    notifyComResponse.ResponseContent = "";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Current Status: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                if (IVRServiceResponseText == "Universal Error")
                                {
                                    UnivError += 1;        //if it continues to return Universl Error allow a way to get out
                                }
                                QueryCall += 1;
                            }
                            else
                            {
                                notifyComResponse.IsSucceeded = false;
                                if (notifyComResponse.ResponseContent != null)
                                {
                                    if (!notifyComResponse.ResponseContent.ToString().Contains("ERROR"))         //only add line if it has not already been logged
                                    {
                                        //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                        notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " >";
                                    }
                                }
                                else
                                {
                                    //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " >";
                                }
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Current Status: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                QueryCall += 1;
                            }
                            if (QueryCall > 2 || Answered || (UnivError > 10))
                            {
                                break;
                            }
                        }
                    }catch (Exception ex)
                    {
                        LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.CDYNEIvrClientHelper MAkeTheCall", ErrorSeverity.High);
                    }


                    if (!callConnected || !Answered)
                    {
                        //write to TTNotificationLog

                        if (notifyComResponse.ResponseContent != null)
                        {
                            if (notifyComResponse.ResponseContent.ToString() != "")
                            {
                                notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.FAIL, NotifyTypes.VOICE);
                            }
                        }
                        notifyComResponse.ResponseContent = "";

                        //write to TTIVRNotifications
                        UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID);
                        // System.Threading.Thread.Sleep(30 * 1000); //wait and try that number 1 more time before trying next person
                        dailAttempts += 1;
                        retValue      = false;
                        if (((totalCallAttempts + dailAttempts.ToInt())) > CDYNE_RETRIES.ToInt16() + 1)
                        {        //try each person X times from config
                            LogBook.Write("Exhausted  " + (CDYNE_RETRIES.ToInt()) + " Re-Try Attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                            notifyComResponse.IsInProcess = false;

                            if (UnivError >= 10)         //reset call counter, so it will re-attempt to call person has CDyne never truly made a call
                            {                            //4th param in below function
                                UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, 0, TransactionID, threadID);
                            }
                            else
                            {
                                UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID);
                            }
                            retValue = false;
                            alarmObject.IVRSuccess = false;
                            break;
                        }
                        else
                        {
                            LogBook.Write("Trying Retry Call Attempt " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " Attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID);
                        }
                    }
                    else
                    {
                        LogBook.Write("Call Complete.  Alert Success during call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                        notifyComResponse.IsInProcess = false;
                        notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.PASS, NotifyTypes.VOICE);
                        notifyComResponse.ResponseContent = "";
                        UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID);
                        retValue = true;
                        alarmObject.IVRSuccess = true;
                    }
                }
                break;         //end call attempts

            default:
                break;
            }

            if (method.ToLower() == "cooperatkins.notificationserver.notifyengine.ivrnotificationcom")
            {
                NotificationStyle notificationStyle = new NotificationStyle();

                foreach (string responseLine in response.Split(new string[] { "\n" }, StringSplitOptions.None))
                {
                    if (responseLine.ToLower().Contains("succeeded"))
                    {
                        succeeded = responseLine.ToLower().Replace("succeeded :", string.Empty);
                    }
                    else if (responseLine.ToLower().Contains("error"))
                    {
                        error = responseLine.ToLower().Replace("error :", string.Empty);
                    }
                }


                LogBook.Write("ResponseContent:" + response + ", IsSucceeded:" + succeeded + ", IsError:" + error);


                /* record the notification information to the database. */
                if (succeeded == "no")
                {
                    notificationStyle.RecordNotification(response.Remove(0, 60).Replace("\n", "\r\n"), notificationID, 0, NotifyStatus.FAIL, NotifyTypes.VOICE);
                }
                else
                {
                    notificationStyle.RecordNotification(response.Remove(0, 60).Replace("\n", "\r\n"), notificationID, 0, NotifyStatus.PASS, NotifyTypes.VOICE);
                }


                retValue = succeeded == "yes";
            }

            return(retValue);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Generate a Discord embed Pokemon message
        /// </summary>
        /// <param name="guildId">Guild the notification is for</param>
        /// <param name="client">Discord client</param>
        /// <param name="whConfig">Webhook config</param>
        /// <param name="alarm">Webhook alarm</param>
        /// <param name="city">City the Pokemon was found in</param>
        /// <returns>DiscordEmbedNotification object to send</returns>
        public DiscordEmbedNotification GeneratePokemonMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            // If IV has value then use alarmText if not null otherwise use default. If no stats use default missing stats alarmText
            var server          = whConfig.Servers[guildId];
            var alertType       = IsMissingStats ? AlertMessageType.PokemonMissingStats : AlertMessageType.Pokemon;
            var alert           = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var pokemonImageUrl = IconFetcher.Instance.GetPokemonIcon(server.IconStyle, Id, FormId, 0, Gender, Costume, false);
            var properties      = GetProperties(new MessageProperties
            {
                Guild    = client.Guilds[guildId],
                Config   = whConfig,
                City     = city,
                ImageUrl = pokemonImageUrl,
            });
            var eb = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = MatchesGreatLeague || MatchesUltraLeague
                    ? GetPvPColor(GreatLeague, UltraLeague, server)
                    : IV.BuildPokemonIVColor(server),
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text, properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
        /// <summary>
        /// Get Sms notification list
        /// </summary>
        /// <param name="notifySmsAddressList"></param>
        /// <returns></returns>
        private List <INotifyObject> GetNotificationList(NotifyMobileList notifyMobileList, AlarmObject alarmObject, GenStoreInfo genStoreInfo)
        {
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            foreach (NotifyMobiles notifyMobiles in notifyMobileList)
            {
                /*Check for Notification Sms Address and exit the sending process, if NotificationSmsAddress object is NULL*/
                if (notifyMobiles != null)
                {
                    /*Get Notification Object*/
                    INotifyObject notifyObject = GetNotifyObject(alarmObject, genStoreInfo, notifyMobiles);

                    if (notifyObject.NotifierSettings["ToPhoneNumber"].ToStr() == string.Empty || notifyObject.NotifierSettings["COMSettings"].ToStr() == string.Empty)
                    {
                        LogBook.Write("Missing mobile number or COM Settings");
                        /*Record notification if Sms parameters are not supplied properly*/
                        notificationStyle.RecordNotification(ErrorMessages.SMSComposer_InvalidSettings, notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.FAIL, NotifyTypes.SMS);
                    }
                    else
                    {
                        //Add notification object to array list
                        notifyList.Add(notifyObject);
                    }
                }
                else
                {
                    /*Record notification if Sms parameters are not supplied properly*/
                    notificationStyle.RecordNotification(ErrorMessages.SMSComposer_InvalidSettings, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.SMS);
                }
            }
            return(notifyList);
        }
Exemplo n.º 29
0
        public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city, bool useLure, bool useInvasion)
        {
            var server     = whConfig.Servers[guildId];
            var alertType  = useInvasion ? AlertMessageType.Invasions : useLure ? AlertMessageType.Lures : AlertMessageType.Pokestops;
            var alert      = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client.Guilds[guildId], whConfig, city, useLure, useInvasion);
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = useInvasion
                    ? new DiscordColor(MasterFile.Instance.DiscordEmbedColors.Pokestops.Invasions)
                    : useLure
                        ? LureType.BuildLureColor(MasterFile.Instance.DiscordEmbedColors)
                        : DiscordColor.CornflowerBlue,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text, properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Generates a Discord embed message for a Pokestop Quest
        /// </summary>
        /// <param name="guildId">Discord Guild ID related to the data</param>
        /// <param name="client">Discord client to use</param>
        /// <param name="whConfig">Config to use</param>
        /// <param name="alarm">Alarm to use</param>
        /// <param name="city">City to specify</param>
        /// <returns></returns>
        public DiscordEmbedNotification GenerateQuestMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            var server     = whConfig.Servers[guildId];
            var alertType  = AlertMessageType.Quests;
            var alert      = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var properties = GetProperties(client.Guilds[guildId], whConfig, city, IconFetcher.Instance.GetQuestIcon(whConfig.Servers[guildId].IconStyle, this));
            var eb         = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = new DiscordColor(MasterFile.Instance.DiscordEmbedColors.Pokestops.Quests),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text, properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            }));
        }