Esempio n. 1
0
        private Response SavePushoverNotifications()
        {
            var settings = this.Bind <PushoverNotificationSettings>();
            var valid    = this.Validate(settings);

            if (!valid.IsValid)
            {
                return(Response.AsJson(valid.SendJsonError()));
            }
            Log.Trace(settings.DumpJson());

            var result = PushoverService.SaveSettings(settings);

            if (settings.Enabled)
            {
                NotificationService.Subscribe(new PushoverNotification(PushoverApi, PushoverService));
            }
            else
            {
                NotificationService.UnSubscribe(new PushoverNotification(PushoverApi, PushoverService));
            }

            Log.Info("Saved email settings, result: {0}", result);
            return(Response.AsJson(result
                ? new JsonResponseModel {
                Result = true, Message = "Successfully Updated the Settings for Pushover Notifications!"
            }
                : new JsonResponseModel {
                Result = false, Message = "Could not update the settings, take a look at the logs."
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// Send button click processing
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                var pushoverService = new PushoverService(AppToken);
                pushoverService.SendMessage(UserKey, Message);
            }
            catch
            {
                ViewData["Result"] = $"The operation failed.";
                return(this.Page());
            }

            ViewData["Result"] = "The message was successfully sent!";

            return(this.Page());
        }
Esempio n. 3
0
        private async Task <Response> TestPushoverNotifications()
        {
            var settings = this.Bind <PushoverNotificationSettings>();
            var valid    = this.Validate(settings);

            if (!valid.IsValid)
            {
                return(Response.AsJson(valid.SendJsonError()));
            }
            var notificationModel = new NotificationModel
            {
                NotificationType = NotificationType.Test,
                DateTime         = DateTime.Now
            };
            var currentSettings = await PushoverService.GetSettingsAsync();

            try
            {
                NotificationService.Subscribe(new PushoverNotification(PushoverApi, PushoverService));
                settings.Enabled = true;
                await NotificationService.Publish(notificationModel, settings);

                Log.Info("Sent pushover notification test");
            }
            catch (Exception)
            {
                Log.Error("Failed to subscribe and publish test Pushover Notification");
            }
            finally
            {
                if (!currentSettings.Enabled)
                {
                    NotificationService.UnSubscribe(new PushoverNotification(PushoverApi, PushoverService));
                }
            }
            return(Response.AsJson(new JsonResponseModel {
                Result = true, Message = "Successfully sent a test Pushover Notification!"
            }));
        }
Esempio n. 4
0
        private Negotiator PushoverNotifications()
        {
            var settings = PushoverService.GetSettings();

            return(View["PushoverNotifications", settings]);
        }