/// <summary> /// This method represent to ExecuteDataTable and return data table result /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> protected override async Task <DataTable> ExecuteNativeDataTable(DataAccessRequest dataAccessRequest) { DataTable dataTable = null; IDataReader dataReader = await ExecuteNativeReader(dataAccessRequest); if (!(null == dataReader)) { DataTable schemaDataTable = dataReader.GetSchemaTable(); dataTable = new DataTable(); foreach (DataRow dataRow in schemaDataTable.Rows) { DataColumn dataColumn = new DataColumn(); dataColumn.ColumnName = dataRow["ColumnName"].ToString(); dataColumn.DataType = Type.GetType(dataRow["DataType"].ToString()); dataColumn.ReadOnly = (bool)dataRow["IsReadOnly"]; dataColumn.AutoIncrement = (bool)dataRow["IsAutoIncrement"]; dataColumn.Unique = (bool)dataRow["IsUnique"]; dataTable.Columns.Add(dataColumn); } while (dataReader.Read()) { DataRow dataRow = dataTable.NewRow(); for (int i = 0; i < dataTable.Columns.Count - 1; i++) { dataRow[i] = dataReader[i]; } dataTable.Rows.Add(dataRow); } } return(dataTable); }
public async Task <IActionResult> GetPetDetails(int id) { var userId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User); // Just request all for the user while waiting for improvements on Core data access // logic. var request = new DataAccessRequest <IPet> { UserId = userId, // TODO: when capable swap to something that'd enable specifying the exact // entity to access. Strategy = DataAccessRequest <IPet> .AcquisitionStrategy.All }; var port = new BasicPresenter <GenericDataResponse <IPet> >(); var success = await _getPetDataUseCase.Handle(request, port); if (!success) { return(BadRequest()); } // search for the requested Id: var pet = port.Response.Result.FirstOrDefault(p => p.Id == id); return((pet != null) ? new OkObjectResult(PetDto.From(pet)) : BadRequest()); }
public async Task <bool> Handle(DataAccessRequest <ISpecies> message, IOutboundPort <GenericDataResponse <ISpecies> > outputPort) { // no need to validate user - species data not user specific. var response = new GenericDataResponse <ISpecies>(); switch (message.Strategy) { case DataAccessRequest <ISpecies> .AcquisitionStrategy.All: response.Result = await _petStore.GetSpeciesInfo(); break; case DataAccessRequest <ISpecies> .AcquisitionStrategy.Range: response.Result = (await _petStore.GetSpeciesInfo()) .Where(message.SelectionPredicate) .ToArray(); break; case DataAccessRequest <ISpecies> .AcquisitionStrategy.Single: response.Result = new[] { (await _petStore.GetSpeciesInfo()).FirstOrDefault(message.SelectionPredicate) }; break; default: throw new ArgumentOutOfRangeException(nameof(message)); } outputPort.Handle(response); return(true); }
public async Task <bool> Handle(DataAccessRequest <IEnvironment> message, IOutboundPort <GenericDataResponse <IEnvironment> > outputPort) { switch (message.Strategy) { case DataAccessRequest <IEnvironment> .AcquisitionStrategy.All: // Acquire all associated environments, null-cascade throughout var user = await _userStore.GetUserById(message.UserId); if (user != null) { await _userStore.LoadEnvironments(user); } var envs = user?.Environments; foreach (var env in envs) { await _envStore.LoadControllerFor(env); await _envStore.LoadPetFor(env); } // Compose a response. var response = new GenericDataResponse <IEnvironment> { Result = envs?.ToList() }; outputPort.Handle(response); return(envs != null); default: throw new ArgumentOutOfRangeException(nameof(message.Strategy)); } }
static void Main(string[] args) { DataAccessResponse Response = null; List <TransactionParameter> TransactionParameters = new List <TransactionParameter>(); TransactionParameters.Add(new TransactionParameter() { DataType = DataTypeEnum.STRING, Value = "Vinod" }); TransactionParameters.Add(new TransactionParameter() { DataType = DataTypeEnum.STRING, Value = "Kumar" }); TransactionParameters.Add(new TransactionParameter() { DataType = DataTypeEnum.STRING, Value = "Gupta" }); DataAccessRequest Request = new DataAccessRequest() { SecurityParameter = new SecurityParameter() { UserID = "VGupta", OperationCode = OperationCodeEnum.GET_USER }, TransactionParameters = TransactionParameters, }; using (DataAccessFacade facade = new DataAccessFacade()) { Response = facade.Exceute(Request); } }
public async Task <IActionResult> GetAllSpecies() { // Species are not user-specific, so we won't need to specify that in the request. var request = new DataAccessRequest <ISpecies> { Strategy = DataAccessRequest <ISpecies> .AcquisitionStrategy.All }; var port = new BasicPresenter <GenericDataResponse <ISpecies> >(); var success = await _getSpeciesData.Handle(request, port); return((success) ? new OkObjectResult(port.Response.Result.Select(SpeciesDto.From)) : BadRequest()); }
public async Task <bool> Handle(DataAccessRequest <IEnvDataSample> message, IOutboundPort <GenericDataResponse <IEnvDataSample> > outputPort) { // verify the user exists: var user = await _userStore.GetUserById(message.UserId); if (user == null) { return(false); } await _userStore.LoadEnvironments(user); var response = new GenericDataResponse <IEnvDataSample>(); var samples = new List <IEnvDataSample>(); foreach (var env in user.Environments) { await _environmentStore.LoadSamplesFor(env); switch (message.Strategy) { case DataAccessRequest <IEnvDataSample> .AcquisitionStrategy.All: samples.AddRange(env.EnvDataSamples); break; case DataAccessRequest <IEnvDataSample> .AcquisitionStrategy.Range: samples.AddRange(env.EnvDataSamples.Where(message.SelectionPredicate)); break; case DataAccessRequest <IEnvDataSample> .AcquisitionStrategy.Single: // this one is a bit different, if we find a match amongst any environments, // shortcut a return after processing it. var sample = env.EnvDataSamples.FirstOrDefault(message.SelectionPredicate); if (sample != null) { response.Result = new[] { sample }; outputPort.Handle(response); return(true); } break; default: throw new ArgumentOutOfRangeException(nameof(message), "Strategy not recognized."); } } // in the event of strategy being single, samples will be empty, which is a suitable response. response.Result = samples; outputPort.Handle(response); return(true); }
/// <summary> /// This method represent to Build query Command /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> private async Task <DbCommand> BuildCommand(DataAccessRequest dataAccessRequest) { SqlCommand sqlCommand = new SqlCommand() { Transaction = dataAccessRequest.Transaction, CommandType = CommandType.StoredProcedure, CommandText = dataAccessRequest.ProcedureName }; foreach (SqlParameter parameter in BuildParameter(dataAccessRequest?.Parameters)) { sqlCommand.Parameters.Add(parameter); } return(sqlCommand); }
/// <summary> /// This method represent to ExecuteNonQuery and return status /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> protected override async Task <int> ExecuteNativeNonQuery(DataAccessRequest dataAccessRequest) { DbCommand dbCommand = null; int newId = 0; dbCommand = await BuildCommand(dataAccessRequest); using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.ConnectionString)) { newId = dbCommand.ExecuteNonQuery(); } return(newId); }
/// <summary> /// This method represent to ExecuteScalar and return data /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> protected override async Task <int> ExecuteNativeScalar(DataAccessRequest dataAccessRequest) { DbCommand dbCommand = null; int RecordCount = 0; dbCommand = await BuildCommand(dataAccessRequest); using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.ConnectionString)) { RecordCount = Convert.ToInt32(dbCommand.ExecuteScalar()); } return(RecordCount); }
public async Task <IActionResult> GetSamples() { var userId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User); var port = new BasicPresenter <GenericDataResponse <IEnvDataSample> >(); var request = new DataAccessRequest <IEnvDataSample> { UserId = userId, Strategy = DataAccessRequest <IEnvDataSample> .AcquisitionStrategy.All }; var success = await _sampleRetrieval.Handle(request, port); return((success) ? new OkObjectResult(port.Response.Result.Select(SampleDto.From)) : BadRequest()); }
public async Task <IActionResult> GetOwnedNodesForUser() { var request = new DataAccessRequest <IController> { UserId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User), Strategy = DataAccessRequest <IController> .AcquisitionStrategy.All }; var port = new BasicPresenter <GenericDataResponse <IController> >(); var success = await _getUseCase.Handle(request, port); return((success) ? new OkObjectResult(port.Response.Result.Select(ControllerDto.From)) : BadRequest()); }
public async Task <IActionResult> GetAllEnvsForUser() { var request = new DataAccessRequest <IEnvironment> { UserId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User), Strategy = DataAccessRequest <IEnvironment> .AcquisitionStrategy.All }; var port = new BasicPresenter <GenericDataResponse <IEnvironment> >(); var success = await _getEnvironments.Handle(request, port); return((success) ? new OkObjectResult(port.Response.Result.Select(EnvironmentDto.From).ToList()) : BadRequest()); }
public async Task <IActionResult> GetSamples(string from, string to) { if (!ModelState.IsValid || string.IsNullOrWhiteSpace(from)) { return(BadRequest(ModelState)); } DateTime a, b; try { a = DateTime.Parse(from); b = (to != null) ? DateTime.Parse(to) : DateTime.MaxValue; } catch (Exception) { return(BadRequest(ModelState)); } if (a > b) { var tmp = a; a = b; b = tmp; } var userId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User); var port = new BasicPresenter <GenericDataResponse <IEnvDataSample> >(); var request = new DataAccessRequest <IEnvDataSample> { UserId = userId, Strategy = DataAccessRequest <IEnvDataSample> .AcquisitionStrategy.Range, // NOTE: ISTR having issues with DateTime static values not having the unspecified // 'kind', as such we may have some issues with naive DateTimes here. SelectionPredicate = (sample => InDateTimeRange(sample.Captured, a, b)) }; var success = await _sampleRetrieval.Handle(request, port); return((success) ? new OkObjectResult(port.Response.Result.Select(SampleDto.From)) : BadRequest()); }
/// <summary> /// This method represent to ExecuteReader and return result /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> protected override async Task <IDataReader> ExecuteNativeReader(DataAccessRequest dataAccessRequest) { IDataReader dataReader = null; DbCommand dbCommand = null; dbCommand = await BuildCommand(dataAccessRequest); using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.ConnectionString, true)) { try { dataReader = dbCommand.ExecuteReader(); } catch (Exception ex) { string s = ex.Message; } } return(dataReader); }
public async Task <bool> Handle(DataAccessRequest <IController> message, IOutboundPort <GenericDataResponse <IController> > outputPort) { // Load user, verify they exist. var user = await _userStore.GetUserById(message.UserId); if (user == null) { return(false); } // pipe on back through the port. var response = new GenericDataResponse <IController> { // Load controllers (Note: userStore impls must include controller.Environments relation here) // associated to that user. Result = await _userStore.LoadControllers(user) }; outputPort.Handle(response); return(true); }
public async Task <bool> Handle(DataAccessRequest <IPet> message, IOutboundPort <GenericDataResponse <IPet> > outputPort) { var user = await _userStore.GetUserById(message.UserId); if (user == null) { return(false); } await _userStore.LoadPets(user); // Load species data - its trivial to include. foreach (var pet in user.Pets) { await _petStore.LoadSpecies(pet); } var response = new GenericDataResponse <IPet>(); switch (message.Strategy) { case DataAccessRequest <IPet> .AcquisitionStrategy.All: response.Result = user.Pets.ToImmutableList(); outputPort.Handle(response); return(true); case DataAccessRequest <IPet> .AcquisitionStrategy.Range: response.Result = user.Pets.Where(message.SelectionPredicate).ToImmutableList(); outputPort.Handle(response); return(true); case DataAccessRequest <IPet> .AcquisitionStrategy.Single: response.Result = new List <IPet>(new[] { user.Pets.FirstOrDefault(message.SelectionPredicate) }); outputPort.Handle(response); return(true); default: throw new ArgumentOutOfRangeException(nameof(message), "Unrecognized strategy"); } }
public async Task <IActionResult> GetIdsForUsersPets() { var userId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User); // fetch all pets for the given user. var request = new DataAccessRequest <IPet> { UserId = userId, Strategy = DataAccessRequest <IPet> .AcquisitionStrategy.All }; var port = new BasicPresenter <GenericDataResponse <IPet> >(); var success = await _getPetDataUseCase.Handle(request, port); if (!success) { return(BadRequest()); } // Transform into just IDs var idList = port.Response.Result.Select(pet => pet.Id).ToImmutableList(); return(new OkObjectResult(idList)); }
/// <summary> /// This method represent to ExecuteReader and return result /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> protected override async Task <IDataReader> ExecuteNativeReader(DataAccessRequest dataAccessRequest) { IDataReader dataReader = null; DbCommand dbCommand = null; dbCommand = await BuildCommand(dataAccessRequest); if (null == dataAccessRequest.Connection) { using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.ConnectionString, true)) { dataReader = dbCommand.ExecuteReader(); } } else { using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.Connection, true)) { dataReader = dbCommand.ExecuteReader(); } } return(dataReader); }
public async Task <IActionResult> GetEnvInfo(Guid id) { // piggy back off the 'get all' use. var request = new DataAccessRequest <IEnvironment> { UserId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User), Strategy = DataAccessRequest <IEnvironment> .AcquisitionStrategy.All }; var port = new BasicPresenter <GenericDataResponse <IEnvironment> >(); var success = await _getEnvironments.Handle(request, port); if (success) { var match = port.Response.Result.FirstOrDefault(e => e.Id == id); if (match != null) { return(new OkObjectResult(EnvironmentDto.From(match))); } return(NotFound()); } return(BadRequest()); }
/// <summary> /// This method represent to ExecuteScalar and return data /// </summary> /// <param name="dataAccessRequest">DataAccessRequest object</param> /// <returns></returns> protected override async Task <object> ExecuteNativeScalar(DataAccessRequest dataAccessRequest) { DbCommand dbCommand = null; object result; dbCommand = await BuildCommand(dataAccessRequest); if (null == dataAccessRequest.Connection) { using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.ConnectionString)) { result = dbCommand.ExecuteScalar(); } } else { using (ConnectionManager connMgr = new ConnectionManager(dbCommand, dataAccessRequest.Connection)) { result = dbCommand.ExecuteScalar(); } } return(result); }
protected override async Task <DataSet> ExecuteNativeDataSet(DataAccessRequest dataAccessRequest) { throw new NotImplementedException(); }
protected override async Task <object> ExecuteNativeScalar(DataAccessRequest dataAccessRequest) => await NativeManagerFactory.CreateManager(DatabaseType).ExecuteScalar(dataAccessRequest);
protected override async Task <IDisconnectedDataReader> ExecuteNativeDisconnectedReader(DataAccessRequest dataAccessRequest) => await NativeManagerFactory.CreateManager(DatabaseType).ExecuteDisconnectedReader(dataAccessRequest);
protected override async Task <int> ExecuteNativeNonQuery(DataAccessRequest dataAccessRequest) => await NativeManagerFactory.CreateManager(DatabaseType).ExecuteNonQuery(dataAccessRequest);
protected override async Task <DataTable> ExecuteNativeDataTable(DataAccessRequest dataAccessRequest) => await NativeManagerFactory.CreateManager(DatabaseType).ExecuteDataTable(dataAccessRequest);
protected abstract Task <DataTable> ExecuteNativeDataTable(DataAccessRequest dataAccessRequest);
protected abstract Task <IDataReader> ExecuteNativeReader(DataAccessRequest dataAccessRequest);
protected abstract Task <int> ExecuteNativeNonQuery(DataAccessRequest dataAccessRequest);
protected abstract Task <int> ExecuteNativeScalar(DataAccessRequest dataAccessRequest);