Skip to content

Commit d0e7324

Browse files
Merge pull request #113 from progaudi/fix/sample
Use new tarantool library in sample
2 parents d3de4ad + 4a17189 commit d0e7324

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

samples/docker-compose/dotnet/Controllers/HomeController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ private async Task<Tuple<ISpace, IIndex, IIndex>> Initialize()
4040

4141
public async Task<ViewResult> Index()
4242
{
43-
var allDogs = await _primaryIndex.Select<TarantoolTuple<long>, TarantoolTuple<long, string, long, MsgPackToken>>(TarantoolTuple.Create(-1L), new SelectOptions { Iterator = Iterator.All });
44-
var seniorDogs = await _secondaryIndex.Select<TarantoolTuple<long>, TarantoolTuple<long, string, long, MsgPackToken>>(TarantoolTuple.Create(5L), new SelectOptions { Iterator = Iterator.Ge });
45-
var juniorDogs = await _secondaryIndex.Select<TarantoolTuple<long>, TarantoolTuple<long, string, long, MsgPackToken>>(TarantoolTuple.Create(5L), new SelectOptions { Iterator = Iterator.Le });
43+
var allDogs = await _primaryIndex.Select<TarantoolTuple<long>, Dog>(TarantoolTuple.Create(-1L), new SelectOptions { Iterator = Iterator.All });
44+
var seniorDogs = await _secondaryIndex.Select<TarantoolTuple<long>, Dog>(TarantoolTuple.Create(5L), new SelectOptions { Iterator = Iterator.Ge });
45+
var juniorDogs = await _secondaryIndex.Select<TarantoolTuple<long>, Dog>(TarantoolTuple.Create(5L), new SelectOptions { Iterator = Iterator.Le });
4646

4747
return View(new []
4848
{
49-
allDogs.Data.Select(x => new Dog(x)).ToArray(),
50-
seniorDogs.Data.Select(x => new Dog(x)).ToArray(),
51-
juniorDogs.Data.Select(x => new Dog(x)).ToArray()
49+
allDogs.Data,
50+
seniorDogs.Data,
51+
juniorDogs.Data
5252
});
5353
}
5454
}

samples/docker-compose/dotnet/Models/Dog.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@
33

44
namespace dotnet.Models
55
{
6+
[MsgPackArray]
67
public class Dog
78
{
8-
public Dog(TarantoolTuple<long, string, long, MsgPackToken> tuple)
9-
{
10-
Id = tuple.Item1;
11-
Name = tuple.Item2;
12-
Age = tuple.Item3;
13-
var _ = TryParseString(tuple.Item4) || TryParseInt(tuple.Item4);
14-
}
9+
private MsgPackToken _addditionalDataRaw;
1510

16-
public long Id { get; }
11+
[MsgPackArrayElement(0)]
12+
public long Id { get; set; }
1713

18-
public string Name { get; }
14+
[MsgPackArrayElement(1)]
15+
public string Name { get; set; }
1916

20-
public long Age { get; }
17+
[MsgPackArrayElement(2)]
18+
public long Age { get; set; }
19+
20+
[MsgPackArrayElement(3)]
21+
public MsgPackToken AddditionalDataRaw
22+
{
23+
get => _addditionalDataRaw;
24+
set
25+
{
26+
_addditionalDataRaw = value;
27+
var _ = TryParseString(value) || TryParseInt(value);
28+
}
29+
}
2130

2231
public string AdditionalData { get; private set; }
2332

samples/docker-compose/dotnet/Startup.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
using dotnet.Models;
12
using Microsoft.AspNetCore.Builder;
23
using Microsoft.AspNetCore.Hosting;
34
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.DependencyInjection;
56
using Microsoft.Extensions.Logging;
6-
7+
using ProGaudi.MsgPack.Light;
78
using ProGaudi.Tarantool.Client;
9+
using ProGaudi.Tarantool.Client.Model;
810

911
namespace dotnet
1012
{
@@ -28,7 +30,14 @@ public void ConfigureServices(IServiceCollection services)
2830
// Add framework services.
2931
services.AddMvc();
3032

31-
var box = Box.Connect("operator:123123@tarantool1:3301").GetAwaiter().GetResult();
33+
var msgPackContext = new MsgPackContext();
34+
msgPackContext.GenerateAndRegisterArrayConverter<Dog>();
35+
36+
var clientOptions = new ClientOptions("operator:123123@tarantool1:3301", context: msgPackContext);
37+
38+
var box = new Box(clientOptions);
39+
box.Connect().ConfigureAwait(false).GetAwaiter().GetResult();
40+
3241
services.AddSingleton(box);
3342
}
3443

samples/docker-compose/dotnet/dotnet.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
1717
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
1818
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
19-
<PackageReference Include="progaudi.tarantool" Version="0.7.0" />
19+
<PackageReference Include="msgpack.light" Version="1.3.0" />
20+
<PackageReference Include="progaudi.tarantool" Version="0.8.0" />
2021
</ItemGroup>
2122
</Project>

0 commit comments

Comments
 (0)