Skip to content

Commit

Permalink
Evgeniy d/terminal user id error (#61)
Browse files Browse the repository at this point in the history
* add get terminal user id error to marketing

* fix json Serializer #60
  • Loading branch information
mrerro authored May 17, 2023
1 parent 708144b commit 021b972
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
19 changes: 13 additions & 6 deletions PrinterApp/Marketing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ private static void Post(string action, string status, string pathFrom,
string pathTo)
{
var body = new MarketingBody(action: action,
additional_data:
$"{{\"status\": \"{status}\",\"app_version\": \"{AssemblyVersion}\",\"terminal_user_id\": \"{TerminalUserId}\"}}",
additional_data: new MarketingBody.AdditionalData(status, AssemblyVersion,
TerminalUserId),
path_from: pathFrom, path_to: pathTo);
SharedClient.PostAsJsonAsync("action", body);
}

private static void Post(string action, string status)
{
var body = new MarketingBody(action: action,
additional_data:
$"{{\"status\": \"{status}\",\"app_version\": \"{AssemblyVersion}\",\"terminal_user_id\": \"{TerminalUserId}\"}}");
additional_data: new MarketingBody.AdditionalData(status, AssemblyVersion,
TerminalUserId));
SharedClient.PostAsJsonAsync("action", body);
}

private static void Post(string action, string status, float availableMem,
float currentMem)
{
var body = new MarketingBody(action: action,
additional_data:
$"{{\"status\": \"{status}\",\"available_mem\": \"{availableMem}\",\"current_mem\": \"{currentMem}\",\"app_version\": \"{AssemblyVersion}\",\"terminal_user_id\": \"{TerminalUserId}\"}}");
additional_data: new MarketingBody.AdditionalData(status, availableMem, currentMem,
AssemblyVersion, TerminalUserId));
SharedClient.PostAsJsonAsync("action", body);
}

Expand Down Expand Up @@ -213,4 +213,11 @@ public static void HwndSourceError()
action: "print terminal failed to get window HwndSource",
status: "error");
}

public static void TerminalUserIdError()
{
Post(
action: "print terminal failed to get user id",
status: "error");
}
}
46 changes: 38 additions & 8 deletions PrinterApp/MarketingBody.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
using Newtonsoft.Json;

namespace PrinterApp;

public class MarketingBody
{
public MarketingBody(string action, string additional_data, string path_from,
string path_to)
public class AdditionalData
{
this.action = action;
this.additional_data = additional_data;
this.path_from = path_from;
this.path_to = path_to;
public AdditionalData(string status, string app_version, string terminal_user_id)
{
this.status = status;
this.app_version = app_version;
this.terminal_user_id = terminal_user_id;
}

public AdditionalData(string status, float available_mem, float current_mem,
string app_version, string terminal_user_id) : this(status, app_version,
terminal_user_id)
{
this.available_mem = available_mem;
this.current_mem = current_mem;
}

public string? status { get; }
public string? app_version { get; }
public string? terminal_user_id { get; }
public float? available_mem { get; }
public float? current_mem { get; }
}

public MarketingBody(string action, string additional_data)
public MarketingBody(string action, AdditionalData additional_data)
{
this.action = action;
this.additional_data = additional_data;
JsonSerializerSettings jsonSerializerSettings = new()
{
NullValueHandling = NullValueHandling.Ignore,
StringEscapeHandling = StringEscapeHandling.Default
};
this.additional_data =
JsonConvert.SerializeObject(additional_data, jsonSerializerSettings);
}

public MarketingBody(string action, AdditionalData additional_data, string path_from,
string path_to) : this(action, additional_data)
{
this.path_from = path_from;
this.path_to = path_to;
}

public int user_id { get; set; } = -1;
Expand Down
2 changes: 1 addition & 1 deletion PrinterApp/PrinterApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Title>PrinterApp</Title>
<Description>gui for work https://app.profcomff.com/print/docs</Description>
<Authors>Dyakov EI</Authors>
<Version>2.1.9.0</Version>
<Version>2.1.9.1</Version>
<Company>dyakov.space</Company>
<Copyright>dyakov.space @ 2023</Copyright>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions PrinterApp/PrinterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using QRCoder;
using QRCoder.Xaml;
using System.Collections.Generic;
using System.Windows.Documents;

namespace PrinterApp;

Expand Down Expand Up @@ -87,6 +88,10 @@ public PrinterModel(ConfigFile configFile, AutoUpdater autoUpdater)
catch (Exception e)
{
Log.Error($"{GetType().Name} {MethodBase.GetCurrentMethod()?.Name}: {e}");
Marketing.TerminalUserIdError();
MessageBox.Show(
"Терминал не смог получить id. Сообщите ответственному лицу. Перезапустите программу.",
"Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
throw;
}

Expand Down

0 comments on commit 021b972

Please sign in to comment.