프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkusLogview / MARKUS_LOGVIEW / Common / CommonController.cs @ 84578b97

이력 | 보기 | 이력해설 | 다운로드 (6.3 KB)

1
using IKCOM;
2
using MarkusDataModel.Common;
3
using MarkusDataModel.DataModel;
4
using Newtonsoft.Json;
5
using System;
6
using System.Collections.Generic;
7
using System.Linq;
8
using System.Net;
9
using System.Net.Http;
10
using System.Security.Cryptography;
11
using System.Text;
12
using System.Threading.Tasks;
13
using System.Web;
14

    
15
namespace MARKUS_LOGVIEW.Common
16
{
17
    public class CommonController
18
    {
19
        
20
        #region JSON Serialization 으로 변경하는 코드
21

    
22
        public async static Task<StringContent> JsonSerialize<T>(T data)
23
        {
24
            return await toJson(JsonConvert.SerializeObject(data));
25
        }
26

    
27
        public async static Task<StringContent> toJson(string jsonData)
28
        {
29
            return new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json");
30
        }
31

    
32
        public string GetBaseURL()
33
        {
34
            return HttpContext.Current.Request.Url.OriginalString;
35
        }
36

    
37
        #endregion
38

    
39
        #region 응답처리 하는 코드 
40

    
41
        public async static Task<HttpResponseMessage> OK<T>(HttpResponseMessage resp, T Data)
42
        {
43

    
44
            resp.StatusCode = HttpStatusCode.OK;
45
            resp.Content = await JsonSerialize<T>(Data);
46

    
47
            return resp;
48

    
49
        }
50

    
51
        public async static Task<HttpResponseMessage> NotFound<T>(HttpResponseMessage resp, T Data)
52
        {
53

    
54
            resp.StatusCode = HttpStatusCode.NotFound;
55
            resp.Content = await JsonSerialize<T>(Data);
56
            return resp;
57

    
58
        }
59

    
60
        public static HttpResponseMessage InternalServerError(HttpResponseMessage resp, string Message)
61
        {
62
            resp.StatusCode = HttpStatusCode.InternalServerError;
63
            resp.Content = new StringContent(Message);
64
            return resp;
65
        }
66

    
67
        public static HttpResponseMessage Forbidden( HttpResponseMessage resp)
68
        {
69
            resp.StatusCode = HttpStatusCode.Forbidden;
70
            return resp;
71
        }
72

    
73
        public static HttpResponseMessage UnValidation( HttpResponseMessage resp)
74
        {
75
            resp.StatusCode = HttpStatusCode.BadRequest;
76
            resp.Content = new StringContent("필수 정보를 입력하지 않았습니다.");
77
            return resp;
78
        }
79

    
80
        public static HttpResponseMessage BadRequest(HttpResponseMessage resp , object msg ) {
81

    
82
            resp.StatusCode = HttpStatusCode.BadRequest;
83
            resp.Content = new StringContent(msg.ToString());
84
            return resp;
85

    
86
        }
87

    
88

    
89
        #endregion
90

    
91
        #region Markus 프로그램 구동을 위한 파라미터 생성 메서드, ShortGUID 생성 
92

    
93
        public static string CreateMarkusParam(string projectNo, string documentID, string token)
94
        {
95
            ViewInfo viewInfo = new ViewInfo();
96

    
97
            viewInfo.DocumentItemID = documentID;
98
            viewInfo.ProjectNO = projectNo;
99
            viewInfo.UserID = AuthorizationController.GetTokenValue(AuthorizationController.DecodeJWT(token)).ID;
100

    
101
            return ParamEncoding(JsonConvert.SerializeObject(viewInfo));
102

    
103
        }
104

    
105
        public static string ParamEncoding(string EncodingText, System.Text.Encoding oEncoding = null)
106
        {
107

    
108
            if (oEncoding == null)
109
                oEncoding = System.Text.Encoding.UTF8;
110

    
111
            return Convert.ToBase64String(oEncoding.GetBytes(EncodingText));
112

    
113
        }
114

    
115
        public static ViewInfo ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
116
        {
117
            if (oEncoding == null)
118
                oEncoding = System.Text.Encoding.UTF8;
119

    
120
            byte[] byteArray = Convert.FromBase64String(DecodingText);
121

    
122
            string jsonBack = oEncoding.GetString(byteArray);
123

    
124
            return JsonConvert.DeserializeObject<ViewInfo>(jsonBack);
125
        }
126

    
127
        public static string shortGuid()
128
        {
129
            byte[] bytes = new byte[16];
130
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
131
            {
132
                provider.GetBytes(bytes);
133
            }
134

    
135
            var guid = new Guid(bytes);
136

    
137
            return Convert.ToBase64String(guid.ToByteArray())
138
                .Substring(0, 10)
139
                .Replace("/", "")
140
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
141
        }
142
        #endregion
143

    
144

    
145
        /// <summary>
146
        /// 파일 관련 상태값 한글화 
147
        /// </summary>
148
        /// <param name="statusNum"></param>
149
        /// <returns></returns>
150
        public static string GetStatusName(int statusNum)
151
        {
152
            #region status 한글로 변환 
153
            try
154
            {
155
                using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
156
                {
157
                    var status = ent.PROPERTIES.Where(prop => prop.TYPE == "PDFStatus").ToList();
158

    
159
                    string statusName = null;
160

    
161
                    status.ForEach(chk =>
162
                    {
163
                        if (Int32.Parse(chk.VALUE) == statusNum)
164
                        {
165
                            statusName = chk.PROPERTY;
166
                        }
167

    
168
                    });
169

    
170
                    return statusName;
171

    
172
                }
173
            }
174
            catch (Exception ex)
175
            {
176
                throw;
177
            }
178
            #endregion
179
        }
180

    
181

    
182
        /// <summary>
183
        /// 접속 관련 상태값 한글화
184
        /// </summary>
185
        /// <param name="statusNum"></param>
186
        /// <returns></returns>
187
        public static string GetLogStatusName( int statusNum)
188
        {
189
            #region status name 반환
190
            MARKUS_CONNECTION_STR name = new MARKUS_CONNECTION_STR();
191
            string ret = String.Empty;
192

    
193
            try
194
            {
195

    
196
                switch (statusNum)
197
                {
198
                    case (int)MARKUS_CONNECTION_TYPE.PROCESSING:
199
                        ret = name.processing;
200
                        break;
201
                    case (int)MARKUS_CONNECTION_TYPE.REJECT:
202
                        ret = name.reject;
203
                        break;
204
                    case (int)MARKUS_CONNECTION_TYPE.TERMINATE:
205
                        ret = name.terminate;
206
                        break;
207
                }
208

    
209
                return ret;
210

    
211
            }
212
            catch (Exception ex)
213
            {
214
                throw;
215
            }
216
            #endregion
217
        }
218

    
219
    }
220
}
클립보드 이미지 추가 (최대 크기: 500 MB)