PST SDK  6.0.0.0-272350a
restserver/restserver.cs
// Copyright PS-Tech B.V. All Rights Reserved.
using System;
using System.Runtime.InteropServices;
using System.Threading;
using PSTech.Pstsdk;
namespace PSTech.RestServer
{
public class RestServer
{
//Registering control handler function.
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(ConsoleEventHandler handler, bool add);
private delegate bool ConsoleEventHandler(CtrlType sig);
static ConsoleEventHandler ConsoleCtrlEventHandler;
public enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogOffEvent = 5,
CtrlShutdownEvent = 6,
}
private static bool ConsoleHandler(CtrlType sig)
{
Exithandler((int)sig);
return true;
}
static void Exithandler(int sig)
{
Tracker.DisableRestServer();
Tracker.Shutdown();
Environment.Exit(0);
}
static int Main(string[] args)
{
// Register the exit handler with the application
ConsoleCtrlEventHandler += new ConsoleEventHandler(ConsoleHandler);
SetConsoleCtrlHandler(ConsoleCtrlEventHandler, true);
// Implement error handling of PSTech.TrackerException exceptions to prevent
// improper PST Tracker shutdown on errors.
try
{
// Create an instance of the Tracker object using the default configuration path and file names.
Tracker tracker = new Tracker();
// Start the tracker server.
tracker.StartTracker();
// Enable the REST server. To check if the REST server is started correctly, browse to
// http://localhost:7278/PSTapi/SystemCheck
// In order to use 127.0.0.1 an an address on Windows 7, execute the following command
// on an elevated command prompt to allow communication to this address:
// "netsh http add urlacl url=http://127.0.0.1:7278/ user=EVERYONE listen=yes delegate=no"
Tracker.EnableRestServer("localhost", "7278");
Console.Write("PST REST server enabled. See the PST SDK Manual for example commands.\n");
// Wait for one minute before terminating this application.
Thread.Sleep(60000);
// Disable the REST server
Tracker.DisableRestServer();
}
catch (Exception e)
{
Console.Write(e + "\n");
// Handle the error.
}
finally
{
// Make sure that the connection to the PST Tracker is shut down properly.
Tracker.Shutdown();
}
return 0;
}
}
}
PSTech.Pstsdk
Definition: CApi.cs:8
Exception
PSTech
Definition: CApi.cs:8