Пример #1
0
        public void Save()
        {
            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();

                cmd.Parameters.Add("@hotelId", SqlDbType.Int).Value = this.HotelId;
                cmd.CommandText = (@"SELECT hotelId
                                     FROM Hotels
                                     WHERE hotelId = @hotelId");
                bool hasRows = false;
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    hasRows = reader.HasRows;
                }
                if (hasRows)
                {
                    Update(connection);
                }
                else
                {
                    Add(connection);
                }
            }
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var dbConfiguration = new DBConfiguration();

            dbConfiguration.ConnectionString = Configuration.GetConnectionString("DBConnection");
            services.Add(new ServiceDescriptor(typeof(DBConfiguration), dbConfiguration));

            var clientConfiguration = File.ReadAllText("secrets.json");
            var config = JsonSerializer.Deserialize <ClientConfiguration>(clientConfiguration);

            services.Add(new ServiceDescriptor(typeof(ClientConfiguration), config));

            services.AddHttpClient <IAuthHttpClient, AuthHttpClient>(client =>
            {
                client.BaseAddress = new Uri("https://auth.truelayer.com/");
            });
            services.AddHttpClient <IDataHttpClient, DataHttpClient>(client =>
            {
                client.BaseAddress = new Uri("https://api.truelayer.com/data/v1/");
            });

            services.AddSingleton <IAuthService, AuthService>();

            services.AddSingleton <ITransactionRepository, TransactionRepository>();
        }
Пример #3
0
        public MongoWrapper(IOptionsMonitor <DBConfiguration> dbConfig)
        {
            _options = dbConfig.CurrentValue;
            var mongoClient = new MongoClient(_options.ConnectionString);

            db = mongoClient.GetDatabase(_options.JobDatabase);
        }
Пример #4
0
        public ApplicationContext CreateDbContext(string[] args)
        {
            var builder          = new DbContextOptionsBuilder <ApplicationContext>();
            var connectionString = DBConfiguration.GetConnection();

            builder.UseMySql(connectionString);
            return(new ApplicationContext(builder.Options));
        }
Пример #5
0
 public static void AddConfiguration(this IServiceCollection service)
 {
     DBConfiguration.Register(service);
     RepositoriesDI.Register(service);
     ServicesDI.Register(service);
     CorsConfiguration.RegisterCors(service);
     SwaggerConfiguration.RegisterSwagger(service);
 }
Пример #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddControllers();

            var config = new DBConfiguration();

            Configuration.Bind("DBConnection", config);
            services.AddSingleton(config);
        }
        public void TestSetConfiguration()
        {
            using (DataBaseService dbService = new DataBaseService())
            {
                DBConfiguration dbConfiguration = new DBConfiguration(connectionStringName);

                DataControl.Interfaces.IDataAccessService dataAccessService =
                    dbService.SetConfiguration(dbConfiguration);

                Assert.AreSame(dbService, dataAccessService);
            }
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DBConfiguration db = DBConfiguration.Load(Configuration);

            ConfigureDBServices(db, services);

            LinkedServerConfiguration server = LinkedServerConfiguration.Load(Configuration);

            ConfigureIdentityServices(server, Configuration, services);

            ConfigureFinalServices(Configuration, services);
        }
        private DBConfiguration SetDBConfigurationAndClearDriverInfoTable()
        {
            DBConfiguration dbConfiguration = new DBConfiguration(connectionStringName);

            var allDriverInfo = dbConfiguration.UnitOfWork.DriverInfoRepository.Get(filter: q => true);

            foreach (var driverInfo in allDriverInfo)
            {
                dbConfiguration.UnitOfWork.DriverInfoRepository.Delete(driverInfo);
            }
            dbConfiguration.UnitOfWork.Save();
            return(dbConfiguration);
        }
        private DBConfiguration SetDBConfigurationAndClearScoreAndDriverInfoTable()
        {
            DBConfiguration dbConfiguration = SetDBConfigurationAndClearDriverInfoTable();

            var allScores = dbConfiguration.UnitOfWork.ScoreRepository.Get(filter: q => true);

            foreach (var score in allScores)
            {
                dbConfiguration.UnitOfWork.ScoreRepository.Delete(score);
            }
            dbConfiguration.UnitOfWork.Save();
            return(dbConfiguration);
        }
Пример #11
0
        /* public void Save()
         * {
         *   using ( SqlConnection connection = DBConfiguration.GetConnection() )
         *   {
         *       SqlCommand cmd = connection.CreateCommand();
         *       cmd.Parameters.Add( "@hotelId", SqlDbType.Int ).Value = this.HotelId;
         *       cmd.Parameters.Add( "@hotelName", SqlDbType.VarChar ).Value = this.Name;
         *       cmd.Parameters.Add( "@phone", SqlDbType.VarChar ).Value = this.Phone;
         *       cmd.Parameters.Add( "@state", SqlDbType.Int ).Value = this.State;
         *       cmd.Parameters.Add( "@address", SqlDbType.VarChar ).Value = this.Address;
         *       cmd.Parameters.Add( "@email", SqlDbType.VarChar ).Value = this.Email;
         *
         *       cmd.CommandText = ( @"UPDATE Hotels
         *                          SET name = @hotelName,
         *                           addres = @address,
         *                           phone = @phone,
         *                           email = @email,
         *                           state = @state
         *                          WHERE hotelId = @hotelId" );
         *       cmd.ExecuteReader();
         *   }
         * }*/

        public static void Delete(int hotelId)
        {
            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@hotelId", SqlDbType.Int).Value = hotelId;
                cmd.CommandText = @"DELETE FROM Hotels WHERE hotelId = @hotelId";
                using (SqlCommand command = cmd)
                {
                    command.ExecuteNonQuery();
                }
            }
        }
Пример #12
0
        public void SetConfiguration(DBConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (string.IsNullOrWhiteSpace(config.ConnectionString))
            {
                throw new ArgumentException(nameof(config.ConnectionString));
            }

            this.connectionString = config.ConnectionString;
        }
Пример #13
0
 public static void ConfigureDBServices(DBConfiguration db, IServiceCollection services)
 {
     services.AddDbContext <ApplicationDbContext>(options =>
     {
         if (db.Type == DBType.MySql)
         {
             options.UseMySql(db.ConnectionString);
         }
         else
         {
             options.UseSqlServer(db.ConnectionString);
         }
     });
 }
        public MainWindow()
        {
            InitializeComponent();

            // la connection a sqlite
            monInstancePrincipale = DBConfiguration.GetInstance();

            // get parametrage application
            this.paramApplication = monInstancePrincipale.GetParametrage();

            // dessiner les elipse en cas d'existance ville au lancement du programme
            this.DessinerEllipseVilles();

            this.DataContext = this;
        }
Пример #15
0
 public static void ConfigureDBServices(DBConfiguration db, IServiceCollection services)
 {
     services.AddDbContext <Data.Providers.SqlServer.Models.DataContext>(options =>
     {
         if (db.Type == DBType.MySql)
         {
             options.UseMySql(db.ConnectionString);
         }
         else
         {
             options.UseSqlServer(db.ConnectionString);
         }
     });
     services.AddScoped <Data.Providers.IDataProvider, Data.Providers.SqlServer.DataProvider>();
 }
Пример #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DBConfiguration db = DBConfiguration.Load(Configuration);

            ConfigureDBServices(db, services);

            LinkedServerConfiguration server = LinkedServerConfiguration.Load(Configuration);

            ConfigureIdentityServices(server, services);

            ConfigureDocumentServices(server, services);

            services.AddScoped <IIdentityDataGetter, IdentityDataGetter>();

            ConfigureFinalServices(Configuration, services);
        }
        public static void SetConfiguration()
        {
            DBConfiguration.SetCascadeOnActivate(typeof(BooksData));
            DBConfiguration.SetCascadeOnActivate(typeof(Dictionary <Author, List <Book> >));
            DBConfiguration.SetCascadeOnActivate(typeof(Dictionary <Tag, List <Book> >));
            DBConfiguration.SetCascadeOnActivate(typeof(Dictionary <PublishingHouse, List <Book> >));
            DBConfiguration.SetCascadeOnActivate(typeof(Dictionary <YearOfPublishing, List <Book> >));
            DBConfiguration.SetCascadeOnActivate(typeof(List <Book>));
            DBConfiguration.SetCascadeOnActivate(typeof(Book));
            DBConfiguration.SetCascadeOnActivate(typeof(List <Author>));
            DBConfiguration.SetCascadeOnActivate(typeof(List <Tag>));
            DBConfiguration.SetCascadeOnActivate(typeof(List <PublishingHouse>));
            DBConfiguration.SetCascadeOnActivate(typeof(List <YearOfPublishing>));
            DBConfiguration.SetCascadeOnActivate(typeof(Author));
            DBConfiguration.SetCascadeOnActivate(typeof(Tag));
            DBConfiguration.SetCascadeOnActivate(typeof(PublishingHouse));
            DBConfiguration.SetCascadeOnActivate(typeof(YearOfPublishing));
            DBConfiguration.SetCascadeOnActivate(typeof(Folder));
            DBConfiguration.SetCascadeOnActivate(typeof(File));
            DBConfiguration.SetCascadeOnActivate(typeof(List <IDiscEntry>));
            DBConfiguration.SetCascadeOnActivate(typeof(CustomBuffer));

            DBConfiguration.SetCascadeOnDelete(typeof(Folder));
            DBConfiguration.SetCascadeOnDelete(typeof(File));
            DBConfiguration.SetCascadeOnDelete(typeof(List <IDiscEntry>));
            DBConfiguration.SetCascadeOnDelete(typeof(CustomBuffer));

            DBConfiguration.SetCascadeOnUpdate(typeof(BooksData));
            DBConfiguration.SetCascadeOnUpdate(typeof(Dictionary <Author, List <Book> >));
            DBConfiguration.SetCascadeOnUpdate(typeof(Dictionary <Tag, List <Book> >));
            DBConfiguration.SetCascadeOnUpdate(typeof(Dictionary <PublishingHouse, List <Book> >));
            DBConfiguration.SetCascadeOnUpdate(typeof(Dictionary <YearOfPublishing, List <Book> >));
            DBConfiguration.SetCascadeOnUpdate(typeof(List <Book>));
            DBConfiguration.SetCascadeOnUpdate(typeof(Book));
            DBConfiguration.SetCascadeOnUpdate(typeof(List <Author>));
            DBConfiguration.SetCascadeOnUpdate(typeof(List <Tag>));
            DBConfiguration.SetCascadeOnUpdate(typeof(List <PublishingHouse>));
            DBConfiguration.SetCascadeOnUpdate(typeof(List <YearOfPublishing>));
            DBConfiguration.SetCascadeOnUpdate(typeof(Author));
            DBConfiguration.SetCascadeOnUpdate(typeof(Tag));
            DBConfiguration.SetCascadeOnUpdate(typeof(PublishingHouse));
            DBConfiguration.SetCascadeOnUpdate(typeof(YearOfPublishing));
            DBConfiguration.SetCascadeOnUpdate(typeof(Folder));
            DBConfiguration.SetCascadeOnUpdate(typeof(File));
            DBConfiguration.SetCascadeOnUpdate(typeof(List <IDiscEntry>));
            DBConfiguration.SetCascadeOnUpdate(typeof(CustomBuffer));
        }
Пример #18
0
        protected void Application_Start()
        {
            DBConfiguration db = new DBConfiguration()
            {
                dbEngine          = "SqlServer",
                dbProvider        = "SqlClient",
                dbName            = "APCPruebas",
                server            = "192.168.1.234",
                useIntegratedAuth = false,
                userName          = "******",
                password          = "******"
            };

            db.Save();
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
Пример #19
0
        public void Add()
        {
            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@hotelId", SqlDbType.Int).Value      = this.HotelId;
                cmd.Parameters.Add("@roomName", SqlDbType.VarChar).Value = this.Name;
                cmd.Parameters.Add("@adultBeds", SqlDbType.Int).Value    = this.AdultBeds;
                cmd.Parameters.Add("@state", SqlDbType.Int).Value        = this.State;
                cmd.Parameters.Add("@childrenBeds", SqlDbType.Int).Value = this.ChildrenBeds;
                cmd.Parameters.Add("@roomId", SqlDbType.Int).Value       = this.RoomId;

                cmd.CommandText = (@"INSERT INTO Rooms ( hotelId, name, adultBeds, childrenBeds, state) 
                                    VALUES ( @hotelId, @roomName, @adultBeds, @childrenBeds, @state)");
                cmd.ExecuteReader();
            }
        }
Пример #20
0
        /// <exception cref="System.Exception"/>
        public virtual int Run(string[] args)
        {
            //Usage DBCountPageView [driverClass dburl]
            string driverClassName = DriverClass;
            string url             = DbUrl;

            if (args.Length > 1)
            {
                driverClassName = args[0];
                url             = args[1];
            }
            Initialize(driverClassName, url);
            Configuration conf = GetConf();

            DBConfiguration.ConfigureDB(conf, driverClassName, url);
            Job job = new Job(conf);

            job.SetJobName("Count Pageviews of URLs");
            job.SetJarByClass(typeof(DBCountPageView));
            job.SetMapperClass(typeof(DBCountPageView.PageviewMapper));
            job.SetCombinerClass(typeof(LongSumReducer));
            job.SetReducerClass(typeof(DBCountPageView.PageviewReducer));
            DBInputFormat.SetInput(job, typeof(DBCountPageView.AccessRecord), "Access", null,
                                   "url", AccessFieldNames);
            DBOutputFormat.SetOutput(job, "Pageview", PageviewFieldNames);
            job.SetMapOutputKeyClass(typeof(Text));
            job.SetMapOutputValueClass(typeof(LongWritable));
            job.SetOutputKeyClass(typeof(DBCountPageView.PageviewRecord));
            job.SetOutputValueClass(typeof(NullWritable));
            int ret;

            try
            {
                ret = job.WaitForCompletion(true) ? 0 : 1;
                bool correct = Verify();
                if (!correct)
                {
                    throw new RuntimeException("Evaluation was not correct!");
                }
            }
            finally
            {
                Shutdown();
            }
            return(ret);
        }
Пример #21
0
        public static List <Hotel> GetAllHotels()
        {
            List <Hotel> hotelList = new List <Hotel>();

            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = (@"SELECT * 
                                   FROM Hotels");
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Hotel hotel = new Hotel(reader);
                        hotelList.Add(hotel);
                    }
                }
            }
            return(hotelList);
        }
Пример #22
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var toggleAppDbContext = services.GetRequiredService <ToggleAppDbContext>();
                    DBConfiguration.CreateDbData(toggleAppDbContext);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
Пример #23
0
        public static Hotel GetInstance(int id)
        {
            Hotel hotel = null;

            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
                cmd.CommandText = (@"SELECT * 
                                   FROM Hotels
                                   WHERE hotelId=@id");

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        hotel = new Hotel(reader);
                    }
                }
            }
            return(hotel);
        }
Пример #24
0
        public static List <Room> GetAllRooms(int HotelId)
        {
            List <Room> roomList = new List <Room>();

            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@HotelId", SqlDbType.Int).Value = HotelId;
                cmd.CommandText = (@"SELECT * 
                                   FROM Rooms
                                   WHERE hotelId = @HotelId");
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Room room = new Room(reader);
                        roomList.Add(room);
                    }
                }
            }
            return(roomList);
        }
Пример #25
0
        public static Room GetInstance(int id)
        {
            Room room = null;

            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
                cmd.CommandText = (@"SELECT * 
                                   FROM Rooms 
                                   WHERE roomId=@id");

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        room = new Room(reader);
                    }
                }
            }
            return(room);
        }
Пример #26
0
        public void Save()
        {
            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@hotelId", SqlDbType.Int).Value      = this.HotelId;
                cmd.Parameters.Add("@roomName", SqlDbType.VarChar).Value = this.Name;
                cmd.Parameters.Add("@adultBeds", SqlDbType.Int).Value    = this.AdultBeds;
                cmd.Parameters.Add("@state", SqlDbType.Int).Value        = this.State;
                cmd.Parameters.Add("@childrenBeds", SqlDbType.Int).Value = this.ChildrenBeds;
                cmd.Parameters.Add("@roomId", SqlDbType.Int).Value       = this.RoomId;

                cmd.CommandText = (@"UPDATE Rooms 
                                   SET name = @roomName, 
                                    hotelId = @hotelId, 
                                    adultBeds = @adultBeds, 
                                    childrenBeds = @childrenBeds, 
                                    state = @state  
                                   WHERE roomId = @roomId");
                cmd.ExecuteReader();
            }
        }
Пример #27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddScoped <IGamesRepository, GamesRepository>();
            services.AddScoped <IGameService, GameService>();
            services.AddScoped <GameDTOToGame>();
            services.AddScoped <IConnectionFactory, ConnectionFactory>();

            var dbConfiguration = new DBConfiguration();

            dbConfiguration.ConnectionString = Configuration.GetConnectionString("connectionString");

            services.AddSingleton <DBConfiguration>(dbConfiguration);

            //DBConfiguration.ConnectionString =

            //Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "GamesLibraryy", Version = "v1"
                });
            });
        }
Пример #28
0
        static public List <SearchResult> FindTariff(SearchRequest searchParams)
        {
            List <SearchResult> searchResultList = new List <SearchResult>();

            using (SqlConnection connection = DBConfiguration.GetConnection())
            {
                int        foundHotelId = -1;
                int        foundRoomlId = -1;
                SqlCommand findHotelId  = connection.CreateCommand();
                findHotelId.Parameters.Add("@hotelName", SqlDbType.VarChar).Value = searchParams.HotelName;
                findHotelId.CommandText = (@"SELECT [Hotels].[hotelId] FROM [dbo].[Hotels] WHERE  [Hotels].[name]=@hotelName");
                using (SqlDataReader reader = findHotelId.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        foundHotelId = reader.GetInt32(reader.GetOrdinal("hotelId"));
                    }
                }

                if (foundHotelId == -1)
                {
                    return(new List <SearchResult>());
                }

                SqlCommand findRoomId = connection.CreateCommand();
                findRoomId.Parameters.Add("@roomName", SqlDbType.VarChar).Value = searchParams.RoomName;
                findRoomId.Parameters.Add("@hotelId", SqlDbType.Int).Value      = foundHotelId;
                findRoomId.CommandText = (@"SELECT [Rooms].[roomId] FROM [dbo].[Rooms] WHERE [Rooms].[name]=@roomName AND [Rooms].[hotelId]=@hotelId");
                using (SqlDataReader reader = findRoomId.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        foundRoomlId = reader.GetInt32(reader.GetOrdinal("roomId"));
                    }
                }

                if (foundRoomlId == -1)
                {
                    return(new List <SearchResult>());
                }

                SqlCommand cmd = connection.CreateCommand();
                cmd.Parameters.Add("@hotelId", SqlDbType.Int).Value    = foundHotelId;
                cmd.Parameters.Add("@roomId", SqlDbType.VarChar).Value = foundRoomlId;
                cmd.Parameters.Add("@date", SqlDbType.Date).Value      = searchParams.Date;
                cmd.CommandText = (@"SELECT  
                                    [Price].[tariffId]
                                    ,[Tariff].[name]
                                    ,[Price].[price]
                                    ,[Price].[datePrice] 
                                    ,[Price].[roomId]
                                    FROM [dbo].[Price]  
                                    LEFT JOIN [Tariff] ON [Price].[tariffId] = [Tariff].[tariffId]
                                    WHERE [Tariff].[hotelId] = @hotelId
                                    AND [Price].[roomId] = @roomId
                                    AND [Price].[datePrice]  = @date");

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        SearchResult result = new SearchResult();
                        result.SetData(reader);
                        searchResultList.Add(result);
                    }
                }
            }
            return(searchResultList);
        }
 public void InitDBLayer(Configuration.DBConfiguration config)
 {
     this.config = config;
 }
Пример #30
0
 public static void ItemTests(TestContext ts)
 {
     DBConfiguration.SetConnection("server=localhost;user id=root;password=root;port=8889;database=sc_todolist_test;");
 }