프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Common / Globals.cs @ eef9d0c2

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

    
7
using System.IO;
8
using System.Security.Cryptography;
9
using System.Text.RegularExpressions;
10
using System.Configuration;
11
using System.Xml.Linq;
12
using System.Xml.XPath;
13

    
14
namespace ID2.Manager.Common
15
{
16
    public class Globals
17
    {
18
        private static Globals m_Globals;
19

    
20
        public static Globals GetInstance
21
        {
22
            get
23
            {
24
                if (m_Globals == null)
25
                {
26
                    m_Globals = new Globals();
27
                }
28

    
29
                return m_Globals;
30
            }
31
        }
32

    
33
        public static string Name
34
        {
35
            get
36
            {
37
                return "Samsung IDUS";
38
            }
39
        }
40

    
41
        public static string EncryptionSHA256(string Data)
42
        {
43
            using (SHA256 sha = new SHA256Managed())
44
            {
45
                return Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(Data)));
46

    
47
            }
48
        }
49

    
50
        public static string Base64Encoding(string EncodingText, Encoding oEncoding = null)
51
        {
52
            if (oEncoding == null)
53
                oEncoding = Encoding.UTF8;
54

    
55
            byte[] arr = oEncoding.GetBytes(EncodingText);
56
            return System.Convert.ToBase64String(arr);
57
        }
58

    
59
        public static string Base64Decoding(string DecodingText, Encoding oEncoding = null)
60
        {
61
            if (oEncoding == null)
62
                oEncoding = Encoding.UTF8;
63

    
64
            byte[] arr = System.Convert.FromBase64String(DecodingText);
65
            return oEncoding.GetString(arr);
66
        }
67

    
68
        public static bool IsMatchEmailFormat(string EmailText)
69
        {
70
            return Regex.IsMatch(EmailText, @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");
71
        }
72

    
73
        public static string ProgramDataFolder
74
        {
75
            get
76
            {
77
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "ID2Manager");
78
            }
79
        }
80

    
81
        public static string GetProjectDBFilePath()
82
        {
83
            string prjDBPath = string.Empty;
84

    
85
            try
86
            {
87
                var userConfigPath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
88
                if (File.Exists(userConfigPath))
89
                {
90
                    XDocument xdoc = XDocument.Load(userConfigPath);
91
                    XElement id2xElement = xdoc.XPathSelectElements("//setting[@name=\"ID2SQLiteInfo\"]").FirstOrDefault();
92
                    if (id2xElement != null)
93
                    {
94
                        if (!string.IsNullOrEmpty(id2xElement.Value))
95
                        {
96
                            if (File.Exists(id2xElement.Value))
97
                            {
98
                                prjDBPath = id2xElement.Value;
99
                                return prjDBPath;
100
                            }
101
                        }
102
                    }
103
                }
104

    
105
                var appConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ConfigurationManager.AppSettings["ID2SQLiteInfo"]);
106
                if (File.Exists(appConfigPath))
107
                {
108
                    prjDBPath = appConfigPath;
109
                    return prjDBPath;
110
                }
111
            }
112
            catch (Exception ex)
113
            {
114
                throw ex;
115
            }
116

    
117
            return prjDBPath;
118
        }
119

    
120
        public static string GetProjectDBConnstr()
121
        {
122
            string prjDBConnstr = string.Empty;
123

    
124
            try
125
            {
126
                string prjDBPath = GetProjectDBFilePath();
127
                if (!string.IsNullOrEmpty(prjDBPath))
128
                {
129
                    prjDBConnstr = String.Format(ConfigurationManager.AppSettings["ID2SQLite"], prjDBPath);
130
                }
131
            }
132
            catch (Exception ex)
133
            {
134
                throw ex;
135
            }
136

    
137
            return prjDBConnstr;
138
        }
139

    
140
        public static bool IsProjectDBConnstr()
141
        {
142
            bool isDBPath = false;
143

    
144
            try
145
            {
146
                isDBPath = !string.IsNullOrEmpty(GetProjectDBConnstr());
147
            }
148
            catch (Exception ex)
149
            {
150
                throw ex;
151
            }
152
            //catch
153
            //{
154
            //    Program.logger.Error($"An exception occurred from {MethodBase.GetCurrentMethod().Name}", ex);
155
            //}
156

    
157
            return isDBPath;
158
        }
159
    }
160
}
클립보드 이미지 추가 (최대 크기: 500 MB)