BigMemory Max 4.3.2 | Component Documentation | Cross-Language Clients User Guide | BigMemory .NET Client | .NET Client Demo Samples
 
.NET Client Demo Samples
The following examples are provided in the code-samples/ directory in the kit.
BSON - C# Example
The BSON - C# example consists of three files:
*Recipe2.cs is the C# implementation of the recipe domain class. It includes classes for the Recipe2 class itself, plus support classes for things like Ingredient, MethodItem, etc., which are used by the Recipe2 class. In this class, some of the domain attributes have been annotated for the BSON serializer. It is not necessary to annotate in the domain. However, if you do not, then you will have to add some extra code to your serializer class.
*Recipe2BsonSerializer.cs implements the CacheSerializer<string, Recipe2> interface. It is responsible for serializing and deserializing keys and values, moving between the Recipe2 domain object and the Thrift types Value and StoredValue. Serialization and deserialization of the Recipe2 objects is handled through the Json.net automatic BSON serializer.
*Recipe2ConsoleApp.cs contains a main class, and tiny repository of pre-generated recipes. The console app understands get and put. Assuming you start a CL Connector on the same machine, you may do:
*Recipe2ConsoleApp put "Mac&Cheese"
*Recipe2ConsoleApp put "BreadedChicken"
*Recipe2ConsoleApp get "Mac&Cheese"
*Recipe2ConsoleApp get "BreadedChicken" where ("Mac&Cheese" and "BreadedChicken" are the two preloaded recipes).
To run the BSON - C# example:
1. Create a new Visual Studio project and add the three .CS recipe files.
2. Add the following libraries in the References section of your project:
*bigmemory_csharp.dll (included in the kit)
*Thrift.dll (included in the kit)
*Nirvana DotNet.dll (included in the kit)
*Newtonsoft.json.dll (available from http://json.codeplex.com/)
3. Start the server as described in Installing and Configuring the .NET Client , in the step "Start the CL Connector", and then run the console application (Recipe2ConsoleApp.cs).
Protocol Buffer - C# Example
The Protocol Buffer - C# example consists of the following files:
*recipe.cs is the C# implementation of the recipe domain class. This was automatically generated and has the annotation included in the domain.
*RecipeSerializer.cs implements the CacheSerializer interface. Serialization and deserialization of the recipe object is handled by the Google Protocol Buffer serializer.
*SimpleRecipeConsoleApp.cs contains the main class and does simple get and put.
The example is a recipe package that includes ingredients, measurements, and instructions.
package RecipeProject;

message RecipeStructure {
required string name = 1;
required string description = 2;
required int32 preparation_time = 3;
required Method method = 6;
required Ingredients ingredients = 5;
optional int32 baking_time = 4;
optional ServingInstructions instructions = 7;
}

message Ingredients {
repeated Ingredient ingredient = 1;
}

message Ingredient {
required float quantity = 1;
required Measurement measurement = 2;
required IngredientDescription ingredient = 3;
}

message Measurement {
required string measurement_type = 1;
}

message IngredientDescription {
required string ingredient = 1;
optional Ingredient alternative_ingredient = 2;
}

message Method {
repeated MethodItem items = 1;
}

message MethodItem {
required int32 step_number = 1;
required string instruction = 2;
}

message ServingInstructions {
required int32 servings = 1;
required Measurement serving_measurement = 2;
optional Method method = 3;
}
To run the Protocol Buffer - C# example:
1. Create a new Visual Studio project and add the three .CS recipe files.
2. Add the following libraries in the References section of your project:
*bigmemory_csharp.dll (included in the kit)
*Thrift.dll (included in the kit)
*Nirvana DotNet.dll (included in the kit)
*protobuf-net.dll (available from http://code.google.com/p/protobuf-net/)
3. Start the server as described in Installing and Configuring the .NET Client , in the step "Start the CL Connector", and then run the console application (SimpleRecipeConsoleApp.cs).
Note: If you have already installed the BigMemory Client and Cross-Language Connector, you can run this example by adding the external protobuf dependency. The maven link is
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
This dependency will need to be in both BigMemory .Net Client and CL Connector classpaths. For the CL Connector, the component that needs to be set is EhcacheThriftConfiguration.Builder().cacheSerializerFactory(RecipeSerializerFactory.class) so that the RecipeSerializerFactory, RecipeSerializer, and Recipe classes will be in the CL Connector's classpath. For the BigMemory .Net Client, the component that will be run is SimpleRecipeConsoleApp, which requires the SimpleRecipeConsoleApp, RecipeSerializer, and Recipe classes to be on the classpath along with the BigMemory .Net Client dependencies.

Copyright © 2010 - 2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.