using Azure;
using CloudBuilder.Core.DependencyInjection.Form;
using CloudBuilder.Core.DependencyInjection.Request;
using CloudBuilder.Core.Service;
using CloudBuilder.Gui;
using CloudBuilder.Gui.DependencyInjection;
using CloudBuilder.Security.Data;
using CloudBuilder.Security.Gui;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Net.NetworkInformation;


namespace CloudBuilderLauncher
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // To customize application configuration such as set high DPI settings or default font,
            // see https://aka.ms/applicationconfiguration.
            ApplicationConfiguration.Initialize();

            //Application.Run(new Form1());
            try
            {
                var services = new ServiceCollection();
                //容器初始化
                services.Initialize();
                //构造容器
                services.Build();

                LoginForm login = ApplicationServiceContext.ServiceProvider.GetRequiredKeyedService<LoginForm>(typeof(LoginForm).Name);

                login.InitForm();

                if (DialogResult.OK.Equals(login.ShowDialog()))
                {
                    login.Close();

                    MainForm mf = ApplicationServiceContext.ServiceProvider.GetRequiredKeyedService<MainForm>(typeof(MainForm).Name);
                    mf.InitForm();

                    Application.Run(mf);
                }
            }
            catch (ValidatedException ex)
            {
                ShowMessageBox.ShowInfo(ex.Message);
            }
            catch (ServiceErrorException ex)
            {
                ShowMessageBox.ShowError(ex.Message);
            }
            catch (Exception ex)
            {
                ShowMessageBox.ShowError(ex.Message);
            }
            //容器初始化开始


        }

    }
}
