Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            // StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                //app.UseHsts();
            }

            //app.UseHttpsRedirection();
            //Allow Any Web Site To Enter My Api we can change this to specified Web site
            //trialData.TrialUsers();
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseAuthentication();
            app.UseMvc();
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // https جزء خاص بالسيكيوريتي
                // app.UseHsts();
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            // نراعي الترتيب حسب الخمة المطلوب تشغيلها اولا
            // app.UseHttpsRedirection();
            // app.UseCors اضافة صلاحيات الوصول للويب سيرفس
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseAuthentication();
            app.UseMvc();
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // UseExceptionHandler is a middleware to the pipeline that will catch exceptions
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                // app.UseHsts();
            }

            // app.UseHttpsRedirection();
            // trialData.TrialUsers();
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseAuthentication();
            app.UseMvc();
        }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                                  BuilderExtensions =>
                {
                    BuilderExtensions.WithOrigins("*");
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title   = "My API",
                    Version = "v1",
                    Contact = new OpenApiContact
                    {
                        Name  = "Gustavo Rizzo",
                        Email = "*****@*****.**",
                        Url   = new Uri("https://github.com/GustavoRizzo/API-Otimizacao-Classica"),
                    }
                });
            });
        }
Esempio n. 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions => {
                    BuilderExtensions.Run(async context => {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                // app.UseHsts();
            }

            // app.UseHttpsRedirection();
            //  trialData.TrialUser();
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseAuthentication();
            app.UseMvc();
            app.UseStaticFiles();
        }
Esempio n. 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(options =>
     {
         options.AddPolicy(MyAllowSpecificOrigins,
                           BuilderExtensions =>
         {
             BuilderExtensions.WithOrigins("*");
         });
     });
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
 }
Esempio n. 7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            string corsOrigin = "http://localhost:4200";

            //StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            StripeConfiguration.ApiKey = Configuration.GetSection("Stripe:SecretKey").Value;
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message, corsOrigin);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                // app.UseHsts();
            }

            /* app.UseSpa(spa =>
             * {
             *  // To learn more about options for serving an Angular SPA from ASP.NET Core,
             *  // see https://go.microsoft.com/fwlink/?linkid=864501
             *
             *  spa.Options.SourcePath = "ZawajSPA";
             *
             *  if (env.IsDevelopment())
             *  {
             *      //spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
             *      spa.UseAngularCliServer(npmScript: "start");
             *  }
             * });  */

            trialData.TrialUsers();
            app.UseHttpsRedirection();
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            app.UseSignalR(options =>
            {
                options.MapHub <ChatHub>("/chatHub");
            });
            app.UseAuthentication();
            app.UseMvc();
        }
Esempio n. 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TrialData trialData)
        {
            StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //  app.UseHsts();

                // for any error handler
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            // app.UseMvc();
            // app.UseHttpsRedirection();

            trialData.TrialUsers();
            //app.UseCors(x =>x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseCors();

            app.UseAuthentication();

            app.UseRouting();

            app.UseAuthorization();

            // in asp core 2.1  only
            //app.UseSignalR(routes => {  routes.MapHub<ChatHub>("/chat"); });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                // in asp core 3 above
                endpoints.MapHub <ChatHub>("/chat");
            });
        }
Esempio n. 9
0
    List <IGrouping <int, DirectoryInfo> > GetReleaseAddInDirectories()
    {
        var project         = BuilderExtensions.GetProject(Solution, MainProjectName);
        var addInsDirectory = new DirectoryInfo(project.GetBinDirectory()).GetDirectories()
                              .Where(dir => dir.Name.StartsWith(AddInBinPrefix))
                              .Where(dir => dir.Name.Contains(BuildConfiguration))
                              .GroupBy(info => info.Name.Length)
                              .ToList();

        if (addInsDirectory.Count == 0)
        {
            throw new Exception("There are no packaged assemblies in the project. Try to build the project again.");
        }
        return(addInsDirectory);
    }
Esempio n. 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TrialData trialData)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PortfolioApp.API v1"));
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context => {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            // //--> Ajouter UserTrialData
            // trialData.TrialUsers();
            // //--> Ajouter ProjectTrialData
            // trialData.TrialProjects();
            // //--> Ajouter SkillTrialData
            //  trialData.TrialSkills();


            //--> Permet d'avoir autorisation pour tous les site d'accédé a notre service web
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 11
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions => {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                //app.UseHsts();
            }

            trialData.TrialUsers();
            app.UseHttpsRedirection();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseSignalR(routes => {
                routes.MapHub <ChatHub>("/chat");
            });
            app.UseAuthentication();
            app.Use(async(context, next) =>
            {
                await next();
                if (context.Response.StatusCode == 404)
                {
                    context.Request.Path = "/index.html";
                    await next();
                }
            });
            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseMvc();
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


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

            services.AddDbContext <SalesWebContext>(options =>
                                                    options.UseMySql(Configuration.GetConnectionString("SalesWebContext"), BuilderExtensions =>
                                                                     BuilderExtensions.MigrationsAssembly("SalesWeb")));

            services.AddScoped <SeedingService>();
        }
Esempio n. 13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions => {
                    // builderEctensions  تعامل مع الخطأ داخل ال pipe line
                    BuilderExtensions.Run(async context => {
                        // HttpStstusCode يحمل كل ارقام الاخطاء -- InternalServerError يبني ال Error
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        // features عبارة عن مجموعة من الاماكن يمدنا بها السيرفير نخده بال get
                        var error = context.Features.Get <IExceptionHandlerFeature> ();
                        // لو ظهر خطأ
                        if (error != null)
                        {
                            // اضافة الدالة المضافة في ال Helpers للسماح لاي Origin بالدخول بعدم ظهور خطا ال cors
                            context.Response.AddApplicationError(error.Error.Message);
                            // يطلع الخطا في رساله لا تخرج الا علي شكل رقم ويظهر الرسالة الخاصة بالرقم
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            //app.UseHttpsRedirection();

            app.UseRouting();
            app.UseCors(x => x.SetIsOriginAllowed(options => _ = true).AllowAnyMethod().AllowAnyHeader().AllowCredentials());

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();

                endpoints.MapHub <ChatHub> ("/chat");
            });
        }
Esempio n. 14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //public void Configure(IApplicationBuilder app, IWebHostEnvironment env , TrialData trialData)
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }


            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();

            //trialData.TrialUsers();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", BuilderExtensions =>
                {
                    BuilderExtensions.WithOrigins("http://localhost:4200")
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            });

            services.AddDbContext <BookstoreContext>(options =>
                                                     options.UseNpgsql(Configuration.GetConnectionString("BookstoreContext")));

            //add this for identity
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <BookstoreContext>()
            .AddDefaultTokenProviders();

            services.AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(jwtOptions =>
            {
                jwtOptions.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateActor    = true,
                    ValidateAudience = true,
                    ValidateLifetime = true,
                    ValidIssuer      = Configuration["JWTConfiguration:Issuer"],
                    ValidAudience    = Configuration["JWTConfiguration:Audience"],
                    IssuerSigningKey = new
                                       SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWTConfiguration.Key"]))
                };
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Esempio n. 16
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     else
     {
         app.UseExceptionHandler(BuilderExtensions =>
         {
             BuilderExtensions.Run(async context =>
             {
                 context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                 var error = context.Features.Get <IExceptionHandlerFeature>();
                 if (error != null)
                 {
                     context.Response.addApplicationError(error.Error.Message);
                     await context.Response.WriteAsync(error.Error.Message);
                 }
             });
         });
         // app.UseHsts();
     }
     trialData.TrialSuppliers();
     app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
     app.UseDefaultFiles();
     app.UseAuthentication();
     app.Use(async(context, next) => {
         await next();
         if (context.Response.StatusCode == 404)
         {
             context.Request.Path = "/index.html";
             await next();
         }
     });
     app.UseStaticFiles();
     app.UseMvc();
 }
Esempio n. 17
0
    IEnumerable <IGrouping <int, DirectoryInfo> > GetBuildDirectories()
    {
        var directories = new List <DirectoryInfo>();

        foreach (var projectName in Projects)
        {
            var project       = BuilderExtensions.GetProject(Solution, projectName);
            var directoryInfo = new DirectoryInfo(project.GetBinDirectory()).GetDirectories();
            directories.AddRange(directoryInfo);
        }

        if (directories.Count == 0)
        {
            throw new Exception("There are no packaged assemblies in the project. Try to build the project again.");
        }

        var addInsDirectory = directories
                              .Where(dir => dir.Name.StartsWith(AddInBinPrefix))
                              .Where(dir => dir.Name.Contains(BuildConfiguration))
                              .GroupBy(dir => dir.Name.Length);

        return(addInsDirectory);
    }
Esempio n. 18
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // Add Golable ExceptionHandler in Prodaction mode
                app.UseExceptionHandler(BuilderExtensions => BuilderExtensions.Run(async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.StackTrace);
                    }
                })
                                        );


                // app.UseHsts();
            }

            // app.UseHttpsRedirection();
            // trialData.TrialUsers();
            // add Corss MidllWare
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            // add Corss MidllWare

            // add authentication Midllware
            app.UseAuthentication();

            app.UseMvc();
        }
Esempio n. 19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


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

            services.AddDbContext <SalesWebMvcContext>(options =>
                                                       options.UseMySql(Configuration.GetConnectionString("SalesWebMvcContext"), BuilderExtensions => BuilderExtensions.MigrationsAssembly("SalesWebMvc")));
            //options.UseMySql(Configuration.GetConnectionString("ContextClass"), BuilderExtensions => BuilderExtensions.MigrationsAssembly("ProjectName")));

            // Services registered in the dependency injection system
            services.AddScoped <SeedingService>();
            services.AddScoped <SellersService>();
            services.AddScoped <DepartmentsService>();
            services.AddScoped <SalesRecordsService>();
        }