Esempio n. 1
0
        private async Task PrepareBlobConnectionAsync()
        {
            var connString = _appConfiguration.GetConnectionString("StorageConnectionString");

            if (!CloudStorageAccount.TryParse(connString, out var storageAccount))
            {
                throw new ArgumentException("Invalid Cloud Storage Account connection string.", connString);
            }
            if (string.IsNullOrWhiteSpace(_blobContainerName))
            {
                throw new ArgumentNullException(_blobContainerName);
            }

            _blobClient = storageAccount.CreateCloudBlobClient();
            _blobClient.DefaultRequestOptions = new BlobRequestOptions
            {
                RetryPolicy          = new ExponentialRetry(TimeSpan.FromSeconds(1), 6),
                MaximumExecutionTime = TimeSpan.FromSeconds(70)
            };

            _container = _blobClient.GetContainerReference(_blobContainerName);
            var exists = await _container.ExistsAsync().ConfigureAwait(false);

            if (!exists)
            {
                await _blobClient.GetContainerReference(_blobContainerName).CreateAsync().ConfigureAwait(false);
            }
        }
        public List <PricingModelAssociation> Get()
        {
            using (var conn = new SQLiteConnection(_config.GetConnectionString()))
            {
                conn.Open();
                const string parkingLotQuery = "SELECT id, name FROM t_parking_lot";
                var          parkingLot      = conn.Query <ParkingLotCategoryRow>(parkingLotQuery);

                const string vehicleTypeQuery = "SELECT id, type, max_weight FROM t_vehicle_type";
                var          vehicleType      = conn.Query <VehicleTypeRow>(vehicleTypeQuery);

                const string pricingTypeQuery = "SELECT id, type, min_hour, max_hour FROM t_pricing_type";
                var          pricingType      = conn.Query <PricingTypeRow>(pricingTypeQuery);

                const string pricingModelQuery =
                    "SELECT id, model_name, pricing_type_id, vehicle_type_id, price FROM t_pricing_model";
                var pricingModel = conn.Query <PricingModelRow>(pricingModelQuery);

                const string pricingAssociationQuery =
                    "SELECT lot_id, pricing_model_id FROM t_pricing_model_association";
                var pricingAssociation = conn.Query <PricingModelAssociationRow>(pricingAssociationQuery);

                return(_pricingModelMapper.Map(parkingLot.ToList(), vehicleType.ToList(), pricingType.ToList(), pricingModel.ToList(),
                                               pricingAssociation.ToList()));
            }
        }
Esempio n. 3
0
        public List <ParkingLotOverview> Get()
        {
            using (var conn = new SQLiteConnection(_config.GetConnectionString()))
            {
                conn.Open();
                const string parkingLotQuery = "SELECT id, name FROM t_parking_lot";
                var          parkingLot      = conn.Query <ParkingLotCategoryRow>(parkingLotQuery);

                const string vehicleTypeQuery = "SELECT id, type, max_weight FROM t_vehicle_type";
                var          vehicleType      = conn.Query <VehicleTypeRow>(vehicleTypeQuery);

                const string pricingTypeQuery = "SELECT id, type, min_hour, max_hour FROM t_pricing_type";
                var          pricingType      = conn.Query <PricingTypeRow>(pricingTypeQuery);

                const string pricingCapacityQuery = "SELECT id, vehicle_type_id, lot_id, capacity FROM t_capacity";
                var          pricingCapacity      = conn.Query <CapacityRow>(pricingCapacityQuery);

                const string pricingModelQuery =
                    "SELECT id, model_name, pricing_type_id, vehicle_type_id, price FROM t_pricing_model";
                var pricingModel = conn.Query <PricingModelRow>(pricingModelQuery);

                const string pricingAssociationQuery =
                    "SELECT lot_id, pricing_model_id FROM t_pricing_model_association";
                var pricingAssociation = conn.Query <PricingModelAssociationRow>(pricingAssociationQuery);

                const string vehicleLogQuery =
                    "SELECT id, lot_id, vehicle_type_id, vehicle_no, in_time, out_time,amount, weight FROM t_vehicle_log";
                var vehicleLog = conn.Query <VehicleLogRow>(vehicleLogQuery);


                return(_parkingLotOverviewMapper.Map(parkingLot.ToList(), vehicleType.ToList(), pricingType.ToList(),
                                                     pricingCapacity.ToList(), pricingModel.ToList(),
                                                     pricingAssociation.ToList(), vehicleLog.ToList()));
            }
        }
        public List <VehicleLog> Get()
        {
            using (var conn = new SQLiteConnection(_config.GetConnectionString()))
            {
                conn.Open();
                const string vehicleLogQuery =
                    "SELECT id, lot_id, vehicle_type_id, vehicle_no, in_time, out_time,amount, weight FROM t_vehicle_log";
                var vehicleLog = conn.Query <VehicleLogRow>(vehicleLogQuery);

                const string parkingLotQuery = "SELECT id, name FROM t_parking_lot";
                var          parkingLot      = conn.Query <ParkingLotCategoryRow>(parkingLotQuery);

                const string vehicleTypeQuery = "SELECT id, type, max_weight FROM t_vehicle_type";
                var          vehicleType      = conn.Query <VehicleTypeRow>(vehicleTypeQuery);

                return(_vehicleLogMapper.Map(vehicleLog, parkingLot, vehicleType));
            }
        }
        public async Task <CloudTable> GetTableReference(string tableName)
        {
            var connection     = Configuration.GetConnectionString("StorageConnectionString");
            var storageAccount = CloudStorageAccount.Parse(connection);
            var tableClient    = storageAccount.CreateCloudTableClient();
            var table          = tableClient.GetTableReference(tableName);
            await table.CreateIfNotExistsAsync();

            return(table);
        }
Esempio n. 6
0
 public List <UserRole> Get()
 {
     using (var conn = new SQLiteConnection(_config.GetConnectionString()))
     {
         conn.Open();
         const string userRoleQuery        = "SELECT id, role FROM t_user_profile";
         var          userRoles            = conn.Query <RoleRow>(userRoleQuery);
         const string userAssociationQuery = "SELECT token_id, role_id FROM t_user_association";
         var          userAssociation      = conn.Query <UserAssociationRow>(userAssociationQuery);
         return(_userRoleMapper.Map(userRoles, userAssociation));
     }
 }
Esempio n. 7
0
        public IReadOnlyCollection <TResult> ExecuteReader <TResult>(SqlQuery query, string connectionStringName, Func <SqlQueryDataReader, TResult> createResult)
        {
            var results = new List <TResult>();

            string connectionString = configuration.GetConnectionString(connectionStringName);

            if (string.IsNullOrEmpty(connectionStringName))
            {
                throw new ArgumentException($"Connection string does not exist: `{connectionStringName}`.", nameof(connectionStringName));
            }

            using (var connection = new SqlConnection(connectionString))
            {
                SqlCommand command = CreateSqlCommand(query, connection);

                connection.Open();

                using (var dataReader = new SqlQueryDataReader(command.ExecuteReader()))
                {
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            TResult result = createResult.Invoke(dataReader);

                            if (result == null)
                            {
                                continue;
                            }

                            results.Add(result);
                        }
                    }
                }
            }

            return(results.AsReadOnly());
        }