Last active
December 25, 2015 10:09
-
-
Save DevJohnC/6959218 to your computer and use it in GitHub Desktop.
AdjutantOS example script
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
| // | |
| // Author: John Carruthers (johnc@frag-labs.com) | |
| // | |
| // Copyright (C) 2013 John Carruthers | |
| // | |
| // Permission is hereby granted, free of charge, to any person obtaining | |
| // a copy of this software and associated documentation files (the | |
| // "Software"), to deal in the Software without restriction, including | |
| // without limitation the rights to use, copy, modify, merge, publish, | |
| // distribute, sublicense, and/or sell copies of the Software, and to | |
| // permit persons to whom the Software is furnished to do so, subject to | |
| // the following conditions: | |
| // | |
| // The above copyright notice and this permission notice shall be | |
| // included in all copies or substantial portions of the Software. | |
| // | |
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
| // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
| // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
| // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| // | |
| // | |
| // Example AdjutantOS script. | |
| // Defines an app for install, a simple job and a service. | |
| // | |
| using System; | |
| using FragLabs.AdjutantOS.API; | |
| using FragLabs.AdjutantOS.API.Apps; | |
| using FragLabs.AdjutantOS.API.Jobs; | |
| using FragLabs.AdjutantOS.API.Services; | |
| namespace FragLabs.AdjutantOS.Scripts.Example | |
| { | |
| /// <summary> | |
| /// An example app. | |
| /// </summary> | |
| [AppManifest("ExampleScript", "{2C0238C4-F014-4B18-A8A8-2653219F1BBF}", "1.0.0.0", "John Carruthers", "johnc@frag-labs.com", | |
| "http://adjutantos.com/", "Demos authoring an app within a script")] | |
| public class ExampleScriptApp : AppBase | |
| { | |
| public override void Start() | |
| { | |
| Console.WriteLine("ExampleScriptApp was started!"); | |
| JobScheduler.Current.Add(new ExampleJob()); | |
| } | |
| } | |
| /// <summary> | |
| /// Example job that runs every minute. | |
| /// </summary> | |
| public class ExampleJob : CronJob | |
| { | |
| public ExampleJob() | |
| : base("* * * * *") | |
| { | |
| ServiceInvoker.Call<EchoResponse>(DeviceRepository.Server, new Echo { EchoText = "Echo!" }).ContinueWith(t => { | |
| var result = t.Result; | |
| Console.WriteLine("{0}: {1}", result.RequestTime, result.EchoText); | |
| }); | |
| } | |
| } | |
| /// <summary> | |
| /// Echo service request DTO. | |
| /// </summary> | |
| [BelongsToApp("ExampleScript")] | |
| public class Echo : RequestDtoBase | |
| { | |
| /// <summary> | |
| /// Text to echo. | |
| /// </summary> | |
| public string EchoText { get; set; } | |
| } | |
| /// <summary> | |
| /// Echo service response DTO. | |
| /// </summary> | |
| public class EchoResponse | |
| { | |
| /// <summary> | |
| /// DateTime of request. | |
| /// </summary> | |
| public DateTime RequestTime { get; set; } | |
| /// <summary> | |
| /// Echo text. | |
| /// </summary> | |
| public string EchoText { get; set; } | |
| } | |
| /// <summary> | |
| /// Echo service. | |
| /// </summary> | |
| public class EchoService : ServiceBase<Echo> | |
| { | |
| public override object Execute(Echo request) | |
| { | |
| return new EchoResponse | |
| { | |
| RequestTime = DateTime.Now, | |
| EchoText = request.EchoText | |
| }; | |
| } | |
| } | |
| } |
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
| ' | |
| ' Author: John Carruthers (johnc@frag-labs.com) | |
| ' | |
| ' Copyright (C) 2013 John Carruthers | |
| ' | |
| ' Permission is hereby granted, free of charge, to any person obtaining | |
| ' a copy of this software and associated documentation files (the | |
| ' "Software"), to deal in the Software without restriction, including | |
| ' without limitation the rights to use, copy, modify, merge, publish, | |
| ' distribute, sublicense, and/or sell copies of the Software, and to | |
| ' permit persons to whom the Software is furnished to do so, subject to | |
| ' the following conditions: | |
| ' | |
| ' The above copyright notice and this permission notice shall be | |
| ' included in all copies or substantial portions of the Software. | |
| ' | |
| ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| ' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| ' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| ' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
| ' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
| ' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
| ' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| ' | |
| ' | |
| ' Example AdjutantOS script. | |
| ' Defines an app for install, a simple job and a service. | |
| ' | |
| Imports FragLabs.AdjutantOS.API | |
| Imports FragLabs.AdjutantOS.API.Apps | |
| Imports FragLabs.AdjutantOS.API.Jobs | |
| Imports FragLabs.AdjutantOS.API.Services | |
| Namespace FragLabs.AdjutantOS.Scripts.Example | |
| ''' <summary> | |
| ''' An example app. | |
| ''' </summary> | |
| <AppManifest("ExampleScript", "{2C0238C4-F014-4B18-A8A8-2653219F1BBF}", "1.0.0.0", "John Carruthers", "johnc@frag-labs.com", "http://adjutantos.com/", _ | |
| "Demos authoring an app within a script")> _ | |
| Public Class ExampleScriptApp | |
| Inherits AppBase | |
| Public Overrides Sub Start() | |
| Console.WriteLine("ExampleScriptApp was started!") | |
| JobScheduler.Current.Add(New ExampleJob()) | |
| End Sub | |
| End Class | |
| ''' <summary> | |
| ''' Example job that runs every minute. | |
| ''' </summary> | |
| Public Class ExampleJob | |
| Inherits CronJob | |
| Public Sub New() | |
| MyBase.New("* * * * *") | |
| ServiceInvoker.[Call](Of EchoResponse)(DeviceRepository.Server, New Echo() With { _ | |
| Key .EchoText = "Echo!" _ | |
| }).ContinueWith(Function(t) | |
| Dim result = t.Result | |
| Console.WriteLine("{0}: {1}", result.RequestTime, result.EchoText) | |
| End Function) | |
| End Sub | |
| End Class | |
| ''' <summary> | |
| ''' Echo service request DTO. | |
| ''' </summary> | |
| <BelongsToApp("ExampleScript")> _ | |
| Public Class Echo | |
| Inherits RequestDtoBase | |
| ''' <summary> | |
| ''' Text to echo. | |
| ''' </summary> | |
| Public Property EchoText() As String | |
| Get | |
| Return m_EchoText | |
| End Get | |
| Set | |
| m_EchoText = Value | |
| End Set | |
| End Property | |
| Private m_EchoText As String | |
| End Class | |
| ''' <summary> | |
| ''' Echo service response DTO. | |
| ''' </summary> | |
| Public Class EchoResponse | |
| ''' <summary> | |
| ''' DateTime of request. | |
| ''' </summary> | |
| Public Property RequestTime() As DateTime | |
| Get | |
| Return m_RequestTime | |
| End Get | |
| Set | |
| m_RequestTime = Value | |
| End Set | |
| End Property | |
| Private m_RequestTime As DateTime | |
| ''' <summary> | |
| ''' Echo text. | |
| ''' </summary> | |
| Public Property EchoText() As String | |
| Get | |
| Return m_EchoText | |
| End Get | |
| Set | |
| m_EchoText = Value | |
| End Set | |
| End Property | |
| Private m_EchoText As String | |
| End Class | |
| ''' <summary> | |
| ''' Echo service. | |
| ''' </summary> | |
| Public Class EchoService | |
| Inherits ServiceBase(Of Echo) | |
| Public Overrides Function Execute(request As Echo) As Object | |
| Return New EchoResponse() With { _ | |
| Key .RequestTime = DateTime.Now, _ | |
| Key .EchoText = request.EchoText _ | |
| } | |
| End Function | |
| End Class | |
| End Namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment