Skip to content

Instantly share code, notes, and snippets.

View DevJohnC's full-sized avatar

John Carruthers DevJohnC

View GitHub Profile
private void ShutdownComputer(IDevice computer, ISecurityCredentials credentials)
{
ServiceHelper.Call<ShutdownResponse>(computer, new Shutdown(), credentials, (shutdownResponse, exception) =>
{
if (exception is API.Exceptions.PermissionDeniedException)
{
// pincode required for call, prompt user for it in full version
if (credentials == null)
{
var dummyCredentials = new API.Security.PinCode
@DevJohnC
DevJohnC / OfficeControlScript.cs
Created August 14, 2013 17:00
My office control script for Adjutant
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
{
@DevJohnC
DevJohnC / scriptcaller.vb
Created August 12, 2013 00:24
Example scripting
Imports System
Imports FragLabs.Adjutant.API.Helpers
Namespace ScriptingExample
Public Class Script
Sub Run
Services.Call("/scripts/csharp", Sub(str as String, ex as Exception)
Console.WriteLine("CSharp says: {0}", str)
End Sub
)
@DevJohnC
DevJohnC / gist:6207182
Created August 11, 2013 22:30
VB.NET scripting example in Adjutant
Imports System
Imports FragLabs.Adjutant.API.Helpers
Namespace ScriptingExample
Public Class Script
Sub Run
Services.Add(""/scripts/vbnet"", Function()
return ""Hello Scripts From VB.NET""
End Function
)
@DevJohnC
DevJohnC / RconClient.cs
Created August 9, 2013 04:48
Socket client
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using FragLabs.Adjutant.Network.Exceptions;
using FragLabs.Adjutant.Network.Interfaces;
namespace FragLabs.Adjutant.Network.Sockets
{
/// <summary>
@DevJohnC
DevJohnC / gist:6175080
Created August 7, 2013 15:25
Socket send troubles :S
public void Send(Message message)
{
if (message == null) throw new ArgumentNullException("message");
if (!IsConnected)
throw new Exception("Socket not connected");
var rawMessage = message.Encode();
if (rawMessage.Length > uint.MaxValue)
throw new Exception("Message too long");
var fullMessage = new byte[rawMessage.Length + 4];
var len = BitConverter.GetBytes((uint)rawMessage.Length);
@DevJohnC
DevJohnC / gist:6152415
Created August 4, 2013 23:01
Adjutant shutdown speech command example
private void SetupSpeechCommands()
{
var recognizer = Speech.GetRecognizer();
if (recognizer == null)
{
throw new SpeechRecognitionException("Recognizer not available.");
}
var locationNames = new List<string>();
foreach (var location in Locations.Get())
@DevJohnC
DevJohnC / FriendsService.cs
Created July 13, 2013 06:52
Hosting OAuth services is so easy - based on the new ServiceStack API.
using ServiceStack.ServiceInterface;
namespace OAuth.Services
{
[TwoLegged]
[ThreeLegged]
public class Friends : OAuth.Service
{
public object Get(DTOs.Friends friends)
{
var i = 0;
var upperBound = itemsToDisplay + startOffset;
foreach (var item in Items)
{
if (i < startOffset || i >= upperBound)
{
if (item.IsDisplayed)
{
_layout.Remove(item.ProxyDrawable);
item.IsDisplayed = false;
using FragLabs.Adjutant.API.Services;
using FragLabs.Adjutant.Modules.Video.Dtos;
namespace FragLabs.Adjutant.Modules.Video.Services
{
public class BrowseService : Service<Browse>
{
public override object Execute(Browse request)
{
var app = (VideoApp)Context.App;