服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-04-12 646ce5990fb03908a0371fc4ca8416905b27a4d1
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Rhea.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Tiger.IBusiness
{
    public class ApiConfig
    {
        public static IServiceProvider ServiceProvider;
        public static IConfiguration Configuration;
 
        public static void InitConfig(IConfiguration _configuration)
        {
            Configuration = _configuration;
        }
 
        private static string _AllowUrl = string.Empty;
        /// <summary>
        /// 链接白名单(可不做身份验证)
        /// </summary>
        public static List<string> AllowUrl
        {
            get
            {
                if (string.IsNullOrEmpty(_AllowUrl))
                {
                    _AllowUrl = Configuration["AllowUrl"];
                }
                List<string> listUrls = new List<string>();
                if (!string.IsNullOrEmpty(_AllowUrl))
                {
                    string[] urls = System.Text.RegularExpressions.Regex.Split(_AllowUrl, ",");
                    if (urls.Length > 0)
                    {
                        foreach (string url in urls)
                        {
                            if (!listUrls.Contains(url))
                            {
                                listUrls.Add(url);
                            }
                        }
                    }
 
                }
                return listUrls;
            }
        }
 
        private static string _FilePath = string.Empty;
        /// <summary>
        /// 文件路径
        /// </summary>
        public static string FilePath
        {
            get
            {
                if (string.IsNullOrEmpty(_FilePath))
                {
                    _FilePath = Configuration["CommonSettings:FilePath"];
                }
                return _FilePath;
            }
        }
 
 
        /// <summary>
        /// 更新路径
        /// </summary>
        public static string UpgradePath => (string.IsNullOrEmpty(Configuration["Upgrade:Path"]) ? (AppDomain.CurrentDomain.BaseDirectory + "Upgrade") : Configuration["Upgrade:Path"]) + "\\";
 
        private static string _IsOpenCache = string.Empty;
        /// <summary>
        /// 是否使用Redis
        /// </summary>
        public static bool IsOpenCache
        {
            get
            {
                if (string.IsNullOrEmpty(_IsOpenCache))
                {
                    _IsOpenCache = Configuration["Redis:IsOpenRedis"];
                }
                if (_IsOpenCache.ToLower() == "true")
                {
                    return true;
                }
                return false;
            }
        }
 
        private static string _RedisConnectionString = string.Empty;
        /// <summary>
        /// Redis默认连接串
        /// </summary>
        public static string RedisConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_RedisConnectionString))
                {
                    _RedisConnectionString = Configuration["Redis:ConnectionString"];
                }
                return _RedisConnectionString;
            }
        }
 
        /// <summary>
        /// 统一请求页面实体
        /// </summary>
        public static HttpContext HttpCurrent
        {
            get
            {
                object factory = ServiceProvider.GetService(typeof(IHttpContextAccessor));
                HttpContext context = ((IHttpContextAccessor)factory).HttpContext;
                return context;
            }
        }
 
        /// <summary>
        /// 事务超时小时数
        /// </summary>
        public static int Transaction_TimeoutHours
        {
            get => Convert.ToInt32(Configuration["Transaction:TimeoutHours"] ?? "12");
        }
 
        /// <summary>
        /// 事务超时分钟数
        /// </summary>
        public static double Client_TimeoutMinutes
        {
            get => Convert.ToDouble(Configuration["Timeout:Client_Minutes"] ?? "60");
        }
 
        /// <summary>
        /// 是否测试版本
        /// </summary>
        public static bool IsTestVersion
        {
            get => Configuration.AsEnumerable().Where(q => q.Key.StartsWith("StartUpSetting:UseUrls") && q.Value == "http://*:9520").Any();
        }
 
        /// <summary>
        /// 旧系统版本 
        /// </summary>
        public static bool IsOldVersion
        {
            get => Configuration.AsEnumerable().Where(q => q.Key.StartsWith("StartUpSetting:UseUrls") && q.Value == "http://*:9527").Any();
        }
 
        /// <summary>
        /// 是否开发版本
        /// </summary>
        public static bool IsDevVersion
        {
            get => Configuration.AsEnumerable().Where(q => q.Key.StartsWith("StartUpSetting:UseUrls") && q.Value == "http://*:9510").Any();
        }
 
        /// <summary>
        /// RunInterface
        /// </summary>
        public static bool RunInterface
        {
            get => (Configuration["RunInterface"] ?? "").ToLower() == "true";
        }
 
        public static bool IsTestServer
        {
            get => (BizConfig.Configuration["IsTestServer"] ?? "").ToLower() == "true";
        }
    }
 
    public class BizConfig
    {
        public static IConfiguration Configuration => RheaConfig.Configuration;
        public static string DB_ModelAssembly => RheaConfig.DB_ModelAssembly;
        public static string MQTTService_IPAddress => RheaConfig.MQTTService_IPAddress;
        public static string DefaultLanguage => Configuration["DefaultLanguage"] ?? "en";
        public static void InitConfig(IConfiguration _configuration, Dictionary<string, Dictionary<string, string>> language)
        {
            //Init Rhea
            Rhea.Common.RheaConfig.InitConfig(_configuration);
            Rhea.Common.Language.Default = DefaultLanguage;
            Rhea.Common.Language.Dictionary = language;
        }
    }
}