|
| 1 | +# Tutorial |
| 2 | + |
| 3 | +The most commonly used C# driver is [progaudi.tarantool](https://github.com/progaudi/progaudi.tarantool). It was previously named `tarantool-csharp`. It is not supplied as part of the Tarantool repository; it must be installed separately. The makers recommend cross-platform installation using Nuget. To be consistent with the other instructions in this chapter, here is an way to install the driver directly on Ubuntu 16.04. |
| 4 | + |
| 5 | +## Install .net core from Microsoft |
| 6 | + |
| 7 | +Use .net core installation instructions at https://www.microsoft.com/net/core#linuxubuntu |
| 8 | +NOTE: |
| 9 | +1. Mono will not work, nor will .Net from xbuild. Only .net core supported on linux and mac. |
| 10 | +2. Read the Microsoft End User License Agreement first, because it is not an ordinary open-source agreement and there will be a message during installation saying “This software may collect information about you and your use of the software, and send that to Microsoft.” |
| 11 | +3. You can opt-out from telemetry by setting environment variable. See instructions at https://docs.microsoft.com/en-us/dotnet/core/tools/telemetry#behavior |
| 12 | + |
| 13 | + |
| 14 | +## Create new console project |
| 15 | + |
| 16 | +``` |
| 17 | +cd ~ |
| 18 | +mkdir progaudi.tarantool.test |
| 19 | +cd progaudi.tarantool.test |
| 20 | +dotnet new console |
| 21 | +``` |
| 22 | + |
| 23 | +## Add progaudi.tarantool reference |
| 24 | + |
| 25 | +``` |
| 26 | +dotnet add package progaudi.tarantool |
| 27 | +``` |
| 28 | + |
| 29 | +## Change code in Program.cs |
| 30 | + |
| 31 | +``` |
| 32 | +cat <<EOT > Program.cs |
| 33 | +using System; |
| 34 | +using System.Threading.Tasks; |
| 35 | +using ProGaudi.Tarantool.Client; |
| 36 | +
|
| 37 | +public class HelloWorld |
| 38 | +{ |
| 39 | + static public void Main () |
| 40 | + { |
| 41 | + Test().GetAwaiter().GetResult(); |
| 42 | + } |
| 43 | + static async Task Test() |
| 44 | + { |
| 45 | + var box = await Box.Connect("127.0.0.1:3301"); |
| 46 | + var schema = box.GetSchema(); |
| 47 | + var space = await schema.GetSpace("examples"); |
| 48 | + await space.Insert((99999, "BB")); |
| 49 | + } |
| 50 | +} |
| 51 | +EOT |
| 52 | +
|
| 53 | +``` |
| 54 | + |
| 55 | +## Build and run your app |
| 56 | + |
| 57 | +Before trying to run, check that the server is listening at `localhost:3301` and that the space `examples` exists, as described [earlier](https://tarantool.org/en/doc/1.7/book/connectors/index.html#index-connector-setting). |
| 58 | + |
| 59 | +``` |
| 60 | +dotnet restore |
| 61 | +dotnet run |
| 62 | +``` |
| 63 | + |
| 64 | +The program will connect using an application-specific definition of the space. The program will open a socket connection with the Tarantool server at `localhost:3301`, then send an INSERT request, then — if all is well — end without saying anything. If Tarantool is not running on localhost with listen port = 3301, or if user guest does not have authorization to connect, or if the insert request fails for any reason, the program will print an error message, among other things (stacktrace, etc). |
| 65 | + |
| 66 | +The example program only shows one request and does not show all that’s necessary for good practice. For that, please see the [progaudi.tarantool](https://github.com/progaudi/progaudi.tarantool) driver repository. |
0 commit comments