예제 #1
0
        public static IDbDataAdapter CreateDataAdapter(EnumProviders provider)
        {
            IDbDataAdapter da;

            switch (provider)
            {
                case EnumProviders.SqlServer:
                    da = new System.Data.SqlClient.SqlDataAdapter();
                    break;
                case EnumProviders.OleDb:
                    da = new System.Data.OleDb.OleDbDataAdapter();
                    break;
                case EnumProviders.Odbc:
                    da = new System.Data.Odbc.OdbcDataAdapter();
                    break;
                case EnumProviders.Oracle:
                    throw new NotImplementedException("Provider not implemented");
                    break;
                default:
                    da = new System.Data.SqlClient.SqlDataAdapter();
                    break;
            }

            return da;
        }
예제 #2
0
        // The following methods handles SQL Server, Oledb, Odbc
        public static IDbConnection CreateConnection(EnumProviders provider)
        {
            IDbConnection cnn;

            switch (provider)
            {
                case EnumProviders.SqlServer:
                    cnn = new System.Data.SqlClient.SqlConnection();
                    break;
                case EnumProviders.OleDb:
                    cnn = new System.Data.OleDb.OleDbConnection();
                    break;
                case EnumProviders.Odbc:
                    cnn = new System.Data.Odbc.OdbcConnection();
                    break;
                case EnumProviders.Oracle:
                    throw new NotImplementedException("Provider not implemented");
                    break;
                default:
                    cnn = new System.Data.SqlClient.SqlConnection();
                    break;
            }

            return cnn;
        }
예제 #3
0
        /// <summary>
        /// This method creates a new parameter object with the given name.
        /// It fills in the DataType property with the passed in data type.
        /// It also fills in the value with the passed in Value.
        /// </summary>
        /// <param name="ParameterName">Parameter name</param>
        /// <param name="DataType">Parameter data type</param>
        /// <param name="Value">Parameter Value</param>
        /// <param name="Provider">The Provider type that the parameter will be returned</param>
        /// <returns>Data Parameter</returns>
        public static IDataParameter CreateParameter(string ParameterName, DbType DataType, object Value, EnumProviders Provider)
        {
            IDataParameter param;

            param = CreateParameter(ParameterName, DataType, Provider);
            //param = DataProvider.CreateParameter();
            //param.ParameterName = ParameterName;
            //param.DbType = DataType;
            param.Value = Value;

            return param;
        }
예제 #4
0
        /// <summary>
        /// This method creates a new parameter object with the given name.
        /// </summary>
        /// <param name="ParameterName">Parameter name</param>
        /// <returns>Data Parameter</returns>
        public static IDataParameter CreateParameter(string ParameterName, EnumProviders Provider)
        {
            IDataParameter param;

            param = DataProvider.CreateParameter(Provider);
            param.ParameterName = ParameterName;

            return param;
        }
예제 #5
0
        public static IDataParameter CreateParameter(EnumProviders provider)
        {
            IDataParameter param;

            switch (provider)
            {
                case EnumProviders.SqlServer:
                    param = new System.Data.SqlClient.SqlParameter();
                    break;
                case EnumProviders.OleDb:
                    param = new System.Data.OleDb.OleDbParameter();
                    break;
                case EnumProviders.Odbc:
                    param = new System.Data.Odbc.OdbcParameter();
                    break;
                case EnumProviders.Oracle:
                    throw new NotImplementedException("Provider not implemented");
                    break;
                default:
                    param = new System.Data.SqlClient.SqlParameter();
                    break;
            }

            return param;
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IConfiguration>(Configuration);
            services.AddSingleton <ILoggerFactory, LoggerFactory>();
            services.AddSingleton(typeof(ILogger <>), typeof(Logger <>));
            services.AddLogging((builder) => builder.SetMinimumLevel(LogLevel.Error));
            services.AddLogging();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Sistema de Gestão Imobiliário", Version = "v1", Contact = new Contact()
                    {
                        Email = "*****@*****.**", Name = "Afonso Dutra Nogueira", Url = "http://api.afonsoft.com.br"
                    }
                });
                c.AddSecurityDefinition("Bearer", new ApiKeyScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey",
                });

                // Swagger 2.+ support
                c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > {
                    { "Bearer", new string[] { } }
                });
            });


            // Add service and create Policy with options
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });


            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            });

            services.AddResponseCaching();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            string        connectionString = Configuration["Connection:ConnectionString"];
            EnumProviders provider         = Configuration["Connection:Provider"].ToEnum <EnumProviders>(EnumProviders.SqlServer);
            string        key    = Configuration["Jwt:Key"];
            string        issuer = Configuration["Jwt:Issuer"];

            services.Configure <Settings>(options =>
            {
                options.Connection.ConnectionString = connectionString;
                options.Connection.Provider         = provider;
                options.Token.Key    = key;
                options.Token.Issuer = issuer;
            });

            //services.AddDbContext<CepContext>(options => options.UseSqlite("DataSource=CEP.db"));
            services.AddDbContext <SgiDbContext>(options =>
            {
                switch (provider)
                {
                case EnumProviders.MySQL:
                    options.UseMySql(connectionString);
                    break;

                case EnumProviders.SqlServer:
                    options.UseSqlServer(connectionString);
                    break;

                default:
                    options.UseSqlServer(connectionString);
                    break;
                }
            }, ServiceLifetime.Transient);
        }