Skip to content

Commit

Permalink
Fixes (#993)
Browse files Browse the repository at this point in the history
* Exception handling for scheduler.

* Image hover

* Fix transfer.

* Fixes

* Flush write.

* OpenApi fixes
  • Loading branch information
SebastianStehle authored May 20, 2023
1 parent 9dfee4d commit c3c72c0
Show file tree
Hide file tree
Showing 164 changed files with 843 additions and 477 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public StackdriverExceptionHandler(IContextExceptionLogger logger, IHttpContextA
httpContextWrapper = new HttpContextWrapper(httpContextAccessor);
}

public void Append(IObjectWriter writer, SemanticLogLevel logLevel, Exception exception)
public void Append(IObjectWriter writer, SemanticLogLevel logLevel, Exception? exception)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Squidex.Extensions.APM.Stackdriver;

public sealed class StackdriverSeverityLogAppender : ILogAppender
{
public void Append(IObjectWriter writer, SemanticLogLevel logLevel, Exception exception)
public void Append(IObjectWriter writer, SemanticLogLevel logLevel, Exception? exception)
{
var severity = GetSeverity(logLevel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public sealed record AlgoliaAction : RuleAction
[Display(Name = "Document", Description = "The optional custom document.")]
[Editor(RuleFieldEditor.TextArea)]
[Formattable]
public string Document { get; set; }
public string? Document { get; set; }

[Display(Name = "Deletion", Description = "The condition when to delete the entry.")]
[Editor(RuleFieldEditor.Text)]
public string Delete { get; set; }
public string? Delete { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AlgoliaActionHandler(RuleEventFormatter formatter, IScriptEngine scriptEn

var ruleDescription = string.Empty;
var contentId = entityEvent.Id.ToString();
var content = (AlgoliaContent)null;
var content = (AlgoliaContent?)null;

if (delete)
{
Expand All @@ -58,7 +58,7 @@ public AlgoliaActionHandler(RuleEventFormatter formatter, IScriptEngine scriptEn

try
{
string jsonString;
string? jsonString;

if (!string.IsNullOrEmpty(action.Document))
{
Expand All @@ -70,7 +70,7 @@ public AlgoliaActionHandler(RuleEventFormatter formatter, IScriptEngine scriptEn
jsonString = ToJson(@event);
}

content = serializer.Deserialize<AlgoliaContent>(jsonString);
content = serializer.Deserialize<AlgoliaContent>(jsonString!);
}
catch (Exception ex)
{
Expand All @@ -92,7 +92,7 @@ public AlgoliaActionHandler(RuleEventFormatter formatter, IScriptEngine scriptEn
ApiKey = action.ApiKey,
Content = serializer.Serialize(content, true),
ContentId = contentId,
IndexName = await FormatAsync(action.IndexName, @event)
IndexName = (await FormatAsync(action.IndexName, @event))!
};

return (ruleDescription, ruleJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed record AzureQueueAction : RuleAction
[Display(Name = "Payload (Optional)", Description = "Leave it empty to use the full event as body.")]
[Editor(RuleFieldEditor.TextArea)]
[Formattable]
public string Payload { get; set; }
public string? Payload { get; set; }

protected override IEnumerable<ValidationError> CustomValidate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AzureQueueActionHandler(RuleEventFormatter formatter)
{
var queueName = await FormatAsync(action.Queue, @event);

string requestBody;
string? requestBody;

if (!string.IsNullOrEmpty(action.Payload))
{
Expand All @@ -51,7 +51,7 @@ public AzureQueueActionHandler(RuleEventFormatter formatter)
var ruleJob = new AzureQueueJob
{
QueueConnectionString = action.ConnectionString,
QueueName = queueName,
QueueName = queueName!,
MessageBodyV2 = requestBody
};

Expand All @@ -75,5 +75,5 @@ public sealed class AzureQueueJob

public string QueueName { get; set; }

public string MessageBodyV2 { get; set; }
public string? MessageBodyV2 { get; set; }
}
4 changes: 2 additions & 2 deletions backend/extensions/Squidex.Extensions/Actions/ClientPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Squidex.Extensions.Actions;

internal sealed class ClientPool<TKey, TClient>
internal sealed class ClientPool<TKey, TClient> where TKey : notnull
{
private static readonly TimeSpan TimeToLive = TimeSpan.FromMinutes(30);
private readonly MemoryCache memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
Expand All @@ -37,6 +37,6 @@ public async Task<TClient> GetClientAsync(TKey key)
memoryCache.Set(key, client, TimeToLive);
}

return client;
return client!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public sealed record CommentAction : RuleAction

[Display(Name = "Client", Description = "An optional client name.")]
[Editor(RuleFieldEditor.Text)]
public string Client { get; set; }
public string? Client { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CommentActionHandler(RuleEventFormatter formatter, ICommandBus commandBus
AppId = contentEvent.AppId
};

ruleJob.Text = await FormatAsync(action.Text, @event);
ruleJob.Text = (await FormatAsync(action.Text, @event))!;

if (!string.IsNullOrEmpty(action.Client))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CreateContentActionHandler(RuleEventFormatter formatter, IAppProvider app

var json = await FormatAsync(action.Data, @event);

ruleJob.Data = jsonSerializer.Deserialize<ContentData>(json);
ruleJob.Data = jsonSerializer.Deserialize<ContentData>(json!);

if (!string.IsNullOrEmpty(action.Client))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public sealed record DiscourseAction : RuleAction
[Display(Name = "Title", Description = "The optional title when creating new topics.")]
[Editor(RuleFieldEditor.Text)]
[Formattable]
public string Title { get; set; }
public string? Title { get; set; }

[Display(Name = "Topic", Description = "The optional topic id.")]
[Editor(RuleFieldEditor.Text)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public DiscourseActionHandler(RuleEventFormatter formatter, IHttpClientFactory h
{
var url = $"{action.Url.ToString().TrimEnd('/')}/posts.json?api_key={action.ApiKey}&api_username={action.ApiUsername}";

var json = new Dictionary<string, object>
var json = new Dictionary<string, object?>
{
["title"] = await FormatAsync(action.Title, @event)
["title"] = await FormatAsync(action.Title!, @event)
};

if (action.Topic != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public sealed record ElasticSearchAction : RuleAction

[Display(Name = "Username", Description = "The optional username.")]
[Editor(RuleFieldEditor.Text)]
public string Username { get; set; }
public string? Username { get; set; }

[Display(Name = "Password", Description = "The optional password.")]
[Editor(RuleFieldEditor.Text)]
public string Password { get; set; }
public string? Password { get; set; }

[Display(Name = "Document", Description = "The optional custom document.")]
[Editor(RuleFieldEditor.TextArea)]
[Formattable]
public string Document { get; set; }
public string? Document { get; set; }

[Display(Name = "Deletion", Description = "The condition when to delete the document.")]
[Editor(RuleFieldEditor.Text)]
public string Delete { get; set; }
public string? Delete { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace Squidex.Extensions.Actions.ElasticSearch;

public sealed class ElasticSearchActionHandler : RuleActionHandler<ElasticSearchAction, ElasticSearchJob>
{
private readonly ClientPool<(Uri Host, string Username, string Password), ElasticLowLevelClient> clients;
private readonly ClientPool<(Uri Host, string? Username, string? Password), ElasticLowLevelClient> clients;
private readonly IScriptEngine scriptEngine;
private readonly IJsonSerializer serializer;

public ElasticSearchActionHandler(RuleEventFormatter formatter, IScriptEngine scriptEngine, IJsonSerializer serializer)
: base(formatter)
{
clients = new ClientPool<(Uri Host, string Username, string Password), ElasticLowLevelClient>(key =>
clients = new ClientPool<(Uri Host, string? Username, string? Password), ElasticLowLevelClient>(key =>
{
var config = new ConnectionConfiguration(key.Host);

Expand Down Expand Up @@ -61,7 +61,7 @@ public ElasticSearchActionHandler(RuleEventFormatter formatter, IScriptEngine sc
var ruleText = string.Empty;
var ruleJob = new ElasticSearchJob
{
IndexName = await FormatAsync(action.IndexName, @event),
IndexName = (await FormatAsync(action.IndexName, @event))!,
ServerHost = action.Host.ToString(),
ServerUser = action.Username,
ServerPassword = action.Password,
Expand All @@ -79,7 +79,7 @@ public ElasticSearchActionHandler(RuleEventFormatter formatter, IScriptEngine sc
ElasticSearchContent content;
try
{
string jsonString;
string? jsonString;

if (!string.IsNullOrEmpty(action.Document))
{
Expand All @@ -91,7 +91,7 @@ public ElasticSearchActionHandler(RuleEventFormatter formatter, IScriptEngine sc
jsonString = ToJson(@event);
}

content = serializer.Deserialize<ElasticSearchContent>(jsonString);
content = serializer.Deserialize<ElasticSearchContent>(jsonString!);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -156,9 +156,9 @@ public sealed class ElasticSearchJob
{
public string ServerHost { get; set; }

public string ServerUser { get; set; }
public string? ServerUser { get; set; }

public string ServerPassword { get; set; }
public string? ServerPassword { get; set; }

public string ContentId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public EmailActionHandler(RuleEventFormatter formatter)
ServerHost = action.ServerHost,
ServerPassword = action.ServerPassword,
ServerPort = action.ServerPort,
ServerUsername = await FormatAsync(action.ServerUsername, @event),
MessageFrom = await FormatAsync(action.MessageFrom, @event),
MessageTo = await FormatAsync(action.MessageTo, @event),
MessageSubject = await FormatAsync(action.MessageSubject, @event),
MessageBody = await FormatAsync(action.MessageBody, @event)
ServerUsername = (await FormatAsync(action.ServerUsername, @event))!,
MessageFrom = (await FormatAsync(action.MessageFrom, @event))!,
MessageTo = (await FormatAsync(action.MessageTo, @event))!,
MessageSubject = (await FormatAsync(action.MessageSubject, @event))!,
MessageBody = (await FormatAsync(action.MessageBody, @event))!
};

var description = $"Send an email to {action.MessageTo}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public sealed record KafkaAction : RuleAction
[Display(Name = "Payload (Optional)", Description = "Leave it empty to use the full event as body.")]
[Editor(RuleFieldEditor.TextArea)]
[Formattable]
public string Payload { get; set; }
public string? Payload { get; set; }

[Display(Name = "Key", Description = "The message key, commonly used for partitioning.")]
[Editor(RuleFieldEditor.Text)]
[Formattable]
public string Key { get; set; }
public string? Key { get; set; }

[Display(Name = "Partition Key", Description = "The partition key, only used when we don't want to define partiontionig with key.")]
[Editor(RuleFieldEditor.Text)]
[Formattable]
public string PartitionKey { get; set; }
public string? PartitionKey { get; set; }

[Display(Name = "Partition Count", Description = "Define the number of partitions for specific topic.")]
[Editor(RuleFieldEditor.Text)]
Expand All @@ -49,9 +49,9 @@ public sealed record KafkaAction : RuleAction
[Display(Name = "Headers (Optional)", Description = "The message headers in the format '[Key]=[Value]', one entry per line.")]
[Editor(RuleFieldEditor.TextArea)]
[Formattable]
public string Headers { get; set; }
public string? Headers { get; set; }

[Display(Name = "Schema (Optional)", Description = "Define a specific AVRO schema in JSON format.")]
[Editor(RuleFieldEditor.TextArea)]
public string Schema { get; set; }
public string? Schema { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public KafkaActionHandler(RuleEventFormatter formatter, KafkaProducer kafkaProdu

protected override async Task<(string Description, KafkaJob Data)> CreateJobAsync(EnrichedEvent @event, KafkaAction action)
{
string value, key;
string? value, key;

if (!string.IsNullOrEmpty(action.Payload))
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public KafkaActionHandler(RuleEventFormatter formatter, KafkaProducer kafkaProdu
return (Description, ruleJob);
}

private async Task<Dictionary<string, string>> ParseHeadersAsync(string headers, EnrichedEvent @event)
private async Task<Dictionary<string, string>?> ParseHeadersAsync(string? headers, EnrichedEvent @event)
{
if (string.IsNullOrWhiteSpace(headers))
{
Expand All @@ -76,12 +76,12 @@ private async Task<Dictionary<string, string>> ParseHeadersAsync(string headers,

if (indexEqual > 0 && indexEqual < line.Length - 1)
{
var key = line[..indexEqual];
var val = line[(indexEqual + 1)..];
var headerKey = line[..indexEqual];
var headerValue = line[(indexEqual + 1)..];

val = await FormatAsync(val, @event);
headerValue = await FormatAsync(headerValue, @event);

headersDictionary[key] = val;
headersDictionary[headerKey] = headerValue!;
}
}

Expand All @@ -108,15 +108,15 @@ public sealed class KafkaJob
{
public string TopicName { get; set; }

public string MessageKey { get; set; }
public string? MessageKey { get; set; }

public string MessageValue { get; set; }
public string? MessageValue { get; set; }

public string Schema { get; set; }
public string? Schema { get; set; }

public string PartitionKey { get; set; }
public string? PartitionKey { get; set; }

public Dictionary<string, string> Headers { get; set; }
public Dictionary<string, string>? Headers { get; set; }

public int PartitionCount { get; set; }
}
Loading

0 comments on commit c3c72c0

Please sign in to comment.