-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (77 loc) · 3.71 KB
/
Program.cs
File metadata and controls
88 lines (77 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* © Copyright 2018-2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
* This material contains sample programming source code ("Sample Code").
* ScaleOut Software, Inc. (SSI) grants you a nonexclusive license to compile,
* link, run, display, reproduce, and prepare derivative works of
* this Sample Code. The Sample Code has not been thoroughly
* tested under all conditions. SSI, therefore, does not guarantee
* or imply its reliability, serviceability, or function. SSI
* provides no support services for the Sample Code.
*
* All Sample Code contained herein is provided to you "AS IS" without
* any warranties of any kind. THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGMENT ARE EXPRESSLY
* DISCLAIMED. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
* WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU. IN NO
* EVENT WILL SSI BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
* SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THE SAMPLE CODE
* INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS
* INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION
* HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGES.
*/
using System;
using Scaleout.Client;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Scaleout.Samples
{
internal class Program
{
static void Main(string[] args)
{
var serviceCollection = new ServiceCollection();
// Load appsetting.json and build configuration
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
// Add logging
serviceCollection.AddLogging(builder =>
{
builder.AddConfiguration(configuration.GetSection("Logging"));
builder.AddConsole();
});
// Build a local service provider with all registered services
var serviceProvider = serviceCollection.BuildServiceProvider();
// Retrieve ILoggerFactory
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
// Configuring logging for Scaleout.Client library
Scaleout.Client.GridConnection.SetLoggerFactory(loggerFactory);
///
/// Sample code with Scaleout.Client that does a few basic caching operations
///
var conn = GridConnection.Connect("bootstrapGateways=localhost:721");
// Create cache "Scientific Discoveries" that changed the world
// The object key is a year of discovery
var cacheBuilder = new CacheBuilder<int, string>("Scientific Discoveries", conn);
var cache = cacheBuilder.Build();
// Add an object to the cache:
var keyDiscoveryYear = 1543;
var addResponse = cache.Add(keyDiscoveryYear, "First Model of Earth’s Motion");
if (addResponse.Result != ServerResult.Added)
Console.WriteLine($"Unexpected add result: {addResponse.Result}");
// Retrieve the object:
var readResponse = cache.Read(1543);
if (readResponse.Result == ServerResult.Retrieved)
Console.WriteLine($"Copernicus creates the {readResponse.Value} in {keyDiscoveryYear}");
else
Console.WriteLine($"Unexpected read result: {readResponse.Result}");
Console.WriteLine("Press any key to finish the program");
Console.ReadLine();
}
}
}