예제 #1
0
파일: Global.asax.cs 프로젝트: bobbinck/wrv
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            var container = ContainerFactory();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // MVC
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); // WebApi

            // JSON formatting
            var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
            json.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
            json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Fix JSON.NET self referencing hell
            json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

            _logger = DependencyResolver.Current.GetService<INLogger>();
            _logger.Info("Application is starting");

            //added for web api - return JSON instead of XML
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {

                // DI
                IKernel _kernal = new StandardKernel();
                _kernal.Bind<INLogger>().To<NLogger>().InSingletonScope();
                _kernal.Bind<IRepo>().To<Repo>().InSingletonScope();
                _kernal.Bind<IOutputHelper>().To<OutputHelper>().InSingletonScope();
                _logger = _kernal.Get<NLogger>();
                _repo = _kernal.Get<Repo>();
                _output = _kernal.Get<OutputHelper>();

                //ValidateRunLengths();
                var duplicates = ValidateIRIAVG();

                var export = new ExcelExport().AddSheet("Duplicates", duplicates.ToArray());
                export.ExportTo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), System.Configuration.ConfigurationManager.AppSettings["excel:exportFileName"].ToString()));
            }
            catch (Exception ex)
            {
                _output.Write(string.Format("Error: {0}", ex.Message), true);
            }
            Console.WriteLine("Done. Press any key to exist.");
            Console.ReadKey();
        }
예제 #3
0
        public void ResponseMessageIsLoggedForSuccessfulResponses()
        {
            // Arrange
            INLogger _logger        = Substitute.For <INLogger>();
            var      configSettings = new Settings {
                RequestCorrelationIdIsRequired = true
            };
            var pipelineHelper = TestSetup.SetupPipelineHelper(configSettings, logger: _logger);

            var responseBody = new JObject();

            responseBody.Add("Batman", "Begins");

            var response = new Nancy.Response()
            {
                StatusCode = Nancy.HttpStatusCode.OK,
                Contents   = stream =>
                {
                    using (var writer = new StreamWriter(stream))
                    {
                        writer.Write(responseBody);
                    }
                }
            };

            // Act
            pipelineHelper.LogAndFormatResponse(response);

            // Assert
            _logger.Received(1).Trace(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>());
            Assert.AreEqual(Nancy.HttpStatusCode.OK, response.StatusCode);
        }
예제 #4
0
 public HomeController(
     UserManager <AppUser> userManager,
     SignInManager <AppUser> signInManager, INLogger nLogger,
     IMapper mapper) : base(userManager)
 {
     _nLogger       = nLogger;
     _signInManager = signInManager;
     _mapper        = mapper;
 }
 public ControlManager(
     INLogger logger,
     IProcessClient processClient,
     IWin32APIClient win32APIClient)
 {
     this.Logger         = logger;
     this.ProcessClient  = processClient;
     this.Win32APIClient = win32APIClient;
 }
예제 #6
0
 public static void LogResponse(this INLogger logger, string message, Error error = null)
 {
     if (error != null)
     {
         logger.Error(error.Message);
     }
     else
     {
         logger.Info(message);
     }
 }
예제 #7
0
 public OHMProvider(INLogger logger)
 {
     this.Logger                    = logger;
     this.Computer                  = new Computer();
     this.Computer.CPUEnabled       = true;
     this.Computer.RAMEnabled       = true;
     this.Computer.HDDEnabled       = true;
     this.Computer.GPUEnabled       = true;
     this.Computer.MainboardEnabled = true;
     this.Computer.Open();
 }
예제 #8
0
        public void ErrorMessageIsLogged()
        {
            // Arrange
            INLogger _logger        = Substitute.For <INLogger>();
            var      pipelineHelper = TestSetup.SetupPipelineHelper(logger: _logger);

            // Act
            pipelineHelper.LogError(new Exception());

            // Assert
            _logger.Received(1).Error(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>());
        }
예제 #9
0
 public SystemMonitorDataBuilder(
     INLogger logger,
     IHardwareStaticBuilder hardwareStaticBuilder,
     IHardwareStaticAnalyzer hardwareStaticAnalyzer,
     IHardwareDynamicBuilder hardwareDynamicBuilder,
     ISoftwareStaticBuilder softwareStaticBuilder,
     ISoftwareDynamicBuilder softwareDynamicBuilder)
 {
     this.Logger = logger;
     this.HardwareStaticBuilder  = hardwareStaticBuilder;
     this.HardwareStaticAnalyzer = hardwareStaticAnalyzer;
     this.HardwareDynamicBuilder = hardwareDynamicBuilder;
     this.SoftwareStaticBuilder  = softwareStaticBuilder;
     this.SoftwareDynamicBuilder = softwareDynamicBuilder;
 }
예제 #10
0
        public void ErrorResponseMessageIsLoggedAndSuppliedErrorCodeReturnedToUser()
        {
            // Arrange
            INLogger _logger        = Substitute.For <INLogger>();
            var      pipelineHelper = TestSetup.SetupPipelineHelper(logger: _logger);

            // Act
            var actual = pipelineHelper.BuildErrorResponse(ErrorCode.CORRELATIONID_REQUIRED.ToString());

            var actualPayload = Utils.ResponseToJObject(actual);

            // Assert
            _logger.Received(1).Trace(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>());
            Assert.AreEqual(1, actualPayload["Errors"].ToList().Count);
            Assert.AreEqual(ErrorCode.CORRELATIONID_REQUIRED.ToString(), actualPayload["Errors"].ToList()[0]["ErrorCode"]);
            Assert.AreEqual("CorrelationId must be passed.", actualPayload["Errors"].ToList()[0]["ErrorMessage"]);
        }
예제 #11
0
        public void ErrorResponseMessageIsLoggedAndErrorDefaultsWhenWnexpectedMessageSupplied()
        {
            // Arrange
            INLogger _logger        = Substitute.For <INLogger>();
            var      pipelineHelper = TestSetup.SetupPipelineHelper(logger: _logger);

            // Act
            var actual = pipelineHelper.BuildErrorResponse("Something went wrong");

            var actualPayload = Utils.ResponseToJObject(actual);

            // Assert
            _logger.Received(1).Trace(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>());
            Assert.AreEqual(1, actualPayload["Errors"].ToList().Count);
            Assert.AreEqual(ErrorCode.UNEXPECTED_ERROR.ToString(), actualPayload["Errors"].ToList()[0]["ErrorCode"]);
            Assert.AreEqual("An unexpected error has occurred. Please try again later.", actualPayload["Errors"].ToList()[0]["ErrorMessage"]);
        }
예제 #12
0
        public void RequestMessageIsLogged()
        {
            // Arrange
            INLogger _logger        = Substitute.For <INLogger>();
            var      pipelineHelper = TestSetup.SetupPipelineHelper(logger: _logger);

            var requestBody = new JObject();

            requestBody.Add("Batman", "Begins");

            var request = Entities.GenerateNancyRequest(body: requestBody);

            // Act
            pipelineHelper.LogRequest(request);

            // Assert
            _logger.Received(1).Trace(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>());
        }
예제 #13
0
        public void ResponseMessageIsLoggedForResponsesContainingErrors()
        {
            // Arrange
            INLogger _logger        = Substitute.For <INLogger>();
            var      configSettings = new Settings {
                RequestCorrelationIdIsRequired = true
            };
            var pipelineHelper = TestSetup.SetupPipelineHelper(configSettings, logger: _logger);

            var responseBody = JsonSerializer.ToJson(new
            {
                Batman = "Begins",
                Errors = new List <object> {
                    new {
                        ErrorCode    = "ErrorCode",
                        ErrorMessage = "ErrorMessage"
                    }
                }
            });

            var response = new Nancy.Response()
            {
                StatusCode = Nancy.HttpStatusCode.OK,
                Contents   = stream =>
                {
                    using (var writer = new StreamWriter(stream))
                    {
                        writer.Write(responseBody);
                    }
                }
            };

            // Act
            pipelineHelper.LogAndFormatResponse(response);

            // Assert
            _logger.Received(1).Trace(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>());
            Assert.AreEqual(Nancy.HttpStatusCode.BadRequest, response.StatusCode);
        }
예제 #14
0
 public StoryController(IMediator mediator, INLogger logger) : base(mediator, logger)
 {
 }
예제 #15
0
 public WMIClient(INLogger logger)
 {
     this.Logger = logger;
 }
예제 #16
0
 public OutputHelper(INLogger logger)
 {
     this._logger = logger;
 }
예제 #17
0
 public FriendController(IMediator mediator, INLogger logger) : base(mediator, logger)
 {
 }
예제 #18
0
 public AdminController(IMediator mediator, INLogger logger) : base(mediator, logger)
 {
 }
예제 #19
0
 public BaseApiController(INLogger logger)
 {
     this._logger = logger;
 }
 public PipelineHelper(IConfigurationManager configuration, INLoggerFactory loggerFactory, ICorrelationId correlationId)
 {
     _configuration = configuration;
     _logger        = loggerFactory.CreateLogger <Bootstrapper>();
     _correlationId = correlationId;
 }
예제 #21
0
 public DatabaseManager(IRolesService rolesService, INLogger logger)
 {
     this.rolesService = rolesService;
     this.logger       = logger;
 }
예제 #22
0
 public ConnectionController(IMediator mediator, INLogger logger) : base(mediator, logger)
 {
 }
예제 #23
0
 public GuestsController(INLogger logger, IGuestRepository guestRepository)
     : base(logger)
 {
     _guestRepository = guestRepository;
 }
예제 #24
0
        public static PipelineHelper SetupPipelineHelper(Settings settingsMock = null, INLogger logger = null, IConfigurationManager configurationManager = null, ICorrelationId correlationId = null)
        {
            Nancy.Json.JsonSettings.RetainCasing = true;

            configurationManager = configurationManager != null ? configurationManager : Substitute.For <IConfigurationManager>();
            logger        = logger != null ? logger : Substitute.For <INLogger>();
            correlationId = correlationId != null ? correlationId : Substitute.For <ICorrelationId>();

            settingsMock = settingsMock != null ? settingsMock : Entities.GetSettingsMockData();

            logger.When(x => x.Trace(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>())).DoNotCallBase();
            logger.When(x => x.Error(Arg.Any <string>(), Arg.Any <Exception>(), Arg.Any <Guid>())).DoNotCallBase();

            configurationManager.Instance.Returns(settingsMock);

            return(new PipelineHelper(configurationManager, logger, correlationId));
        }
예제 #25
0
 public GroupManagerController(IMediator mediator, INLogger logger) : base(mediator, logger)
 {
 }
예제 #26
0
 public MessengerController(IMediator mediator, INLogger logger)
 {
     this.mediator = mediator;
     this.logger   = logger;
 }
예제 #27
0
 public HomeController(INLogger logger)
 {
     this.logger = logger;
 }
예제 #28
0
 public CommentController(IMediator mediator, INLogger logger) : base(mediator, logger)
 {
 }
 public PipelineHelper(IConfigurationManager configuration, INLogger logger, ICorrelationId correlationId)
 {
     _configuration = configuration;
     _logger        = logger;
     _correlationId = correlationId;
 }
예제 #30
0
 public DataLoadController(INLogger logger, IDataLoadRepository repo) : base(logger)
 {
     this._repo = repo;
 }
예제 #31
0
 public LogsHostedService(INLogger logger, IServiceProvider services) : base(logger, services)
 {
     TimeInterval = Constants.ServerHostedServiceTimeInMinutes;
 }
예제 #32
0
 public HomeController(INLogger logger)
 {
     this.logger = logger;
 }
 public SoftwareDynamicProvider(INLogger logger, IWin32APIClient win32APIClient)
 {
     this.Logger         = logger;
     this.Win32APIClient = win32APIClient;
 }
예제 #34
0
 public SocialController(IMediator mediator, INLogger logger)
 {
     this.mediator = mediator;
     this.logger   = logger;
 }
예제 #35
0
 public ApiBaseController(INLogger logger)
 {
     Logger = logger;
 }
예제 #36
0
 public Builder Logger(INLogger logger)
 {
     client.Logger           = logger;
     client.transport.Logger = logger;
     return(this);
 }