using BLWWS_BLL;
using BLWWSCore.SOAP;
using SoapCore;

namespace BLWWSCore
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddHttpContextAccessor();

            //ConfigurationManager.ConnectionStrings["DefaultConnection"]?.ConnectionString;
            //builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            //                      .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
            //                      .AddEnvironmentVariables();
            // 注册 SOAP 服务
            var a1 = builder.Configuration.GetSection("face_url").Get<string>();
            var a2 = builder.Configuration.GetSection("face_url_new").Get<string>();
            var a3 = builder.Configuration.GetSection("ImageMaxHeight").Get<int>();
            var a4 = builder.Configuration.GetSection("ImageMaxWidth").Get<int>();
            var a5 = builder.Configuration.GetSection("ImageMinHeight").Get<int>();
            var a6 = builder.Configuration.GetSection("ImageMinWidth").Get<int>();
            BLL._face_url = a1;
            BLL._face_url_new = a2;
            BLL.ImageMaxHeight = a3;
            BLL.ImageMaxWidth = a4;
            BLL.ImageMinHeight = a5;
            BLL.ImageMinWidth = a6;
            var sqlconstr = builder.Configuration.GetConnectionString("connectionString");
            SqlHelper.connectionString = sqlconstr;
            builder.Services.AddSoapCore();
            builder.Services.AddScoped<IWebServices, BLWWebServices>();
            builder.Services.AddScoped<Isyncstatus, syncstatus>();

            // 如果使用 Mvc，还需要添加
            // services.AddMvc();
            builder.Services.AddControllers();

            var app = builder.Build();

            string sss = System.Configuration.ConfigurationManager.AppSettings["connectionString"];
            // Configure the HTTP request pipeline.

            app.UseRouting();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.UseSoapEndpoint<IWebServices>("/blwws.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
                endpoints.UseSoapEndpoint<Isyncstatus>("/syncstatus.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
            });

            app.MapControllers();

            app.Run();
        }
    }
}
