Пример #1
0
        private static BrokerOptions GetBrokerOptions(IConfiguration configuration, ILogger logger = null)
        {
            var output = configuration.GetSection("BrokerOptions").Get <BrokerOptions>();

            output.Address = EnviromentHelper.GetSetting("BROKER_ADDRESS", output.Address);
            logger?.LogInformation($"[SETTINGS]: BROKER_ADDRESS (Message Broker Address) - {output.Address}");

            output.UserName = EnviromentHelper.GetSetting("BROKER_USERNAME", output.UserName, allowEmpty: true);
            if (!string.IsNullOrEmpty(output.UserName))
            {
                logger?.LogInformation($"[SETTINGS]: BROKER_USERNAME - '{output.UserName}'");
            }

            output.Password = EnviromentHelper.GetSetting("BROKER_PASSWORD", output.Password, allowEmpty: true);
            if (!string.IsNullOrEmpty(output.Password))
            {
                logger?.LogInformation($"[SETTINGS]: BROKER_PASSWORD - '{output.Password}'");
            }

            if (!RabbitMqHelper.TryConnect(output.Address, output.UserName, output.Password, out Exception ex))
            {
                throw new ApplicationException($"Unable to connect to Broker: {output.Address}, username: {output.UserName}, password: {output.Password} ({ex.Message})");
            }

            return(output);
        }
Пример #2
0
        private static ConverterOptions BuildConverterOptions(IConfiguration config)
        {
            // Get.
            var options = config.GetSection("ConverterOptions").Get <ConverterOptions>();

            options.DownloadStore   = EnviromentHelper.GetSetting("CONVERTER_DOWNLOADSTORE", options.DownloadStore);
            options.ProcessingStore = EnviromentHelper.GetSetting("CONVERTER_PROCESSINGSTORE", options.ProcessingStore);
            options.QueueStore      = EnviromentHelper.GetSetting("CONVERTER_QUEUESTORE", options.QueueStore);
            options.ProcessedStore  = EnviromentHelper.GetSetting("CONVERTER_PROCESSEDSTORE", options.ProcessedStore);

            // Validate.
            if (!Directory.Exists(options.DownloadStore))
            {
                throw new ApplicationException($"Download Store does not exist: {options.DownloadStore}");
            }

            if (!Directory.Exists(options.ProcessingStore))
            {
                throw new ApplicationException($"Processing Store does not exist: {options.ProcessingStore}");
            }

            if (!Directory.Exists(options.QueueStore))
            {
                throw new ApplicationException($"Queue Store does not exist: {options.QueueStore}");
            }

            if (!Directory.Exists(options.ProcessedStore))
            {
                throw new ApplicationException($"Processed Store does not exist: {options.ProcessedStore}");
            }

            return(options);
        }
Пример #3
0
        private static MediaInfoClientOptions BuildMediaInfoClientOptions(IConfiguration config)
        {
            // Get.
            var options = config.GetSection("MediaInfoOptions").Get <MediaInfoClientOptions>();

            options.Address = EnviromentHelper.GetSetting("STORAGE_MEDIAINFOADDRESS", options.Address);

            return(options);
        }
Пример #4
0
        private static DiscordOptions GetDiscordOptions(IConfiguration configuration, ILogger logger = null)
        {
            var output = configuration.GetSection("DiscordOptions").Get <DiscordOptions>();

            output.Token = EnviromentHelper.GetSetting("DISCORD_TOKEN", output.Token);
            logger?.LogInformation($"[SETTINGS]: DISCORD_TOKEN (Auth Token) - {output.Token}");

            output.AlertChannelName = EnviromentHelper.GetSetting("DISCORD_ALERTCHANNELNAME", output.AlertChannelName);
            logger?.LogInformation($"[SETTINGS]: DISCORD_ALERTCHANNELNAME (Channel names to show alerts) - {output.AlertChannelName}");

            output.ViewerDomain = EnviromentHelper.GetSetting("DISCORD_VIEWERDOMAIN", output.ViewerDomain);
            logger?.LogInformation($"[SETTINGS]: DISCORD_VIEWERDOMAIN (Web Address to view media) - {output.ViewerDomain}");

            return(output);
        }
Пример #5
0
        private static BrokerOptions BuildBrokerOptions(IConfiguration config)
        {
            // Get.
            var options = config.GetSection("BrokerOptions").Get <BrokerOptions>();

            options.Address  = EnviromentHelper.GetSetting("BROKER_ADDRESS", options.Address);
            options.UserName = EnviromentHelper.GetSetting("BROKER_USERNAME", options.UserName, allowEmpty: true);
            options.Password = EnviromentHelper.GetSetting("BROKER_PASSWORD", options.Password, allowEmpty: true);

            // Validate.
            if (!RabbitMqHelper.TryConnect(options.Address, options.UserName, options.Password, out Exception ex))
            {
                throw new ApplicationException($"Could not connect to RabbitMq Server on the hostname: {options.Address}, username: {options.UserName}, password: {options.Password} ({ex.Message})");
            }

            return(options);
        }
Пример #6
0
        private static MediaInfoClientOptions GetMediaInfoOptions(IConfiguration configuration, ILogger logger = null)
        {
            var output = configuration.GetSection("MediaInfoOptions").Get <MediaInfoClientOptions>();

            output.Address = EnviromentHelper.GetSetting("MEDIAINFO_ADDRESS", output.Address);

            // Ensure we can send a message!
            try {
                new MediaInfoClient(new HttpClient(), output)
                .GetEpisode(100);
            }
            catch (Exception ex) {
                logger?.LogCritical($"Error with setup request to MediaInfo: {output.Address}");
                throw ex;
            }

            logger?.LogInformation($"[SETTINGS]: MEDIAINFO_ADDRESS - {output.Address}");
            return(output);
        }
Пример #7
0
        private static HandbrakeOptions BuildHandbrakeOptions(IConfiguration config)
        {
            // Get.
            var options = config.GetSection("HandbrakeOptions").Get <HandbrakeOptions>();

            options.CmdPath      = EnviromentHelper.GetSetting("HANDBRAKE_CMDPATH", options.CmdPath);
            options.StandardArgs = EnviromentHelper.GetSetting("HANDBRAKE_STANDARDARGS", options.StandardArgs);
            options.SubtitleArgs = EnviromentHelper.GetSetting("HANDBRAKE_SUBTITLEARGS", options.SubtitleArgs);

            // Validate.
            if (!File.Exists(options.CmdPath))
            {
                throw new ApplicationException($"Path to handbrake CLI not found: {options.CmdPath}");
            }

            // Check Args point at a valid json configuration file (if they are pointing at one).
            int pathIndex = options.SubtitleArgs.IndexOf(".json");

            if (pathIndex > -1)
            {
                string path = StringHelper.GetWordAtIndex(options.SubtitleArgs, pathIndex);
                if (!string.IsNullOrWhiteSpace(path) && !File.Exists(path))
                {
                    throw new ApplicationException($"File used in SubtitleArgs cannot be found: {path} (Full Args: {options.SubtitleArgs}).");
                }
            }

            pathIndex = options.StandardArgs.IndexOf(".json");
            if (pathIndex > -1)
            {
                string path = StringHelper.GetWordAtIndex(options.StandardArgs, pathIndex);
                if (!string.IsNullOrWhiteSpace(path) && !File.Exists(path))
                {
                    throw new ApplicationException($"File used in StandardArgs cannot be found: {path} (Full Args: {options.StandardArgs}).");
                }
            }

            return(options);
        }