AppSession.cs 4.47 KB
using HHECS.Model.Entities;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net.Http;

namespace HHECS.Bll
{
    public class AppSession
    {
        public static void Init()
        {
            //默认是支持sqlserver,这里更改为mysql
            Dapper.SimpleCRUD.SetDialect(Dapper.SimpleCRUD.Dialect.MySQL);
            //赋值
            AppSession.WarehouseId = int.Parse(ConfigurationManager.AppSettings["WarehouseId"]);
            AppSession.WarehouseCode = ConfigurationManager.AppSettings["WarehouseCode"];
            AppSession.ConnectionString = ConfigurationManager.AppSettings["ConnectionStr"];
            AppSession.WmsUser = ConfigurationManager.AppSettings["WmsUser"];
            AppSession.WmsPassword = ConfigurationManager.AppSettings["WmsPassword"];
            AppSession.PrinterName = ConfigurationManager.AppSettings["printerName"];
            AppSession.Report = ConfigurationManager.AppSettings["printerReport"];
            AppSession.Interval = Convert.ToDouble(ConfigurationManager.AppSettings["interval"]);
            AppSession.Bll = new DefaultBll(ConnectionString);
            AppSession.LEDExcute = new LEDExcute();
            AppSession.Client = AppSession.InitHttpClient();
        }

        public static User User { get; set; }
        public static string ConnectionString { get; set; }
        public static BaseBll Bll { get; set; }
        public static LEDExcute LEDExcute { get; set; }
        public static int WarehouseId { get; set; } = 1;
        public static string WarehouseCode { get; set; }
        public static string WmsUser { get; set; }
        public static string WmsPassword { get; set; }
        public static List<MenuOperation> MenuOperations { get; set; }
        public static String PrinterName { get; set; }
        public static String Report { get; set; }


        /// <summary>
        /// 时钟间隔
        /// </summary>
        public static double Interval { get; set; }

        public static HttpClient Client { get; set; }

        public static HttpClient InitHttpClient()
        {
            Uri uri = new Uri(ConfigurationManager.AppSettings["ServerUrl"]);
            HttpClientHandler handler = new HttpClientHandler() { UseCookies = true };
            HttpClient client = new HttpClient(handler) { BaseAddress = uri };
            return client;
        }

        public static List<DictDetail> Urls = new List<DictDetail>()
        {
            // 完成任务
            { new DictDetail{ Code = "TaskComplete", Value ="wms/task/task/complete"} },
            // 下发任务
            {new DictDetail{ Code = "TaskExecute", Value ="wms/task/task/execute" }},
            // 登陆
            {new DictDetail{ Code = "Login", Value ="wms/login" }},
            // wms心跳连接
            {new DictDetail{ Code = "Heartbeat", Value ="wms/mobile/heartbeat" }},
            // 空出处理
            {new DictDetail{ Code = "HandleEmptyOut", Value ="wms/task/task/handleEmptyOut" }},
            // 设置库位
            {new DictDetail{ Code = "GetLocation", Value ="wms/task/task/setLocationCode" }},
            //todo:完善取货错误处理接口路径
            {new DictDetail{ Code = "HandleForkError", Value ="wms/task/task/createTransfer" } },
            // 全自动出库
            {new DictDetail{ Code = "AutoShipment", Value ="wms/shipment/shippingCombination/autoShipment" } },
            // 电梯口入库
            {new DictDetail{ Code = "AutoReceipCache", Value ="wms/receipt/receiving/autoReceipCache" } },
            // 分拣线入库
            {new DictDetail{ Code = "AutoReceipTray", Value ="wms/receipt/receiving/autoReceipTray" } },
            // 分拣线入库
            {new DictDetail{ Code = "Produced", Value ="wms/receipt/receiving/produced" } },
            // 入空托盘
            {new DictDetail{ Code = "ReceiptAirflare", Value ="wms/receipt/receiving/receiptAirflare" } },
        };

        //public static void SendLED(Equipment station, TaskEntity task)
        //{
        //    switch (station.Code)
        //    {
        //        case "InStation1":
        //            LEDExcute.LeftInfoQueue.Enqueue(AppSession.Bll.GetTaskDetailsForLED(task));
        //            break;
        //        case "OutStation1":
        //            LEDExcute.RightInfoQueue.Enqueue(AppSession.Bll.GetTaskDetailsForLED(task));
        //            break;
        //        default:
        //            break;
        //    }

        //}
    }
}