using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DatabaseClient;


namespace WebApi
{

    internal class Program
    {
        static void Main(string[] args)
        {

            // CallDbFactoryTest();

            #region DBConfig
            var DatabaseType = System.Configuration.ConfigurationManager.AppSettings["DatabaseType"];
            var connString = "";
            switch (DatabaseType.ToLower())
            {
                case "mysql":
                    {
                        connString = System.Configuration.ConfigurationManager.AppSettings["MysqlConnectString"];
                        break;
                    }
                case "mssql":
                    {
                        connString = System.Configuration.ConfigurationManager.AppSettings["MssqlConnectString"];
                        break;
                    }
                case "sqlite":
                    {
                        connString = System.Configuration.ConfigurationManager.AppSettings["SqliteConnectString"];
                        break;
                    }
                default:
                    {
                        connString = System.Configuration.ConfigurationManager.AppSettings["MysqlConnectString"];
                        break;
                    }
            }

            GlobalVar.dbClient = new DBClientFactory(DatabaseType).Create();
            GlobalVar.dbClient.Connect(connString);
            #endregion

            var WebApiUrl = System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"];
            new InitServer(WebApiUrl);


            //GlobalVar.log.Error("错误", new Exception("发生了一个异常"));//错误
            //GlobalVar.log.Fatal("严重错误", new Exception("发生了一个致命错误"));//严重错误
            //GlobalVar.log.Info("信息"); //记录一般信息
            //GlobalVar.log.Debug("调试信息");//记录调试信息
            //GlobalVar.log.Warn("警告");//记录警告信息


            GlobalVar.log.Info("Start WebApi server..."); //记录一般信息
            GlobalVar.log.Info("<URL> " + WebApiUrl); //记录一般信息
            // Console.WriteLine("Start WebApi server...");
            // Console.WriteLine("<URL> " + WebApiUrl);

            Console.ReadKey();
        }

        static void CallDbFactoryTest()
        {
            DBClientFactory factory = new DBClientFactory("Mysql");
            // 只需切换 MySqlDatabaseFactory 就可切换数据库
            var mySqlClient = factory.Create();


            // MySqlClient sqlClient = new MySqlClient();
            mySqlClient.Connect("server=localhost;database=mytest;username=root;password=123456;");
            var ds = mySqlClient.ExecQuery("select * from Z_Save_Position");
            var zSavePositionList = Z_Save_Position.DataTableToClass(ds);
        }
    }
}
