zhao
2021-07-19 8347f2fbddbd25369359dcb2da1233ac48a19fdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using log4net;
using HH.AutoBom.Core;
using System.Configuration;
using HH.WMS.Common;
using Newtonsoft.Json;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Sys;
using HH.WMS.Common.External;
using System.IO;
using System.Text;
 
namespace HH.WMS.WebUI
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
    // 请访问 http://go.microsoft.com/?LinkId=9394801
 
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //将一个大型的MVC站点划分成多个Area区域,然后各自的Area有着自己的Controller、Action、View等元素
            AreaRegistration.RegisterAllAreas();
            //注册WebAPI路由
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            //全局过滤器,
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            //注册路由规则
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //注册捆绑规则
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //全局配置
            FrameworkConfig.Register();
            try
            {
                string wms_ipAddress = ConfigurationManager.AppSettings["wms_ipAddress"].ToString();
                if (wms_ipAddress != "")
                {
                    //获取服务端配置的Config
                    Constants.SysConfig.WMS_API = wms_ipAddress;
                    string strResult = WebApiManager.HttpWMS_Get("api/Strategy/GetWebConfig");
                    OperateResult or = JsonConvert.DeserializeObject<OperateResult>(strResult);
                    if (or.Status == ResultStatus.Success)
                    {
                        Constants.SysConfig = JsonConvert.DeserializeObject<SysConfigParamEntity>(or.Data.ToString());
                        Constants.SysConfig.WMS_API = wms_ipAddress;
                    }
                    new ProjectConfigs(Constants.SysConfig.PROJECT_CODE);
                }
            }
            catch (Exception ex)
            {
            }
 
            InitialLanguagePack();
        }
 
        /// <summary>
        /// 初始化加载语言包
        /// </summary>
        public void InitialLanguagePack()
        {
            //所有语言集合
            Dictionary<string, Dictionary<string, string>> lanGroup = new Dictionary<string, Dictionary<string, string>>();
 
            try
            {
                string js = "";
                //判断路径
                if (Directory.Exists(Server.MapPath("~/Content/LanguagePack/")))
                {
                    //获取路径下所有文件,循环每个文件,取出内容
                    string[] files = Directory.GetFiles(Server.MapPath("~/Content/LanguagePack/"));
                    
                    js += "LanguageInfo.lanGroup={";
                    foreach (var item in files)
                    {
                        using (StreamReader sr = new StreamReader(File.Open(item, FileMode.Open)))
                        {
                            string content = sr.ReadToEnd();
                            string key = Path.GetFileName(item).Replace(Path.GetExtension(item), "");
                            var lanContent = JsonConvert.DeserializeObject<Dictionary<string, string>>(content);
                            lanGroup.Add(key, lanContent);
                            js += "\"" + key + "\":" + content + ",";
                        }
                    }
                    js = js.TrimEnd(',');
                    js += "}";
                }
                //将生成的语言包存放到缓存中
                HttpRuntime.Cache.Insert("lanGroup", lanGroup);
                //生成文件,并保存
                File.WriteAllText(Server.MapPath("~/Content/LanguagePack/Js/lanGroup.js"), js, Encoding.UTF8);
            }
            catch (Exception)
            {
 
                throw;
            }
        }
    }
}