Skip to content

Commit a9c6245

Browse files
committed
Added node extensions to library
1 parent 3fc33ad commit a9c6245

File tree

6 files changed

+196
-13
lines changed

6 files changed

+196
-13
lines changed

src/EmberLibConsumer.net/Lawo.EmberPlusSharp/Model/Element.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public object Tag
6464
get { return this.tag; }
6565
set { this.SetValue(ref this.tag, value); }
6666
}
67+
6768
/// <inheritdoc/>
68-
6969
public string GetPath()
7070
{
7171
var path = new StringBuilder(64);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#region copyright
2+
/*
3+
* NuGet EmBER+ Consumer Lib
4+
*
5+
* Copyright (c) 2021 Roger Sandholm & Fredrik Bergholtz, Stockholm, Sweden
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
* 3. The name of the author may not be used to endorse or promote products
16+
* derived from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
#endregion copyright
30+
31+
using System.Collections.Generic;
32+
using System.Linq;
33+
using System.Threading.Tasks;
34+
using EmberPlusConsumerClassLib.Model;
35+
using Lawo.EmberPlusSharp.Model;
36+
37+
namespace EmberPlusConsumerClassLib.EmberHelpers
38+
{
39+
public static class NodeExtensions
40+
{
41+
public static async Task<IParameter> GetParameter(this INode node, string s, Consumer<MyRoot> consumer)
42+
{
43+
if (node.Children.Count == 0)
44+
{
45+
node.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
46+
await consumer.SendAsync();
47+
}
48+
return node.Children.FirstOrDefault(c => c.Identifier == s) as IParameter;
49+
}
50+
51+
public static async Task<IFunction> GetFunction(this INode node, string s, Consumer<MyRoot> consumer)
52+
{
53+
if (node.Children.Count == 0)
54+
{
55+
node.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
56+
await consumer.SendAsync();
57+
}
58+
return node.Children.FirstOrDefault(c => c.Identifier == s) as IFunction;
59+
}
60+
61+
public static async Task<IEnumerable<INode>> ChildNodes(this INode node, Consumer<MyRoot> consumer)
62+
{
63+
if (node.Children.Count == 0)
64+
{
65+
node.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
66+
await consumer.SendAsync();
67+
}
68+
return node.Children.OfType<INode>();
69+
}
70+
71+
public static async Task<INode> GetChildNode(this INode node, string identifier, Consumer<MyRoot> consumer)
72+
{
73+
if (node.Children.Count == 0)
74+
{
75+
node.ChildrenRetrievalPolicy = ChildrenRetrievalPolicy.DirectOnly;
76+
await consumer.SendAsync();
77+
}
78+
return node.Children.OfType<INode>().FirstOrDefault(c => c.Identifier == identifier);
79+
}
80+
81+
public static async Task<INode> NavigateToNode(this INode root, string path, Consumer<MyRoot> consumer)
82+
{
83+
string[] steps = path.Split('/');
84+
85+
INode node = root;
86+
foreach (string identifier in steps)
87+
{
88+
node = await node.GetChildNode(identifier, consumer);
89+
if (node == null)
90+
{
91+
break;
92+
}
93+
}
94+
return node;
95+
}
96+
}
97+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="NLog" Version="4.7.4" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\EmberLibConsumer.net\Lawo.EmberPlusSharp\Lawo.EmberPlusSharp.csproj" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#region copyright
2+
/*
3+
* NuGet EmBER+ Consumer Lib
4+
*
5+
* Copyright (c) 2021 Roger Sandholm & Fredrik Bergholtz, Stockholm, Sweden
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
* 3. The name of the author may not be used to endorse or promote products
16+
* derived from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
#endregion copyright
30+
31+
using Lawo.EmberPlusSharp.Model;
32+
33+
namespace EmberPlusConsumerClassLib.Model
34+
{
35+
public sealed class MyRoot : DynamicRoot<MyRoot>
36+
{
37+
// Root for consumer
38+
}
39+
}

src/Nuget.EmberPlusConsumerLib.NetStandard/Nuget.EmberPlusConsumerLib.NetStandard.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@
5151
<Private>true</Private>
5252
<IncludeAssets>true</IncludeAssets>
5353
</ProjectReference>
54-
<ProjectReference Include="..\EmberLibConsumer.net\Lawo\Lawo.csproj">
54+
<ProjectReference Include="..\EmberLibConsumer.net\Lawo\Lawo.csproj">
55+
<Pack>true</Pack>
56+
<Private>true</Private>
57+
<IncludeAssets>true</IncludeAssets>
58+
</ProjectReference>
59+
<ProjectReference Include="..\EmberPlusConsumerClassLib\EmberPlusConsumerClassLib.csproj">
5560
<Pack>true</Pack>
5661
<Private>true</Private>
5762
<IncludeAssets>true</IncludeAssets>

src/nuget-ember-plus-consumer-lib.sln

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1010
EmberLibConsumer.net\CodeAnalysis.ruleset = EmberLibConsumer.net\CodeAnalysis.ruleset
1111
EmberLibConsumer.net\CodeAnalysisDictionary.xml = EmberLibConsumer.net\CodeAnalysisDictionary.xml
1212
EmberLibConsumer.net\CodeCoverage.runsettings = EmberLibConsumer.net\CodeCoverage.runsettings
13+
..\.github\workflows\ContinuousIntegration.yml = ..\.github\workflows\ContinuousIntegration.yml
1314
EmberLibConsumer.net\Logo.ico = EmberLibConsumer.net\Logo.ico
1415
EmberLibConsumer.net\README.md = EmberLibConsumer.net\README.md
16+
..\README.md = ..\README.md
1517
EmberLibConsumer.net\SharedAssemblyInfo.cs = EmberLibConsumer.net\SharedAssemblyInfo.cs
1618
EmberLibConsumer.net\StrongNameKey.snk = EmberLibConsumer.net\StrongNameKey.snk
1719
EmberLibConsumer.net\stylecop.json = EmberLibConsumer.net\stylecop.json
18-
..\README.md = ..\README.md
19-
..\.github\workflows\ContinuousIntegration.yml = ..\.github\workflows\ContinuousIntegration.yml
2020
EndProjectSection
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lawo.UnitTesting", "EmberLibConsumer.net\Lawo.UnitTesting\Lawo.UnitTesting.csproj", "{018D45FD-BC81-433E-9B90-788D4AE2D31C}"
@@ -33,12 +33,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lawo.EmberPlusSharp", "Embe
3333
EndProject
3434
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lawo", "EmberLibConsumer.net\Lawo\Lawo.csproj", "{47067303-08C7-442D-AEFD-5793595B179F}"
3535
EndProject
36-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nuget.EmberPlusConsumerLib.NetStandard", "Nuget.EmberPlusConsumerLib.NetStandard\Nuget.EmberPlusConsumerLib.NetStandard.csproj", "{FF061512-7A72-482B-BE37-2F4C73B0D7FE}"
36+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nuget.EmberPlusConsumerLib.NetStandard", "Nuget.EmberPlusConsumerLib.NetStandard\Nuget.EmberPlusConsumerLib.NetStandard.csproj", "{FF061512-7A72-482B-BE37-2F4C73B0D7FE}"
3737
EndProject
3838
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CC781669-0B88-4B87-8440-132EB37FF16D}"
3939
EndProject
4040
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ember-plus", "ember-plus", "{3827E5DC-6235-49F5-80B3-CAFA0AE2D893}"
4141
EndProject
42+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmberPlusConsumerClassLib", "EmberPlusConsumerClassLib\EmberPlusConsumerClassLib.csproj", "{402C4B73-F8BD-4806-9A03-5AD21CCFF365}"
43+
EndProject
4244
Global
4345
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4446
Debug|Any CPU = Debug|Any CPU
@@ -235,23 +237,48 @@ Global
235237
{FF061512-7A72-482B-BE37-2F4C73B0D7FE}.Release|x64.Build.0 = Release|Any CPU
236238
{FF061512-7A72-482B-BE37-2F4C73B0D7FE}.Release|x86.ActiveCfg = Release|Any CPU
237239
{FF061512-7A72-482B-BE37-2F4C73B0D7FE}.Release|x86.Build.0 = Release|Any CPU
240+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
241+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|Any CPU.Build.0 = Debug|Any CPU
242+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|ARM.ActiveCfg = Debug|Any CPU
243+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|ARM.Build.0 = Debug|Any CPU
244+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|x64.ActiveCfg = Debug|Any CPU
245+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|x64.Build.0 = Debug|Any CPU
246+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|x86.ActiveCfg = Debug|Any CPU
247+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Debug|x86.Build.0 = Debug|Any CPU
248+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|Any CPU.ActiveCfg = Debug|Any CPU
249+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|Any CPU.Build.0 = Debug|Any CPU
250+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|ARM.ActiveCfg = Debug|Any CPU
251+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|ARM.Build.0 = Debug|Any CPU
252+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|x64.ActiveCfg = Debug|Any CPU
253+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|x64.Build.0 = Debug|Any CPU
254+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|x86.ActiveCfg = Debug|Any CPU
255+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.PackNuGet|x86.Build.0 = Debug|Any CPU
256+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|Any CPU.ActiveCfg = Release|Any CPU
257+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|Any CPU.Build.0 = Release|Any CPU
258+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|ARM.ActiveCfg = Release|Any CPU
259+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|ARM.Build.0 = Release|Any CPU
260+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|x64.ActiveCfg = Release|Any CPU
261+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|x64.Build.0 = Release|Any CPU
262+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|x86.ActiveCfg = Release|Any CPU
263+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365}.Release|x86.Build.0 = Release|Any CPU
238264
EndGlobalSection
239265
GlobalSection(SolutionProperties) = preSolution
240266
HideSolutionNode = FALSE
241267
EndGlobalSection
242-
GlobalSection(ExtensibilityGlobals) = postSolution
243-
SolutionGuid = {4CCEB7E0-F2FD-41D3-9E4E-BAA95A7FC762}
244-
EndGlobalSection
245268
GlobalSection(NestedProjects) = preSolution
246-
{47067303-08C7-442D-AEFD-5793595B179F} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
247-
{1BE88B2D-2A49-47C0-9C60-59D662C0821A} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
248269
{D93DC0DD-C137-428F-B84B-3F4387124C85} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
249-
{A81DC2B8-8E3C-442E-B311-A38B22D18DFF} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
250-
{8273A6F1-CFC5-4A5E-8B2B-089EA6317312} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
251-
{C9E3FDA8-F9A9-48BC-9249-36E86A18D371} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
252270
{018D45FD-BC81-433E-9B90-788D4AE2D31C} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
253271
{60335AC8-4085-4890-AF0C-51D2273772E5} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
272+
{8273A6F1-CFC5-4A5E-8B2B-089EA6317312} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
273+
{C9E3FDA8-F9A9-48BC-9249-36E86A18D371} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
274+
{A81DC2B8-8E3C-442E-B311-A38B22D18DFF} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
275+
{1BE88B2D-2A49-47C0-9C60-59D662C0821A} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
276+
{47067303-08C7-442D-AEFD-5793595B179F} = {3827E5DC-6235-49F5-80B3-CAFA0AE2D893}
254277
{FF061512-7A72-482B-BE37-2F4C73B0D7FE} = {CC781669-0B88-4B87-8440-132EB37FF16D}
255278
{3827E5DC-6235-49F5-80B3-CAFA0AE2D893} = {CC781669-0B88-4B87-8440-132EB37FF16D}
279+
{402C4B73-F8BD-4806-9A03-5AD21CCFF365} = {CC781669-0B88-4B87-8440-132EB37FF16D}
280+
EndGlobalSection
281+
GlobalSection(ExtensibilityGlobals) = postSolution
282+
SolutionGuid = {4CCEB7E0-F2FD-41D3-9E4E-BAA95A7FC762}
256283
EndGlobalSection
257284
EndGlobal

0 commit comments

Comments
 (0)