Summary: Build and run your first .NET application.

Overview

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

  1. Prerequisites/Installing GigaSpaces
  2. Set up a Visual Studio Project
  3. Write and read objects
  4. Run the space
  5. View the data

Installing GigaSpaces

For instructions on how to install XAP.NET, refer to the Installing XAP.NET section.

Creating a New .NET Project

  1. Start your edition of Visual Studio: Choose Start > All Programs > Microsoft Visual Studio > Microsoft Visual Studio
  2. In Visual Studio choose File > New > Project, to create a new project.
  3. From the New Project window, click the Console Application icon.
  4. Store the application project files under GigaSpaces Root\Examples.

Project References

Add the GigaSpaces.Core.dll file located under GigaSpaces Root\Bin into your project references.

Creating a Data Class

  1. To create a new class, on the main menu, click Project > Add Class...
  2. Set the Name to MyData.cs and press Enter
  3. Change the content of the file as follows:

    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);
        }
    }

Starting the GigaSpaces Management Center

The GigaSpaces Management Center is a graphical user interface that allows application developers and administrators to manage GigaSpaces components.

Choose Start Menu > All Programs > GigaSpaces XAP.NET 6.6.0 > GigaSpaces Management Center

Starting the 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
    

Building and Running 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.

Viewing the Data inside the Space

  1. Start the GigaSpaces Browser:



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

Viewing 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:

GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence