public PostMongoRepository(
     MongoConnection mongoConnection,
     IServiceLogger <PostMongoRepository> logger)
 {
     Connection = mongoConnection;
     _logger    = logger;
 }
Exemple #2
0
 public StandardComponentController(
     IStandardRepository standardRepository,
     IServiceLogger <StandardComponentController> logger)
 {
     _standardRepository = standardRepository;
     _logger             = logger;
 }
Exemple #3
0
 public BackupService(
     IAppServiceProvider appServiceProvider,
     IStandardServiceProvider standardServiceProvider,
     IChartServiceProvider chartServiceProvider,
     IDynamicListServiceProvider dynamicListServiceProvider,
     IDatabaseServiceProvider databaseServiceProvider,
     IPageServiceProvider pageServiceProvider,
     IFileSeviceProvider fileSeviceProvider,
     IBackupRepository backupRepository,
     ICompositeControlServiceProvider compositeControlServiceProvider,
     IOptionsMonitor <BackupOptions> backupOptions,
     IServiceLogger <BackupService> logger
     )
 {
     _appServiceProvider              = appServiceProvider;
     _standardServiceProvider         = standardServiceProvider;
     _chartServiceProvider            = chartServiceProvider;
     _dynamicListServiceProvider      = dynamicListServiceProvider;
     _databaseServiceProvider         = databaseServiceProvider;
     _fileSeviceProvider              = fileSeviceProvider;
     _pageServiceProvider             = pageServiceProvider;
     _backupRepository                = backupRepository;
     _compositeControlServiceProvider = compositeControlServiceProvider;
     _backupOptions = backupOptions;
     _logger        = logger;
 }
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="traceId">A unique identifier used to correlate debugging and diagnostics messages</param>
        /// <param name="componentName">The name of the component to use when writing debugging and diagnostics messages</param>
        /// <param name="serviceContext">The stateless service context that the context of the service running the listener</param>
        /// <param name="logger">A service logger used to write debugging and diagnostics messages</param>
        /// <param name="configurationProvider">The configuration provider for the gateway settings</param>
        /// <param name="unsupportedConfigurationChangeCallback">A method to call when an unsupported configuration change occurs.</param>
        public MqttCommunicationListener(Guid traceId, string componentName, StatelessServiceContext serviceContext, IServiceLogger logger, IConfigurationProvider <GatewayConfiguration> configurationProvider, UnsupportedConfigurationChange unsupportedConfigurationChangeCallback)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException(nameof(serviceContext));
            }
            if (configurationProvider == null)
            {
                throw new ArgumentNullException(nameof(configurationProvider));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.logger                = logger;
            this.componentName         = componentName;
            this.serviceContext        = serviceContext;
            this.configurationProvider = configurationProvider;
            this.unsupportedConfigurationChangeCallback = unsupportedConfigurationChangeCallback;

            // optimizing IOCP performance
            int minWorkerThreads;
            int minCompletionPortThreads;

            ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
            ThreadPool.SetMinThreads(minWorkerThreads, Math.Max(16, minCompletionPortThreads));

            this.logger.CreateCommunicationListener(traceId, this.componentName, this.GetType().FullName, this.BuildListeningAddress(this.configurationProvider.Config));
        }
Exemple #5
0
        public ReportingService()
        {
            this.initialInterval = ConfigurationManager.GenerationIntervalInMinutes;
            this.logger          = new ServiceLogger(LogStrategy.WindowsEventLog);

            this.InitializeComponent();
        }
 public DeployExceptionHandler(IDeployEvents callback, IConf appSettings, IServiceLogger logger, ISession session)
 {
     _callback    = callback;
     _session     = session;
     _appSettings = appSettings;
     _logger      = logger;
 }
Exemple #7
0
        //------------------------------------------------------------------------------
        /// <summary>
        /// The handler for the Azure function "GetStuff"
        /// </summary>
        //------------------------------------------------------------------------------
        public Stuff GetStuff(HelloArguments args, IServiceLogger log)
        {
            // The signature of the handler method is important.  First argument should be
            // your own special argument class that RocketScience will fill out for you.
            // The Second argument must be an IServiceLogger.

            // THROWING EXCEPTIONS:
            // If you want to throw an exception: throw a ServiceOperationException and include a message
            // that the user can understand how to address the problem.
            // If the exception is something the user can't fix, then throw any other kind of exception and
            // RocketScience will automatically generate a genertic error message with a log key.
            if (args.UserId == 8888)
            {
                throw new ServiceOperationException(
                          ServiceOperationError.BadParameter,
                          "Please use a less auspicious UserId");
            }

            // You can return anything you want.  RocketScience will automatically package it
            // in the "Values" property on the return object.
            return(new Stuff()
            {
                Description = "Something old, something new" +
                              (args.FishTypes == null ? "" : string.Join("", args.FishTypes.Select(a => ", something " + a))),
                AwesomeFactor = 1000 * args.UserId
            });
        }
        //--------------------------------------------------------------------------------
        /// <summary>
        /// Error response
        /// </summary>
        //--------------------------------------------------------------------------------
        internal HttpResponseMessage Error(Exception error, IServiceLogger logger)
        {
            if (error is TargetInvocationException)
            {
                error = ((TargetInvocationException)error).InnerException;
            }
            var logKey = CurrentLogKey;

            logger.Error($"{logKey} Service Error: {error.Message}", error);


            var statusCode = HttpStatusCode.BadRequest;
            var response   = new ServiceResponse(null);

            if (error is ServiceOperationException)
            {
                var serviceError = error as ServiceOperationException;
                response.ErrorCode    = serviceError.ErrorCode.ToString();
                response.ErrorMessage = serviceError.Message + $"\r\nThe Log Key for this error is {logKey}";
            }
            else
            {
                response.ErrorCode    = ServiceOperationError.FatalError.ToString();
                statusCode            = HttpStatusCode.InternalServerError;
                response.ErrorMessage = $"There was a fatal service error.\r\nThe Log Key for this error is {logKey}\r\n{GetExceptionHint(error)}";
            }

            return(new HttpResponseMessage(statusCode)
            {
                Content = new StringContent(JsonConvert.SerializeObject(response, Formatting.Indented), Encoding.UTF8, "application/json")
            });
        }
 public CombiningPageRequestMiddleware(
     ISiteRequestAccessor siteRequest,
     IServiceLogger <CombiningPageRequestMiddleware> logger)
 {
     _siteRequest = siteRequest;
     _logger      = logger;
 }
Exemple #10
0
 public FilesController(
     IFileService fileService,
     IServiceLogger <FilesController> logger)
 {
     _fileService = fileService;
     _logger      = logger;
 }
 public CompositeControlsController(
     IServiceLogger <CompositeControlsController> logger,
     ICompositeControlRepository controlRepository)
 {
     _logger            = logger;
     _controlRepository = controlRepository;
 }
 public async Task Invoke(HttpContext httpContext,
                          IServiceLogger <CatchGlobalExceptionMiddleware> serviceLogger)
 {
     try
     {
         await _next.Invoke(httpContext);
     }
     catch (Exception ex)
     {
         httpContext.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
         httpContext.Response.ContentType = "application/json";
         if (ex is CoreException coreException)
         {
             serviceLogger.Warning(coreException, "Wrong business flow with error {$coreException}", coreException);
             httpContext.Items[Constants.OccurredException] = coreException;
             await httpContext.Response.WriteAsync(coreException.ToJsonString());
         }
         else
         {
             serviceLogger.Critical(ex, "Internal server error {$error}", ex);
             var responseBody = (new CoreException(ErrorCodes.InternalException)).ToJsonString();
             httpContext.Items[Constants.OccurredException] = responseBody;
             await httpContext.Response.WriteAsync(responseBody);
         }
     }
 }
        //------------------------------------------------------------------------------
        /// <summary>
        /// Execute this call as an Http request
        /// </summary>
        //------------------------------------------------------------------------------
        public object ExecuteHttpRequest(HttpRequestMessage req, IServiceLogger logger, params object[] extras)
        {
            var handler             = _handlerStaticProperty.GetValue(null);
            var generatedParameters = new List <object>();

            if (_parameterDefinitions == null)
            {
                var newDefinitions   = new List <ParameterDefinition>();
                var targetParameters = _callMe.GetParameters();
                if (extras == null)
                {
                    extras = new Tuple <string, object> [0];
                }
                if (targetParameters.Length != 2 + extras.Length)
                {
                    throw new ApplicationException($"The target method '{_callMe.Name}' should have {2 + extras.Length} parameters, but has {targetParameters.Length}.");
                }

                // The first parameter is the user's custom property bag class which we will generically construct
                // from the request using the ReadParameters method
                var firstParameterType   = targetParameters[0].ParameterType;
                var context              = this.GetType();
                var readParametersMethod = context.GetMethod("ReadParameters", BindingFlags.Static | BindingFlags.Public);
                _constructParameters = readParametersMethod.MakeGenericMethod(new[] { firstParameterType });
                newDefinitions.Add(new ParameterDefinition()
                {
                    Create = (r, l, e) => _constructParameters.Invoke(null, new object[] { r })
                });

                // The second parameter is just the passed in IserviceLogger
                if (targetParameters[1].ParameterType.Name != "IServiceLogger")
                {
                    throw new ApplicationException($"The target method '{_callMe.Name}' second parameter should be type IServiceLogger.");
                }
                newDefinitions.Add(new ParameterDefinition()
                {
                    Create = (r, l, e) => l
                });

                // fill in any remaining parameters with the extra named arguments
                for (int i = 2; i < targetParameters.Length; i++)
                {
                    var index = i - 2;
                    newDefinitions.Add(new ParameterDefinition()
                    {
                        Create = (r, l, e) => e[index]
                    });
                }

                _parameterDefinitions = newDefinitions.ToArray();
            }

            foreach (var parameter in _parameterDefinitions)
            {
                generatedParameters.Add(parameter.Create(req, logger, extras));
            }


            return(_callMe.Invoke(handler, generatedParameters.ToArray()));
        }
 public LogCollectorService(
     IServiceLogger <LogCollectorService> logger,
     ILogEventProvider logEventProvider)
 {
     _logger           = logger;
     _logEventProvider = logEventProvider;
 }
Exemple #15
0
 public CheckingResponseCachingMiddleware(
     ISiteRequestAccessor siteRequest,
     IServiceLogger <CheckingResponseCachingMiddleware> logger)
 {
     _siteRequest = siteRequest;
     _logger      = logger;
 }
 public DeployExceptionHandler(IDeployEvents callback, IConf appSettings, IServiceLogger logger, ISession session)
 {
     _callback = callback;
     _session = session;
     _appSettings = appSettings;
     _logger = logger;
 }
 public ServiceConfigurationService(
     IServiceLogger <ServiceConfigurationService> logger,
     IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
 }
        /// <summary>
        /// Instantiate to be able to get the trades required.
        /// </summary>
        /// <param name="service">The type of API service.</param>
        /// <param name="trade">The type of trade.</param>
        public TradesFetcher(IPowerService service, TradeType trade, IServiceLogger logger)
        {
            this.service = service;
            this.trade   = trade;
            this.logger  = logger;

            Environment.SetEnvironmentVariable("Trade", trade.ToString());
        }
 public FlightRequestService(IFlightRequestRepository flightRequestRepository,
                             IUserRepository userRepository,
                             IServiceLogger logger)
 {
     _flightRequestRepository = flightRequestRepository;
     _userRepository          = userRepository;
     _logger = logger;
 }
 public GenericApiConnector(IServiceLogger logger, IHttpClientFactory clientFactory, IConfiguration configuration, string url, string path)
 {
     _logger        = logger;
     _clientFactory = clientFactory;
     _configuration = configuration;
     _url           = url;
     _path          = path;
 }
Exemple #21
0
        public SerilogServiceLoggerTests()
        {
            _serviceLoggerFactoryMock = new Mock <ISerilogServiceLoggerFactory>();

            _fixture = new Fixture();

            _sut = new SerilogServiceLogger(_serviceLoggerFactoryMock.Object);
        }
Exemple #22
0
 public UnitOfWork(IServiceLogger serviceLogger, IHttpClientFactory clientFactory, IConfiguration configuration)
 {
     _logger        = serviceLogger;
     _clientFactory = clientFactory;
     _configuration = configuration;
     _url           = _configuration.GetSection("ApiCallSettings").GetSection("url").Value;
     _path          = _configuration.GetSection("LogSettings").GetSection("path").Value;
 }
 public PdfDocumentHandler(
     IPdfDocumentsRepository pdfDocumentRepository,
     IFileStorageHandler fileStorageHandler,
     IServiceLogger logger)
 {
     _pdfDocumentRepository = pdfDocumentRepository;
     _fileStorageHandler    = fileStorageHandler;
     _logger = logger;
 }
Exemple #24
0
 public EntitySchemasController(
     IEntitySchemaRepository entitySchemaRepository,
     IEntitySchemaService entitySchemaService,
     IServiceLogger <EntitySchemasController> logger)
 {
     _entitySchemaRepository = entitySchemaRepository;
     _entitySchemaService    = entitySchemaService;
     _logger = logger;
 }
Exemple #25
0
 public DeployService(IDeployServiceFactory dsFactory, IConfFactory cFactory)
 {
     _dsFactory = dsFactory;
     _cFactory = cFactory;
     _logger = _dsFactory.CreateLoggerObj();
     _logger.Info("Service instance is created");
     if (OperationContext.Current != null)
         OperationContext.Current.Channel.Closing += ClearLocks;
 }
 public ServiceMonitorService(
     IServiceLogger <ServiceMonitorService> logger,
     IMonitorProvider monitorProvider,
     IServiceManagementProvider serviceManagementProvider)
 {
     _logger                    = logger;
     _monitorProvider           = monitorProvider;
     _serviceManagementProvider = serviceManagementProvider;
 }
Exemple #27
0
        public void PrepareEnvironment()
        {
            _logger     = new ServiceLoggerStub();
            _callback   = new CallbackChannelStub();
            _surveyName = "Test" + TestUtils.GetPostfix();
            _surveyPath = "D:\\sss\\" + _surveyName;

            _files = new SendingFiles(1024 * 1024 * 3);
        }
 public LocalizationController(
     ILocalizationRepository localizationRepository,
     ILocalizationProvider localizationProvider,
     IServiceLogger <LocalizationController> logger)
 {
     _localizationRepository = localizationRepository;
     _localizationProvider   = localizationProvider;
     _logger = logger;
 }
 public PdfDocumentController(
     IPdfDocumentHandler pdfDocumentHandler,
     IConfiguration configuration,
     IServiceLogger logger)
 {
     _pdfDocumentHandler = pdfDocumentHandler;
     _configuration      = configuration;
     _logger             = logger;
 }
Exemple #30
0
 public ChartsController(
     IChartRepository chartRepository,
     IChartService chartService,
     IServiceLogger <ChartsController> logger)
 {
     _chartService    = chartService;
     _chartRepository = chartRepository;
     _logger          = logger;
 }
 public BackupsController(
     IBackupService backupService,
     IBackupRepository backupRepository,
     IServiceLogger <BackupsController> logger)
 {
     _backupRepository = backupRepository;
     _backupService    = backupService;
     _logger           = logger;
 }
Exemple #32
0
        public void Stop()
        {
            IServiceLogger logger = ServiceLogger.Current;

            logger.Write("Disposing _context ...", TraceEventType.Information);
            _context.Dispose();
            logger.Write("Disposed _context.", TraceEventType.Information);
            logger.Write("Service stopped.", TraceEventType.Stop);
        }
 public DeployServiceFactory(
     IServiceLogger logger,
     Func<IDeployEvents> callbackFactory,
     Func<string, DeployContext, IConfFactory, IConf> confFactory,
     Func<IConf, IEnumerable<IValidator>> validatorsFactory, 
     Func<IConf, IEnumerable<IDeployer>> deployersFactory,
     Func<IConf, string, ISession> sessionFactory,
     Func<IDeployEvents, IConf, IServiceLogger, ISession, IDeployExceptionHandler> exHandlerFactory)
 {
     _logger = logger;
     _callbackFactory = callbackFactory;
     _confFactory = confFactory;
     _validatorsFactory = validatorsFactory;
     _deployersFactory = deployersFactory;
     _sessionFactory = sessionFactory;
     _exHandlerFactory = exHandlerFactory;
 }
        /// <summary>
        /// The settings provider used to bridge Service Fabric configuration information and DotNetty
        /// </summary>
        /// <param name="traceId">The unique identifier used to correlate debugging and diagnostics messages</param>
        /// <param name="componentName">The component name used for debug and diagnostics messages</param>
        /// <param name="logger">The service fabric logger to be used when writing debug and diagnostics information</param>
        /// <param name="gatewayConfiguration">The gateway configuration used to get current configuration information for DotNetty</param>
        /// <param name="iotHubConfiguration">The IotHub Client configuration used to get current configuration information for DotNetty</param>
        /// <param name="mqttConfiguration">The MQTT configuration used to get current configuration information for DotNetty</param>
        public ServiceFabricConfigurationProvider(Guid traceId, string componentName, IServiceLogger logger, GatewayConfiguration gatewayConfiguration, IoTHubConfiguration iotHubConfiguration, MqttServiceConfiguration mqttConfiguration)
        {
            this.componentName = componentName;
            this.logger = logger;

            this.logger.Verbose(traceId, this.componentName, "Initializing configuration provider.");

            var baseProperties = new Dictionary<string, string>();

            foreach (PropertyInfo element in typeof(GatewayConfiguration).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!element.PropertyType.IsArray)
                {
                    object value = element.GetValue(gatewayConfiguration, null);
                    baseProperties.Add(element.Name, element.PropertyType == typeof(string) ? value as string : value.ToString());
                }
            }

            foreach (PropertyInfo element in typeof(MqttServiceConfiguration).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!element.PropertyType.IsArray)
                {
                    object value = element.GetValue(mqttConfiguration, null);
                    baseProperties.Add(element.Name, element.PropertyType == typeof(string) ? value as string : value.ToString());
                }
            }

            foreach (PropertyInfo element in typeof(IoTHubConfiguration).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!element.PropertyType.IsArray)
                {
                    object value = element.GetValue(iotHubConfiguration, null);
                    baseProperties.Add($"IotHubClient.{element.Name}", value?.ToString());
                }
            }



            this.configurationValues = baseProperties.ToImmutableDictionary();
            this.logger.Informational(traceId, this.componentName, "Initializing configuration provider complete.");
        }
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="traceId">A unique identifier used to correlate debugging and diagnostics messages</param>
        /// <param name="componentName">The name of the component to use when writing debugging and diagnostics messages</param>
        /// <param name="serviceContext">The stateless service context that the context of the service running the listener</param>
        /// <param name="logger">A service logger used to write debugging and diagnostics messages</param>
        /// <param name="configurationProvider">The configuration provider for the gateway settings</param>
        /// <param name="unsupportedConfigurationChangeCallback">A method to call when an unsupported configuration change occurs.</param>
        public MqttCommunicationListener(Guid traceId, string componentName, StatelessServiceContext serviceContext, IServiceLogger logger, IConfigurationProvider<GatewayConfiguration> configurationProvider, UnsupportedConfigurationChange unsupportedConfigurationChangeCallback)
        {
            if (serviceContext == null) throw new ArgumentNullException(nameof(serviceContext));
            if (configurationProvider == null) throw new ArgumentNullException(nameof(configurationProvider));
            if (logger == null) throw new ArgumentNullException(nameof(logger));

            this.logger = logger;
            this.componentName = componentName;
            this.serviceContext = serviceContext;
            this.configurationProvider = configurationProvider;
            this.unsupportedConfigurationChangeCallback = unsupportedConfigurationChangeCallback;

            // optimizing IOCP performance
            int minWorkerThreads;
            int minCompletionPortThreads;

            ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
            ThreadPool.SetMinThreads(minWorkerThreads, Math.Max(16, minCompletionPortThreads));
            
            this.logger.CreateCommunicationListener(traceId, this.componentName, this.GetType().FullName, this.BuildListeningAddress(this.configurationProvider.Config));
        }
 public static DeployExceptionHandler Create(IDeployEvents callback, IConf appSettings, IServiceLogger logger, ISession session)
 {
     return new DeployExceptionHandler(callback, appSettings, logger, session);
 }
Exemple #37
0
        public void PrepareEnvironment()
        {
            _logger = new ServiceLoggerStub();
            _callback = new CallbackChannelStub();
            _surveyName = "Test" + TestUtils.GetPostfix();
            _surveyPath = "D:\\sss\\" + _surveyName;

            _files = new SendingFiles(1024 * 1024 * 3);
        }
 public static void SetCurrentLogger(IServiceLogger serviceLogger)
 {
     Current = serviceLogger;
 }
 public RabbitBusLoggerAdapter(IServiceLogger logger)
 {
     _logger = logger;
 }
 public IDeployExceptionHandler CreateDeployExHandlerObj(IDeployEvents callback, IConf settings, IServiceLogger logger, ISession session)
 {
     return _exHandlerFactory(callback, settings, logger, session);
 }
 public ServiceExceptionsHandler(string bindingName, IServiceLogger logger)
 {
     _logger = logger;
     BindingName = bindingName;
 }