private void LoadModulesFromconfiguration()
        {
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            var coreSystemSection = config.GetSection(BillingwareConfigurationSection.SectionName) as BillingwareConfigurationSection;

            if (coreSystemSection != null)
            {
                foreach (ProviderSettings element in coreSystemSection.ServiceModules)
                {
                    if (Activator.CreateInstance(Type.GetType(element.Type)) is IBillingwareModule notificationModule)
                    {
                        _serviceModules.Add(notificationModule);

                        CommonLogger.Info <BillingwareServiceControl>($"{element.Name} module added.");
                    }
                    else
                    {
                        CommonLogger.Warn <BillingwareServiceControl>($"{element.Name} does not implement IBillingwareModule. Will ignore.");
                    }
                }
            }
            else
            {
                CommonLogger.Debug <BillingwareServiceControl>($"{BillingwareConfigurationSection.SectionName} is not defined");
                throw new ConfigurationErrorsException($"{BillingwareConfigurationSection.SectionName} is not defined");
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                      CancellationToken cancellationToken)
        {
            var mesg = await request.Content.ReadAsStringAsync();

            CommonLogger.Info <HttpLogHandler>($"\n----------------------------REQUEST----------------------------------------\nUrl: {request.RequestUri} \r\n Method: {request.Method} " + $"\r\n Headers: {request.Headers} \r\n Body: {mesg} \r\n");

            return(await await base.SendAsync(request,
                                              cancellationToken).ContinueWith(async c =>
            {
                var response = await c;

                var rawResponse = string.Empty;
                if (request.RequestUri.ToString().Contains("api/ui/index"))
                {
                    return response;
                }
                if (request.RequestUri.ToString().Contains("api/ui"))
                {
                    return response;
                }
                if (request.RequestUri.ToString().Contains("docs"))
                {
                    return response;
                }
                try
                {
                    if (response.Content == null)
                    {
                        rawResponse = response.ReasonPhrase;
                    }
                    else
                    {
                        rawResponse = await response.Content.ReadAsStringAsync();
                    }
                }
                catch (Exception exception) { CommonLogger.Warn <HttpLogHandler>(exception.Message); }
                CommonLogger.Info <HttpLogHandler>($"\n--------------------------------RESPONSE-----------------------------------\nHeaders: {response.Headers} " + $"\r\n Body: {rawResponse}");
                return response;
            },
                                                                              cancellationToken));
        }
Пример #3
0
        private static void ShutdownHttpServer()
        {
            try
            {
                if (_apiListener == null)
                {
                    CommonLogger.Warn <PublicApiModule>("Public HTTP Service is not up and running.");
                    return;
                }

                //Startup.EventhandlerModules.ForEach(e => e.Release(SierraBoxEventsManager.Instance.Events));
                _apiListener.Dispose();
                CommonLogger.Info <PublicApiModule>("HTTP listener has been successfully shut down :|");
            }
            catch (Exception exception)
            {
                CommonLogger.Error <PublicApiModule>(exception,
                                                     exception.Message);
            }
        }