public string Description { get; }
The textual description of the event log.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Jpip;
using Leadtools.Jpip.Client.WinForms;
using Leadtools.Jpip.Client.InteractiveDecoder;
using Leadtools.Jpip.Server;
using Leadtools.Jpip.Logging;
private JpipServer _server;
private WindowsLogWriter _logWriter;
private int _responseCount;
private string _loggingFileName;
private bool _loggingFileEnabled;
private const string LOCAL_IP_ADDRESS = "127.0.0.1";
private const string SERVER_NAME = "LEAD JPIP Server - Test Server";
private const int PORT_107 = 107;
private string CACHE_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");
private string IMAGES_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");
private string IMAGE_NAME = Path.Combine(LEAD_VARS.ImagesDir, "Earth8000_Precint_4_.j2k");
private string LOG_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "Server Logs");
private string LOG_FILE_NAME = Path.Combine(LEAD_VARS.ImagesDir, "log.txt");
public RunServerExamples()
{
Leadtools.Examples.Support.SetLicense();
_server = new JpipServer();
_logWriter = new WindowsLogWriter();
_responseCount = 0;
_loggingFileEnabled = true;
if (!File.Exists(LOG_DIRECTORY + LOG_FILE_NAME))
{
Directory.CreateDirectory(LOG_DIRECTORY);
File.WriteAllText(LOG_FILE_NAME, " ");
}
_loggingFileName = LOG_FILE_NAME;
}
void EventLogger_EventLog(object sender, Leadtools.Jpip.Logging.EventLogEntry e)
{
Console.WriteLine("Server Name: {0}; Server IP: {1}; Server Port: {2}; Client IP: {3}; Client Port: {4}; Channel ID: {5}; Event Type: {6}; Description: {7}",
e.ServerName, e.ServerIPAddress, e.ServerPort,
e.ClientIPAddress, e.ClientPort, e.ChannelID,
e.Type.ToString(), e.Description);
}
void _server_ResponseSending(object sender, ResponseSendingEventArgs e)
{
string dataFolder;
string dumpClientIP;
int dumpClientPort;
dataFolder = Path.Combine(LEAD_VARS.ImagesDir, "ServerResponses");
dumpClientIP = "127.0.0.1";
dumpClientPort = 1207;
if (!Directory.Exists(dataFolder))
{
Directory.CreateDirectory(dataFolder);
}
if ((e.ClientIpAddress == dumpClientIP) && (e.ClientPort == dumpClientPort))
{
string subDirectoryPath;
string responseDataFile;
_responseCount++;
subDirectoryPath = string.Concat(dataFolder, "\\", dumpClientIP);
responseDataFile = string.Concat(subDirectoryPath, "\\response_", _responseCount);
if (!Directory.Exists(subDirectoryPath))
{
Directory.CreateDirectory(subDirectoryPath);
}
File.WriteAllBytes(responseDataFile, e.Data);
}
}
void _server_RequestReceived(object sender, RequestReceivedEventArgs e)
{
string denyClientIpAddress = "127.0.0.1";
int denyClientPort = 120;
if ((e.ClientIpAddress == denyClientIpAddress) && (e.ClientPort == denyClientPort))
{
e.Deny = true;
e.StatusCode = (int)HttpStatusCode.Forbidden;
e.Description = "Server refused to process request.";
}
}
public void ResetServerConfiguration()
{
if (!_server.IsRunning)
{
JpipConfiguration appConfigSettings;
//for reading from configuration file settings
appConfigSettings = new JpipConfiguration();
//Server Settings
_server.Configuration.ServerName = SERVER_NAME;
_server.Configuration.IPAddress = LOCAL_IP_ADDRESS;
_server.Configuration.Port = PORT_107;
_server.Configuration.ImagesFolder = IMAGES_DIRECTORY;
_server.Configuration.CacheFolder = CACHE_DIRECTORY;
_server.Configuration.MaxServerBandwidth = ConfigurationDefaults.MaxServerBandwidth;
_server.Configuration.CacheSize = appConfigSettings.CacheSize;
_server.Configuration.DivideSuperBoxes = true;
_server.Configuration.ChunkSize = 512;
_server.Configuration.MaxClientCount = 5;
_server.Configuration.ConnectionIdleTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.ConnectionIdleTimeout);
_server.Configuration.MaxSessionLifetime = TimeSpan.FromSeconds(ConfigurationDefaults.MaxSessionLifetime);
_server.Configuration.MaxConnectionBandwidth = ConfigurationDefaults.MaxConnectionBandwidth;
//Communication Settings
_server.Configuration.MaxTransportConnections = 15;
_server.Configuration.HandshakeTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.HandshakeTimeout);
_server.Configuration.RequestTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.RequestTimeout);
_server.Configuration.ChunkSize = ConfigurationDefaults.ChunkSize;
//Images Settings
_server.Configuration.ImageParsingTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.ImageParsingTimeout);
_server.Configuration.PartitionBoxSize = 30;
_server.Configuration.DivideSuperBoxes = appConfigSettings.DivideSuperBoxes;
//Logging Settings
_server.Configuration.LoggingFile = _loggingFileName;
_server.Configuration.EnableLogging = _loggingFileEnabled;
_server.Configuration.LogInformation = true;
_server.Configuration.LogWarnings = true;
_server.Configuration.LogDebug = true;
_server.Configuration.LogErrors = true;
AddAliasFolders();
}
}
private void AddAliasFolders()
{
string alias = "LeadImages";
string physicalPath = LEAD_VARS.ImagesDir;
//Set server aliases folder
if (_server.Configuration.IsAliasExists(alias))
{
if (_server.Configuration.GetAliasPath(alias) != physicalPath)
{
_server.Configuration.RemoveAliasFolder(alias);
}
else
{
return;
}
}
_server.Configuration.AddAliasFolder(alias, physicalPath);
}
public void SetViewer(JpipRasterImageViewer viewer)
{
viewer.CacheDirectoryName = CACHE_DIRECTORY;
viewer.PortNumber = PORT_107;
viewer.IPAddress = LOCAL_IP_ADDRESS;
viewer.PacketSize = 16384;
viewer.ChannelType = JpipChannelTypes.HttpChannel;
}
private class WindowsLogWriter : ILoggingChannel
{
public void WriteLog(Leadtools.Jpip.Logging.EventLogEntry logEntry)
{
string message;
message = string.Format("Server Name: {0}; Server IP: {1}; Server Port: {2}; Client IP: {3}; Client Port: {4}; Channel ID: {5}; Event Type: {6}; Description: {7}",
logEntry.ServerName, logEntry.ServerIPAddress, logEntry.ServerPort,
logEntry.ClientIPAddress, logEntry.ClientPort, logEntry.ChannelID,
logEntry.Type.ToString(), logEntry.Description);
System.Diagnostics.EventLog.WriteEntry("JPIP LEAD Server", message);
}
}
public void StartServer()
{
ResetServerConfiguration();
//Interactive handling
_server.RequestReceived += new EventHandler<RequestReceivedEventArgs>(_server_RequestReceived);
_server.ResponseSending += new EventHandler<ResponseSendingEventArgs>(_server_ResponseSending);
//Handle event logs
EventLogger.EventLog += new EventHandler<Leadtools.Jpip.Logging.EventLogEntry>(EventLogger_EventLog);
//clear the server cache
_server.ClearCacheContents();
//Add custom logging channel
if (!EventLogger.ContainsLoggingChannel(_logWriter))
{
EventLogger.AddLoggingChannel(_logWriter);
}
EventLogger.LogEvent(SERVER_NAME, LOCAL_IP_ADDRESS, PORT_107.ToString(), "", "",
DateTime.Now, Leadtools.Jpip.Logging.EventLogEntryEventType.Information,
"", "LEAD Example Started");
//start the server
_server.Start();
Debug.Assert(_server.IsRunning, "Server did not start.");
/* client side */
JpipRasterImageViewer jpipViewer = new JpipRasterImageViewer();
jpipViewer.FileOpened += new EventHandler(jpipViewer_FileOpened);
SetViewer(jpipViewer);
jpipViewer.Open(IMAGE_NAME);
}
void jpipViewer_FileOpened(object sender, EventArgs e)
{
JpipRasterImageViewer jpipViewer = (JpipRasterImageViewer)sender;
jpipViewer.ZoomIn();
jpipViewer.Close();
/*Server side*/
if (_server.IsRunning)
{
_server.Stop();
}
EventLogger.LogEvent(SERVER_NAME, LOCAL_IP_ADDRESS, PORT_107.ToString(), "", "",
DateTime.Now, Leadtools.Jpip.Logging.EventLogEntryEventType.Information,
"", "LEAD Example Ended");
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}