blob: 1b8f5624f8a504a7c1e23d27fee8cd627114c5f8 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* The PutAllGetAllOperations QuickStart Example.
*
* This example takes the following steps:
*
* 1. Create a Geode Cache using CacheFactory. By default it will connect to "localhost" at port 40404".
* 2. Create a Example Region.
* 3. PutAll Entries (Key and Value pairs) into the Region.
* 4. GetAll Entries from the Region.
* 5. Close the Cache.
*
*/
// Use standard namespaces
using System;
using System.Collections.Generic;
// Use the Geode namespace
using Apache.Geode.Client;
namespace Apache.Geode.Client.QuickStart
{
// The PutAllGetAllOperations QuickStart example.
class PutAllGetAllOperations
{
static void Main(string[] args)
{
try
{
//Create a Geode Cache using CacheFactory. By default it will connect to "localhost" at port 40404".
Cache cache = CacheFactory.CreateCacheFactory().Create();
Console.WriteLine("Created the Geode Cache");
//Set Attributes for the region.
RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
//Create exampleRegion
IRegion<int, string> region = regionFactory.Create<int, string>("exampleRegion");
Console.WriteLine("Created exampleRegion");
// PutAll Entries (Key and Value pairs) into the Region.
Dictionary<int, string> entryMap = new Dictionary<int, string>();
for (Int32 item = 0; item < 100; item++)
{
int key = item;
string value = item.ToString();
entryMap.Add(key, value);
}
region.PutAll(entryMap);
Console.WriteLine("PutAll 100 entries into the Region");
//GetAll Entries back out of the Region
List<int> keys = new List<int>();
for (int item = 0; item < 100; item++)
{
int key = item;
keys.Add(key);
}
Dictionary<int, string> values = new Dictionary<int, string>();
region.GetAll(keys.ToArray(), values, null, true);
Console.WriteLine("Obtained 100 entries from the Region");
// Close the Geode Cache.
cache.Close();
Console.WriteLine("Closed the Geode Cache");
}
// An exception should not occur
catch (GeodeException gfex)
{
Console.WriteLine("PutAllGetAllOperations Geode Exception: {0}", gfex.Message);
}
}
}
}