wzp
2022-10-25 1961452ebc018cf758924f26d9c7aa0b31495227
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<%@ WebHandler Language="C#" Class="GwApHandler" %>
 
using Dao;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
 
public class GwApHandler : PageHandler<SysUser>
{
    private GwApDao _Dao = new GwApDao();
 
    private string GetAlarmExpressionText(GwAp i)
    {
        string str = "未启用告警";
        if (!string.IsNullOrEmpty(i.AlarmData))
        {
            JToken token = JsonConvert.DeserializeObject<JToken>(i.AlarmData);
            if ((token != null) && ((token.Value<int>("apInThreshold") > 0) || (token.Value<int>("apPendingThreshold") > 0)))
            {
                str = string.Empty;
            }
            if (token.Value<int>("apInThreshold") > 0)
            {
                str = str + "当入口流量小于 <span class='label label-success'>" + token.Value<string>("apInThreshold") + "条/5分钟</span> 时告警;";
            }
            if (token.Value<int>("apPendingThreshold") > 0)
            {
                str = str + "当入口流量阻塞大于<span class='label label-success'>" + token.Value<string>("apPendingThreshold") + "条</span> 时告警";
            }
        }
        return str;
    }
 
    private JsonPageResult GetAp(PageContext<SysUser> context)
    {
        string apID = context.GetString("apid");
        return new JsonPageResult(true, this._Dao.Get(apID));
    }
 
    private JsonPageResult LoadToGwApPageList(PageContext<SysUser> context)
    {
        int num;
        int @int = context.GetInt("pageSize", 20);
        int pageIndex = context.GetInt("pageIndex", 1);
        List<GwAp> list = this._Dao.LoadInfoList(out num, @int, pageIndex);
        string str = "";
        if ((list != null) && (list.Count > 0))
        {
            foreach (GwAp ap in list)
            {
                str = str + "<tr >";
                object obj2 = str;
                str = string.Concat(new object[] { obj2, "<td>", ap.ApID, "</td><td>", ap.ApName, "</td><td>", ap.ApPort, "</td>" });
                str = str + "<td style=\"word-wrap: break-word; word-break: break-all; overflow: hidden;\">" + ap.AccessCode + "</td>";
                str = str + "<td> <div class=\"text-muted\">" + this.GetAlarmExpressionText(ap) + "</div></td>";
                str = str + "<td>";
                str = str + string.Format(" <a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-edit btn btn-success btn-xs \"><i class=\"fa fa-edit\"></i> 编辑</a> ", ap.ApID);
                str = str + "</td>";
                str = str + "</tr>";
            }
        }
        else
        {
            str = str + "<tr><td colspan=\"8\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
        }
        return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = num });
    }
 
    public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context)
    {
        string str = context.GetString("action");
        switch (str)
        {
            case "getAp":
                return this.GetAp(context);
 
            case "save":
                return this.Save(context);
 
            case "loadToGwApPageList":
                return this.LoadToGwApPageList(context);
        }
        throw new Exception("Invalid Action=" + str);
    }
 
    private JsonPageResult Save(PageContext<SysUser> context)
    {
        int @int = context.GetInt("apid");
        string str = context.GetString("accessCode");
        string apName = context.GetString("apName");
        int port = context.GetInt("apPort");
        string str3 = context.GetString("cmSegments");
        string str4 = context.GetString("cuSegments");
        string str5 = context.GetString("ctSegments");
        int num3 = context.GetInt("apInThreshold");
        int num4 = context.GetInt("apPendingThreshold");
        if (@int == 0)
        {
            throw new ArgumentException("APID参数异常!");
        }
        if (this._Dao.IsNameEixsts(apName, @int))
        {
            throw new Exception("接入点名称重复,请重新输入!");
        }
        if (this._Dao.IsPortExits(port, @int))
        {
            throw new Exception("接入点监听端口重复,请重新输入!");
        }
        GwAp o = new GwAp();
        o.ApID = @int;
        o.ApName = apName;
        o.ApPort = port;
        o.AccessCode = str;
        o.CMSegments = str3;
        o.UNSegments = str4;
        o.CTSegments = str5;
        o.AlarmData = JsonConvert.SerializeObject(new { apInThreshold = num3, apPendingThreshold = num4 });
        this._Dao.Update(o);
        this._Dao.UpdateSegments(o);
        return new JsonPageResult(true, "接入点" + @int + "信息更新成功!");
    }
}
 
 
 
/*
using System;
using System.Web;
using Dao;
using Model;
using Common;
 
public class GwApHandler : PageHandler<Model.SysUser>
{
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
 
        switch (action)
        {
            case "getAp":
                return GetAp(context);
            case "save":
                return Save(context);
                
            default:
                throw new Exception("Invalid Action=" + action);
        }
    }
 
    private GwApDao _Dao = new GwApDao();
 
    private JsonPageResult Save(PageContext<SysUser> context)
    {
        int apid = context.GetInt("apid");
        string accessCode = context.GetString("accessCode");
        string apName = context.GetString("apName");
        int apPort = context.GetInt("apPort");
        string cmSegments = context.GetString("cmSegments");
        string cuSegments = context.GetString("cuSegments");
        string ctSegments = context.GetString("ctSegments");
        //string alarmData = context.GetString("alarmData");
 
        //if (Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JToken>(alarmData) == null)
        //{
        //    throw new ArgumentException("告警参数格式异常!");
        //}
 
        int apInThreshold = context.GetInt("apInThreshold");
        int apPendingThreshold = context.GetInt("apPendingThreshold");
        
        if (apid == 0)
        {
            throw new ArgumentException("APID参数异常!");
        }
 
        if (_Dao.IsNameEixsts(apName, apid))
        {
            throw new Exception("接入点名称重复,请重新输入!");
        }
 
        if (_Dao.IsPortExits(apPort, apid))
        {
            throw new Exception("接入点监听端口重复,请重新输入!");
        }
        
        GwAp ap = new GwAp();
        ap.ApID = apid;
        ap.ApName = apName;
        ap.ApPort = apPort;
        ap.AccessCode = accessCode;
        ap.CMSegments = cmSegments;
        ap.UNSegments = cuSegments;
        ap.CTSegments = ctSegments;
        ap.AlarmData = Newtonsoft.Json.JsonConvert.SerializeObject(new { apInThreshold = apInThreshold, apPendingThreshold = apPendingThreshold }); ;
 
        _Dao.Update(ap);
        
        return new JsonPageResult(true, "接入点"+ apid+"信息更新成功!");
    }
    
    private JsonPageResult GetAp(PageContext<SysUser> context)
    {
        string apid = context.GetString("apid");
 
        return new JsonPageResult(true, _Dao.Get(apid));
    }
}
*/