Skip to content

Commit cabe28d

Browse files
committed
Some code cleanup
1 parent 4715ab6 commit cabe28d

24 files changed

+402
-167
lines changed

.editorconfig

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,63 @@ insert_final_newline = true
88
charset = utf-8
99

1010
[*.cs]
11+
# General Formatting
1112
indent_style = tab
1213
indent_size = tab
1314
tab_width = 4
1415
trim_trailing_whitespace = true
1516

17+
#### .NET Coding Conventions ####
18+
19+
# Organize usings
20+
dotnet_separate_import_directive_groups = false
21+
dotnet_sort_system_directives_first = false
22+
23+
# this. and Me. preferences
24+
dotnet_style_qualification_for_event = false:silent
25+
dotnet_style_qualification_for_field = false:silent
26+
dotnet_style_qualification_for_method = false:suggestion
27+
dotnet_style_qualification_for_property = false:silent
28+
29+
# Language keywords vs BCL types preferences
30+
dotnet_style_predefined_type_for_locals_parameters_members = true
31+
dotnet_style_predefined_type_for_member_access = true
32+
# var preferences
33+
csharp_style_var_elsewhere = false:silent
34+
csharp_style_var_for_built_in_types = false:silent
35+
csharp_style_var_when_type_is_apparent = true:suggestion
36+
37+
# Expression-bodied members
38+
csharp_style_expression_bodied_accessors = true:silent
39+
csharp_style_expression_bodied_constructors = false:silent
40+
csharp_style_expression_bodied_methods = true:silent
41+
csharp_style_expression_bodied_properties = true:silent
42+
43+
# Expression-level preferences
44+
csharp_style_inlined_variable_declaration = true:suggestion
45+
46+
# 'using' directive preferences
47+
csharp_using_directive_placement = outside_namespace:suggestion
48+
49+
#### C# Formatting Rules ####
50+
51+
# Indentation preferences
1652
csharp_indent_switch_labels = false
1753

54+
# Space preferences
55+
csharp_space_after_cast = false
56+
csharp_space_after_colon_in_inheritance_clause = true
57+
csharp_space_after_keywords_in_control_flow_statements = true
58+
csharp_space_before_colon_in_inheritance_clause = true
59+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
60+
csharp_space_between_method_call_name_and_opening_parenthesis = false
61+
csharp_space_between_method_call_parameter_list_parentheses = false
62+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
63+
csharp_space_between_method_declaration_parameter_list_parentheses = false
64+
65+
# Wrapping preferences
66+
csharp_preserve_single_line_blocks = true
67+
csharp_preserve_single_line_statements = true
68+
1869
[*.{tt,ttinclude}]
1970
insert_final_newline = false

TS3ABotUnitTests/TS3ABotUnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="NUnit" Version="3.12.0" />
1515
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

TS3AudioBot.ruleset

Lines changed: 0 additions & 97 deletions
This file was deleted.

TS3AudioBot.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
appveyor.yml = appveyor.yml
1515
GitVersion.yml = GitVersion.yml
1616
README.md = README.md
17-
TS3AudioBot.ruleset = TS3AudioBot.ruleset
1817
EndProjectSection
1918
EndProject
2019
Global

TS3AudioBot/Bot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ private void EnableIdleTickWorker()
522522
return;
523523
}
524524
idleTickWorker.Interval = idleTime;
525-
idleTickWorker.Active = true;
525+
idleTickWorker.Enable();
526526
}
527527

528-
private void DisableIdleTickWorker() => idleTickWorker.Active = false;
528+
private void DisableIdleTickWorker() => idleTickWorker.Disable();
529529

530530
#endregion
531531

TS3AudioBot/Environment/Stats.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void UpdateMeta()
100100
public void StartTimer(bool upload)
101101
{
102102
uploadParamEnabled = upload;
103-
ticker.Active = true;
103+
ticker.Enable();
104104
}
105105

106106
private async Task SendStats(StatsPing sendPacket)

TS3AudioBot/Helper/WebWrapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10+
using Newtonsoft.Json;
1011
using System;
1112
using System.IO;
13+
using System.Linq;
1214
using System.Net;
1315
using System.Net.Http;
16+
using System.Net.Http.Headers;
1417
using System.Threading.Tasks;
1518
using TS3AudioBot.Localization;
16-
using System.Net.Http.Headers;
17-
using Newtonsoft.Json;
18-
using System.Linq;
1919

2020
namespace TS3AudioBot.Helper
2121
{

TS3AudioBot/ResourceFactories/ISearchResolver.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10+
using System.Collections.Generic;
11+
using System.Threading.Tasks;
12+
1013
namespace TS3AudioBot.ResourceFactories
1114
{
12-
using System.Collections.Generic;
13-
using System.Threading.Tasks;
14-
1515
public interface ISearchResolver : IResolver
1616
{
1717
Task<IList<AudioResource>> Search(ResolveContext ctx, string keyword);

TS3AudioBot/ResourceFactories/MediaResolver.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10-
using Heijden.DNS;
1110
using PlaylistsNET.Content;
1211
using System;
1312
using System.Collections.Generic;
1413
using System.IO;
1514
using System.Linq;
16-
using System.Net;
1715
using System.Threading.Tasks;
1816
using TS3AudioBot.Config;
1917
using TS3AudioBot.Helper;
@@ -66,18 +64,18 @@ public async Task<PlayResource> GetResourceById(ResolveContext ctx, AudioResourc
6664

6765
public string RestoreLink(ResolveContext _, AudioResource resource) => resource.ResourceId;
6866

69-
private async Task<ResData> ValidateFromString(ConfBot config, string uriStr)
67+
private Task<ResData> ValidateFromString(ConfBot config, string uriStr)
7068
{
7169
var uri = GetUri(config, uriStr);
72-
return await ValidateUri(uri);
70+
return ValidateUri(uri);
7371
}
7472

75-
private async Task<ResData> ValidateUri(Uri uri)
73+
private Task<ResData> ValidateUri(Uri uri)
7674
{
7775
if (uri.IsWeb())
78-
return await ValidateWeb(uri);
76+
return ValidateWeb(uri);
7977
if (uri.IsFile())
80-
return ValidateFile(uri);
78+
return Task.Run(() => ValidateFile(uri));
8179

8280
throw Error.LocalStr(strings.error_media_invalid_uri);
8381
}
@@ -211,11 +209,8 @@ public async Task<Playlist> GetPlaylist(ResolveContext ctx, string url)
211209
{
212210
if (uri.IsFile())
213211
{
214-
if (File.Exists(url))
215-
{
216-
using var stream = File.OpenRead(uri.AbsolutePath);
217-
return await GetPlaylistContentAsync(stream, url);
218-
}
212+
using var stream = File.OpenRead(uri.AbsolutePath);
213+
return await GetPlaylistContentAsync(stream, url);
219214
}
220215
else if (uri.IsWeb())
221216
{
@@ -252,15 +247,6 @@ private Playlist GetPlaylistContent(Stream stream, string url, string? mime = nu
252247
switch (anyId)
253248
{
254249
case ".m3u":
255-
{
256-
var parser = new M3uContent();
257-
var list = parser.GetFromStream(stream);
258-
259-
items = new List<PlaylistItem>(
260-
from e in list.PlaylistEntries
261-
select new PlaylistItem(new AudioResource(e.Path, e.Title, ResolverFor)));
262-
break;
263-
}
264250
case ".m3u8":
265251
case "application/mpegurl":
266252
case "application/x-mpegurl":
@@ -269,7 +255,7 @@ from e in list.PlaylistEntries
269255
case "application/vnd.apple.mpegurl":
270256
case "application/vnd.apple.mpegurl.audio":
271257
{
272-
var parser = new M3u8Content();
258+
var parser = new M3uContent();
273259
var list = parser.GetFromStream(stream);
274260

275261
items = new List<PlaylistItem>(

TS3AudioBot/ResourceFactories/SoundcloudResolver.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10-
using Newtonsoft.Json;
11-
using Newtonsoft.Json.Linq;
1210
using System;
1311
using System.Globalization;
1412
using System.IO;

0 commit comments

Comments
 (0)