Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fix Issue #775 #808

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion src/Common/Helpers/ImportExportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public class ImportExportHelper
private const string EventHubPath = "EventHubPath";
private const string SqlExpression = "SqlExpression";
private const string CorrelationId = "CorrelationId";
private const string MessageId = "MessageId";
private const string To = "To";
private const string ReplyTo = "ReplyTo";
private const string Label = "Label";
private const string SessionId = "SessionId";
private const string ReplyToSessionId = "ReplyToSessionId";
private const string ContentType = "ContentType";
private const string MaxSizeInMegabytes = "MaxSizeInMegabytes";
private const string ForwardTo = "ForwardTo";
private const string Rights = "Rights";
Expand Down Expand Up @@ -1348,7 +1355,17 @@ private Filter CreateFilter(XElement filter)
}
if (filter.Name == string.Format(NodeNameFormat, Namespace, CorrelationFilterEntity))
{
ruleFilter = new CorrelationFilter(propertyValue[CorrelationId] as string);
ruleFilter = new CorrelationFilter()
{
ContentType = !string.IsNullOrWhiteSpace(propertyValue[ContentType] as string) ? propertyValue[ContentType] as string : null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is it necessary to use ternary condition if it's either a value or a null? Could this (one example) be it?

ContentType = propertyValue[ContentType] as string,

Copy link
Author

@NaorisKong NaorisKong Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If use the code
ContentType = propertyValue[ContentType] as string
May cause the exception "Exception: The argument contentType is null or white space."
Because when the xml be like this <ContentType></ContentType>, use propertyValue[ContentType] will get a empty string and I guess the construction function of CorrelationFilter can`t accept a empty string.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. This is to avoid empty string. Thank you for elaboration. In that case, could you make it a local function and pass the property name? On the local function you could put XML documentation or a comment elaborating the rationale. Thank you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will try to create a function to deal with it and add some comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a extension method on Dictionary<string, object>.Think it`s cleaner.

CorrelationId = !string.IsNullOrWhiteSpace(propertyValue[CorrelationId] as string) ? propertyValue[CorrelationId] as string : null,
Label = !string.IsNullOrWhiteSpace(propertyValue[Label] as string) ? propertyValue[Label] as string : null,
MessageId = !string.IsNullOrWhiteSpace(propertyValue[MessageId] as string) ? propertyValue[MessageId] as string : null,
To = !string.IsNullOrWhiteSpace(propertyValue[To] as string) ? propertyValue[To] as string : null,
ReplyTo = !string.IsNullOrWhiteSpace(propertyValue[ReplyTo] as string) ? propertyValue[ReplyTo] as string : null,
ReplyToSessionId = !string.IsNullOrWhiteSpace(propertyValue[ReplyToSessionId] as string) ? propertyValue[ReplyToSessionId] as string : null,
SessionId = !string.IsNullOrWhiteSpace(propertyValue[SessionId] as string) ? propertyValue[SessionId] as string : null,
};
}
if (ruleFilter != null)
{
Expand Down