コード例 #1
0
        private Response SaveSlackNotifications()
        {
            var settings = this.BindAndValidate <SlackNotificationSettings>();

            if (!ModelValidationResult.IsValid)
            {
                return(Response.AsJson(ModelValidationResult.SendJsonError()));
            }

            var result = SlackSettings.SaveSettings(settings);

            if (settings.Enabled)
            {
                NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings));
            }
            else
            {
                NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings));
            }

            Log.Info("Saved slack settings, result: {0}", result);
            return(Response.AsJson(result
                ? new JsonResponseModel {
                Result = true, Message = "Successfully Updated the Settings for Slack Notifications!"
            }
                : new JsonResponseModel {
                Result = false, Message = "Could not update the settings, take a look at the logs."
            }));
        }
コード例 #2
0
ファイル: AdminModule.cs プロジェクト: pyrostic/Ombi
        private async Task <Response> SaveDiscordNotifications()
        {
            var settings = this.BindAndValidate <DiscordNotificationSettings>();

            if (!ModelValidationResult.IsValid)
            {
                return(Response.AsJson(ModelValidationResult.SendJsonError()));
            }

            var result = await DiscordSettings.SaveSettingsAsync(settings);

            if (settings.Enabled)
            {
                NotificationService.Subscribe(new DiscordNotification(DiscordApi, DiscordSettings));
            }
            else
            {
                NotificationService.UnSubscribe(new DiscordNotification(DiscordApi, DiscordSettings));
            }

            Log.Info("Saved discord settings, result: {0}", result);
            return(Response.AsJson(result
                ? new JsonResponseModel {
                Result = true, Message = "Successfully Updated the Settings for Discord Notifications!"
            }
                : new JsonResponseModel {
                Result = false, Message = "Could not update the settings, take a look at the logs."
            }));
        }
コード例 #3
0
        private Response TestSlackNotification()
        {
            var settings = this.BindAndValidate <SlackNotificationSettings>();

            if (!ModelValidationResult.IsValid)
            {
                return(Response.AsJson(ModelValidationResult.SendJsonError()));
            }
            var notificationModel = new NotificationModel
            {
                NotificationType = NotificationType.Test,
                DateTime         = DateTime.Now
            };

            try
            {
                NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings));
                settings.Enabled = true;
                NotificationService.Publish(notificationModel, settings);
                Log.Info("Sent slack notification test");
            }
            catch (Exception e)
            {
                Log.Error(e, "Failed to subscribe and publish test Slack Notification");
            }
            finally
            {
                NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings));
            }
            return(Response.AsJson(new JsonResponseModel {
                Result = true, Message = "Successfully sent a test Slack Notification! If you do not receive it please check the logs."
            }));
        }
コード例 #4
0
ファイル: AdminModule.cs プロジェクト: pyrostic/Ombi
        private async Task <Response> TestDiscordNotification()
        {
            var settings = this.BindAndValidate <DiscordNotificationSettings>();

            if (!ModelValidationResult.IsValid)
            {
                return(Response.AsJson(ModelValidationResult.SendJsonError()));
            }
            var notificationModel = new NotificationModel
            {
                NotificationType = NotificationType.Test,
                DateTime         = DateTime.Now
            };

            var currentDicordSettings = await DiscordSettings.GetSettingsAsync();

            try
            {
                NotificationService.Subscribe(new DiscordNotification(DiscordApi, DiscordSettings));
                settings.Enabled = true;
                await NotificationService.Publish(notificationModel, settings);

                Log.Info("Sent Discord notification test");
            }
            catch (Exception e)
            {
                Log.Error(e, "Failed to subscribe and publish test Discord Notification");
            }
            finally
            {
                if (!currentDicordSettings.Enabled)
                {
                    NotificationService.UnSubscribe(new DiscordNotification(DiscordApi, DiscordSettings));
                }
            }
            return(Response.AsJson(new JsonResponseModel {
                Result = true, Message = "Successfully sent a test Discord Notification! If you do not receive it please check the logs."
            }));
        }