Exemple #1
0
        private string WriteToFile([NotNull] object obj, [NotNull] string extension)
        {
            var json = JsonConvert.SerializeObject(obj, Formatting.Indented).NotNull();
            var hash = _Hasher.Hash(json);

            var filePath = Path.Combine(_Configuration.Value().Path, hash + extension);

            if (!File.Exists(filePath))
            {
                File.WriteAllText(filePath, json, Encoding.UTF8);
            }

            return(filePath);
        }
 public async Task Execute(CancellationToken cancellationToken)
 {
     while (!cancellationToken.IsCancellationRequested)
     {
         _Logger.LogInformation(_Configuration.Value().Value);
         await Task.Delay(1000, cancellationToken);
     }
 }
Exemple #3
0
        public void Finalize(IContainer container)
        {
            var uniqueDirectoryPaths = _Configuration.Value().DirectoryPaths.Select(Path.GetFullPath).Distinct().ToList();

            foreach (var directoryPath in uniqueDirectoryPaths)
            {
                LoadPluginsFromDirectory(directoryPath, container);
            }
        }
        public void Finalize(IContainer container)
        {
            var configuration = _Configuration.Value();

            if (string.IsNullOrWhiteSpace(configuration.Key))
            {
                return;
            }

            global::Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(configuration.Key);
        }
Exemple #5
0
        public async Task SendNotificationAsync(string subject, string body)
        {
            var configuration = _Configuration.Value();

            if (!configuration.IsEnabled())
            {
                _Logger.Log(LogLevel.Debug, "Pushbullet notification channel is not enabled");
                return;
            }

            var client = new PushBulletClient(configuration.AccessToken);
            await client.PushAsync(subject, body, null).NotNull();
        }
        public bool?IsEnabled(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var configuration = _Configuration.Value();

            if (configuration.Root is null)
            {
                return(null);
            }

            string[] keyParts = key.Split('/', '.');

            JToken current = configuration.Root;

            foreach (string part in keyParts)
            {
                JToken wildcard = current["*"];
                if (wildcard != null)
                {
                    return(wildcard.Value <bool>());
                }

                JToken child;
                if (current is JObject obj)
                {
                    child = obj.GetValue(part, StringComparison.InvariantCultureIgnoreCase);
                }
                else
                {
                    child = current[part];
                }

                if (child == null)
                {
                    return(null);
                }

                current = child;
            }

            return(current.Value <bool>());
        }
        public async Task SendNotificationAsync(string subject, string body)
        {
            var configuration = _Configuration.Value();

            if (!configuration.IsEnabled())
            {
                _Logger.Log(LogLevel.Debug, "Email notification channel is not enabled");
                return;
            }

            assume(configuration.Profile != null);
            assume(configuration.From != null);

            var client         = _SmtpClientProvider.Provide(configuration.Profile);
            var messageBuilder = client.CreateEmailMessageBuilder();

            messageBuilder.From = configuration.From;
            messageBuilder.To.AddRange(configuration.To);
            messageBuilder.Subject = subject;
            messageBuilder.Body    = body;

            await client.SendEmailMessageAsync(messageBuilder.Build());
        }
Exemple #8
0
 public string TryGetPassword(string passwordName) => _Configuration.Value().GetValueOrDefault(passwordName);
Exemple #9
0
        public async Task Execute(CancellationToken cancellationToken)
        {
            using (var evt = new ManualResetEvent(false))
            {
                void notify(WorkQueueItemAddedMessage message)
                {
                    // ReSharper disable once AccessToDisposedClosure
                    evt.Set();
                }

                using (_Bus.Subscribe <WorkQueueItemAddedMessage>(notify))
                {
                    bool workerQueueIsEmpty = false;
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        evt.Reset();

                        var  cts       = new CancellationTokenSource();
                        Task delayTask = Task.Delay(5000, cts.Token);
                        Task evtTask   = evt.AsTask();

                        await Task.WhenAny(delayTask, evtTask).NotNull();

                        cts.Cancel();

                        if (cancellationToken.IsCancellationRequested)
                        {
                            break;
                        }

                        IEnumerable <Task <bool> > workerThreads = Enumerable.Range(1, _Configuration.Value().WorkerThreads).Select(_ => ProcessMessages(cancellationToken));

                        bool[] workerThreadProcessedMessages = await Task.WhenAll(workerThreads).NotNull();

                        if (workerThreadProcessedMessages.Any(b => b))
                        {
                            workerQueueIsEmpty = false;
                        }
                        else
                        {
                            if (!workerQueueIsEmpty)
                            {
                                workerQueueIsEmpty = true;
                                await _Bus.PublishAsync(WorkQueueEmptyMessage.Instance);
                            }
                        }
                    }
                }
            }
        }