Fix C# code formatting

This commit is contained in:
chylex 2021-08-15 21:58:32 +02:00
parent 3f763bbf6b
commit bbb50dc50c
No known key found for this signature in database
GPG Key ID: 4DE42C8F19A80548
6 changed files with 49 additions and 40 deletions

View File

@ -3,46 +3,56 @@ using System;
namespace DHT.Desktop.Dialogs {
public static class DialogResult {
public enum All {
Ok, Yes, No, Cancel
Ok,
Yes,
No,
Cancel
}
public enum OkCancel {
Closed, Ok, Cancel
Closed,
Ok,
Cancel
}
public enum YesNo {
Closed, Yes, No
Closed,
Yes,
No
}
public enum YesNoCancel {
Closed, Yes, No, Cancel
Closed,
Yes,
No,
Cancel
}
public static OkCancel ToOkCancel(this All? result) {
return result switch {
null => OkCancel.Closed,
All.Ok => OkCancel.Ok,
All.Cancel => OkCancel.Cancel,
_ => throw new ArgumentException("Cannot convert dialog result " + result + " to ok/cancel.")
null => OkCancel.Closed,
All.Ok => OkCancel.Ok,
All.Cancel => OkCancel.Cancel,
_ => throw new ArgumentException("Cannot convert dialog result " + result + " to ok/cancel.")
};
}
public static YesNo ToYesNo(this All? result) {
return result switch {
null => YesNo.Closed,
All.Yes => YesNo.Yes,
All.No => YesNo.No,
_ => throw new ArgumentException("Cannot convert dialog result " + result + " to yes/no.")
null => YesNo.Closed,
All.Yes => YesNo.Yes,
All.No => YesNo.No,
_ => throw new ArgumentException("Cannot convert dialog result " + result + " to yes/no.")
};
}
public static YesNoCancel ToYesNoCancel(this All? result) {
return result switch {
null => YesNoCancel.Closed,
All.Yes => YesNoCancel.Yes,
All.No => YesNoCancel.No,
All.Cancel => YesNoCancel.Cancel,
_ => throw new ArgumentException("Cannot convert dialog result " + result + " to yes/no/cancel.")
null => YesNoCancel.Closed,
All.Yes => YesNoCancel.Yes,
All.No => YesNoCancel.No,
All.Cancel => YesNoCancel.Cancel,
_ => throw new ArgumentException("Cannot convert dialog result " + result + " to yes/no/cancel.")
};
}
}

View File

@ -16,4 +16,3 @@ namespace DHT.Desktop.Main {
}
}
}

View File

@ -19,11 +19,11 @@ namespace DHT.Desktop.Main.Controls {
public string StatusText {
get {
return CurrentStatus switch {
Status.Starting => "STARTING",
Status.Ready => "READY",
Status.Stopping => "STOPPING",
Status.Stopped => "STOPPED",
_ => ""
Status.Starting => "STARTING",
Status.Ready => "READY",
Status.Stopping => "STOPPING",
Status.Stopped => "STOPPED",
_ => ""
};
}
}

View File

@ -8,28 +8,28 @@ namespace DHT.Server.Data {
public static class ServerTypes {
public static ServerType? FromString(string? str) {
return str switch {
"SERVER" => ServerType.Server,
"GROUP" => ServerType.Group,
"DM" => ServerType.DirectMessage,
_ => null
"SERVER" => ServerType.Server,
"GROUP" => ServerType.Group,
"DM" => ServerType.DirectMessage,
_ => null
};
}
public static string ToString(ServerType? type) {
return type switch {
ServerType.Server => "SERVER",
ServerType.Group => "GROUP",
ServerType.DirectMessage => "DM",
_ => "UNKNOWN"
ServerType.Server => "SERVER",
ServerType.Group => "GROUP",
ServerType.DirectMessage => "DM",
_ => "UNKNOWN"
};
}
public static string ToJsonViewerString(ServerType? type) {
return type switch {
ServerType.Server => "server",
ServerType.Group => "group",
ServerType.DirectMessage => "user",
_ => "unknown"
ServerType.Server => "server",
ServerType.Group => "group",
ServerType.DirectMessage => "user",
_ => "unknown"
};
}
}

View File

@ -27,24 +27,24 @@ namespace DHT.Server.Endpoints {
var requestToken = request.Headers["X-DHT-Token"];
if (requestToken.Count != 1 || requestToken[0] != parameters.Token) {
Log.Error("Token: " + (requestToken.Count == 1 ? requestToken[0] : "<missing>"));
response.StatusCode = (int)HttpStatusCode.Forbidden;
response.StatusCode = (int) HttpStatusCode.Forbidden;
return;
}
try {
var (statusCode, output) = await Respond(ctx);
response.StatusCode = (int)statusCode;
response.StatusCode = (int) statusCode;
if (output != null) {
await response.WriteAsJsonAsync(output);
}
} catch (HttpException e) {
Log.Error(e);
response.StatusCode = (int)e.StatusCode;
response.StatusCode = (int) e.StatusCode;
await response.WriteAsync(e.Message);
} catch (Exception e) {
Log.Error(e);
response.StatusCode = (int)HttpStatusCode.InternalServerError;
response.StatusCode = (int) HttpStatusCode.InternalServerError;
}
}

View File

@ -56,7 +56,7 @@ namespace DHT.Server.Endpoints {
Name = ele.RequireString("name", path),
Type = ele.HasKey("type") ? ele.RequireString("type", path) : null,
Url = ele.RequireString("url", path),
Size = (ulong)ele.RequireLong("size", path)
Size = (ulong) ele.RequireLong("size", path)
});
private static IEnumerable<Embed> ReadEmbeds(JsonElement.ArrayEnumerator array, string path) => array.Select(ele => new Embed {