markus / KCOM / Common / Commons.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (1.6 KB)
1 | 03960fa5 | taeseongkim | using System; |
---|---|---|---|
2 | 7fa95b67 | humkyung | using System.Net.Http; |
3 | 4b33593a | taeseongkim | using System.Text; |
4 | 7fa95b67 | humkyung | using System.Threading.Tasks; |
5 | 24678e06 | humkyung | |
6 | namespace KCOM.Common |
||
7 | { |
||
8 | public class Commons |
||
9 | { |
||
10 | 5a223b60 | humkyung | public static string ShortGuid() |
11 | 24678e06 | humkyung | { |
12 | 4b33593a | taeseongkim | char[] chars = "ABCDEF1234567890".ToCharArray(); |
13 | byte[] data = new byte[1]; |
||
14 | System.Security.Cryptography.RNGCryptoServiceProvider crypto = new System.Security.Cryptography.RNGCryptoServiceProvider(); |
||
15 | crypto.GetNonZeroBytes(data); |
||
16 | data = new byte[32]; |
||
17 | crypto.GetNonZeroBytes(data); |
||
18 | StringBuilder result = new StringBuilder(32); |
||
19 | |||
20 | foreach (byte b in data) |
||
21 | { |
||
22 | result.Append(chars[b % (chars.Length - 1)]); |
||
23 | } |
||
24 | |||
25 | return result.ToString(); |
||
26 | } |
||
27 | |||
28 | 24678e06 | humkyung | //강인구 추가 |
29 | 5a223b60 | humkyung | public static string ShortFileKey() |
30 | 24678e06 | humkyung | { |
31 | //byte[] bytes = new byte[3]; |
||
32 | //using (var provider = System.IO.Path.GetRandomFileName()) |
||
33 | //{ |
||
34 | // provider.GetBytes(bytes); |
||
35 | //} |
||
36 | |||
37 | return System.IO.Path.GetRandomFileName(); |
||
38 | } |
||
39 | 7fa95b67 | humkyung | |
40 | /// <summary> |
||
41 | /// url의 파일이 존재하는지 검사하여 결과를 리턴한다. |
||
42 | /// </summary> |
||
43 | /// <param name="url"></param> |
||
44 | /// <returns></returns> |
||
45 | public static async Task<bool> DoesFileExist(string url) |
||
46 | { |
||
47 | using (HttpClient client = new HttpClient()) |
||
48 | { |
||
49 | var restponse = await client.GetAsync(url); |
||
50 | |||
51 | return restponse.StatusCode == System.Net.HttpStatusCode.OK; |
||
52 | } |
||
53 | } |
||
54 | 24678e06 | humkyung | } |
55 | } |