Skip to content

Commit 57d8731

Browse files
authored
Merge pull request #5 from jacqueskang/develop
Develop
2 parents 8543c81 + e297f0c commit 57d8731

File tree

8 files changed

+104
-4
lines changed

8 files changed

+104
-4
lines changed

src/IpcServiceSample.ConsoleClient/Program.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ private static async Task MainAsync(string[] args)
2222
float result1 = await client.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
2323
Console.WriteLine($"sum of 2 floating number is: {result1}");
2424

25-
// test 1: call IPC service method with complex types
25+
// test 2: call IPC service method with complex types
2626
ComplexNumber result2 = await client.InvokeAsync(x => x.AddComplexNumber(
2727
new ComplexNumber(0.1f, 0.3f),
2828
new ComplexNumber(0.2f, 0.6f)));
2929
Console.WriteLine($"sum of 2 complexe number is: {result2.A}+{result2.B}i");
3030

31-
// test 3: call IPC service method without parameter or return
31+
// test 3: call IPC service method with an array of complex types
32+
ComplexNumber result3 = await client.InvokeAsync(x => x.AddComplexNumbers(new[]
33+
{
34+
new ComplexNumber(0.5f, 0.4f),
35+
new ComplexNumber(0.2f, 0.1f),
36+
new ComplexNumber(0.3f, 0.5f),
37+
}));
38+
Console.WriteLine($"sum of 3 complexe number is: {result3.A}+{result3.B}i");
39+
40+
// test 4: call IPC service method without parameter or return
3241
await client.InvokeAsync(x => x.DoNothing());
3342
Console.WriteLine($"invoked DoNothing()");
3443
}

src/IpcServiceSample.ConsoleServer/ComputingService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IpcServiceSample.ServiceContracts;
1+
using System.Collections.Generic;
2+
using IpcServiceSample.ServiceContracts;
23
using Microsoft.Extensions.Logging;
34

45
namespace IpcServiceSample.ConsoleServer
@@ -18,6 +19,17 @@ public ComplexNumber AddComplexNumber(ComplexNumber x, ComplexNumber y)
1819
return new ComplexNumber(x.A + y.A, x.B + y.B);
1920
}
2021

22+
public ComplexNumber AddComplexNumbers(IEnumerable<ComplexNumber> numbers)
23+
{
24+
_logger.LogInformation($"{nameof(AddComplexNumbers)} called.");
25+
var result = new ComplexNumber(0, 0);
26+
foreach (var number in numbers)
27+
{
28+
result = new ComplexNumber(result.A + number.A, result.B + number.B);
29+
}
30+
return result;
31+
}
32+
2133
public float AddFloat(float x, float y)
2234
{
2335
_logger.LogInformation($"{nameof(AddFloat)} called.");

src/IpcServiceSample.ServiceContracts/IComputingService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
namespace IpcServiceSample.ServiceContracts
1+
using System.Collections.Generic;
2+
3+
namespace IpcServiceSample.ServiceContracts
24
{
35
public interface IComputingService
46
{
57
float AddFloat(float x, float y);
68
ComplexNumber AddComplexNumber(ComplexNumber x, ComplexNumber y);
9+
ComplexNumber AddComplexNumbers(IEnumerable<ComplexNumber> numbers);
710
void DoNothing();
811
}
912

src/JKang.IpcServiceFramework.Client/JKang.IpcServiceFramework.Client.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<RepositoryUrl>https://github.com/jacqueskang/IpcServiceFramework</RepositoryUrl>
1212
<PackageTags>dotnetcore,named-pipes,interprocess-communication</PackageTags>
1313
<PackageProjectUrl>https://github.com/jacqueskang/IpcServiceFramework</PackageProjectUrl>
14+
<PackageReleaseNotes>1.0.1
15+
- support passing array parameters</PackageReleaseNotes>
16+
<Version>1.0.1</Version>
1417
</PropertyGroup>
1518

1619
<ItemGroup>

src/JKang.IpcServiceFramework.Core.Tests/DefaultValueConverterTest.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using Newtonsoft.Json;
44
using System;
5+
using System.Collections.Generic;
56

67
namespace JKang.IpcServiceFramework.Core.Tests
78
{
@@ -70,6 +71,66 @@ public void TryConvert_JObjectToComplexType()
7071
Assert.AreEqual(expected.StringValue, ((ComplexType)actual).StringValue);
7172
}
7273

74+
[TestMethod]
75+
public void TryConvert_Int32Array()
76+
{
77+
int[] expected = new[] { 1, 2 };
78+
object jObj = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(expected));
79+
80+
bool succeed = _sut.TryConvert(jObj, typeof(int[]), out object actual);
81+
82+
Assert.IsTrue(succeed);
83+
Assert.IsInstanceOfType(actual, typeof(int[]));
84+
var actualArray = actual as int[];
85+
Assert.AreEqual(expected.Length, actualArray.Length);
86+
for (int i = 0; i < expected.Length; i++)
87+
{
88+
Assert.AreEqual(expected[i], actualArray[i]);
89+
}
90+
}
91+
92+
[TestMethod]
93+
public void TryConvert_Int32List()
94+
{
95+
var expected = new List<int> { 1, 2 };
96+
object jObj = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(expected));
97+
98+
bool succeed = _sut.TryConvert(jObj, typeof(List<int>), out object actual);
99+
100+
Assert.IsTrue(succeed);
101+
Assert.IsInstanceOfType(actual, typeof(List<int>));
102+
var actualList = actual as List<int>;
103+
Assert.AreEqual(expected.Count, actualList.Count);
104+
for (int i = 0; i < expected.Count; i++)
105+
{
106+
Assert.AreEqual(expected[i], actualList[i]);
107+
}
108+
}
109+
110+
[TestMethod]
111+
public void TryConvert_ComplexTypeArray()
112+
{
113+
ComplexType[] expected = new[]
114+
{
115+
new ComplexType { Int32Value = 123, StringValue = "abc" },
116+
new ComplexType { Int32Value = 456, StringValue = "edf" },
117+
};
118+
object jObj = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(expected));
119+
120+
bool succeed = _sut.TryConvert(jObj, typeof(ComplexType[]), out object actual);
121+
122+
Assert.IsTrue(succeed);
123+
Assert.IsInstanceOfType(actual, typeof(ComplexType[]));
124+
var actualArray = actual as ComplexType[];
125+
Assert.AreEqual(expected.Length, actualArray.Length);
126+
for (int i = 0; i < expected.Length; i++)
127+
{
128+
Assert.IsNotNull(actualArray[i]);
129+
Assert.AreEqual(expected[i].Int32Value, actualArray[i].Int32Value);
130+
Assert.AreEqual(expected[i].StringValue, actualArray[i].StringValue);
131+
}
132+
}
133+
73134
class ComplexType
74135
{
75136
public int Int32Value { get; set; }

src/JKang.IpcServiceFramework.Core/JKang.IpcServiceFramework.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<RepositoryUrl>https://github.com/jacqueskang/IpcServiceFramework</RepositoryUrl>
1313
<PackageTags>dotnetcore,named-pipes,interprocess-communication</PackageTags>
1414
<PackageProjectUrl>https://github.com/jacqueskang/IpcServiceFramework</PackageProjectUrl>
15+
<PackageReleaseNotes>1.0.1
16+
- support passing array parameters</PackageReleaseNotes>
17+
<Version>1.0.1</Version>
1518
</PropertyGroup>
1619

1720
<ItemGroup>

src/JKang.IpcServiceFramework.Core/Services/DefaultValueConverter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public bool TryConvert(object origValue, Type destType, out object destValue)
2222
return true;
2323
}
2424

25+
if (origValue is JArray jArray)
26+
{
27+
destValue = jArray.ToObject(destType);
28+
return true;
29+
}
30+
2531
try
2632
{
2733
destValue = Convert.ChangeType(origValue, destType);

src/JKang.IpcServiceFramework.Server/JKang.IpcServiceFramework.Server.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ This package is for server hosting.</Description>
1414
<PackageProjectUrl>https://github.com/jacqueskang/IpcServiceFramework</PackageProjectUrl>
1515
<RepositoryUrl>https://github.com/jacqueskang/IpcServiceFramework</RepositoryUrl>
1616
<PackageTags>dotnetcore,named-pipes,interprocess-communication</PackageTags>
17+
<Version>1.0.1</Version>
18+
<PackageReleaseNotes>1.0.1
19+
- support passing array parameters</PackageReleaseNotes>
1720
</PropertyGroup>
1821

1922
<ItemGroup>

0 commit comments

Comments
 (0)