示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LibraryAddedNotifier"/> class.
        /// </summary>
        /// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
        /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
        /// <param name="httpClient">Instance of the <see cref="IHttpClient"/> interface.</param>
        /// <param name="applicationHost">Instance of the <see cref="IApplicationHost"/> interface.</param>
        public LibraryAddedNotifier(ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpClient httpClient, IApplicationHost applicationHost)
        {
            _logger          = loggerFactory.CreateLogger <LibraryAddedNotifier>();
            _libraryManager  = libraryManager ?? throw new ArgumentNullException(nameof(libraryManager));
            _applicationHost = applicationHost;

            _itemProcessQueue          = new ConcurrentDictionary <Guid, QueuedItemContainer>();
            _libraryManager.ItemAdded += ItemAddedHandler;

            HandlebarsFunctionHelpers.RegisterHelpers();
            _cancellationTokenSource = new CancellationTokenSource();
            PeriodicAsyncHelper.PeriodicAsync(
                async() =>
            {
                try
                {
                    await ProcessItemsAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.LogWarning(ex, "Error");
                }
            }, TimeSpan.FromMilliseconds(Constants.RecheckIntervalMs),
                _cancellationTokenSource.Token)
            .ConfigureAwait(false);

            _discordDestination = new DiscordDestination(
                loggerFactory.CreateLogger <DiscordDestination>(),
                httpClient);

            _gotifyDestination = new GotifyDestination(
                loggerFactory.CreateLogger <GotifyDestination>(),
                httpClient);
        }
示例#2
0
 /// <inheritdoc />
 public Task RunAsync()
 {
     _libraryManager.ItemAdded += ItemAddedHandler;
     HandlebarsFunctionHelpers.RegisterHelpers();
     return(Task.CompletedTask);
 }
示例#3
0
 /// <summary>
 /// Gets the compiled handlebars template.
 /// </summary>
 /// <returns>The compiled handlebars template.</returns>
 public HandlebarsTemplate <object, string> GetCompiledTemplate()
 {
     return(_compiledTemplate ??= Handlebars.Compile(HandlebarsFunctionHelpers.Base64Decode(Template)));
 }