Skip to content

Commit f3f3d8f

Browse files
committed
Eventghost plugin added
1 parent 62cd73c commit f3f3d8f

8 files changed

Lines changed: 346 additions & 0 deletions

File tree

Plugins/EventGhost/EventGhost.cs

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
namespace OSAE.EventGhost
2+
{
3+
using System;
4+
using System.Text;
5+
using System.Net;
6+
using System.Net.Sockets;
7+
8+
public class EventGhost : OSAEPluginBase
9+
{
10+
/// <summary>
11+
/// Provides access to logging
12+
/// </summary>
13+
// Logging logging = Logging.GetLogger("EventGhost");
14+
private static OSAE.General.OSAELog Log = new General.OSAELog();
15+
16+
/// <summary>
17+
/// Plugin name
18+
/// </summary>
19+
string pName;
20+
21+
22+
23+
/// <summary>
24+
/// OSA Plugin Interface - Commands the be processed by the plugin
25+
/// </summary>
26+
/// <param name="method">Method containging the command to run</param>
27+
public override void ProcessCommand(OSAEMethod method)
28+
{
29+
30+
31+
String methodName = method.MethodName;
32+
String objectName = method.ObjectName;
33+
String combinedString = objectName + "_" + methodName;
34+
35+
//get the called objects properties to see if there is a computer objet defined
36+
OSAEObject calledObject = OSAEObjectManager.GetObjectByName(method.ObjectName);
37+
OSAEObjectPropertyCollection ComputerProperty = calledObject.Properties;
38+
OSAEObjectCollection eventGhostObjects = OSAEObjectManager.GetObjectsByType("Computer");
39+
OSAEObject computer = new OSAEObject();
40+
41+
42+
43+
//if there are no properties defined then grab the first available Computer object
44+
//logging.AddToLog("The Count of the Computer Properties is : " + ComputerProperty.Count, true);
45+
if (ComputerProperty.Count == 0)
46+
{
47+
48+
//get the last object in the list
49+
50+
foreach (OSAEObject test in eventGhostObjects)
51+
{
52+
computer = test;
53+
}
54+
55+
//add log entry if mulptiple computer objects were dectected and no property was used to select which object
56+
if (eventGhostObjects.Count > 1) {
57+
58+
59+
Log.Info("There are multiple eventghost computer objects detected. " + computer.Name + " with an address of: " + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "IPAddress") + ":" + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "EventGhost Port") + " is being used to transmit the package. Please add a property called 'Computer' with a value of the object name of the computer you wish to transmit the UDP packet to.");
60+
}
61+
62+
63+
}
64+
// if the object type contains a property with ID "Computer" use that property to select the appropriate object
65+
else
66+
{
67+
68+
OSAEObjectProperty whichComputer = OSAEObjectPropertyManager.GetObjectPropertyValue(calledObject.Name,"Computer");
69+
computer = eventGhostObjects.Find(whichComputer.Value);
70+
71+
//check to see if a computer object was found if none print the logged property value and select another object to use
72+
if (computer == null){
73+
foreach (OSAEObject test in eventGhostObjects)
74+
{
75+
computer = test;
76+
}
77+
78+
if (eventGhostObjects.Count > 1)
79+
{
80+
Log.Info("A computer object was unable to be matched to " + whichComputer.Value + " please ensure that " + calledObject.Name + " contains a property called Computer with a value mathing the name of the appropriate computer object.");
81+
Log.Info(computer.Name + " with an address of: " + computer.Address + ":" + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "EventGhost Port") + " is being used to transmit the package.");
82+
}
83+
}
84+
85+
}
86+
87+
88+
89+
// logging.AddToLog(address, true);
90+
// logging.AddToLog(objectName, true);
91+
// logging.AddToLog(combinedString, true);
92+
93+
94+
//get the server address indicated in the address for the object passed to the method
95+
String ipAddress = computer.Address;
96+
97+
//check to make sure computer object has address, if not assume local host
98+
if (ipAddress.Equals("", StringComparison.Ordinal)) {
99+
ipAddress = "Localhost";
100+
101+
}
102+
103+
OSAEObjectProperty portAddress = OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "Port");
104+
105+
//if not value for port use default value of 33333
106+
int port = 0;
107+
108+
if ((portAddress.Value).Equals("",StringComparison.Ordinal)){
109+
port = 33333;
110+
}
111+
else{
112+
port = Int32.Parse(portAddress.Value);
113+
}
114+
115+
116+
117+
// logging.AddToLog(port, true);
118+
// logging.AddToLog(ipAddress, true);
119+
IPAddress serverAddr = IPAddress.Parse(ipAddress);
120+
IPEndPoint endPoint = new IPEndPoint(serverAddr, port);
121+
122+
//send the updpacket
123+
UdpClient udp = new UdpClient();
124+
byte[] sendBytes = Encoding.ASCII.GetBytes(combinedString);
125+
udp.Send(sendBytes, sendBytes.Length, endPoint);
126+
127+
128+
129+
}
130+
131+
/// <summary>
132+
/// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
133+
/// </summary>
134+
/// <param name="pluginName">The name of the plugin from the system</param>
135+
public override void RunInterface(string pluginName)
136+
{
137+
pName = pluginName;
138+
139+
try
140+
{
141+
Log.Info("Starting EventGhost...");
142+
143+
// on startup ensure that there is at least one computer setup to receive eventghost commands
144+
OSAEObjectCollection computers = OSAEObjectManager.GetObjectsByType("COMPUTER");
145+
146+
// check to make sure that the Compuer Objecttype has the needed property
147+
//add eventghost property to the computer object type
148+
149+
// need to implement check before i use the method below
150+
151+
// OSAEObjectTypeManager.ObjectTypePropertyAdd("EventGhost Port", "String", "", "Computer", false);
152+
153+
154+
155+
156+
foreach (OSAEObject acomputer in computers){
157+
158+
String computerName = acomputer.Name;
159+
String IPAddress = acomputer.Address;
160+
String eventGhostPort = (OSAEObjectPropertyManager.GetObjectPropertyValue(computerName, "EventGhost Port").Value);
161+
162+
//if no port for property indicate that the default port of 333333 will be used
163+
if (eventGhostPort.Equals("", StringComparison.Ordinal)) {
164+
Log.Info("There is no port information for " + acomputer.Name + " the default port of 33333 will be used when this computer is called");
165+
}
166+
//check to see if computer has address, if no log that "local host will be used"
167+
if ((acomputer.Address).Equals("", StringComparison.Ordinal)){
168+
Log.Info("There is no address information for " + acomputer.Name + "localhost will be used for this location");
169+
}
170+
171+
}
172+
173+
}
174+
catch (Exception ex)
175+
{
176+
Log.Error("Error during RunInterface: " + ex.Message);
177+
}
178+
179+
180+
181+
182+
}
183+
184+
/// <summary>
185+
/// OSA Plugin Interface - The plugin has been asked to shut down
186+
/// </summary>
187+
public override void Shutdown()
188+
{
189+
Log.Info("Stopping EventGhost...");
190+
191+
// Place any code required to shut down your plugin here leave empty if no action is required
192+
}
193+
}
194+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{AF008EA4-CD39-481C-9F6B-3C6B97243658}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>OSAE.EventGhost</RootNamespace>
12+
<AssemblyName>OSAE.EventGhost</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>..\..\output\Plugins\EventGhost\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>..\..\output\Plugins\EventGhost\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="OSAE.API">
36+
<HintPath>..\..\output\OSAE.API.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.ServiceModel" />
41+
<Reference Include="System.ServiceModel.Web" />
42+
<Reference Include="System.Xml.Linq" />
43+
<Reference Include="System.Data.DataSetExtensions" />
44+
<Reference Include="Microsoft.CSharp" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="EventGhost.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="EventGhost.osapd">
54+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
55+
<SubType>Designer</SubType>
56+
</None>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Content Include="install.sql">
60+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
61+
</Content>
62+
<Content Include="Screenshot.jpg">
63+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64+
</Content>
65+
</ItemGroup>
66+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
67+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
68+
Other similar extension points exist, see Microsoft.Common.targets.
69+
<Target Name="BeforeBuild">
70+
</Target>
71+
<Target Name="AfterBuild">
72+
</Target>
73+
-->
74+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<plugin-description xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="3.0">
3+
<plugin-name>EventGhost</plugin-name>
4+
<plugin-id>ffaf8042-7007-45eb-9e7d-eb988f8e229d</plugin-id>
5+
<plugin-version>0.1.4</plugin-version>
6+
<plugin-state>beta</plugin-state>
7+
<short-description>Send events to computers running EventGhost</short-description>
8+
<author>Zachary R. Christiansen</author>
9+
<destination-folder>EventGhost</destination-folder>
10+
<main-file></main-file>
11+
<wiki-url>http://www.opensourceautomation.com/wiki/index.php?title=EventGhost</wiki-url>
12+
<additional-assemblies>
13+
<name>install.sql</name>
14+
<name>Screenshot.jpg</name>
15+
</additional-assemblies>
16+
<x64-additional-assemblies>
17+
</x64-additional-assemblies>
18+
</plugin-description>
39.6 KB
Binary file not shown.

Plugins/EventGhost/EventGhost.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventGhost", "EventGhost.csproj", "{AF008EA4-CD39-481C-9F6B-3C6B97243658}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{AF008EA4-CD39-481C-9F6B-3C6B97243658}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{AF008EA4-CD39-481C-9F6B-3C6B97243658}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{AF008EA4-CD39-481C-9F6B-3C6B97243658}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{AF008EA4-CD39-481C-9F6B-3C6B97243658}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("EventGhost")]
9+
[assembly: AssemblyDescription("Open Source Automation Plugin")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("EventGhost")]
13+
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("af786d6f-1a3b-4298-8516-c6ee18d3fd5f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Plugins/EventGhost/Screenshot.jpg

5.38 KB
Loading

Plugins/EventGhost/install.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CALL osae_sp_object_type_add ('EventGhost','EventGhost','','Plugin',1,0,0,1);
2+
CALL osae_sp_object_type_property_add ('Computer','EventGhost Port','String','','',0);

0 commit comments

Comments
 (0)