Skip to content
Merged
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
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
pull_request:
branches: [ master ]

permissions:
contents: read
packages: write

env:
DOTNET_VERSION: "10.0.x"
NODE_VERSION: "20"
Expand All @@ -18,6 +14,9 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: read

steps:
- name: Checkout repository
Expand Down Expand Up @@ -54,6 +53,9 @@ jobs:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
if: github.repository_owner == 'BpsLogicBuilder'
permissions:
contents: read
packages: write
needs: test

steps:
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ on:
release:
types: [published]

permissions:
contents: read
packages: write
id-token: write

env:
DOTNET_VERSION: "10.0.x"
NODE_VERSION: "20"
Expand All @@ -17,6 +12,9 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: read

steps:
- name: Checkout repository
Expand Down Expand Up @@ -53,6 +51,10 @@ jobs:
name: Publish Package to GitHub Packages and NuGet.org
runs-on: ubuntu-latest
if: github.repository_owner == 'BpsLogicBuilder'
permissions:
contents: read
packages: write
id-token: write
needs: test

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace LogicBuilder.Workflow.ComponentModel
{
public class AssemblyRef
public static class AssemblyRef
{
public const string ActivitiesAssemblyRef = "LogicBuilder.Workflow.Activities.Rules, Version=2.0.0.0, Culture=neutral, PublicKeyToken=646893bec0268535";
public const string DialogAssemblyRef = "LogicBuilder.Workflow.Activities.Rules.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=646893bec0268535";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace LogicBuilder.Workflow.ComponentModel.Compiler
{
[Serializable()]
public sealed class ValidationError
public sealed class ValidationError(string errorText, int errorNumber, bool isWarning, string propertyName)
{
private readonly string errorText = string.Empty;
private readonly int errorNumber = 0;
private readonly string errorText = errorText;
private readonly int errorNumber = errorNumber;
private Hashtable userData = null;
private readonly bool isWarning = false;
string propertyName = null;
private readonly bool isWarning = isWarning;

public ValidationError(string errorText, int errorNumber)
: this(errorText, errorNumber, false, null)
Expand All @@ -23,24 +22,8 @@ public ValidationError(string errorText, int errorNumber, bool isWarning)
{
}

public ValidationError(string errorText, int errorNumber, bool isWarning, string propertyName)
{
this.errorText = errorText;
this.errorNumber = errorNumber;
this.isWarning = isWarning;
this.propertyName = propertyName;
}
public string PropertyName
{
get
{
return this.propertyName;
}
set
{
this.propertyName = value;
}
}
public string PropertyName { get; set; } = propertyName;

public string ErrorText
{
get
Expand All @@ -66,15 +49,14 @@ public IDictionary UserData
{
get
{
if (this.userData == null)
this.userData = new Hashtable();
this.userData ??= [];
return this.userData;
}
}

public static ValidationError GetNotSetValidationError(string propertyName)
{
ValidationError error = new ValidationError(SR.GetString(SR.Error_PropertyNotSet, propertyName), ErrorNumbers.Error_PropertyNotSet)
ValidationError error = new(SR.GetString(SR.Error_PropertyNotSet, propertyName), ErrorNumbers.Error_PropertyNotSet)
{
PropertyName = propertyName
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa
{
if (propertyType.IsAssignableFrom(typeof(System.Drawing.Color)))
{
string colorValue = value as string;
string colorValue = value;
if (!String.IsNullOrEmpty(colorValue))
{
if (colorValue.StartsWith("0X", StringComparison.OrdinalIgnoreCase))
{
long propertyValue = Convert.ToInt64((string)value, 16) & 0xFFFFFFFF;
long propertyValue = Convert.ToInt64(value, 16) & 0xFFFFFFFF;
return System.Drawing.Color.FromArgb((Byte)(propertyValue >> 24), (Byte)(propertyValue >> 16), (Byte)(propertyValue >> 8), (Byte)(propertyValue));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ internal static XmlWriter CreateXmlWriter(object output)
CloseOutput = true
};

if (output is string)
return XmlWriter.Create(output as string, settings);
else if (output is TextWriter)
return XmlWriter.Create(output as TextWriter, settings);
if (output is string outputString)
return XmlWriter.Create(outputString, settings);
else if (output is TextWriter outputTextWriter)
return XmlWriter.Create(outputTextWriter, settings);
else
{
Debug.Assert(false, "Invalid argument type. 'output' must either be string or TextWriter.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa
{
object point = Point.Empty;

string pointValue = value as string;
string pointValue = value;
if (!String.IsNullOrWhiteSpace(pointValue))
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Point));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa
{
object size = Size.Empty;

string sizeValue = value as string;
string sizeValue = value;
if (!String.IsNullOrWhiteSpace(sizeValue))
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Size));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ protected internal override string SerializeToString(WorkflowMarkupSerialization
return typeName;
}
}
//
// If we get a real type make sure that we get the correct fully qualified name for the target framework version
string assemblyFullName = null;


// If we didn't find an assembly value it is either a local type or something is wrong
// However per the general guidance on multi-targeting it is up to the caller
// to make sure that writers (such as Xoml) are given types that exist in the target framework
// This makes it the job of the rules designer or rules validator to not call the Xoml stack
// with types that do not exist in the target framework
return string.IsNullOrEmpty(assemblyFullName)
? type.AssemblyQualifiedName
: string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName);
return type.AssemblyQualifiedName;
}

protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected internal override IList GetChildren(WorkflowMarkupSerializationManager
throw new ArgumentNullException("obj");

if (!IsValidCollectionType(obj.GetType()))
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));
throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

IEnumerable enumerable = obj as IEnumerable ?? Enumerable.Empty<object>();
ArrayList arrayList = [.. enumerable];
Expand All @@ -34,7 +34,7 @@ protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializatio
return false;

if (!IsValidCollectionType(value.GetType()))
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));
throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

IEnumerable<object> enumerable = (value as IEnumerable)?.OfType<object>();

Expand All @@ -47,7 +47,7 @@ protected internal override void ClearChildren(WorkflowMarkupSerializationManage
throw new ArgumentNullException("obj");

if (!IsValidCollectionType(obj.GetType()))
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));
throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

if (obj is ICollection) /*Updating from collection == null - appears to be a bug e.g. List of T passes IsValidCollectionType and implements System.Collections.ICollection.*/
obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, [], CultureInfo.InvariantCulture);
Expand All @@ -59,7 +59,7 @@ protected internal override void AddChild(WorkflowMarkupSerializationManager ser
throw new ArgumentNullException(nameof(parentObject));

if (!IsValidCollectionType(parentObject.GetType()))
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObject.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));
throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, parentObject.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

parentObject.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObject, [childObj], CultureInfo.InvariantCulture);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class DictionaryMarkupSerializer : WorkflowMarkupSerializer
protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
{
IDictionary dictionary = obj as IDictionary ?? throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));
List<object> childEntries = new List<object>();
List<object> childEntries = [];
foreach (DictionaryEntry dictionaryEntry in dictionary)
{
childEntries.Add(dictionaryEntry);
Expand All @@ -29,15 +29,15 @@ protected internal override IList GetChildren(WorkflowMarkupSerializationManager

protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
{
return new PropertyInfo[] { };
return [];
}

protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value)
{
if (value == null)
return false;

if (!(value is IDictionary))
if (value is not IDictionary)
throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));

return (((IDictionary)value).Count > 0);
Expand Down Expand Up @@ -115,33 +115,32 @@ protected internal override void OnAfterDeserialize(WorkflowMarkupSerializationM

internal override ExtendedPropertyInfo[] GetExtendedProperties(WorkflowMarkupSerializationManager manager, object extendee)
{
List<ExtendedPropertyInfo> extendedProperties = new List<ExtendedPropertyInfo>();
List<ExtendedPropertyInfo> extendedProperties = [];
DictionaryEntry? entry = null;
if (manager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
entry = (DictionaryEntry)manager.WorkflowMarkupStack[typeof(DictionaryEntry)];
if (this.deserializingDictionary || (entry.HasValue && entry.Value.Value == extendee))
{
ExtendedPropertyInfo extendedProperty =
new ExtendedPropertyInfo(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance),
new(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance),
new GetValueHandler(OnGetKeyValue),
new SetValueHandler(OnSetKeyValue),
new GetQualifiedNameHandler(OnGetXmlQualifiedName), manager);

extendedProperties.Add(extendedProperty);
}
return extendedProperties.ToArray();
return [.. extendedProperties];
}

private object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee)
private static object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee)
{
DictionaryEntry? entry = null;
if (extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
entry = (DictionaryEntry)extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)];
else
Debug.Assert(false, "Dictionary Entry not found in the WorkflowMarkupStack");

if (entry.HasValue && entry.Value.Value == extendee)
return entry.Value.Key;

return null;
}

Expand All @@ -151,7 +150,7 @@ private void OnSetKeyValue(ExtendedPropertyInfo extendedProperty, object extende
this.keylookupDictionary.Add(value, extendee);
}

private XmlQualifiedName OnGetXmlQualifiedName(ExtendedPropertyInfo extendedProperty, WorkflowMarkupSerializationManager manager, out string prefix)
private static XmlQualifiedName OnGetXmlQualifiedName(ExtendedPropertyInfo extendedProperty, WorkflowMarkupSerializationManager manager, out string prefix)
{
prefix = StandardXomlKeys.Definitions_XmlNs_Prefix;
return new XmlQualifiedName(extendedProperty.Name, StandardXomlKeys.Definitions_XmlNs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public string ArgumentName
}

[ExcludeFromCodeCoverage]
public abstract class MarkupExtension
public abstract class MarkupExtension //NOSONAR
{
public abstract object ProvideValue(IServiceProvider provider);
}
Expand All @@ -116,22 +116,22 @@ public TypeExtension() { }

public TypeExtension(string type)
{
this.typeName = type ?? throw new ArgumentNullException("typeName");
this.typeName = type ?? throw new ArgumentNullException(nameof(type));
}
public TypeExtension(Type type)
{
this.type = type ?? throw new ArgumentNullException("type");
this.type = type ?? throw new ArgumentNullException(nameof(type));
}
public override object ProvideValue(IServiceProvider provider)
{
if (this.type != null)
return this.type;

if (provider == null)
throw new ArgumentNullException("provider");
throw new ArgumentNullException(nameof(provider));

if (this.typeName == null)
throw new InvalidOperationException("typename");
throw new InvalidOperationException(nameof(typeName));

WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager ?? throw new ArgumentNullException("provider");
if (manager.WorkflowMarkupStack[typeof(XmlReader)] is not XmlReader reader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
return UnStringify(value as string);
if (value is string stringValue)
return UnStringify(stringValue);

return base.ConvertFrom(context, culture, value);
}
Expand Down
Loading