Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Net.Http.Json;
using System.Reflection;
using System.Security.Cryptography;
using System.Windows;
using System.Windows.Shell;
Expand Down Expand Up @@ -125,7 +126,7 @@ public static void FinalizeExceptionHandling(Exception ex, bool log = true)

_showingExceptionDialog = true;

SendLog();
SendLog(ex);

if (Bootstrapper?.Dialog != null)
{
Expand Down Expand Up @@ -198,16 +199,23 @@ public static async void SendStat(string key, string value)
}
}

public static async void SendLog()
public static async void SendLog(Exception exception)
{
if (!Settings.Prop.EnableAnalytics || !CanSendLogs())
return;

var request = new PostExceptionV2Request
{
Type = exception.GetType().ToString(),
Message = exception.Message,
Log = Logger.AsDocument
};

try
{
await HttpClient.PostAsync(
$"https://{WebUrl}/metrics/post-exception",
new StringContent(Logger.AsDocument)
await HttpClient.PostAsJsonAsync(
$"https://{WebUrl}/metrics/post-exception-v2",
request
);
}
catch (Exception ex)
Expand Down
1 change: 1 addition & 0 deletions Bloxstrap/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
global using Bloxstrap.Models.Persistable;
global using Bloxstrap.Models.SettingTasks;
global using Bloxstrap.Models.SettingTasks.Base;
global using Bloxstrap.Models.Web;
global using Bloxstrap.Resources;
global using Bloxstrap.UI;
global using Bloxstrap.Utility;
14 changes: 14 additions & 0 deletions Bloxstrap/Models/Web/PostExceptionV2Request.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Bloxstrap.Models.Web
{
internal class PostExceptionV2Request
{
[JsonPropertyName("type")]
public string Type { get; set; } = "";

[JsonPropertyName("message")]
public string Message { get; set; } = "";

[JsonPropertyName("log")]
public string Log { get; set; } = "";
}
}
9 changes: 8 additions & 1 deletion Bloxstrap/UI/Elements/Settings/Pages/BloxstrapPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@

<!-- This does not need i18n as this is locked behind "Developer Mode" -->
<controls:OptionControl
Visibility="{Binding Path=WebEnvironmentVisibility, Mode=OneTime}"
Visibility="{Binding Path=DeveloperOptionVisibility, Mode=OneTime}"
Header="Web environment"
Description="Site to use for metrics"
HelpLink="https://admin.bloxstraplabs.com/Wiki/Developers/Web-Environments">
<ComboBox Width="200" Padding="10,5,10,5" ItemsSource="{Binding WebEnvironments, Mode=OneWay}" SelectedValue="{Binding WebEnvironment, Mode=TwoWay}" />
</controls:OptionControl>

<controls:OptionControl
Visibility="{Binding Path=DeveloperOptionVisibility, Mode=OneTime}"
Header="Debug crash"
Description="All our builds keep blowing up!">
<Button Padding="10,5,10,5" Content="Self-destruct" Command="{Binding DebugCrashCommand, Mode=OneTime}" />
</controls:OptionControl>

<ui:CardExpander Margin="0,8,0,0" IsExpanded="True">
<ui:CardExpander.Header>
<Grid>
Expand Down
9 changes: 8 additions & 1 deletion Bloxstrap/UI/ViewModels/Settings/BloxstrapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ public WebEnvironment WebEnvironment
set => App.Settings.Prop.WebEnvironment = value;
}

public Visibility WebEnvironmentVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed;
public Visibility DeveloperOptionVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed;

public bool ShouldExportConfig { get; set; } = true;

public bool ShouldExportLogs { get; set; } = true;

public ICommand DebugCrashCommand => new RelayCommand(DebugCrash);

public ICommand ExportDataCommand => new RelayCommand(ExportData);

private void DebugCrash()
{
throw new ApplicationException("Pretend like something terrible has happened");
}

private void ExportData()
{
string timestamp = DateTime.UtcNow.ToString("yyyyMMdd'T'HHmmss'Z'");
Expand Down