public GetRecordVoteListHelper(TelemetryClient telemetryClient, string storageAccount, string rpcClient, MongoDBConnectionInfo dbConnectionInfo) { this.telemetryClient = telemetryClient; this.STORAGE_ACCOUNT = storageAccount; this.RPC_CLIENT = rpcClient; this.DBCONNECTION_INFO = dbConnectionInfo; }
public static MongoDBConnectionInfo GetMongoDbConnectionInfo() { MongoDBConnectionInfo mongoDbConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.COSMOSDB_CONNECTIONSTRING, DatabaseId = Settings.COSMOSDB_DATABASEID, ContactAccountCollection = Settings.COSMOSDB_CONTACTINFOACCOUNTCOLLECTION }; return(mongoDbConnectionInfo); }
public static MongoDBConnectionInfo GetMongoDbConnectionInfo() { MongoDBConnectionInfo mongoDbConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.MongoDBConnectionString, DatabaseId = Settings.MongoDBDatabaseId, PersonCollection = Settings.PersonCollection }; return(mongoDbConnectionInfo); }
private static void Init() { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); Console.WriteLine($"Environment: {environment}"); var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.{environment}.json", true, true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections ApplicationSettings.ConnectionString = Configuration.GetSection("ApplicationSettings:ConnectionString")?.Value; ApplicationSettings.DatabaseId = Configuration.GetSection("ApplicationSettings:DatabaseId")?.Value; ApplicationSettings.UserCollection = Configuration.GetSection("ApplicationSettings:UserCollection")?.Value; ApplicationSettings.RabbitMQUsername = Configuration.GetSection("ApplicationSettings:RabbitMQUsername")?.Value; ApplicationSettings.RabbitMQPassword = Configuration.GetSection("ApplicationSettings:RabbitMQPassword")?.Value; ApplicationSettings.RabbitMQHostname = Configuration.GetSection("ApplicationSettings:RabbitMQHostname")?.Value; ApplicationSettings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("ApplicationSettings:RabbitMQPort")?.Value); ApplicationSettings.UserRegistrationQueueName = Configuration.GetSection("ApplicationSettings:UserRegistrationQueueName")?.Value; ApplicationSettings.KeyVaultCertificateName = Configuration.GetSection("ApplicationSettings:KeyVaultCertificateName")?.Value; ApplicationSettings.KeyVaultClientId = Configuration.GetSection("ApplicationSettings:KeyVaultClientId")?.Value; ApplicationSettings.KeyVaultClientSecret = Configuration.GetSection("ApplicationSettings:KeyVaultClientSecret")?.Value; ApplicationSettings.KeyVaultIdentifier = Configuration.GetSection("ApplicationSettings:KeyVaultIdentifier")?.Value; ApplicationSettings.KeyVaultEncryptionKey = Configuration.GetSection("ApplicationSettings:KeyVaultEncryptionKey")?.Value; ApplicationSettings.SendGridAPIKey = Configuration.GetSection("ApplicationSettings:SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = ApplicationSettings.ConnectionString, DatabaseId = ApplicationSettings.DatabaseId, UserCollection = ApplicationSettings.UserCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = ApplicationSettings.KeyVaultCertificateName, ClientId = ApplicationSettings.KeyVaultClientId, ClientSecret = ApplicationSettings.KeyVaultClientSecret, KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(ApplicationSettings.KeyVaultEncryptionKey).Result; } using (BlockchainHelper blockchainHelper = new BlockchainHelper()) { wordlist = blockchainHelper.ReadMnemonic(); } }
public static MongoDBConnectionInfo GetMongoDbConnectionInfo() { MongoDBConnectionInfo mongoDbConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.COSMOSDB_CONNECTIONSTRING, DatabaseId = Settings.COSMOSDB_DATABASEID, UserAccountCollection = Settings.COSMOSDB_USERACCOUNTCOLLECTION, RecordItemCollection = Settings.COSMOSDB_RECORDITEMCOLLECTION, RecordVoteCollection = Settings.COSMOSDB_RECORDVOTECOLLECTION, }; return(mongoDbConnectionInfo); }
private static void Init() { var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections Settings.ConnectionString = Configuration.GetSection("ConnectionString")?.Value; Settings.DatabaseId = Configuration.GetSection("DatabaseId")?.Value; Settings.UserCollection = Configuration.GetSection("UserCollection")?.Value; Settings.RabbitMQUsername = Configuration.GetSection("RabbitMQUsername")?.Value; Settings.RabbitMQPassword = Configuration.GetSection("RabbitMQPassword")?.Value; Settings.RabbitMQHostname = Configuration.GetSection("RabbitMQHostname")?.Value; Settings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("RabbitMQPort")?.Value); Settings.UserRegistrationQueueName = Configuration.GetSection("UserRegistrationQueueName")?.Value; Settings.KeyVaultCertificateName = Configuration.GetSection("KeyVaultCertificateName")?.Value; Settings.KeyVaultClientId = Configuration.GetSection("KeyVaultClientId")?.Value; Settings.KeyVaultClientSecret = Configuration.GetSection("KeyVaultClientSecret")?.Value; Settings.KeyVaultIdentifier = Configuration.GetSection("KeyVaultIdentifier")?.Value; Settings.KeyVaultEncryptionKey = Configuration.GetSection("KeyVaultEncryptionKey")?.Value; Settings.SendGridAPIKey = Configuration.GetSection("SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.ConnectionString, DatabaseId = Settings.DatabaseId, UserCollection = Settings.UserCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = Settings.KeyVaultCertificateName, ClientId = Settings.KeyVaultClientId, ClientSecret = Settings.KeyVaultClientSecret, KeyVaultIdentifier = Settings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(Settings.KeyVaultEncryptionKey).Result; } using (BlockchainHelper blockchainHelper = new BlockchainHelper()) { wordlist = blockchainHelper.ReadMnemonic(); } }
private static void Init() { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("secrets/appsettings.secrets.json", optional: true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections ApplicationSettings.ConnectionString = Configuration.GetSection("ApplicationSettings:ConnectionString")?.Value; ApplicationSettings.DatabaseId = Configuration.GetSection("ApplicationSettings:DatabaseId")?.Value; ApplicationSettings.ReportCollection = Configuration.GetSection("ApplicationSettings:ReportCollection")?.Value; ApplicationSettings.RabbitMQUsername = Configuration.GetSection("ApplicationSettings:RabbitMQUsername")?.Value; ApplicationSettings.RabbitMQPassword = Configuration.GetSection("ApplicationSettings:RabbitMQPassword")?.Value; ApplicationSettings.RabbitMQHostname = Configuration.GetSection("ApplicationSettings:RabbitMQHostname")?.Value; ApplicationSettings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("ApplicationSettings:RabbitMQPort")?.Value); ApplicationSettings.DispatchQueueName = Configuration.GetSection("ApplicationSettings:DispatchQueueName")?.Value; ApplicationSettings.KeyVaultCertificateName = Configuration.GetSection("ApplicationSettings:KeyVaultCertificateName")?.Value; ApplicationSettings.KeyVaultClientId = Configuration.GetSection("ApplicationSettings:KeyVaultClientId")?.Value; ApplicationSettings.KeyVaultClientSecret = Configuration.GetSection("ApplicationSettings:KeyVaultClientSecret")?.Value; ApplicationSettings.KeyVaultIdentifier = Configuration.GetSection("ApplicationSettings:KeyVaultIdentifier")?.Value; ApplicationSettings.KeyVaultEncryptionKey = Configuration.GetSection("ApplicationSettings:KeyVaultEncryptionKey")?.Value; ApplicationSettings.SendGridAPIKey = Configuration.GetSection("ApplicationSettings:SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = ApplicationSettings.ConnectionString, DatabaseId = ApplicationSettings.DatabaseId, UserCollection = ApplicationSettings.ReportCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = ApplicationSettings.KeyVaultCertificateName, ClientId = ApplicationSettings.KeyVaultClientId, ClientSecret = ApplicationSettings.KeyVaultClientSecret, KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(ApplicationSettings.KeyVaultEncryptionKey).Result; } pdfTools = new PdfTools(); converter = new SynchronizedConverter(pdfTools); }
public MongoDBHelper(MongoDBConnectionInfo mongoDBConnectionInfo) : base(mongoDBConnectionInfo) { }
public DBBaseHelper(MongoDBConnectionInfo databaseInfo) { this.databaseInfo = databaseInfo; }
public DBUserAccountHelper(MongoDBConnectionInfo databaseInfo) : base(databaseInfo) { collection = GetMongoDatabase().GetCollection<UserAccount>(GetMongoDBConnectionInfo().UserAccountCollection); }
public DBBaseHelper(MongoDBConnectionInfo mongoDBConnectionInfo) { this.mongoDBConnectionInfo = mongoDBConnectionInfo; }
public UserRegistrationDataHelper(MongoDBConnectionInfo databaseInfo) : base(databaseInfo) { }
public IActionResult Post([FromBody] UserAuthenticationRequest model) { // non-forced-to-disposal string response = string.Empty; UserAuthenticationResult result = new UserAuthenticationResult { IsSucceded = true, ResultId = (int)UserAuthenticationResultEnum.Success }; // forced-to-disposal MongoDBConnectionInfo mongoDBConnectionInfo = null; SymmetricSecurityKey secretKey = null; SigningCredentials signinCredentials = null; User user = null; try { if (string.IsNullOrEmpty(model.Email)) { throw new BusinessException((int)UserAuthenticationResultEnum.FailedEmptyEmail); } if (string.IsNullOrEmpty(model.Password)) { throw new BusinessException((int)UserAuthenticationResultEnum.FailedEmptyPassword); } mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.ConnectionString, DatabaseId = Settings.DatabaseId, UserCollection = Settings.UserCollection }; using (UserAuthenticationDataHelper userAuthenticationDataHelper = new UserAuthenticationDataHelper(mongoDBConnectionInfo)) { user = userAuthenticationDataHelper.GetUser(model.Email); } if (user == null) { throw new BusinessException((int)UserAuthenticationResultEnum.FailedNotExistsInactiveAccount); } string password = string.Empty; using (HashHelper hh = new HashHelper()) { password = hh.GetSha256Hash(model.Password); } if (user.email != model.Email || user.password != password) { throw new BusinessException((int)UserAuthenticationResultEnum.FailedIncorrectCredentials); } secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Settings.AuthorizationKey)); signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var tokeOptions = new JwtSecurityToken( issuer: "https://rf.identity.api", audience: "https://rf.identity.api", claims: new List <Claim>(), expires: DateTime.Now.AddDays(1), signingCredentials: signinCredentials ); response = new JwtSecurityTokenHandler().WriteToken(tokeOptions); } catch (Exception ex) { result.IsSucceded = false; if (ex is BusinessException) { result.ResultId = ((BusinessException)ex).ResultId; } else { result.ResultId = (int)UserAuthenticationResultEnum.Failed; this.logger.LogError($">> Exception: {ex.Message}, StackTrace: {ex.StackTrace}"); if (ex.InnerException != null) { this.logger.LogError($">> Inner Exception Message: {ex.InnerException.Message}, Inner Exception StackTrace: {ex.InnerException.StackTrace}"); } } } finally { mongoDBConnectionInfo = null; secretKey = null; signinCredentials = null; user = null; GC.Collect(); } string message = EnumDescription.GetEnumDescription((UserAuthenticationResultEnum)result.ResultId); this.logger.LogInformation($">> Message information: {message}"); return((result.IsSucceded) ? (ActionResult) new OkObjectResult(new { token = response }) : (ActionResult) new BadRequestObjectResult(new { message = message })); }
public ContractDeploymentDataHelper(MongoDBConnectionInfo databaseInfo) : base(databaseInfo) { }
public async Task <IActionResult> Post([FromBody] UserRegistrationRequest model) { // non-forced-to-disposal UserRegistrationResult result = new UserRegistrationResult { IsSucceded = true, ResultId = (int)UserRegistrationResultEnum.Success }; // forced-to-disposal MongoDBConnectionInfo mongoDBConnectionInfo = null; KeyVaultConnectionInfo keyVaultConnectionInfo = null; User user = null; try { if (string.IsNullOrEmpty(model.Fullname)) { throw new BusinessException((int)UserRegistrationResultEnum.FailedEmptyFullname); } if (string.IsNullOrEmpty(model.Email)) { throw new BusinessException((int)UserRegistrationResultEnum.FailedEmptyEmail); } if (string.IsNullOrEmpty(model.Password)) { throw new BusinessException((int)UserRegistrationResultEnum.FailedEmptyPassword); } using (ValidationHelper validationHelper = new ValidationHelper()) { bool validationEmail = validationHelper.IsValidEmail(model.Email); if (!validationEmail) { throw new BusinessException((int)UserRegistrationResultEnum.FailedNotValidEmail); } } mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.ConnectionString, DatabaseId = Settings.DatabaseId, UserCollection = Settings.UserCollection }; using (UserRegistrationDataHelper userRegistrationDataHelper = new UserRegistrationDataHelper(mongoDBConnectionInfo)) { user = userRegistrationDataHelper.GetUser(model.Email); } if (user != null) { throw new BusinessException((int)UserRegistrationResultEnum.FailedEmailAlreadyExists); } string password = string.Empty; using (HashHelper hashHelper = new HashHelper()) { password = hashHelper.GetSha256Hash(model.Password); } keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = Settings.KeyVaultCertificateName, ClientId = Settings.KeyVaultClientId, ClientSecret = Settings.KeyVaultClientSecret, KeyVaultIdentifier = Settings.KeyVaultIdentifier }; using (MessageQueueHelper messageQueueHelper = new MessageQueueHelper()) { UserRegistrationMessage userRegistrationMessage = new UserRegistrationMessage() { fullname = model.Fullname, email = model.Email, password = password }; await messageQueueHelper.QueueMessageAsync(userRegistrationMessage, Settings.UserRegistrationQueueName, keyVaultConnectionInfo); } } catch (Exception ex) { result.IsSucceded = false; if (ex is BusinessException) { result.ResultId = ((BusinessException)ex).ResultId; } else { result.ResultId = (int)UserRegistrationResultEnum.Failed; this.logger.LogError($">> Exception: {ex.Message}, StackTrace: {ex.StackTrace}"); if (ex.InnerException != null) { this.logger.LogError($">> Inner Exception Message: {ex.InnerException.Message}, Inner Exception StackTrace: {ex.InnerException.StackTrace}"); } } } finally { mongoDBConnectionInfo = null; keyVaultConnectionInfo = null; user = null; GC.Collect(); } string message = EnumDescription.GetEnumDescription((UserRegistrationResultEnum)result.ResultId); this.logger.LogInformation($">> Message information: {message}"); return((result.IsSucceded) ? (ActionResult) new OkObjectResult(new { message = message }) : (ActionResult) new BadRequestObjectResult(new { message = message })); }
public DBRecordItemHelper(MongoDBConnectionInfo databaseInfo) : base(databaseInfo) { collection = GetMongoDatabase().GetCollection <RecordItem>(GetMongoDBConnectionInfo().RecordItemCollection); }
public UserActivationDataHelper(MongoDBConnectionInfo databaseInfo) : base(databaseInfo) { }
private static void Init() { var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections Settings.ConnectionString = Configuration.GetSection("ConnectionString")?.Value; Settings.DatabaseId = Configuration.GetSection("DatabaseId")?.Value; Settings.ContractCollection = Configuration.GetSection("ContractCollection")?.Value; Settings.RabbitMQUsername = Configuration.GetSection("RabbitMQUsername")?.Value; Settings.RabbitMQPassword = Configuration.GetSection("RabbitMQPassword")?.Value; Settings.RabbitMQHostname = Configuration.GetSection("RabbitMQHostname")?.Value; Settings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("RabbitMQPort")?.Value); Settings.ContractDeploymentQueueName = Configuration.GetSection("ContractDeploymentQueueName")?.Value; Settings.KeyVaultCertificateName = Configuration.GetSection("KeyVaultCertificateName")?.Value; Settings.KeyVaultClientId = Configuration.GetSection("KeyVaultClientId")?.Value; Settings.KeyVaultClientSecret = Configuration.GetSection("KeyVaultClientSecret")?.Value; Settings.KeyVaultIdentifier = Configuration.GetSection("KeyVaultIdentifier")?.Value; Settings.KeyVaultEncryptionKey = Configuration.GetSection("KeyVaultEncryptionKey")?.Value; Settings.BlockchainRPCUrl = Configuration.GetSection("BlockchainRPCUrl")?.Value; Settings.BlockchainMasterAddress = Configuration.GetSection("BlockchainMasterAddress")?.Value; Settings.BlockchainMasterPrivateKey = Configuration.GetSection("BlockchainMasterPrivateKey")?.Value; Settings.BlockchainContractABI = Configuration.GetSection("BlockchainContractABI")?.Value; Settings.BlockchainContractByteCode = Configuration.GetSection("BlockchainContractByteCode")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = Settings.ConnectionString, DatabaseId = Settings.DatabaseId, ContractCollection = Settings.ContractCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = Settings.KeyVaultCertificateName, ClientId = Settings.KeyVaultClientId, ClientSecret = Settings.KeyVaultClientSecret, KeyVaultIdentifier = Settings.KeyVaultIdentifier }; blockchainInfo = new BlockchainInfo() { RPCUrl = Settings.BlockchainRPCUrl, MasterAddress = Settings.BlockchainMasterAddress, MasterPrivateKey = Settings.BlockchainMasterPrivateKey, ContractABI = Settings.BlockchainContractABI, ContractByteCode = Settings.BlockchainContractByteCode }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(Settings.KeyVaultEncryptionKey).Result; } account = new Account(blockchainInfo.MasterPrivateKey); web3 = new Web3(account, new RpcClient(new Uri(blockchainInfo.RPCUrl), null, null, new HttpClientHandler() { MaxConnectionsPerServer = 10, UseProxy = false })); }
public async Task <IActionResult> Post() { // non-forced-to-disposal UserRegistrationResponse response = new UserRegistrationResponse { IsSucceded = true, ResultId = (int)UserRegistrationResponseEnum.Success }; // forced-to-disposal UserRegistrationRequest userRegistrationRequest = null; MongoDBConnectionInfo mongoDBConnectionInfo = null; KeyVaultConnectionInfo keyVaultConnectionInfo = null; User user = null; try { userRegistrationRequest = new UserRegistrationRequest(); userRegistrationRequest.Email = HttpContext.User.FindFirst("preferred_username").Value; userRegistrationRequest.Fullname = ((HttpContext.User.FindFirst("name") != null) ? HttpContext.User.FindFirst("name").Value : string.Empty); if (string.IsNullOrEmpty(userRegistrationRequest.Fullname)) { throw new BusinessException((int)UserRegistrationResponseEnum.FailedEmptyFullname); } mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = ApplicationSettings.ConnectionString, DatabaseId = ApplicationSettings.DatabaseId, UserCollection = ApplicationSettings.UserCollection }; using (UserRegistrationDataHelper userRegistrationDataHelper = new UserRegistrationDataHelper(mongoDBConnectionInfo)) { user = userRegistrationDataHelper.GetUser(userRegistrationRequest.Email); } if (user == null) { keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = ApplicationSettings.KeyVaultCertificateName, ClientId = ApplicationSettings.KeyVaultClientId, ClientSecret = ApplicationSettings.KeyVaultClientSecret, KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier }; using (MessageQueueHelper messageQueueHelper = new MessageQueueHelper()) { UserRegistrationMessage userRegistrationMessage = new UserRegistrationMessage() { fullname = userRegistrationRequest.Fullname, email = userRegistrationRequest.Email }; await messageQueueHelper.QueueMessageAsync(userRegistrationMessage, ApplicationSettings.UserRegistrationQueueName, keyVaultConnectionInfo); } } else { response.ResultId = (int)UserRegistrationResponseEnum.SuccessAlreadyExists; } } catch (Exception ex) { response.IsSucceded = false; if (ex is BusinessException) { response.ResultId = ((BusinessException)ex).ResultId; } else { response.ResultId = (int)UserRegistrationResponseEnum.Failed; this.logger.LogError($">> Exception: {ex.Message}, StackTrace: {ex.StackTrace}"); if (ex.InnerException != null) { this.logger.LogError($">> Inner Exception Message: {ex.InnerException.Message}, Inner Exception StackTrace: {ex.InnerException.StackTrace}"); } } } finally { userRegistrationRequest = null; mongoDBConnectionInfo = null; keyVaultConnectionInfo = null; user = null; GC.Collect(); } string message = EnumDescription.GetEnumDescription((UserRegistrationResponseEnum)response.ResultId); this.logger.LogInformation($">> Message information: {message}"); return((response.IsSucceded) ? (ActionResult) new OkObjectResult(new { message = message }) : (ActionResult) new BadRequestObjectResult(new { message = message })); }