Added project "Scheduler"

This commit is contained in:
Micke Prag 2008-02-14 10:53:09 +00:00
parent 396ca1e72b
commit 809659ea17
64 changed files with 27338 additions and 0 deletions

View file

@ -0,0 +1,47 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{292E034F-C3B8-4CED-87DD-479040094118}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DeviceHandler</RootNamespace>
<AssemblyName>DeviceHandler</AssemblyName>
</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="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Handler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>

View file

@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace DeviceHandler
{
public class Handler
{
#region Unmanaged Code
[DllImport("TellUsbD101.dll")]
private static extern bool devTurnOn(int value);
[DllImport("TellUsbD101.dll")]
private static extern bool devTurnOff(int value);
[DllImport("TellUsbD101.dll")]
private static extern int devGetDeviceId(int value);
[DllImport("TellUsbD101.dll")]
private static extern string devGetName(int value);
[DllImport("TellUsbD101.dll")]
private static extern string devGetVendor(int value);
[DllImport("TellUsbD101.dll")]
private static extern int devGetNumberOfDevices();
#endregion
private List<Device> m_Devices = new List<Device>();
public Device Find(int deviceID)
{
foreach (Device item in m_Devices)
{
if (item.ID == deviceID)
return item;
}
return null;
}
/// <summary>
/// Turns off a specific device.
/// </summary>
/// <param name="item">The item in question.</param>
/// <returns>True if the command was successfull and false if not.</returns>
public bool TurnOff(Device item)
{
return devTurnOff(item.ID);
}
public bool TurnOffWithDelay(Device item)
{
bool result = devTurnOff(item.ID);
System.Threading.Thread.Sleep(1000);
return result;
}
/// <summary>
/// Turns on a specific device.
/// </summary>
/// <param name="item">The device in question.</param>
/// <returns>True if the command was successfull.</returns>
public bool TurnOn(Device item)
{
return devTurnOn(item.ID);
}
public bool TurnOnWithDelay(Device item)
{
//Makesure that we halt for 1 second so that the Telldus stick have time to send the signal.
bool result = devTurnOn(item.ID);
System.Threading.Thread.Sleep(1000);
return result;
}
/// <summary>
/// Loads all known devices into a collection.
/// </summary>
/// <returns>True if the process was successfull.</returns>
public bool Load()
{
try
{
m_Devices.Clear();
int count = devGetNumberOfDevices() - 1;
for (int i = 0; i <= count; i++)
{
//Collect information from the driver.
int deviceID = devGetDeviceId(i);
string deviceName = devGetName(deviceID);
string deviceVendor = devGetVendor(deviceID);
m_Devices.Add(new Device(deviceID, deviceName, deviceVendor));
}
return true;
}
catch
{
return false;
}
}
public List<Device> Devices
{
get
{
if (m_Devices.Count == 0)
Load();
return m_Devices;
}
set { m_Devices = value; }
}
}
[Serializable]
public class Device:ISerializable
{
private int m_ID = -1;
private string m_Name = "";
private string m_Vendor = "";
public Device(SerializationInfo info,StreamingContext cntx)
{
}
public Device(int id, string name,string vendor)
{
m_ID = id;
m_Name = name;
m_Vendor = vendor;
}
public int ID
{
get { return m_ID; }
set { m_ID = value; }
}
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public string Vendor
{
get { return m_Vendor; }
set { m_Vendor = value; }
}
public override string ToString()
{
return m_Name;
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}

View file

@ -0,0 +1,35 @@
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("DeviceHandler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Telldus Technologies")]
[assembly: AssemblyProduct("DeviceHandler")]
[assembly: AssemblyCopyright("Copyright © Telldus Technologies 2007")]
[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("f38b6a0f-16f2-4be8-9e86-8706f5335778")]
// 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 Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2007.1.*")]
[assembly: AssemblyFileVersion("2007.1.*")]