Testing

Delphi code posted
created at 09 Jan 21:08

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Imports nsoftware.IPWorks
Imports Newtonsoft.Json

Module MainModule

    Private ReadOnly Usage As String = "Copyright (C) 2012-2013 AnyCo Studios - All Rights Reserved" + vbCrLf +
    vbCrLf +
    "Usage:" + vbCrLf +
    "    SendNotification <Sender> <Title> <Message> <OptionalText> <Snarl> <Mobile> <Icon> <Sound> <Priority> <Timeout>" + vbCrLf +
    vbCrLf +
    "Options" + vbCrLf +
    "    Sender                  Name of the program/system sending the notification" + vbCrLf +
    "    Title                   Title of the notification" + vbCrLf +
    "    Message                 The content of the notification" + vbCrLf +
    "    OptionalText            Optional text to include with the notification, display only" + vbCrLf +
    "    Snarl [True/False]      Send notification to Snarl on Server" + vbCrLf +
    "    Mobile [True/False]     Send notification to mobile device" + vbCrLf +
    "    Icon                    Full path of a Snarl icon to display" + vbCrLf +
    "    Sound                   Full path of a Snarl sound file to play" + vbCrLf +
    "    Priority                0 is regular, set to 1 for high priority" + vbCrLf +
    "    Timeout                 How many seconds to display, 0 is never time out"

    Public Class NotificationClass
        Property Sender As String = ""
        Property Title As String = ""
        Property Message As String = ""
        Property OptionalText As String = ""
        Property NotifySnarl As Boolean = False
        Property NotifyDevices As Boolean = False
        Property Icon As String = ""
        Property Sound As String = ""
        Property Priority As Integer = 0
        Property Timeout As Integer = 0
    End Class

    Sub Main(Args As String())
        Dim Notification As New NotificationClass
        Dim JsonString As String = ""
        Dim Socket As New Udpport

        If Args.Count <> 10 Then
            Console.WriteLine(Usage)
            Environment.Exit(1)
        End If

        Notification.Sender = Args(0).ToString
        Notification.Title = Args(1).ToString
        Notification.Message = Args(2).ToString
        Notification.OptionalText = Args(3).ToString
        Notification.NotifySnarl = UCase(Args(4).ToString) = "TRUE"
        Notification.NotifyDevices = UCase(Args(5).ToString) = "TRUE"
        Notification.Icon = Args(6).ToString
        Notification.Sound = Args(7).ToString
        Notification.Priority = Args(8)
        Notification.Timeout = Args(9)

        JsonString = JsonConvert.SerializeObject(Notification, Formatting.Indented)

        'Console.WriteLine(JsonString)

        Socket.RemoteHost = "192.168.1.100"
        Socket.RemotePort = 10000
        Socket.Active = True
        Socket.Send(System.Text.Encoding.Default.GetBytes(JsonString))
        Socket.Active = False
        Socket.Dispose()
        Socket = Nothing
    End Sub

End Module
2.89 KB in 8 ms with coderay