Skip to content

Commit 21cdf64

Browse files
committed
Demo is done
1 parent b8ec9a2 commit 21cdf64

File tree

21 files changed

+190
-63
lines changed

21 files changed

+190
-63
lines changed

.vscode/launch.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": ".NET Core Launch (web)",
6+
"type": "coreclr",
7+
"request": "launch",
8+
"preLaunchTask": "build",
9+
"program": "${workspaceRoot}/samples/docker-compose/dotnet/bin/Debug/netcoreapp1.0/dotnet.dll",
10+
"args": [],
11+
"cwd": "${workspaceRoot}",
12+
"stopAtEntry": false,
13+
"internalConsoleOptions": "openOnSessionStart",
14+
"launchBrowser": {
15+
"enabled": true,
16+
"args": "${auto-detect-url}",
17+
"windows": {
18+
"command": "cmd.exe",
19+
"args": "/C start ${auto-detect-url}"
20+
},
21+
"osx": {
22+
"command": "open"
23+
},
24+
"linux": {
25+
"command": "xdg-open"
26+
}
27+
},
28+
"env": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
},
31+
"sourceFileMap": {
32+
"/Views": "${workspaceRoot}/Views"
33+
}
34+
},
35+
{
36+
"name": ".NET Core Attach",
37+
"type": "coreclr",
38+
"request": "attach",
39+
"processId": "${command.pickProcess}"
40+
}
41+
]
42+
}

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"tasks": [
99
{
1010
"taskName": "build",
11-
"args": [ "src/tarantool.client", "tests/tarantool.client.tests"],
11+
"args": [ "src/tarantool.client", "tests/tarantool.client.tests", "samples/docker-compose/dotnet"],
1212
"isBuildCommand": true,
1313
"showOutput": "silent",
1414
"problemMatcher": "$msCompile"
1515
}
1616
]
17-
}
17+
}

samples/docker-compose/dotnet/.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43
using System.Threading.Tasks;
4+
using dotnet.Models;
55
using Microsoft.AspNetCore.Mvc;
6+
using Tarantool.Client;
7+
using Tarantool.Client.Model;
8+
using Tarantool.Client.Model.Enums;
69

710
namespace dotnet.Controllers
811
{
912
public class HomeController : Controller
1013
{
11-
public IActionResult Index()
14+
private readonly Box _box;
15+
private readonly Space _space;
16+
private readonly Index _primaryIndex;
17+
private readonly Index _secondaryIndex;
18+
19+
public HomeController(Box box)
20+
{
21+
this._box = box;
22+
23+
var result = this.Initialize().GetAwaiter().GetResult();
24+
this._space = result.Item1;
25+
this._primaryIndex = result.Item2;
26+
this._secondaryIndex = result.Item3;
27+
}
28+
29+
private async Task<Tarantool.Client.Model.Tuple<Space, Index, Index>> Initialize()
1230
{
13-
return View();
31+
var schema = this._box.GetSchema();
32+
33+
var space = await schema.GetSpace("some_space");
34+
var primaryIndex = await space.GetIndex("primary");
35+
var index = await space.GetIndex("some_secondary_index");
36+
37+
return Tarantool.Client.Model.Tuple.Create(space, primaryIndex, index);
38+
}
39+
40+
public async Task<ViewResult> Index()
41+
{
42+
var primaryData = await this._primaryIndex.Select<Tuple<long>, Tuple<long, string, long>>(Tuple.Create(-1L), new SelectOptions { Iterator = Iterator.All });
43+
var secondaryData = await this._secondaryIndex.Select<Tuple<long>, Tuple<long, string, long>>(Tuple.Create(5L), new SelectOptions { Iterator = Iterator.Ge });
44+
45+
return View(new TestData
46+
{
47+
AllDogs = primaryData.Data.Select(x => new Dog(x)).ToArray(),
48+
DogsOlder5Years = secondaryData.Data.Select(x => new Dog(x)).ToArray()
49+
});
1450
}
1551
}
1652
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Tarantool.Client.Model;
2+
3+
namespace dotnet.Models
4+
{
5+
public class Dog
6+
{
7+
public Dog(Tuple<long, string, long> tuple)
8+
{
9+
Id = tuple.Item1;
10+
Name = tuple.Item2;
11+
Age = tuple.Item3;
12+
}
13+
14+
public long Id { get; }
15+
16+
public string Name { get; }
17+
18+
public long Age { get; }
19+
}
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace dotnet.Models
4+
{
5+
public class DogTable
6+
{
7+
public DogTable(IReadOnlyList<Dog> dogs, string caption)
8+
{
9+
Dogs = dogs;
10+
Caption = caption;
11+
}
12+
13+
public IReadOnlyList<Dog> Dogs { get; }
14+
public string Caption { get; }
15+
}
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace dotnet.Models
4+
{
5+
public class TestData
6+
{
7+
public IReadOnlyList<Dog> AllDogs { get; set;}
8+
9+
public IReadOnlyList<Dog> DogsOlder5Years { get; set; }
10+
}
11+
}

samples/docker-compose/dotnet/Startup.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net;
5+
using System.Net.Sockets;
46
using System.Threading.Tasks;
57
using Microsoft.AspNetCore.Builder;
68
using Microsoft.AspNetCore.Hosting;
79
using Microsoft.Extensions.Configuration;
810
using Microsoft.Extensions.DependencyInjection;
911
using Microsoft.Extensions.Logging;
1012

13+
using Tarantool.Client;
14+
using Tarantool.Client.Model;
15+
1116
namespace dotnet
1217
{
1318
public class Startup
@@ -29,6 +34,9 @@ public void ConfigureServices(IServiceCollection services)
2934
{
3035
// Add framework services.
3136
services.AddMvc();
37+
38+
var box = CreateConnectedBox().GetAwaiter().GetResult();
39+
services.AddSingleton(box);
3240
}
3341

3442
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -48,5 +56,20 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
4856
template: "{controller=Home}/{action=Index}/{id?}");
4957
});
5058
}
59+
60+
private async Task<Box> CreateConnectedBox()
61+
{
62+
var addresses = await Dns.GetHostAddressesAsync("tarantool1");
63+
var box = new Box(new ConnectionOptions
64+
{
65+
EndPoint = new IPEndPoint(addresses.First(x => x.AddressFamily == AddressFamily.InterNetwork), 3301),
66+
GuestMode = false,
67+
UserName = "operator",
68+
Password = "123123"
69+
});
70+
await box.Connect();
71+
72+
return box;
73+
}
5174
}
5275
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@model dotnet.Models.DogTable
2+
3+
<div>
4+
<table class="table table-condensed">
5+
<caption>@Model.Caption</caption>
6+
<thead>
7+
<tr>
8+
<th>Id</th>
9+
<th>Name</th>
10+
<th>Age</th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
@foreach (var p in @Model.Dogs)
15+
{
16+
<tr>
17+
<td>@p.Id</td>
18+
<td>@p.Name</td>
19+
<td>@p.Age</td>
20+
</tr>
21+
}
22+
</tbody>
23+
<tfoot>
24+
<tr>
25+
<td colspan="3">@Model.Dogs.Count dogs total</td>
26+
</tr>
27+
</tfoot>
28+
</table>
29+
</div>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
@using dotnet.Models
2+
@model TestData
13
@{
24
ViewData["Title"] = "Tarantool demo page";
35
}
46

5-
<div>
6-
TARANTOOL DEMO
7-
</div>
7+
@Html.Partial("DogTablePartial", new DogTable(Model.AllDogs, "All dogs in Tarantool"))
8+
9+
@Html.Partial("DogTablePartial", new DogTable(Model.DogsOlder5Years, "Senior dogs in Tarantool"))

0 commit comments

Comments
 (0)