Skip to content

Commit

Permalink
remove assembly trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
rducom committed Feb 12, 2022
1 parent b927ac3 commit 2779229
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 15 additions & 10 deletions src/SqlBackupTools/Notification/SlackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Serilog;

namespace SqlBackupTools.Notification
{
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, GenerationMode = JsonSourceGenerationMode.Serialization)]
[JsonSerializable(typeof(SlackMessage))]
[JsonSerializable(typeof(SlackResponse))]
internal partial class SlackJsonContext : JsonSerializerContext
{

}

public class SlackClient
{
private readonly ILogger _logger;
Expand All @@ -26,19 +34,15 @@ public async Task<SlackResponse> SendSlackMessageAsync(SlackMessage message, str
var client = new HttpClient { BaseAddress = new Uri(_slackUri) };
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", slackSecret);

var json = JsonConvert.SerializeObject(message, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});

var json = JsonSerializer.Serialize(message, SlackJsonContext.Default.SlackMessage);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var ok = await client.PostAsync("api/chat.postMessage", content);
if (!ok.IsSuccessStatusCode)
{
throw new NotificationException(ok.StatusCode.ToString());
}

var response = JsonConvert.DeserializeObject<SlackResponse>(await ok.Content.ReadAsStringAsync());
var response = JsonSerializer.Deserialize<SlackResponse>(await ok.Content.ReadAsStringAsync(), SlackJsonContext.Default.SlackResponse);
if (!response.Ok)
{
throw new NotificationException(response.Error);
Expand All @@ -53,11 +57,12 @@ public async Task<SlackResponse> SendSlackMessageAsync(SlackMessage message, str
}
}


public class SlackMessage
{
public string Channel { get; set; }
public string Text { get; set; }
[JsonProperty(PropertyName = "thread_ts")]
[JsonPropertyName("thread_ts")]
public string ThreadTs { get; set; }
public List<Attachment> Attachments { get; set; }

Expand Down
6 changes: 1 addition & 5 deletions src/SqlBackupTools/SqlBackupTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>Link</TrimMode>
<Platforms>x64</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="MailKit" Version="3.1.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 2779229

Please sign in to comment.