개정판 cf1cc862
licensing 수정
Change-Id: I3bffa280e0205be1031c133bf4716929fcbd7c54
License.DB/Database.cs | ||
---|---|---|
4 | 4 |
using System.IO; |
5 | 5 |
using System.Linq; |
6 | 6 |
using System.Net; |
7 |
using System.Runtime.Serialization; |
|
8 |
using System.Runtime.Serialization.Json; |
|
7 | 9 |
using System.Text; |
8 | 10 |
using System.Threading.Tasks; |
9 | 11 |
|
... | ... | |
23 | 25 |
|
24 | 26 |
public DataBase() |
25 | 27 |
{ |
26 |
DataBaseFoloder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataBase"); |
|
28 |
DataBaseFoloder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataBase\\Active");
|
|
27 | 29 |
|
28 | 30 |
if (!System.IO.Directory.Exists(DataBaseFoloder)) |
29 | 31 |
{ |
... | ... | |
63 | 65 |
} |
64 | 66 |
} |
65 | 67 |
|
66 |
public async Task<bool> UploadAsync(Uri uri) |
|
68 |
public async Task<bool> UploadAsync(Uri uri,string SiteName)
|
|
67 | 69 |
{ |
68 | 70 |
bool result = false; |
69 | 71 |
|
70 | 72 |
try |
71 | 73 |
{ |
72 |
var filename = $"{DateTime.Today.AddDays(-1).ToString("yyyyMMdd")}.db"; |
|
73 |
var filepath = System.IO.Path.Combine(DataBaseFoloder, filename); |
|
74 |
var databasedir = new DirectoryInfo(DataBaseFoloder); |
|
74 | 75 |
|
75 |
using (var db = new LiteDatabase(LogConnectionString))
|
|
76 |
if(databasedir.EnumerateFiles().Count() > 0)
|
|
76 | 77 |
{ |
77 |
var collection = db.GetCollection<UploadItem>("Upload"); |
|
78 |
var items = databasedir.GetFiles().Where(x=>x.Name != $"{DateTime.Today.ToString("yyyyMMdd")}.db") |
|
79 |
.Select(x => new { key = int.Parse(x.Name.Replace(".db", "")), fileName = x.Name}) |
|
80 |
.OrderByDescending(x => x.key); |
|
78 | 81 |
|
79 |
var items = collection.Query().Where(x => x.FileName == filename).FirstOrDefault(); |
|
80 |
|
|
81 |
if (items == null && File.Exists(filepath)) |
|
82 |
foreach (var item in items) |
|
82 | 83 |
{ |
83 |
var uploadFilename = await UploadFileAsync(uri, filepath); |
|
84 |
var size = await FileSizeAsync(uri, filename); |
|
85 |
|
|
86 |
var localfileLength = new System.IO.FileInfo(filepath).Length; |
|
84 |
var fileSize = await FileSizeAsync(uri, SiteName, item.fileName); |
|
87 | 85 |
|
88 |
if (long.Parse(size) == localfileLength)
|
|
86 |
if(int.Parse(fileSize) < 0)
|
|
89 | 87 |
{ |
90 |
collection.Insert(new UploadItem(filename, localfileLength)); |
|
91 |
result = true; |
|
88 |
var filepath = System.IO.Path.Combine(DataBaseFoloder, item.fileName); |
|
89 |
var uploadFilename = await UploadFileAsync(uri, SiteName, filepath); |
|
90 |
} |
|
91 |
else |
|
92 |
{ |
|
93 |
break; |
|
92 | 94 |
} |
93 | 95 |
} |
94 |
else |
|
95 |
{ |
|
96 |
result = true; |
|
97 |
} |
|
96 |
|
|
97 |
//using (var db = new LiteDatabase(LogConnectionString)) |
|
98 |
//{ |
|
99 |
// var collection = db.GetCollection<UploadItem>("Upload"); |
|
100 |
|
|
101 |
// var items = collection.Query().Where(x => x.FileName == filename).FirstOrDefault(); |
|
102 |
|
|
103 |
// if (items == null && File.Exists(filepath)) |
|
104 |
// { |
|
105 |
// var uploadFilename = await UploadFileAsync(uri,SiteName, filepath); |
|
106 |
// var size = await FileSizeAsync(uri, filename); |
|
107 |
|
|
108 |
// var localfileLength = new System.IO.FileInfo(filepath).Length; |
|
109 |
|
|
110 |
// if (long.Parse(size) == localfileLength) |
|
111 |
// { |
|
112 |
// collection.Insert(new UploadItem(filename, localfileLength)); |
|
113 |
// result = true; |
|
114 |
// } |
|
115 |
// } |
|
116 |
// else |
|
117 |
// { |
|
118 |
// result = true; |
|
119 |
// } |
|
120 |
//} |
|
98 | 121 |
} |
99 | 122 |
} |
100 | 123 |
catch (Exception) |
... | ... | |
105 | 128 |
return result; |
106 | 129 |
} |
107 | 130 |
|
108 |
private async Task<string> UploadFileAsync(Uri _url, string filePath) |
|
131 |
private async Task<string> UploadFileAsync(Uri _url,string SiteName, string filePath)
|
|
109 | 132 |
{ |
110 | 133 |
try |
111 | 134 |
{ |
... | ... | |
117 | 140 |
client.Headers.Add("Cache-Control", "no-cache"); |
118 | 141 |
client.Encoding = Encoding.UTF8; |
119 | 142 |
|
120 |
var result = await client.UploadFileTaskAsync(_url, filePath);
|
|
143 |
var result = await client.UploadFileTaskAsync($"{_url}/Site={SiteName}", filePath);
|
|
121 | 144 |
string reply = System.Text.Encoding.UTF8.GetString(result); |
122 | 145 |
|
123 | 146 |
return reply; |
... | ... | |
128 | 151 |
} |
129 | 152 |
} |
130 | 153 |
|
131 |
private async Task<string> FileSizeAsync(Uri _url, string filePath) |
|
154 |
private async Task<string> FileSizeAsync(Uri _url, string SiteName, string filePath)
|
|
132 | 155 |
{ |
133 | 156 |
try |
134 | 157 |
{ |
... | ... | |
140 | 163 |
client.Headers.Add("Cache-Control", "no-cache"); |
141 | 164 |
client.Encoding = Encoding.UTF8; |
142 | 165 |
|
143 |
var data = await client.DownloadStringTaskAsync($"{_url}/FileInfo?filename={filePath}");
|
|
166 |
var data = await client.DownloadStringTaskAsync($"{_url}/FileInfo/Site={SiteName}&file={filePath}");
|
|
144 | 167 |
return data; |
145 | 168 |
} |
146 | 169 |
catch (Exception) |
... | ... | |
148 | 171 |
throw; |
149 | 172 |
} |
150 | 173 |
} |
174 |
|
|
175 |
private async Task<string> FileListAsync(Uri _url, string SiteName) |
|
176 |
{ |
|
177 |
try |
|
178 |
{ |
|
179 |
return ""; |
|
180 |
} |
|
181 |
catch (Exception) |
|
182 |
{ |
|
183 |
throw; |
|
184 |
} |
|
185 |
} |
|
151 | 186 |
} |
152 | 187 |
} |
내보내기 Unified diff