Inheritance: IInterceptor, IOnBehalfAware
Example #1
0
        /// <summary>
        /// Gets an instance of the specified service.
        /// </summary>
        /// <param name="serviceTemplate">The service template.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>A service instance.</returns>
        internal TService GetService <TService, TServiceSetting>(
            ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config)
            where TServiceSetting : ServiceSettingsBase, new()
            where TService : GoogleAdsServiceClientBase
        {
            Channel     channel     = CreateChannel(config);
            CallInvoker callInvoker = channel.Intercept(
                LoggingInterceptor.GetInstance(config));

            // Build a service context to bind the service, configuration and CallSettings.
            GoogleAdsServiceContext serviceContext = new GoogleAdsServiceContext();

            // Build the call settings.
            CallSettings callSettings = CreateCallSettings <TServiceSetting>(config,
                                                                             serviceContext);

            serviceContext.CallSettings = callSettings;

            // Create the service settings.
            TServiceSetting serviceSettings = CreateServiceSettings <TServiceSetting>(
                serviceContext);

            // Create the service.
            TService service = Create(serviceTemplate, callInvoker, serviceSettings);

            serviceContext.Service = service;
            service.ServiceContext = serviceContext;
            return(service);
        }
Example #2
0
        private static ServiceControl GetFileHandlerService()
        {
            var loggingInterceptor = new LoggingInterceptor(new AspectLogger(LogManager.GetLogger(nameof(AspectLogger))));

            var generator = new ProxyGenerator();

            var settingsProvider = generator.CreateInterfaceProxyWithTarget <ISettingsProvider>(
                new SettingsProvider(),
                loggingInterceptor);

            var nameHelper = generator.CreateInterfaceProxyWithTarget <INameHelper>(
                new FileNameHelper(settingsProvider),
                loggingInterceptor);

            var pdfService = generator.CreateInterfaceProxyWithTarget <IPdfService>(
                new PdfService(settingsProvider, LogManager.GetLogger(nameof(PdfService))),
                loggingInterceptor);

            var watcherFactory = generator.CreateInterfaceProxyWithTarget <IFileHandlerFactory>(
                new FileHandlerFactory(nameHelper, pdfService),
                loggingInterceptor);

            var fileHandlerService = generator.CreateInterfaceProxyWithTarget <ServiceControl>(
                new FileHandlerService(watcherFactory, settingsProvider, LogManager.GetLogger(nameof(FileHandlerService))),
                loggingInterceptor);

            return(fileHandlerService);
        }
        public static TInterface CreateInterfaceLogger <TInterface, TImplementation>(this ILog log, TImplementation instance,
                                                                                     bool logExceptions = true,
                                                                                     OnBeforeExecution onBeforeExecution = null,
                                                                                     OnAfterExecution onAfterExecution   = null)
            where TImplementation : TInterface
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            var interceptor = new LoggingInterceptor(log, logExceptions, onBeforeExecution, onAfterExecution);

            return((TInterface)PG.CreateInterfaceProxyWithTarget(typeof(TInterface), instance, interceptor));
        }
        /// <summary>
        /// Gets an instance of the specified service.
        /// </summary>
        /// <param name="serviceTemplate">The service template.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>A service instance.</returns>
        internal TService GetService <TService, TServiceSetting>(
            ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config)
            where TServiceSetting : ServiceSettingsBase, new()
            where TService : GoogleAdsServiceClientBase
        {
            Channel     channel     = CreateChannel(config);
            CallInvoker callInvoker = channel.Intercept(
                LoggingInterceptor.GetInstance(config));

            GoogleAdsServiceContext serviceContext  = CreateServiceContext(config);
            TServiceSetting         serviceSettings = CreateServiceSettings <TServiceSetting>(
                serviceContext);
            TService service = Create <TService, TServiceSetting>(
                callInvoker, serviceSettings);

            serviceContext.Service = service;
            service.ServiceContext = serviceContext;
            return(service);
        }
Example #5
0
        public void LogNowMethod_StringInput_WritesToLogFile()
        {
            var loggingInterceptor = new LoggingInterceptor();

            loggingInterceptor.LogNow(this.GetType(), "test");
        }
 public static void Create(LoggingInterceptor interceptor)
 {
     LoggingInterceptor = interceptor ?? LoggingInterceptor.Default;
 }