Skip to content

Commit

Permalink
処理されない例外が発生したときにログを送信できるようにした。
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Aug 19, 2023
1 parent 88d1567 commit 00f5585
Show file tree
Hide file tree
Showing 16 changed files with 1,444 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Beutl.sln
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Beutl.Extensions.FFmpeg", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PropertyEditorViewTests", "tests\PropertyEditorViewTests\PropertyEditorViewTests.csproj", "{EED4AB04-13CD-4382-BD1A-64D7A258957F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Beutl.ExceptionHandler", "src\Beutl.ExceptionHandler\Beutl.ExceptionHandler.csproj", "{AD5AED68-C003-4131-B883-A013AA1C0DDF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -332,6 +334,14 @@ Global
{EED4AB04-13CD-4382-BD1A-64D7A258957F}.Release|Any CPU.Build.0 = Release|Any CPU
{EED4AB04-13CD-4382-BD1A-64D7A258957F}.Release|x64.ActiveCfg = Release|Any CPU
{EED4AB04-13CD-4382-BD1A-64D7A258957F}.Release|x64.Build.0 = Release|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Debug|x64.ActiveCfg = Debug|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Debug|x64.Build.0 = Debug|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Release|Any CPU.Build.0 = Release|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Release|x64.ActiveCfg = Release|Any CPU
{AD5AED68-C003-4131-B883-A013AA1C0DDF}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageVersion Include="Avalonia.Xaml.Interactivity" Version="11.0.2" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.7" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="DeviceId" Version="6.3.0" />
<PackageVersion Include="DynamicData" Version="7.14.2" />
<PackageVersion Include="FFmpeg.AutoGen" Version="6.0.0.2" />
<PackageVersion Include="FluentAvalonia.BreadcrumbBar" Version="2.0.1" />
Expand Down
115 changes: 113 additions & 2 deletions src/Beutl.Api/Generated.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//----------------------
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// </auto-generated>
Expand Down Expand Up @@ -135,6 +135,90 @@ public virtual async System.Threading.Tasks.Task<CheckForUpdatesResponse> CheckF
}
}

/// <exception cref="BeutlApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<FileResponse> SendLogAsync(string deviceId, FileParameter file)
{
return SendLogAsync(deviceId, file, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <exception cref="BeutlApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<FileResponse> SendLogAsync(string deviceId, FileParameter file, System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/v1/app/sendLog/{deviceId}");
urlBuilder_.Replace("{deviceId}", System.Uri.EscapeDataString(ConvertToString(deviceId, System.Globalization.CultureInfo.InvariantCulture)));

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var boundary_ = System.Guid.NewGuid().ToString();
var content_ = new System.Net.Http.MultipartFormDataContent(boundary_);
content_.Headers.Remove("Content-Type");
content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_);

if (file != null)
{
var content_file_ = new System.Net.Http.StreamContent(file.Data);
if (!string.IsNullOrEmpty(file.ContentType))
content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType);
content_.Add(content_file_, "file", file.FileName ?? "file");
}
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream"));

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);

PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200 || status_ == 206)
{
var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false);
var fileResponse_ = new FileResponse(status_, headers_, responseStream_, null, response_);
disposeClient_ = false; disposeResponse_ = false; // response and client are disposed by FileResponse
return fileResponse_;
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new BeutlApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

protected struct ObjectResponseResult<T>
{
public ObjectResponseResult(T responseObject, string responseText)
Expand Down Expand Up @@ -6241,6 +6325,33 @@ public UpdateProfileRequest(long? @avatar_id, string @bio, string @blog_url, str

}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class FileParameter
{
public FileParameter(System.IO.Stream data)
: this (data, null, null)
{
}

public FileParameter(System.IO.Stream data, string fileName)
: this (data, fileName, null)
{
}

public FileParameter(System.IO.Stream data, string fileName, string contentType)
{
Data = data;
FileName = fileName;
ContentType = contentType;
}

public System.IO.Stream Data { get; private set; }

public string FileName { get; private set; }

public string ContentType { get; private set; }
}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class FileResponse : System.IDisposable
{
Expand Down Expand Up @@ -6323,4 +6434,4 @@ public BeutlApiException(string message, int statusCode, string response, System
#pragma warning restore 1591
#pragma warning restore 8073
#pragma warning restore 3016
#pragma warning restore 8603
#pragma warning restore 8603
16 changes: 8 additions & 8 deletions src/Beutl.Core/TypeFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public TypeNameParser(List<Token> tokens, Func<string, Assembly?>? assemblyResol
_assemblyResolver = assemblyResolver ?? DefaultAssemblyResolver;
}

public Type Parse()
public Type? Parse()
{
Token[] asmTokens = TakeAssemblyTokens(_tokens).ToArray();
_assemblyName = string.Concat(asmTokens
Expand Down Expand Up @@ -267,7 +267,7 @@ private static Type[] ParseGenericTypes(Span<Token> tokens)
if (tokens.Length == 0)
return Array.Empty<Type>();

var list = new List<Type>();
var list = new List<Type?>();

if (tokens is [{ Type: TokenType.BeginGenericArguments }, .. var generics, { Type: TokenType.EndGenericArguments }])
{
Expand Down Expand Up @@ -298,7 +298,7 @@ private static Type[] ParseGenericTypes(Span<Token> tokens)
if (list.Any(x => x == null))
throw new InvalidOperationException($"Invalid Tokens: {ConcatTokens(tokens)}");

return list.ToArray();
return list.ToArray()!;
}

// ":List<[System.Runtime]:Int32>"を解析
Expand All @@ -319,22 +319,22 @@ private static string TakeTypeNameTokens(Span<Token> tokens, out Span<Token> gen
}
}

private Type ParseNestedType(Span<Token> tokens)
private Type? ParseNestedType(Span<Token> tokens)
{
string typeName = TakeTypeNameTokens(tokens, out Span<Token> genericTokens, out Span<Token> parents);
Type[] genericArgs = ParseGenericTypes(genericTokens);
string suffix = genericArgs.Length > 0 ? $"`{genericArgs.Length}" : "";

Type type;
Type? type;
if (parents.Length != 0)
{
Type parent = ParseNestedType(parents);
Type? parent = ParseNestedType(parents);
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
type = parent.GetNestedType($"{typeName}{suffix}", flags)!;
type = parent?.GetNestedType($"{typeName}{suffix}", flags)!;
}
else
{
type = _assembly!.GetType($"{_namespace ?? ""}.{typeName}{suffix}")!;
type = _assembly?.GetType($"{_namespace ?? ""}.{typeName}{suffix}")!;
}

if (genericArgs.Length > 0)
Expand Down
Loading

0 comments on commit 00f5585

Please sign in to comment.