markus / KCOM / Common / Commons.cs @ 7fa95b67
이력 | 보기 | 이력해설 | 다운로드 (1.6 KB)
1 |
using System; |
---|---|
2 |
using System.Net.Http; |
3 |
using System.Text; |
4 |
using System.Threading.Tasks; |
5 |
|
6 |
namespace KCOM.Common |
7 |
{ |
8 |
public class Commons |
9 |
{ |
10 |
public static string ShortGuid() |
11 |
{ |
12 |
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 |
//강인구 추가 |
29 |
public static string ShortFileKey() |
30 |
{ |
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 |
|
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 |
} |
55 |
} |