Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HAInterface -> Expanded to allow delegating incoming commands. Basic …
…State Device. Start on Basic REST API. All Unit Tests pass.
- Loading branch information
Showing
10 changed files
with
357 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Netomity.Core; | ||
using Netomity.Interfaces; | ||
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 StateDevice: NetomityObject | ||
{ | ||
HAInterface _iface = null; | ||
string _address = null; | ||
|
||
public StateDevice(HAInterface iface, string address) | ||
{ | ||
_iface = iface; | ||
_address = address; | ||
|
||
_iface.OnCommand(address: _address, action: _CommandReceived); | ||
} | ||
|
||
private void _CommandReceived(Command command) | ||
{ | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Netomity.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Web; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Netomity.Web | ||
{ | ||
[ServiceContract()] | ||
public class RestAPI: NetomityObject | ||
{ | ||
[WebGet(ResponseFormat = WebMessageFormat.Json)] | ||
[OperationContract()] | ||
public long Add(int a, int b) | ||
{ | ||
return (a + b); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Netomity.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Description; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Netomity.Web | ||
{ | ||
public class RestHost : NetomityObject | ||
{ | ||
public const string BASE_URL = "http://localhost:8081/Netomity/API/v1"; | ||
ServiceHost _host = null; | ||
|
||
public RestHost() | ||
{ | ||
Open(); | ||
} | ||
|
||
public void Open() | ||
{ | ||
//http://msdn.microsoft.com/en-us/library/ms733768.aspx | ||
//netsh http add urlacl url=http://+:8081/Netomity/API/v1 user=DOMAIN\user | ||
//netsh http add urlacl url=http://+:8081/Netomity/API/v1 user=jason | ||
_host = new ServiceHost(typeof(RestAPI), | ||
new Uri[] { }); | ||
|
||
WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None); | ||
|
||
ServiceEndpoint endPoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(RestAPI)), | ||
binding, new EndpointAddress(BASE_URL)); | ||
WebHttpBehavior webBehavior = new WebHttpBehavior(); | ||
endPoint.Behaviors.Add(webBehavior); | ||
_host.AddServiceEndpoint(endPoint); | ||
|
||
_host.Open(); | ||
Log("Netomity RestAPI Service Started"); | ||
} | ||
|
||
public void Close() | ||
{ | ||
if (_host == null) | ||
_host.Close(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Netomity.Devices; | ||
using Netomity.Interfaces.HA; | ||
using Netomity.Interfaces.Basic; | ||
|
||
namespace NetomityTests.Devices | ||
{ | ||
[TestClass] | ||
public class StateDeviceTests | ||
{ | ||
StateDevice _sd = null; | ||
HAInterface _ha = null; | ||
BasicInterface _t = null; | ||
|
||
string _data; | ||
|
||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
_t = new Netomity.Interfaces.Basic.Fakes.StubBasicInterface() | ||
{ | ||
SendString = (data) => { _data = data; }, | ||
DataReceivedEvent = (ev) => { _t._DataReceived(ev); }, | ||
}; | ||
_ha = new Netomity.Interfaces.HA.Fakes.StubHAInterface(basicInterface: _t) | ||
{ | ||
|
||
}; | ||
_sd = new StateDevice(iface: _ha, address: "12.34.56"); | ||
} | ||
[TestMethod] | ||
public void TestInstantiation() | ||
{ | ||
Assert.IsNotNull(_sd); | ||
} | ||
} | ||
} |
Oops, something went wrong.