Пример #1
0
        private static void RegisterFileAppender(IApplicationConstants constants)
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayout
            {
                ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
            };

            patternLayout.ActivateOptions();

            var fileAppender = new RollingFileAppender
            {
                AppendToFile       = false,
                File               = constants.LogFile,
                Layout             = patternLayout,
                MaxSizeRollBackups = 3,
                MaximumFileSize    = "1GB",
                RollingStyle       = RollingFileAppender.RollingMode.Size,
                StaticLogFileName  = false
            };

            fileAppender.ActivateOptions();
            hierarchy.Root.AddAppender(fileAppender);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetPaginatedQueryValidator{T}"/> class.
        /// </summary>
        /// <param name="constants">The application constants.</param>
        public GetPaginatedQueryValidator(IApplicationConstants constants)
        {
            Ensure.ArgumentNotNull(constants, nameof(constants));

            RuleFor(x => x.Page).NotNull().GreaterThanOrEqualTo(0);
            RuleFor(x => x.Limit).NotEmpty().GreaterThan(0).In(constants.AllowedPaginationLimitValues);
        }
Пример #3
0
        public LoggingPermissions(IApplicationConstants appConstants, ITelemetryService telemetryService, IRegistry registry) {
            _appConstants = appConstants;
            _telemetryService = telemetryService;
            _registry = registry;

            _registryVerbosity = GetLogLevelFromRegistry();
            _registryFeedbackSetting = GetFeedbackFromRegistry();
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UserStore{TUser}"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="constants">The application constants.</param>
        /// <param name="idGenerator">The generator for unique identifiers.</param>
        public UserStore(IAmiUnitOfWork context, IApplicationConstants constants, IIdGenerator idGenerator)
        {
            this.context     = context ?? throw new ArgumentNullException(nameof(context));
            this.constants   = constants ?? throw new ArgumentNullException(nameof(constants));
            this.idGenerator = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator));

            repository = context.UserRepository as IRepository <TUser>;
        }
Пример #5
0
        public LoggingPermissions(IApplicationConstants appConstants, ITelemetryService telemetryService, [Import(AllowDefault = true)] IRegistry registry)
        {
            _appConstants     = appConstants;
            _telemetryService = telemetryService;
            _registry         = registry ?? new RegistryImpl();

            _registryVerbosity       = GetLogLevelFromRegistry();
            _registryFeedbackSetting = GetFeedbackFromRegistry();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SqliteDbContext"/> class.
 /// </summary>
 /// <param name="options">The database context options.</param>
 /// <param name="configuration">The application configuration.</param>
 /// <param name="constants">The application constants.</param>
 public SqliteDbContext(
     DbContextOptions <SqliteDbContext> options,
     IAppConfiguration configuration,
     IApplicationConstants constants)
     : base(options)
 {
     this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     this.constants     = constants ?? throw new ArgumentNullException(nameof(constants));
 }
Пример #7
0
 /// <summary>
 /// Initializes log4net to log to both a file as well as to the console.
 /// </summary>
 /// <param name="constants"></param>
 /// <param name="args"></param>
 /// <param name="logToConsole"></param>
 public static void Setup(IApplicationConstants constants, string[] args, bool logToConsole = false)
 {
     RegisterFileAppender(constants);
     LogHeader(Constants.Distributor, args);
     if (logToConsole)
     {
         RegisterConsoleAppender();
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetPaginatedQueryValidator{T}"/> class.
        /// </summary>
        /// <param name="constants">The application constants.</param>
        public GetPaginatedQueryValidator(IApplicationConstants constants)
        {
            if (constants == null)
            {
                throw new ArgumentNullException(nameof(constants));
            }

            RuleFor(x => x.Page).NotEmpty().GreaterThan(0);
            RuleFor(x => x.Limit).NotEmpty().GreaterThan(0).In(constants.AllowedPaginationLimitValues);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class.
 /// </summary>
 /// <param name="module">The command handler module.</param>
 /// <param name="idGenerator">The generator for unique identifiers.</param>
 /// <param name="constants">The application constants.</param>
 /// <param name="apiConfiguration">The API configuration.</param>
 public CreateCommandHandler(
     ICommandHandlerModule module,
     IIdGenerator idGenerator,
     IApplicationConstants constants,
     IApiConfiguration apiConfiguration)
     : base(module)
 {
     this.idGenerator      = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator));
     this.constants        = constants ?? throw new ArgumentNullException(nameof(constants));
     this.apiConfiguration = apiConfiguration ?? throw new ArgumentNullException(nameof(apiConfiguration));
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AppLogReader"/> class.
 /// </summary>
 /// <param name="configuration">The application configuration.</param>
 /// <param name="constants">The application constants.</param>
 /// <param name="fileSystemStrategy">The file system strategy.</param>
 /// <param name="serializer">The JSON serializer.</param>
 public AppLogReader(
     IAppConfiguration configuration,
     IApplicationConstants constants,
     IFileSystemStrategy fileSystemStrategy,
     IDefaultJsonSerializer serializer)
 {
     this.configuration      = configuration ?? throw new ArgumentNullException(nameof(configuration));
     this.constants          = constants ?? throw new ArgumentNullException(nameof(constants));
     this.fileSystemStrategy = fileSystemStrategy ?? throw new ArgumentNullException(nameof(fileSystemStrategy));
     this.serializer         = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GatewayService"/> class.
 /// </summary>
 /// <param name="builder">The builder for gateway group names.</param>
 /// <param name="context">The context.</param>
 /// <param name="constants">The application constants.</param>
 /// <param name="gatewayObserverService">The gateway observer service.</param>
 public GatewayService(
     IGatewayGroupNameBuilder builder,
     IAmiUnitOfWork context,
     IApplicationConstants constants,
     IGatewayObserverService gatewayObserverService)
 {
     Builder        = builder ?? throw new ArgumentNullException(nameof(builder));
     this.context   = context ?? throw new ArgumentNullException(nameof(context));
     this.constants = constants ?? throw new ArgumentNullException(nameof(constants));
     this.gatewayObserverService = gatewayObserverService ?? throw new ArgumentNullException(nameof(gatewayObserverService));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryHandlerModule"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="constants">The application constants.</param>
 /// <param name="principalProvider">The principal provider.</param>
 /// <param name="serializer">The JSON serializer.</param>
 public QueryHandlerModule(
     IAmiUnitOfWork context,
     IApplicationConstants constants,
     ICustomPrincipalProvider principalProvider,
     IDefaultJsonSerializer serializer)
 {
     Context           = context ?? throw new ArgumentNullException(nameof(context));
     Constants         = constants ?? throw new ArgumentNullException(nameof(constants));
     PrincipalProvider = principalProvider ?? throw new ArgumentNullException(nameof(principalProvider));
     Serializer        = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
Пример #13
0
        public LoggingPermissions(IApplicationConstants appConstants, ITelemetryService telemetryService, IRegistry registry)
        {
            _appConstants     = appConstants;
            _telemetryService = telemetryService;
            _registry         = registry;

            _registryVerbosity       = GetLogLevelFromRegistry();
            _registryFeedbackSetting = GetFeedbackFromRegistry();

            // Default value for CurrentVerbosity should match default value in IRSettings.
            // https://github.com/Microsoft/RTVS/issues/2705
            CurrentVerbosity = LogVerbosity.Normal;
        }
Пример #14
0
        static Constants()
        {
            FrameworkTitle     = "DPloy";
            AppDataLocalFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), FrameworkTitle);

            var assembly = Assembly.GetExecutingAssembly();
            var name     = assembly.GetName();

            FrameworkVersion = name.Version;

            Node        = new ApplicationConstants(AppDataLocalFolder, "Node");
            Distributor = new ApplicationConstants(AppDataLocalFolder, "Distributor");
        }
Пример #15
0
        public VsAppShell(ITelemetryService telemetryService
                          , IRSettings settings
                          , ICoreServices coreServices
                          , IApplicationConstants appConstants)
        {
            _coreServices  = coreServices;
            AppConstants   = appConstants;
            ProgressDialog = new VsProgressDialog(this);
            FileDialog     = new VsFileDialog(this);

            _settings = settings;
            _settings.PropertyChanged += OnSettingsChanged;
        }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityPrincipal"/> class.
        /// </summary>
        /// <param name="entity">The user entity.</param>
        /// <param name="constants">The application constants.</param>
        public EntityPrincipal(UserEntity entity, IApplicationConstants constants)
        {
            Ensure.ArgumentNotNull(entity, nameof(entity));
            Ensure.ArgumentNotNull(constants, nameof(constants));

            Identity = new CustomIdentity()
            {
                Name = entity.Id.ToString()
            };

            roles = string.IsNullOrWhiteSpace(entity.Roles) ?
                    new HashSet <string>() :
                    new HashSet <string>(entity.Roles.Replace(constants.ValueSeparator, string.Empty).Split(','));
        }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkedObjectUploader" /> class.
        /// </summary>
        /// <param name="mediator">The mediator.</param>
        /// <param name="constants">The application constants.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="fileSystemStrategy">The file system strategy.</param>
        public ChunkedObjectUploader(
            IMediator mediator,
            IApplicationConstants constants,
            IAppConfiguration configuration,
            IFileSystemStrategy fileSystemStrategy)
        {
            this.mediator      = mediator ?? throw new ArgumentNullException(nameof(mediator));
            this.constants     = constants ?? throw new ArgumentNullException(nameof(constants));
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            Ensure.ArgumentNotNull(fileSystemStrategy, nameof(fileSystemStrategy));

            fileSystem     = fileSystemStrategy.Create(configuration.Options.WorkingDirectory);
            baseUploadPath = fileSystem.Path.Combine(configuration.Options.WorkingDirectory, "Upload", "Objects");
        }
Пример #18
0
        private static void LogEnvironment(IApplicationConstants constants)
        {
            var builder = new StringBuilder();

            builder.AppendLine();
            builder.AppendFormat("{0} {1}: v{2}, {3}\r\n",
                                 Constants.FrameworkTitle, constants.Title,
                                 FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductVersion,
                                 Environment.Is64BitProcess ? "64bit" : "32bit");
            builder.AppendFormat(".NET Environment: {0}\r\n", Environment.Version);
            builder.AppendFormat("Operating System: {0}, {1}\r\n",
                                 Environment.OSVersion,
                                 Environment.Is64BitOperatingSystem ? "64bit" : "32bit");
            builder.AppendFormat("Current directory: {0}", Directory.GetCurrentDirectory());

            Log.InfoFormat("Environment: {0}", builder);
        }
Пример #19
0
        public CoreServices(IApplicationConstants appConstants
            , ITelemetryService telemetry
            , ITaskService tasks
            , IMainThread mainThread
            , ISecurityService security) {
            Telemetry = telemetry;
            Registry = new RegistryImpl();
            Security = security;
            LoggingServices = new LoggingServices(new LoggingPermissions(appConstants, telemetry, Registry), appConstants);
            Tasks = tasks;

            ProcessServices = new ProcessServices();
            FileSystem = new FileSystem();
            MainThread = mainThread;

            Log = LoggingServices.GetOrCreateLog(appConstants.ApplicationName);
        }
Пример #20
0
        public CoreServices(IApplicationConstants appConstants
                            , ITelemetryService telemetry
                            , ITaskService tasks
                            , IMainThread mainThread
                            , ISecurityService security)
        {
            Registry           = new RegistryImpl();
            LoggingPermissions = new LoggingPermissions(appConstants, telemetry, Registry);
            Telemetry          = telemetry;
            Security           = security;
            Tasks = tasks;

            ProcessServices = new ProcessServices();
            FileSystem      = new FileSystem();
            MainThread      = mainThread;

            Log = new Logger(appConstants.ApplicationName, Path.GetTempPath(), LoggingPermissions);
        }
Пример #21
0
        /// <summary>
        /// Creates a model based on the given domain entity.
        /// </summary>
        /// <param name="entity">The domain entity.</param>
        /// <param name="constants">The application constants.</param>
        /// <returns>The domain entity as a model.</returns>
        public static WebhookModel Create(WebhookEntity entity, IApplicationConstants constants)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new WebhookModel
            {
                Id = entity.Id.ToString(),
                CreatedDate = entity.CreatedDate,
                ModifiedDate = entity.ModifiedDate,
                Url = entity.Url,
                ApiVersion = entity.ApiVersion,
                EnabledEvents = string.IsNullOrWhiteSpace(entity.EnabledEvents) ?
                                Array.Empty <string>() : entity.EnabledEvents.Replace(constants.ValueSeparator, string.Empty).Split(','),
                UserId = entity.UserId
            });
        }
Пример #22
0
        /// <summary>
        /// Creates a model based on the given domain entity.
        /// </summary>
        /// <param name="entity">The domain entity.</param>
        /// <param name="constants">The application constants.</param>
        /// <returns>The domain entity as a model.</returns>
        public static UserModel Create(UserEntity entity, IApplicationConstants constants)
        {
            if (entity == null || constants == null)
            {
                return(null);
            }

            var model = new UserModel
            {
                Id             = entity.Id.ToString(),
                Username       = entity.Username,
                Email          = entity.Email,
                EmailConfirmed = entity.EmailConfirmed,
                Roles          = string.IsNullOrWhiteSpace(entity.Roles) ?
                                 Array.Empty <string>() : entity.Roles.Replace(constants.ValueSeparator, string.Empty).Split(',')
            };

            return(model);
        }
Пример #23
0
        public CoreServices(IApplicationConstants appConstants
                            , ITelemetryService telemetry
                            , ITaskService tasks
                            , IProcessServices processServices
                            , ILoggingPermissions loggingPermissions
                            , IMainThread mainThread
                            , ISecurityService security)
        {
            LoggingPermissions = loggingPermissions;
            Telemetry          = telemetry;
            Security           = security;
            Tasks = tasks;

            ProcessServices = processServices;
            FileSystem      = new FileSystem();
            MainThread      = mainThread;

            Log = new Logger(appConstants.ApplicationName, Path.GetTempPath(), LoggingPermissions);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="idGenService">The service to generate unique identifiers.</param>
        /// <param name="constants">The application constants.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="fileSystemStrategy">The file system strategy.</param>
        public CreateCommandHandler(
            IAmiUnitOfWork context,
            IIdGenService idGenService,
            IApplicationConstants constants,
            IAmiConfigurationManager configuration,
            IFileSystemStrategy fileSystemStrategy)
            : base()
        {
            this.context       = context ?? throw new ArgumentNullException(nameof(context));
            this.idGenService  = idGenService ?? throw new ArgumentNullException(nameof(idGenService));
            this.constants     = constants ?? throw new ArgumentNullException(nameof(constants));
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            if (fileSystemStrategy == null)
            {
                throw new ArgumentNullException(nameof(fileSystemStrategy));
            }

            fileSystem = fileSystemStrategy.Create(configuration.WorkingDirectory);
        }
Пример #25
0
        public CoreServices(
            IApplicationConstants appConstants
            , ITelemetryService telemetry
            , ILoggingPermissions permissions
            , ISecurityService security
            , [Import(AllowDefault = true)] IActionLog log      = null
            , [Import(AllowDefault = true)] IFileSystem fs      = null
            , [Import(AllowDefault = true)] IRegistry registry  = null
            , [Import(AllowDefault = true)] IProcessServices ps = null)
        {
            LoggingServices = new LoggingServices(permissions, appConstants);
            _appConstants   = appConstants;
            _log            = log;

            Telemetry       = telemetry;
            Security        = security;
            ProcessServices = ps ?? new ProcessServices();
            Registry        = registry ?? new RegistryImpl();
            FileSystem      = fs ?? new FileSystem();
        }
Пример #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class.
        /// </summary>
        /// <param name="module">The command handler module.</param>
        /// <param name="idGenerator">The generator for unique identifiers.</param>
        /// <param name="constants">The application constants.</param>
        /// <param name="apiConfiguration">The API configuration.</param>
        /// <param name="appConfiguration">The application configuration.</param>
        /// <param name="fileSystemStrategy">The file system strategy.</param>
        public CreateCommandHandler(
            ICommandHandlerModule module,
            IIdGenerator idGenerator,
            IApplicationConstants constants,
            IApiConfiguration apiConfiguration,
            IAppConfiguration appConfiguration,
            IFileSystemStrategy fileSystemStrategy)
            : base(module)
        {
            this.idGenerator      = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator));
            this.constants        = constants ?? throw new ArgumentNullException(nameof(constants));
            this.apiConfiguration = apiConfiguration ?? throw new ArgumentNullException(nameof(apiConfiguration));
            this.appConfiguration = appConfiguration ?? throw new ArgumentNullException(nameof(appConfiguration));

            if (fileSystemStrategy == null)
            {
                throw new ArgumentNullException(nameof(fileSystemStrategy));
            }

            fileSystem = fileSystemStrategy.Create(appConfiguration.Options.WorkingDirectory);
        }
Пример #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TokenService"/> class.
        /// </summary>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="configuration">The API configuration.</param>
        /// <param name="constants">The application constants.</param>
        /// <param name="mediator">The mediator.</param>
        /// <param name="serializer">The serializer.</param>
        /// <param name="userManager">The user manager.</param>
        public TokenService(
            ILoggerFactory loggerFactory,
            IApiConfiguration configuration,
            IApplicationConstants constants,
            IMediator mediator,
            IDefaultJsonSerializer serializer,
            UserManager <UserEntity> userManager)
        {
            logger             = loggerFactory?.CreateLogger <TokenService>() ?? throw new ArgumentNullException(nameof(loggerFactory));
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this.constants     = constants ?? throw new ArgumentNullException(nameof(constants));
            this.mediator      = mediator ?? throw new ArgumentNullException(nameof(mediator));
            this.userManager   = userManager ?? throw new ArgumentNullException(nameof(userManager));
            this.serializer    = serializer ?? throw new ArgumentNullException(nameof(serializer));
            var serializerWrapper = new JwtJsonSerializerWrapper(serializer);
            var urlEncoder        = new JwtBase64UrlEncoder();

            encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializerWrapper, urlEncoder);
            var validator = new JwtValidator(serializerWrapper, new UtcDateTimeProvider());

            decoder = new JwtDecoder(serializerWrapper, validator, urlEncoder);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkedObjectUploader" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="fileSystemStrategy">The file system strategy.</param>
        /// <param name="constants">The application constants.</param>
        /// <param name="mediator">The mediator.</param>
        /// <exception cref="ArgumentNullException">
        /// configuration
        /// or
        /// fileSystemStrategy
        /// or
        /// objectService
        /// </exception>
        public ChunkedObjectUploader(
            IAmiConfigurationManager configuration,
            IFileSystemStrategy fileSystemStrategy,
            IApplicationConstants constants,
            IMediator mediator)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (fileSystemStrategy == null)
            {
                throw new ArgumentNullException(nameof(fileSystemStrategy));
            }

            fileSystem     = fileSystemStrategy.Create(configuration.WorkingDirectory);
            baseUploadPath = fileSystem.Path.Combine(configuration.WorkingDirectory, "Upload", "Objects");

            this.constants = constants ?? throw new ArgumentNullException(nameof(constants));
            this.mediator  = mediator ?? throw new ArgumentNullException(nameof(mediator));
        }
Пример #29
0
        public CoreServices(IApplicationConstants appConstants
            , ITelemetryService telemetry
            , ILoggingPermissions permissions
            , ISecurityService security
            , ITaskService tasks
            , IMainThread mainThread
            , IActionLog log
            , IFileSystem fs
            , IRegistry registry
            , IProcessServices ps) {

            LoggingServices = new LoggingServices(permissions, appConstants);
            Log = log;

            Telemetry = telemetry;
            Security = security;
            Tasks = tasks;

            ProcessServices = ps;
            Registry = registry;
            FileSystem = fs;
            MainThread = mainThread;
        }
Пример #30
0
 public LoggingServices(ILoggingPermissions permissions, IApplicationConstants appConstants) {
     Permissions = permissions;
     _appConstants = appConstants;
 }
Пример #31
0
 private static void LogHeader(IApplicationConstants constants, string[] args)
 {
     Log.InfoFormat("Starting {0} {1}...", Constants.FrameworkTitle, constants.Title);
     Log.InfoFormat("Commandline arguments: {0}", string.Join(" ", args));
     LogEnvironment(constants);
 }
Пример #32
0
 public LoggingServices(ILoggingPermissions permissions, IApplicationConstants appConstants)
 {
     Permissions   = permissions;
     _appConstants = appConstants;
 }
        /// <summary>
        /// Writes log events to SQLite.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="options">The application options.</param>
        /// <param name="constants">The application constants.</param>
        public static void WriteToSqlite(this LoggerConfiguration loggerConfiguration, IAppOptions options, IApplicationConstants constants)
        {
            Ensure.ArgumentNotNull(loggerConfiguration, nameof(loggerConfiguration));
            Ensure.ArgumentNotNull(options, nameof(options));
            Ensure.ArgumentNotNull(constants, nameof(constants));

            if (string.IsNullOrWhiteSpace(options.WorkingDirectory))
            {
                throw new UnexpectedNullException("Working directory is not defined.");
            }

            // loggerConfiguration.WriteTo.SQLite(
            //    sqliteDbPath: Path.Combine(options.WorkingDirectory, constants.SqliteLogDatabaseName),
            //    tableName: "ApplicationLogs",
            //    storeTimestampInUtc: true,
            //    formatProvider: CultureInfo.InvariantCulture);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetPaginatedQueryValidator" /> class.
 /// </summary>
 /// <param name="constants">The application constants.</param>
 public GetPaginatedQueryValidator(IApplicationConstants constants)
     : base(constants)
 {
 }