Created
August 14, 2013 17:00
-
-
Save DevJohnC/6233075 to your computer and use it in GitHub Desktop.
My office control script for Adjutant
This file contains hidden or 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
| using FragLabs.Adjutant.API; | |
| using FragLabs.Adjutant.API.Attributes; | |
| using FragLabs.Adjutant.API.Services; | |
| using FragLabs.Adjutant.API.Location; | |
| using FragLabs.Adjutant.API.Devices; | |
| using FragLabs.Adjutant.API.Web; | |
| using FragLabs.Adjutant.API.Apps; | |
| namespace OfficeControlScript | |
| { | |
| // define an entry point for the script, in this case we do nothing | |
| public class Script { public void Run() { } } | |
| // define the control service | |
| public class ControlService : Service<Control> | |
| { | |
| public override object Execute(Control request) | |
| { | |
| var location = Locations.Get("office"); | |
| var computers = Computer.Lookup(location); | |
| foreach (var computer in computers) | |
| { | |
| try | |
| { | |
| if (request.OnOff == "on") | |
| { | |
| computer.WakeUp(); | |
| } | |
| else if (request.OnOff == "off") | |
| { | |
| if (computer.DeviceName.ToLower() == "odin") // prevent the NAS from being turned off | |
| continue; | |
| computer.Sleep(); | |
| } | |
| } | |
| catch { } | |
| } | |
| return new ControlResponse(); | |
| } | |
| } | |
| [BelongsToApp("OfficeControl")] | |
| public class Control : RequestDto | |
| { | |
| public string OnOff { get; set; } | |
| } | |
| public class ControlResponse | |
| { | |
| } | |
| // define the web controller for the basic interface | |
| [BelongsToApp("OfficeControl")] | |
| public class HomeController : Controller | |
| { | |
| public string Index() | |
| { | |
| return @"<html> | |
| <head> | |
| <meta name=""viewport"" content=""width=device-width, initial-scale=1.0""> | |
| <style type=""text/css""> | |
| html,body { width: 100%; height: 100%; padding: 0; margin: 0 ;} | |
| #onButton, #offButton { width: 100%; height: 48%; padding: 0; margin: 0; } | |
| #onButton { padding-bottom: 1% } | |
| #onButton button { background-color: #080 } | |
| #offButton button { background-color: #800 } | |
| #onButton button, #offButton button { width: 100%; height: 100%; padding: 0; margin: 0; } | |
| </style> | |
| <script src=""http://code.jquery.com/jquery-1.10.1.min.js""></script> | |
| <script src=""http://code.jquery.com/jquery-migrate-1.2.1.min.js""></script> | |
| <script type=""text/javascript""> | |
| $(document).ready(function(){ | |
| $(""#onButton button"").click(function(){ | |
| ControlService(true); | |
| }); | |
| $(""#offButton button"").click(function(){ | |
| ControlService(false); | |
| }); | |
| }); | |
| function ControlService(onOff) | |
| { | |
| var requestStr = ""{\""OnOff\"":""; | |
| if (onOff) | |
| requestStr += ""on""; | |
| else | |
| requestStr += ""off""; | |
| requestStr += ""\""}""; | |
| $.post(""/services/officecontrol/control"", requestStr, function(data){}); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <div id=""onButton""> | |
| <button>Turn On</button> | |
| </div> | |
| <div id=""offButton""> | |
| <button>Turn Off</button> | |
| </div> | |
| </body> | |
| </html>"; | |
| } | |
| } | |
| // define the app itself to which the service and controller belong | |
| [AppInfo("OfficeControl", "{3009CBC1-846B-4752-BC66-DF7A4D442BCC}", "1.0", | |
| "John Carruthers", "", "", "Home office control")] | |
| public class OfficeControlApp : App | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment