Skip to content

Commit

Permalink
Add OWIN support, initial website with Razor Templating. Various Enha…
Browse files Browse the repository at this point in the history
…ncements.
  • Loading branch information
zonyl committed Oct 9, 2015
1 parent 2a68d4e commit 838f544
Show file tree
Hide file tree
Showing 26 changed files with 659 additions and 11 deletions.
10 changes: 9 additions & 1 deletion BudMain/App.config
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
10 changes: 8 additions & 2 deletions BudMain/Program.cs
Expand Up @@ -24,13 +24,19 @@ static void Main(string[] args)

var tp = new TCPClient(address: "192.168.12.161", port: 3333);
var plm = new Insteon(iface: tp);
var test_tamp = new StateDevice(address: "00.5B.5d", iface: plm)

var test_lamp = new StateDevice(address: "00.5B.5d", iface: plm)
{
Name = "TestLamp1"
};

var rh = new RestHost(address: BASE_ADDR);
var Bedtime = new Scene(devices: new List<StateDevice>() { test_lamp })
{
Name = "Bedtime"
};

//var rh = new RestHost(address: BASE_ADDR);
var wh = new WebHost(address: "http://localhost:8083/");
ns.Run();

}
Expand Down
10 changes: 9 additions & 1 deletion BudProxy/App.config
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
1 change: 1 addition & 0 deletions Netomity/Core/NetomityObjectType.cs
Expand Up @@ -14,6 +14,7 @@ public sealed class NetomityObjectType
public static readonly NetomityObjectType Unknown = new NetomityObjectType("unknown");
public static readonly NetomityObjectType Device = new NetomityObjectType("device");
public static readonly NetomityObjectType Interface = new NetomityObjectType("interface");
public static readonly NetomityObjectType Scene = new NetomityObjectType("scene");


private NetomityObjectType(String name)
Expand Down
8 changes: 8 additions & 0 deletions Netomity/Core/NetomitySystem.cs
Expand Up @@ -43,5 +43,13 @@ public void Run()
Thread.Sleep(1000);
}
}

public IQueryable<NetomityObject> NetomityObjects
{
get
{
return c_objects.AsQueryable();
}
}
}
}
25 changes: 25 additions & 0 deletions Netomity/Devices/Scene.cs
@@ -0,0 +1,25 @@
using Netomity.Core;
using Netomity.Interfaces.HA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Netomity.Devices
{
public class Scene: StateDevice
{
public Scene(string address = null, HAInterface iface = null, List<StateDevice> devices = null):
base(address: address, iface: iface, devices: devices)
{

}

internal override void _Initialize()
{
base._Initialize();
Type = NetomityObjectType.Scene;
}
}
}
45 changes: 41 additions & 4 deletions Netomity/Devices/StateDevice.cs
Expand Up @@ -22,25 +22,43 @@ public class StateDevice: NetomityObject
List<Action<Command>> _commandDelegates = null;
List<Action<State>> _stateDelegates = null;
List<StateDevice> _devices = null;
List<Command> _commandsAvailable = null;

public StateDevice(string address=null, HAInterface iface=null, List<StateDevice> devices=null)
{
Type = NetomityObjectType.Device;
_iface = iface;
_address = address;
_commandDelegates = new List<Action<Command>>();
_stateDelegates = new List<Action<State>>();
_state = new State()
{
Primary = StateType.Unknown
};

_Initialize();

RegisterDevices(devices);

_state = new State(){
Primary = StateType.Unknown
};

if(_iface !=null)
_iface.OnCommand(source: _address, action: _CommandReceived);
}

internal virtual void _Initialize()
{
Type = NetomityObjectType.Device;

_commandsAvailable = new List<Command>() {
new Command() {
Primary = CommandType.On
},
new Command() {
Primary = CommandType.Off
},
};

}

private void RegisterDevices(List<StateDevice> devices)
{
if (devices != null)
Expand All @@ -64,6 +82,15 @@ public State State
}
}

[DataMember]
public List<Command> CommandsAvailable
{
get
{
return _commandsAvailable;
}
}

private void _CommandReceived(Command command)
{
State newState = null;
Expand Down Expand Up @@ -176,5 +203,15 @@ public void OnStateChange(Action<State> action)
_stateDelegates.Add(action);
}

public Task<bool> On()
{
return Command(commandT: CommandType.On);
}

public Task<bool> Off()
{
return Command(commandT: CommandType.Off);
}

}
}
2 changes: 0 additions & 2 deletions Netomity/Interfaces/Basic/BasicInterface.cs
Expand Up @@ -14,13 +14,11 @@ public BasicInterface(Logger logger=null)
{
if (logger != null)
_logger = logger;
_Initialize();

}

public BasicInterface()
{
_Initialize();
}

protected void _Initialize()
Expand Down
1 change: 1 addition & 0 deletions Netomity/Interfaces/Basic/SerialIO.cs
Expand Up @@ -20,6 +20,7 @@ public SerialIO(string portName="COM4", int portSpeed = 9600)
{
_sp = new SerialPort(portName, portSpeed);
_sp.DataReceived += _serialPort_DataReceived;
_Initialize();
}

public override event DataReceivedHandler DataReceived;
Expand Down
1 change: 1 addition & 0 deletions Netomity/Interfaces/Basic/TCPClient.cs
Expand Up @@ -21,6 +21,7 @@ public class TCPClient: BasicInterface
public override event DataReceivedHandler DataReceived;
public TCPClient(string address = null, int port = 0)
{
Log("tcpconst");
_hostName = address;
_portNumber = port;

Expand Down
45 changes: 45 additions & 0 deletions Netomity/Netomity.csproj
Expand Up @@ -33,6 +33,15 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Owin">
<HintPath>..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Host.HttpListener">
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Hosting">
<HintPath>..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation">
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
Expand All @@ -45,11 +54,36 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Owin">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="RazorEngine">
<HintPath>..\packages\RazorEngine.3.7.2\lib\net45\RazorEngine.dll</HintPath>
</Reference>
<Reference Include="RouteDebugger">
<HintPath>..\packages\routedebugger.2.1.4.0\lib\net40\RouteDebugger.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.Owin">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -66,6 +100,7 @@
<Compile Include="Core\PeriodicTimer.cs" />
<Compile Include="Core\State.cs" />
<Compile Include="Core\StateType.cs" />
<Compile Include="Devices\Scene.cs" />
<Compile Include="Devices\StateDevice.cs" />
<Compile Include="Interfaces\Basic\BasicConnector.cs" />
<Compile Include="Interfaces\Basic\BasicInterface.cs" />
Expand All @@ -80,14 +115,24 @@
<Compile Include="Interfaces\HA\SendParams.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utility\Conversions.cs" />
<Compile Include="Utility\Misc.cs" />
<Compile Include="Web\RestAPI.cs" />
<Compile Include="Web\HomeController.cs" />
<Compile Include="Web\RestController.cs" />
<Compile Include="Web\RestHost.cs" />
<Compile Include="Web\RestResponse.cs" />
<Compile Include="Web\RestResponseStatusType.cs" />
<Compile Include="Web\WebConfig.cs" />
<Compile Include="Web\WebHost.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Web\Content\devicecontrol.html" />
<Content Include="Web\Content\index.html" />
</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.
Expand Down
11 changes: 11 additions & 0 deletions Netomity/Utility/Misc.cs
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Netomity.Utility
{

}

0 comments on commit 838f544

Please sign in to comment.