.NET Upgrade Example
UpgradeSample.cs shows usage of the V10 API, with examples of the V9 API provided for comparison.
using System;
using Apache.Geode.Client;
namespace Apache.Geode.Client.QuickStart
{
// The BasicOperations QuickStart example.
class BasicOperations
{
static void Main(string[] args)
{
try
{
// *** Create the cache *********************************************
// OLD:
// CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
// Cache cache = cacheFactory.Create();
// NEW:
var cacheFactory = new CacheFactory();
var cache = cacheFactory.Create();
// *** Create the region *********************************************
// OLD:
// RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
// IRegion<string, string> region = regionFactory.Create<string, string>("exampleRegion");
// NEW: (pool required)
var poolFactory = cache.GetPoolFactory()
.AddLocator("localhost", 10334);
poolFactory.Create("pool");
var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY)
.SetPoolName("pool");
var region = regionFactory.Create<string, string>("exampleRegion");
// *** Put data into the region ********************************************
// OLD and NEW are the same for the following operations
region["blue"] = "The color of the sky";
string skyColor = region["blue"];
region.Invalidate("blue");
region.Remove("caches");
cache.Close();
}
// An exception should not occur
catch (Exception ex) { }
}
}
}