Skip to content

Commit fe8b350

Browse files
committed
code clean
1 parent 35dc2de commit fe8b350

File tree

9 files changed

+58
-57
lines changed

9 files changed

+58
-57
lines changed

src/c#/GeneralUpdate.Infrastructure/DataServices/Http/HttpService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public sealed class HttpService
99
private static object _lock = new object();
1010
private JsonSerializerOptions _serializerOptions;
1111

12-
public static HttpService Instance
12+
public static HttpService Instance
1313
{
14-
get
14+
get
1515
{
1616
if (_instance == null)
1717
{
@@ -20,8 +20,8 @@ public static HttpService Instance
2020
if (_instance == null) _instance = new HttpService();
2121
}
2222
}
23-
return _instance;
24-
}
23+
return _instance;
24+
}
2525
}
2626

2727
/// <summary>
@@ -33,7 +33,7 @@ public static HttpService Instance
3333
/// <param name="filePath"></param>
3434
/// <param name="reponseCallback"></param>
3535
/// <returns></returns>
36-
public async Task PostFileRequest<T>(string url, Dictionary<string, string> parameters, string filePath , Action<T> reponseCallback) where T : class
36+
public async Task PostFileRequest<T>(string url, Dictionary<string, string> parameters, string filePath, Action<T> reponseCallback) where T : class
3737
{
3838
try
3939
{
@@ -44,7 +44,7 @@ public async Task PostFileRequest<T>(string url, Dictionary<string, string> para
4444
using (var client = new HttpClient())
4545
{
4646
var message = new HttpRequestMessage(HttpMethod.Post, url);
47-
message.Content = MultipartFormDataContentProvider.CreateContent(bytes,Path.GetFileName(filePath), parameters);
47+
message.Content = MultipartFormDataContentProvider.CreateContent(bytes, Path.GetFileName(filePath), parameters);
4848
var responseMessage = await client.SendAsync(message);
4949
if (responseMessage.IsSuccessStatusCode)
5050
{
@@ -62,4 +62,4 @@ public async Task PostFileRequest<T>(string url, Dictionary<string, string> para
6262
}
6363
}
6464
}
65-
}
65+
}

src/c#/GeneralUpdate.Infrastructure/DataServices/Http/MultipartFormDataContentProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ private static List<ByteArrayContent> CreateParamsByteArrayContent(IDictionary<s
4949
return list;
5050
}
5151
}
52-
}
52+
}

src/c#/GeneralUpdate.Infrastructure/DataServices/Pick/IFolderPickerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ public interface IFolderPickerService
44
{
55
Task<string> PickFolderTaskAsync();
66
}
7-
}
7+
}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace GeneralUpdate.Infrastructure.MVVM
1+
namespace GeneralUpdate.Infrastructure.MVVM
82
{
93
public interface IViewModel
104
{
115
void Enter();
126

137
void Exit();
148
}
15-
}
9+
}

src/c#/GeneralUpdate.Infrastructure/MVVM/MessageToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ public class MessageToken
44
{
55
public const string FilesMessageToken = "FilesMessageToken";
66
}
7-
}
7+
}

src/c#/GeneralUpdate.Infrastructure/MVVM/ViewModeBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace GeneralUpdate.Infrastructure.MVVM
94
{
@@ -19,4 +14,4 @@ public void Exit()
1914
throw new NotImplementedException();
2015
}
2116
}
22-
}
17+
}

src/c#/GeneralUpdate.PacketTool/Models/VersionTmplateModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ public class VersionTmplateModel
2727
/// </summary>
2828
public string Url { get; set; }
2929
}
30-
}
30+
}

src/c#/GeneralUpdate.PacketTool/Services/MainService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ namespace GeneralUpdate.PacketTool.Services
44
{
55
public class MainService
66
{
7-
public async Task PostUpgradPakcet<T>(string remoteUrl, string filePath, int clientType, string version, string clientAppKey,string md5,Action<T> reponseCallback) where T : class
7+
public async Task PostUpgradPakcet<T>(string remoteUrl, string filePath, int clientType, string version, string clientAppKey, string md5, Action<T> reponseCallback) where T : class
88
{
9-
if(string.IsNullOrEmpty(remoteUrl)) remoteUrl = "http://127.0.0.1:5001/upload";
9+
if (string.IsNullOrEmpty(remoteUrl)) remoteUrl = "http://127.0.0.1:5001/upload";
1010
var parameters = new Dictionary<string, string>
1111
{
1212
{ "clientType", clientType.ToString() },
1313
{ "version", version },
1414
{ "clientAppKey", clientAppKey },
1515
{ "md5", md5 }
1616
};
17-
await HttpService.Instance.PostFileRequest<T>(remoteUrl,parameters, filePath, reponseCallback);
17+
await HttpService.Instance.PostFileRequest<T>(remoteUrl, parameters, filePath, reponseCallback);
1818
}
1919
}
20-
}
20+
}

src/c#/GeneralUpdate.PacketTool/ViewModels/MainViewModel.cs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class MainViewModel : ViewModeBase
1818
#region Private Members
1919

2020
private string sourcePath, targetPath, patchPath, infoMessage, url, packetName;
21-
private List<string> _formats, _encodings,_appTypes;
21+
private List<string> _formats, _encodings, _appTypes;
2222
private string _currentFormat, _currentEncoding, _currnetAppType, _currentVersion, _currentClientAppKey;
2323
private bool isPublish;
2424
private AsyncRelayCommand buildCommand;
@@ -28,11 +28,11 @@ public class MainViewModel : ViewModeBase
2828
private MainService _mainService;
2929
private const string _jsonTemplateFileName = "version.json";
3030

31-
#endregion
31+
#endregion Private Members
3232

3333
#region Constructors
3434

35-
public MainViewModel(IFolderPickerService folderPickerService)
35+
public MainViewModel(IFolderPickerService folderPickerService)
3636
{
3737
_folderPickerService = folderPickerService;
3838
_mainService = new MainService();
@@ -42,7 +42,7 @@ public MainViewModel(IFolderPickerService folderPickerService)
4242
CurrnetAppType = AppTypes.First();
4343
}
4444

45-
#endregion
45+
#endregion Constructors
4646

4747
#region Public Properties
4848

@@ -64,14 +64,14 @@ public AsyncRelayCommand BuildCommand
6464
get => buildCommand ?? (buildCommand = new AsyncRelayCommand(BuildPacketCallback));
6565
}
6666

67-
public AsyncRelayCommand BuildJsonCommand
67+
public AsyncRelayCommand BuildJsonCommand
6868
{
69-
get => buildJsonCommand ?? (buildJsonCommand = new AsyncRelayCommand(BuildJsonCallback));
69+
get => buildJsonCommand ?? (buildJsonCommand = new AsyncRelayCommand(BuildJsonCallback));
7070
}
7171

7272
public List<string> AppTypes
7373
{
74-
get
74+
get
7575
{
7676
if (_appTypes == null)
7777
{
@@ -100,11 +100,11 @@ public List<string> Formats
100100
}
101101
}
102102

103-
public List<string> Encodings
103+
public List<string> Encodings
104104
{
105-
get
105+
get
106106
{
107-
if (_currentEncoding == null)
107+
if (_currentEncoding == null)
108108
{
109109
_encodings = new List<string>
110110
{
@@ -122,28 +122,29 @@ public List<string> Encodings
122122
}
123123
}
124124

125-
public string CurrentFormat {
125+
public string CurrentFormat
126+
{
126127
get => _currentFormat;
127-
set => SetProperty(ref _currentFormat, value);
128+
set => SetProperty(ref _currentFormat, value);
128129
}
129130

130131
public string CurrentEncoding
131132
{
132-
get => _currentEncoding;
133+
get => _currentEncoding;
133134
set => SetProperty(ref _currentEncoding, value);
134135
}
135136

136-
public string CurrnetAppType
137-
{
138-
get => _currnetAppType;
139-
set => SetProperty(ref _currnetAppType, value);
137+
public string CurrnetAppType
138+
{
139+
get => _currnetAppType;
140+
set => SetProperty(ref _currnetAppType, value);
140141
}
141142

142143
public string CurrentVersion { get => _currentVersion; set => SetProperty(ref _currentVersion, value); }
143144

144145
public string CurrentClientAppKey { get => _currentClientAppKey; set => SetProperty(ref _currentClientAppKey, value); }
145-
146-
#endregion
146+
147+
#endregion Public Properties
147148

148149
#region Private Methods
149150

@@ -164,9 +165,11 @@ private async Task SelectFolderAction(string value)
164165
case "Source":
165166
SourcePath = pickerResult;
166167
break;
168+
167169
case "Target":
168170
TargetPath = pickerResult;
169171
break;
172+
170173
case "Patch":
171174
PatchPath = pickerResult;
172175
break;
@@ -192,20 +195,20 @@ private async Task BuildPacketCallback()
192195

193196
try
194197
{
195-
await DifferentialCore.Instance.Clean(SourcePath, TargetPath, PatchPath, (sender, args) =>{},
196-
String2OperationType(CurrentFormat),String2Encoding(CurrentEncoding), PacketName);
198+
await DifferentialCore.Instance.Clean(SourcePath, TargetPath, PatchPath, (sender, args) => { },
199+
String2OperationType(CurrentFormat), String2Encoding(CurrentEncoding), PacketName);
197200
if (IsPublish)
198201
{
199-
var packetPath = Path.Combine(TargetPath,$"{PacketName}{CurrentFormat}");
200-
if (!File.Exists(packetPath))
202+
var packetPath = Path.Combine(TargetPath, $"{PacketName}{CurrentFormat}");
203+
if (!File.Exists(packetPath))
201204
{
202205
await Shell.Current.DisplayAlert("Build options", $"The package was not found in the following path {packetPath} !", "cancel");
203206
return;
204207
}
205208
var md5 = FileUtil.GetFileMD5(packetPath);
206-
await _mainService.PostUpgradPakcet<UploadReapDTO>(Url,packetPath, String2AppType(CurrnetAppType), CurrentVersion,CurrentClientAppKey, md5, async (resp) =>
209+
await _mainService.PostUpgradPakcet<UploadReapDTO>(Url, packetPath, String2AppType(CurrnetAppType), CurrentVersion, CurrentClientAppKey, md5, async (resp) =>
207210
{
208-
if (resp == null)
211+
if (resp == null)
209212
{
210213
await Shell.Current.DisplayAlert("Build options", "Upload failed !", "cancel");
211214
return;
@@ -270,7 +273,7 @@ private async Task BuildVersionTemplate<T>(string path, T content) where T : cla
270273
if (File.Exists(path)) await Shell.Current.DisplayAlert("Build options", "Generated successfully !", "ok");
271274
}
272275

273-
private bool ValidationParameters() => (string.IsNullOrEmpty(SourcePath) || string.IsNullOrEmpty(TargetPath) || string.IsNullOrEmpty(PatchPath) ||
276+
private bool ValidationParameters() => (string.IsNullOrEmpty(SourcePath) || string.IsNullOrEmpty(TargetPath) || string.IsNullOrEmpty(PatchPath) ||
274277
string.IsNullOrEmpty(PacketName) || string.IsNullOrEmpty(CurrentFormat) || string.IsNullOrEmpty(CurrentEncoding));
275278

276279
private bool ValidationFolder() => (!Directory.Exists(SourcePath) || !Directory.Exists(TargetPath) || !Directory.Exists(PatchPath));
@@ -283,24 +286,31 @@ private Encoding String2Encoding(string encoding)
283286
case "Default":
284287
result = Encoding.Default;
285288
break;
289+
286290
case "UTF8":
287291
result = Encoding.UTF8;
288292
break;
293+
289294
case "UTF7":
290295
result = Encoding.UTF7;
291296
break;
297+
292298
case "Unicode":
293299
result = Encoding.Unicode;
294300
break;
301+
295302
case "UTF32":
296303
result = Encoding.UTF32;
297304
break;
305+
298306
case "BigEndianUnicode":
299307
result = Encoding.BigEndianUnicode;
300308
break;
309+
301310
case "Latin1":
302311
result = Encoding.Latin1;
303312
break;
313+
304314
case "ASCII":
305315
result = Encoding.ASCII;
306316
break;
@@ -316,6 +326,7 @@ private OperationType String2OperationType(string type)
316326
case "ZIP":
317327
result = Zip.Factory.OperationType.GZip;
318328
break;
329+
319330
case "7Z":
320331
result = Zip.Factory.OperationType.G7z;
321332
break;
@@ -331,13 +342,14 @@ private int String2AppType(string appType)
331342
case "Client":
332343
result = 1;
333344
break;
345+
334346
case "UTF8":
335347
result = 2;
336348
break;
337349
}
338350
return result;
339351
}
340352

341-
#endregion
353+
#endregion Private Methods
342354
}
343-
}
355+
}

0 commit comments

Comments
 (0)