The example code below shows how easy it is to integrate LICA use into your own applications
//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="Shore Tech Systems LLP">
// Copyright (c) Shore Tech Systems LLP. All rights reserved.
// </copyright>
// <author>Shore Tech Systems LLP</author>
//<date>30 August 2010</date>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace WSTest2
{
/// <summary>
/// Test WCF client for the LICA Web Service
/// </summary>
class Program
{
static string dir = null; //Directory to read images from
static string userName = null; //Client username
static string password = null; //Client password
/// <summary>
/// Entry point to program
/// </summary>
/// <param name="args">The args - none needed.</param>
static void Main(string[] args)
{
Console.WriteLine("Enter username");
userName = Console.ReadLine();
Console.WriteLine("Enter password");
password = Console.ReadLine();
Console.WriteLine("Type path and file name to send");
dir = Console.ReadLine();
DirectoryInfo d = new DirectoryInfo(dir);
var files = d.GetFiles("*", SearchOption.AllDirectories).OrderBy(_f => _f.Name).ToList();
//For each image in the directory send to the LICA web service
foreach (var f in files)
{
try
{
DoImage(f.FullName);
}
catch (Exception ex)
{
Console.WriteLine("Exception occured: " + ex.Message);
}
}
Console.WriteLine("Press any key to exit");
Console.Read();
}
/// <summary>
/// Does the upload and download of the image to the LICA web service
/// </summary>
/// <param name="o">The o.</param>
static void DoImage(object o)
{
string fileName = o as string;
var fileInfo = new FileInfo(fileName);
DirectoryInfo directory = fileInfo.Directory;
//Creates an instance of the LICA client
var c = new LWS.LicaClient();
//Sets the username
c.ClientCredentials.UserName.UserName = userName;
//Sets the password
c.ClientCredentials.UserName.Password = password;
try
{
//Opens the connection to LICA
c.Open();
//Reads the current number of LICA credits remaining
var creds = c.GetRemainingCredits();
Console.WriteLine(
"You have {0} credits remaining", creds);
//Reads the bytes of the image into a local array
var b = File.ReadAllBytes(fileName);
//Sends the data and image description to the LICA web service
var i = c.NewImageByByteArray(
fileInfo.Name,
b,
fileInfo.Name,
string.Format("Image of {0}", fileInfo.Name),
string.Format("Comments for {0}", fileInfo.Name));
//Converts the LICA image into a line drawing
var g = c.ProcessImage(
i,
"Nature",
string.Format("Process {0}", fileInfo.Name));
Console.WriteLine("Process Image");
//Waits until the image has been processed
while (!c.ConvertedImageExists(g))
{
System.Threading.Thread.Sleep(100);
}
//Gets the converted image data
var cBytes = c.GetImage(g, "converted");
//Saves the converted image to disk
File.WriteAllBytes(
directory + @"\ConvertedImage.jpg", cBytes);
Console.WriteLine(
directory + @"\ConvertedImage.jpg");
}
catch
{
throw;
}
finally
{
c.Close();
}
}
}
}