Building Your First .NET Application

  Search Here
Searching GigaSpaces XAP/EDG 6.0 Documentation

                                               

This page is specific to:
GigaSpaces 6.0

If you're interested in another version, click it below:
GigaSpaces 5.x
GigaSpaces 6.5

Overview

In this section, we build and run .NET applications using the GigaSpaces PONO API:

  1. Set up Visual Studio Project
  2. Write and read objects
  3. Run the space
  4. View the data

Checking Prequisites

Make sure you have the following installed:

Installing GigaSpaces

GigaSpaces is 100% pure Java (server side), and therefore can run on any UNIX or Windows machine that supports Java.

Before installing GigaSpaces, make sure:

  • The JAVA_HOME environment variable points to the correct JDK directory before running GigaSpaces.
  • Your network and machines running GigaSpaces are configured to have multicast enabled.
  • Unzip the zip file (using your favorite unzip tool, for example, WinZip) to the location of your choice.
  • The path under which GigaSpaces is installed doesn't include spaces.

After unzipping the zip file, you should have the following files and folders under the <GigaSpaces Root> folder:

For more details, refer to the Installing GigaSpaces section.

Testing Environment

  1. Run the GigaSpaces Server: Open the <GigaSpaces Root>\bin directory and run the gsInstance.bat command.
  2. It is recommended to verify the parameters in the <GigaSpaces Root>\bin\setenv.bat file.
  3. Note that the VERBOSE variable is set to true in that file.
  4. Make sure gsInstance loads without errors/exceptions.
  5. Run the gs.bat utility from the <GigaSpaces Root>\bin directory using the following syntax:
    gs
    ...
    gs> space ping
    total 1
    [Look And Feel - ServiceGrid] mySpace                     gigaspaces-6.0XAP        PC-LAB
    [2] all
    
    Enter a comma-separated list to ping or "c" to cancel : 1
    ping with:
    Finder URL: -
    Lease Timeout:  FOREVER
    LookupFinder timeout: 5000 milliseconds
    Buffer Size: 100
    Iterations: 5
  6. The following result should appear on the console:
    Started to ping <mySpace> space (1 of 1)...
    Average Time = 25 milliseconds
     successful

For more details, refer to the Testing System Environment section.

Creating New .NET Project

  1. Start the Visual C# 2005 Express Edition.
  2. Create a new project:



  3. Select Console Application.



  4. Store the application project files under GigaSpaces Root\dotnet\examples.

For details on managed and unmanaged references, see Setting up Visual Studio Project References.

Project References

Add the GigaSpaces.Core.dll file located under GigaSpaces Root\dotnet\lib into your project references:

Creating Data Class

Create a new data class as seen below:





using System;
using GigaSpaces.Core.Metadata;

namespace myHelloSpace
{
    class MyData
    {
        [SpaceProperty(Index = SpaceIndexType.Basic)]
        public string firstName;
        public string lastName;
        [SpaceProperty(NullValue = "1/1/1900 12:00:00")]
        public DateTime dob;
    }
}

Write and Read Objects - the Application

using System;
using System.Collections.Generic;
using System.Text;
using GigaSpaces.Core;

namespace myHelloSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Getting space proxy
            ISpaceProxy space = SpaceProxyProviderFactory.Instance.FindSpace("rmi://localhost/./mySpace");
            if (space != null) Console.WriteLine("Connect to space OK!");
            MyData data = new MyData();
            data.firstName = "Joe";
            data.lastName = "lastname";
            data.dob = new DateTime(1980, 1, 20, 10, 20, 0, DateTimeKind.Utc);
            // we write the data object into the space for a day
            space.Write<MyData>(data, null, 1000 * 60 * 24);
            Console.WriteLine("Wrote data to space OK!");
            // read using simple template
            MyData template = new MyData();
            template.firstName = "Joe";
            template.dob = new DateTime(1900, 1, 1, 12, 0, 0, DateTimeKind.Utc); // null value
            MyData dataFromSpace = space.Read<MyData>(template, null, 1000);
            if (dataFromSpace != null) Console.WriteLine("Read data from space OK!");
            Console.WriteLine("FirstName:" + dataFromSpace.firstName +
                " LastName:" + dataFromSpace.lastName +
                " Dob:" + dataFromSpace.dob);
        }
    }

Add GigaSpaces Managment Center Tool

To activate the GigaSpaces Browser (allows you to view spaces, space classes, Entries, etc.), add a new tool directly from the Studio IDE:

Start Space

  1. Open a command line and run the following (instead of <GigaSpaces Root>, type your GigaSpaces installation directory):
    <GigaSpaces Root>\bin\gsInstance.bat "/./mySpace"
    

  2. Once the space starts, the following output is displayed:
    Jun 19, 2007 3:56:57 PM
    INFO [com.gigaspaces.container]: *** Welcome to the GigaSpaces world ! - GigaSpaces Platform(TM)
    6.0XAP Build: 1809-21 Server started successfully ! ***
    
    Jun 19, 2007 3:56:57 PM
    INFO [com.gigaspaces.common.spacefinder]: java:// protocol. Get <mySpace> space from <mySpace_container> container
    

Build and Run the Application

Make sure the following system environment variables are part of your classpath:

  • JAVA_HOME – the path under which Java is installed.
  • JSHOMEDIR – the path under which GigaSpaces is installed (your <GigaSpaces Root> directory).

For example:

JAVA_HOME=D:\JDK\jdk1.5.0_04
JSHOMEDIR=C:\GigaSpacesXAP6.0

Alternatively, the <GigaSpaces Root> directory can be defined in your application configuration file. For more details, refer to the .NET API Configuration section.

View Data Inside Space

  1. Start the GigaSpaces Browser:



  2. The mySpace icon is displayed. Click the Classes icon:

View Space Entries

Select the myData class line, and click the Query button. The Query view is displayed. This shows your .NET PONO inside the space:

64-bit Compilation

Use the /platform:anycpu switch when compiling and running on 64-bit windows machine platforms. Example (based on the Benchmark example):

csc.exe /target:exe /platform:anycpu  /out:Release/benchmark.exe /recurse:./*.cs /reference:..\..\lib\GigaSpaces.Core.dll

For more details, refer to the Microsoft website.

The .NET API does not currently support 64-bit compilation. This will be available in future releases.


GigaSpaces 6.0 Documentation Contents (Current Page in Bold)

    Java

    C++

    .NET

    Middleware Capabilities

    Configuration and Management

Add GigaSpaces wiki search to your browser search engines!
(works on Firefox 2 and Internet Explorer 7)

Labels

 
(None)