Skip to content

Commit

Permalink
Merge branch 'master' into issue-732
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev authored Aug 27, 2022
2 parents de172e4 + 5a98bfd commit 6fea6a5
Show file tree
Hide file tree
Showing 118 changed files with 7,450 additions and 3,710 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Mixed up line endings from PR 917
e12cd15478ef4dd7cc2a391ae74d877f33acee97
20 changes: 16 additions & 4 deletions Bonsai.Configuration/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CommandLineParser
const char WordSeparator = '-';
const char OptionSeparator = ':';
const string CommandPrefix = "--";
readonly Dictionary<string, Action<string>> commands = new Dictionary<string, Action<string>>();
readonly Dictionary<string, Delegate> commands = new Dictionary<string, Delegate>();
Action<string> defaultHandler;

public void RegisterCommand(Action<string> handler)
Expand All @@ -18,10 +18,15 @@ public void RegisterCommand(Action<string> handler)

public void RegisterCommand(string name, Action handler)
{
RegisterCommand(name, option => handler());
RegisterCommandHandler(name, handler);
}

public void RegisterCommand(string name, Action<string> handler)
{
RegisterCommandHandler(name, handler);
}

void RegisterCommandHandler(string name, Delegate handler)
{
if (string.IsNullOrWhiteSpace(name))
{
Expand Down Expand Up @@ -56,9 +61,16 @@ public void Parse(string[] args)
for (int i = 0; i < args.Length; i++)
{
var options = args[i].Split(new[] { OptionSeparator }, 2, StringSplitOptions.RemoveEmptyEntries);
if (commands.TryGetValue(options[0], out Action<string> handler))
if (commands.TryGetValue(options[0], out Delegate handler))
{
handler(options.Length > 1 ? options[1] : string.Empty);
if (handler is Action action) action();
else if (handler is Action<string> command)
{
var argument = string.Empty;
if (options.Length > 1) argument = options[1];
else if (args.Length > i + 1) argument = args[++i];
command(argument);
}
}
else
{
Expand Down
22 changes: 9 additions & 13 deletions Bonsai.Configuration/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,25 @@ public static IDictionary<string, PackageReference> GetPackageReferenceMap(this
return packageMap;
}

public static IEnumerable<PackageReference> GetAssemblyPackageReferences(
public static PackageReference GetAssemblyPackageReference(
this PackageConfiguration configuration,
IEnumerable<string> assemblyNames,
string assemblyName,
IDictionary<string, PackageReference> packageMap)
{
var dependencies = new List<PackageReference>();
foreach (var assemblyName in assemblyNames)
var assemblyLocation = GetAssemblyLocation(configuration, assemblyName);
if (assemblyLocation != null)
{
var assemblyLocation = GetAssemblyLocation(configuration, assemblyName);
if (assemblyLocation != null)
var pathElements = assemblyLocation.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
if (pathElements.Length > 1 && pathElements[0] == RepositoryPath)
{
var pathElements = assemblyLocation.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
if (pathElements.Length > 1 && pathElements[0] == RepositoryPath)
if (packageMap.TryGetValue(pathElements[1], out PackageReference package))
{
if (packageMap.TryGetValue(pathElements[1], out PackageReference package))
{
dependencies.Add(package);
}
return package;
}
}
}

return dependencies;
return null;
}

public static void SetAssemblyResolve(PackageConfiguration configuration)
Expand Down
4 changes: 3 additions & 1 deletion Bonsai.Configuration/ScriptExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public void AddAssemblyReferences(IEnumerable<string> assemblyReferences)
var projectReferences = root.Descendants(PackageReferenceElement).ToArray();
var lastReference = projectReferences.LastOrDefault();

var packageReferences = packageConfiguration.GetAssemblyPackageReferences(assemblyReferences, packageMap);
var packageReferences = assemblyReferences
.Select(assemblyName => packageConfiguration.GetAssemblyPackageReference(assemblyName, packageMap))
.Where(package => package != null);
foreach (var reference in packageReferences)
{
var includeAttribute = new XAttribute(PackageIncludeAttribute, reference.Id);
Expand Down
19 changes: 19 additions & 0 deletions Bonsai.Core.Tests/InspectBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ public void Build_GroupInspectBuilder_ReturnNestedVisualizerElement()
Assert.AreEqual(combinator.Value, visualizerElement.Builder);
}

[TestMethod]
public void Build_PropertyMappedInspectBuilderToWorkflowOutput_ReturnVisualizerElement()
{
var workflowBuilder = new WorkflowBuilder();
var source = workflowBuilder.Workflow.Add(new CombinatorBuilder { Combinator = new Reactive.Range() });
var valueSource = workflowBuilder.Workflow.Add(new CombinatorBuilder { Combinator = new IntProperty() });
var propertyMapping = workflowBuilder.Workflow.Add(new PropertyMappingBuilder { PropertyMappings = { new PropertyMapping { Name = "Count" } } });
var output = workflowBuilder.Workflow.Add(new WorkflowOutputBuilder());
workflowBuilder.Workflow.AddEdge(valueSource, propertyMapping, new ExpressionBuilderArgument());
workflowBuilder.Workflow.AddEdge(propertyMapping, source, new ExpressionBuilderArgument());
workflowBuilder.Workflow.AddEdge(source, output, new ExpressionBuilderArgument());

var inspectable = workflowBuilder.Workflow.ToInspectableGraph();
var inspectOutput = (InspectBuilder)inspectable.ElementAt(workflowBuilder.Workflow.Count - 1).Value;
inspectable.Build();
var visualizerElement = ExpressionBuilder.GetVisualizerElement(inspectOutput);
Assert.AreEqual(source.Value, visualizerElement.Builder);
}

#region Error Classes

class ErrorBuilder : ExpressionBuilder
Expand Down
2 changes: 2 additions & 0 deletions Bonsai.Core/Expressions/AsyncSubjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Bonsai.Expressions
/// sequence to all subscribed and future observers using a shared subject.
/// </summary>
[XmlType("AsyncSubject", Namespace = Constants.XmlNamespace)]
[WorkflowElementIcon(typeof(AsyncSubjectBuilder), nameof(AsyncSubjectBuilder))]
[Description("Broadcasts the last value of an observable sequence to all subscribed and future observers using a shared subject.")]
public class AsyncSubjectBuilder : SubjectBuilder
{
Expand Down Expand Up @@ -42,6 +43,7 @@ AsyncSubject<TSource> CreateSubject<TSource>()
/// </summary>
/// <typeparam name="T">The type of the result stored by the subject.</typeparam>
[XmlType("AsyncSubject", Namespace = Constants.XmlNamespace)]
[WorkflowElementIcon(typeof(AsyncSubjectBuilder), nameof(AsyncSubjectBuilder))]
[Description("Broadcasts the result of the first observable sequence to complete to all subscribed and future observers.")]
public class AsyncSubjectBuilder<T> : SubjectBuilder<T>
{
Expand Down
2 changes: 2 additions & 0 deletions Bonsai.Core/Expressions/BehaviorSubjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Bonsai.Expressions
/// sequence to all subscribed and future observers using a shared subject.
/// </summary>
[XmlType("BehaviorSubject", Namespace = Constants.XmlNamespace)]
[WorkflowElementIcon(typeof(BehaviorSubjectBuilder), nameof(BehaviorSubjectBuilder))]
[Description("Broadcasts the latest value of an observable sequence to all subscribed and future observers using a shared subject.")]
public class BehaviorSubjectBuilder : SubjectBuilder
{
Expand Down Expand Up @@ -43,6 +44,7 @@ BehaviorSubjectBuilder<TSource>.BehaviorSubject CreateSubject<TSource>()
/// </summary>
/// <typeparam name="T">The type of the elements processed by the subject.</typeparam>
[XmlType("BehaviorSubject", Namespace = Constants.XmlNamespace)]
[WorkflowElementIcon(typeof(BehaviorSubjectBuilder), nameof(BehaviorSubjectBuilder))]
[Description("Broadcasts the latest value from other observable sequences to all subscribed and future observers.")]
public class BehaviorSubjectBuilder<T> : SubjectBuilder<T>
{
Expand Down
79 changes: 76 additions & 3 deletions Bonsai.Core/Expressions/BinaryOperatorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ namespace Bonsai.Expressions
/// Provides a base class for expression builders that define a simple binary operator
/// on paired elements of an observable sequence. This is an abstract class.
/// </summary>
[DefaultProperty("Value")]
[TypeDescriptionProvider(typeof(BinaryOperatorTypeDescriptionProvider))]
public abstract class BinaryOperatorBuilder : SelectBuilder, IPropertyMappingBuilder, ISerializableElement
public abstract class BinaryOperatorBuilder : SelectBuilder, IPropertyMappingBuilder, ISerializableElement, ICustomTypeDescriptor
{
static readonly MethodInfo GetEnumeratorMethod = typeof(IEnumerable).GetMethod("GetEnumerator");
static readonly MethodInfo MoveNextMethod = typeof(IEnumerator).GetMethod("MoveNext");
Expand Down Expand Up @@ -173,5 +171,80 @@ protected override Expression BuildSelector(Expression expression)

return ConvertAndBuildSelector(left, right);
}

#region ICustomTypeDescriptor Members

static readonly Attribute[] ValueAttributes = new[]
{
new DescriptionAttribute("The value of the right hand operand in the binary operator.")
};

AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return TypeDescriptor.GetAttributes(GetType());
}

string ICustomTypeDescriptor.GetClassName()
{
return TypeDescriptor.GetClassName(GetType());
}

string ICustomTypeDescriptor.GetComponentName()
{
return null;
}

TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(GetType());
}

EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return null;
}

PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
var operand = Operand;
return operand != null ? new WorkflowPropertyDescriptor("Value", ValueAttributes, operand) : null;
}

object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(GetType(), editorBaseType);
}

EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return EventDescriptorCollection.Empty;
}

EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return EventDescriptorCollection.Empty;
}

PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(ValueAttributes);
}

PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
var defaultProperty = ((ICustomTypeDescriptor)this).GetDefaultProperty();
if (defaultProperty != null)
{
return new PropertyDescriptorCollection(new[] { defaultProperty });
}
else return PropertyDescriptorCollection.Empty;
}

object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
return (object)Operand ?? this;
}

#endregion
}
}
55 changes: 0 additions & 55 deletions Bonsai.Core/Expressions/BinaryOperatorTypeDescriptionProvider.cs

This file was deleted.

Loading

0 comments on commit 6fea6a5

Please sign in to comment.