summaryrefslogtreecommitdiff
path: root/ldtp
diff options
context:
space:
mode:
authorNagappan Alagappan <nagappan@gmail.com>2012-06-18 11:30:16 -0700
committerNagappan Alagappan <nagappan@gmail.com>2012-06-18 11:30:16 -0700
commitead0f70ffb190cd9990f5bc5401c6af689934150 (patch)
treed4d40405a54fffd0f4ac2795ebd1a1886d2dd9a8 /ldtp
parente61fa63988597541ec78e3b06dad461c6e91c5a9 (diff)
C# Ldtp client
C# Ldtp client, initial prototype QA Notes: Testing Done: Documentation Notes: Bug Number: Reviewed by: Approved by: Mailto:
Diffstat (limited to 'ldtp')
-rw-r--r--ldtp/Ldtp/Ldtp.cs201
-rw-r--r--ldtp/Ldtp/Ldtp.csproj54
-rw-r--r--ldtp/Ldtp/LdtpExecutionError.cs15
-rw-r--r--ldtp/Ldtp/Properties/AssemblyInfo.cs36
4 files changed, 306 insertions, 0 deletions
diff --git a/ldtp/Ldtp/Ldtp.cs b/ldtp/Ldtp/Ldtp.cs
new file mode 100644
index 0000000..4a99a62
--- /dev/null
+++ b/ldtp/Ldtp/Ldtp.cs
@@ -0,0 +1,201 @@
+using System;
+using System.Threading;
+using System.Diagnostics;
+using CookComputing.XmlRpc;
+using System.Collections.Generic;
+
+namespace Ldtp
+{
+ public interface ILdtp : IXmlRpcProxy
+ {
+ [XmlRpcMethod("launchapp")]
+ int LaunchApp(string cmd, string[] args, int delay = 5,
+ int env = 1, string lang = "");
+ [XmlRpcMethod("getapplist")]
+ string[] GetAppList();
+ [XmlRpcMethod("getwindowlist")]
+ String[] GetWindowList();
+ [XmlRpcMethod("getobjectlist")]
+ String[] GetObjectList(String windowName);
+ [XmlRpcMethod("guiexist")]
+ int GuiExist(String windowName, String objName = "");
+ [XmlRpcMethod("isalive")]
+ bool IsAlive();
+ }
+ public class Ldtp
+ {
+ ILdtp proxy;
+ Process ps = null;
+ String windowName = null;
+ String serverAddr = null;
+ String serverPort = null;
+ Boolean windowsEnv = false;
+ private void connectToServer()
+ {
+ if (serverAddr == null)
+ serverAddr = Environment.GetEnvironmentVariable("LDTP_SERVER_ADDR");
+ if (serverAddr == null)
+ serverAddr = "localhost";
+ if (serverPort == null)
+ serverPort = Environment.GetEnvironmentVariable("LDTP_SERVER_PORT");
+ if (serverPort == null)
+ serverPort = "4118";
+ String tmpEnv = Environment.GetEnvironmentVariable("LDTP_WINDOWS");
+ if (tmpEnv != null)
+ windowsEnv = true;
+ else
+ {
+ tmpEnv = Environment.GetEnvironmentVariable("LDTP_LINUX");
+ if (tmpEnv != null)
+ windowsEnv = false;
+ else
+ {
+ windowsEnv = true;
+ }
+ }
+ proxy = (ILdtp)XmlRpcProxyGen.Create(typeof(ILdtp));
+ String url = String.Format("http://{0}:{1}/RPC2", serverAddr, serverPort);
+ proxy.Url = url;
+ IsAlive();
+ }
+ private Boolean IsAlive()
+ {
+ Boolean isAlive = false;
+ try
+ {
+ isAlive = proxy.IsAlive();
+ }
+ catch
+ {
+ // Do nothing on exception
+ ;
+ }
+ if (!isAlive)
+ launchLdtpProcess();
+ return isAlive;
+ }
+ void InternalLaunchProcess(object data)
+ {
+ Process ps = data as Process;
+ // Wait for the application to quit
+ ps.WaitForExit();
+ // Close the handle, so that we won't leak memory
+ ps.Close();
+ ps = null;
+ }
+ private void launchLdtpProcess()
+ {
+ String cmd;
+ if (windowsEnv)
+ // Launch Windows LDTP
+ cmd = "CobraWinLDTP.exe";
+ else
+ // Launch Linux LDTP
+ cmd = "ldtp";
+ ps = new Process();
+ try
+ {
+ ProcessStartInfo psi = new ProcessStartInfo();
+ psi.FileName = cmd;
+ psi.UseShellExecute = true;
+ psi.WindowStyle = ProcessWindowStyle.Hidden;
+ ps.StartInfo = psi;
+ ps.Start();
+ Thread thread = new Thread(new ParameterizedThreadStart(
+ InternalLaunchProcess));
+ // Clean up in different thread
+ //thread.Start(ps);
+ // Wait 5 seconds after launching
+ Thread.Sleep(5000);
+ }
+ catch (Exception ex)
+ {
+ throw new LdtpExecutionError(ex.Message);
+ }
+ }
+ ~Ldtp()
+ {
+ Console.WriteLine("Destructor");
+ if (ps != null)
+ {
+ try
+ {
+ ps.Kill();
+ }
+ catch
+ {
+ // Silently ignore any exception
+ }
+ }
+ }
+ public Ldtp(String windowName, String serverAddr = "localhost",
+ String serverPort = "4118", bool windowsEnv = true)
+ {
+ if (windowName == null || windowName == "")
+ {
+ throw new LdtpExecutionError("Window name missing");
+ }
+ this.serverAddr = serverAddr;
+ this.serverPort = serverPort;
+ this.windowName = windowName;
+ this.windowsEnv = windowsEnv;
+ connectToServer();
+ }
+ public int LaunchApp(string cmd, string[] args, int delay = 5,
+ int env = 1, string lang = "")
+ {
+ try
+ {
+ return proxy.LaunchApp(cmd, args, delay, env, lang);
+ }
+ catch (XmlRpcFaultException ex)
+ {
+ throw new LdtpExecutionError(ex.FaultString);
+ }
+ }
+ public String[] GetAppList()
+ {
+ try
+ {
+ return proxy.GetAppList();
+ }
+ catch (XmlRpcFaultException ex)
+ {
+ throw new LdtpExecutionError(ex.FaultString);
+ }
+ }
+ public String[] GetWindowList()
+ {
+ try
+ {
+ return proxy.GetWindowList();
+ }
+ catch (XmlRpcFaultException ex)
+ {
+ throw new LdtpExecutionError(ex.FaultString);
+ }
+ }
+ public String[] GetObjectList()
+ {
+ try
+ {
+ return proxy.GetObjectList(windowName);
+ }
+ catch (XmlRpcFaultException ex)
+ {
+ throw new LdtpExecutionError(ex.FaultString);
+ }
+ }
+ public int GuiExist(String objName = "")
+ {
+ try
+ {
+ return proxy.GuiExist(windowName, objName);
+ }
+ catch (XmlRpcFaultException ex)
+ {
+ throw new LdtpExecutionError(ex.FaultString);
+ }
+ }
+ }
+}
diff --git a/ldtp/Ldtp/Ldtp.csproj b/ldtp/Ldtp/Ldtp.csproj
new file mode 100644
index 0000000..fbd8189
--- /dev/null
+++ b/ldtp/Ldtp/Ldtp.csproj
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{22180E1A-B4B2-4A7A-B15E-DD70F98B3299}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Ldtp</RootNamespace>
+ <AssemblyName>Ldtp</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="CookComputing.XmlRpcV2">
+ <HintPath>..\CobraWinLDTP\CookComputing.XmlRpcV2.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Ldtp.cs" />
+ <Compile Include="LdtpExecutionError.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/ldtp/Ldtp/LdtpExecutionError.cs b/ldtp/Ldtp/LdtpExecutionError.cs
new file mode 100644
index 0000000..48785b7
--- /dev/null
+++ b/ldtp/Ldtp/LdtpExecutionError.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Ldtp
+{
+ [Serializable]
+ class LdtpExecutionError : Exception
+ {
+ public LdtpExecutionError(string message) : base(message)
+ {
+ }
+ }
+}
diff --git a/ldtp/Ldtp/Properties/AssemblyInfo.cs b/ldtp/Ldtp/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..6ebd199
--- /dev/null
+++ b/ldtp/Ldtp/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Ldtp")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Ldtp")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("6224fb32-17ae-4f37-9432-47add2f4c96d")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]