4using System.Threading.Tasks;
45 get => this.addresses;
46 set => this.addresses = value;
56 set => this.urls = value;
62 public override string Resource =>
"/Settings/Notification.md";
84 return Task.CompletedTask;
102 this.testAddresses = WebServer.
Register(
"/Settings/TestNotificationAddresses",
null, this.TestNotificationAddresses,
true,
false,
true);
104 return base.InitSetup(WebServer);
115 return base.UnregisterSetup(WebServer);
135 !(Content.
Decoded is Dictionary<string, object> Obj) ||
136 !Obj.TryGetValue(
"NotificationAddresses", out
object Obj2) ||
137 !(Obj2 is
string NotificationAddresses) ||
138 !Obj.TryGetValue(
"NotificationUrls", out Obj2) ||
139 !(Obj2 is
string NotificationUrls))
145 string TabID = Request.
Header[
"X-TabID"];
147 List<CaseInsensitiveString>
Addresses =
new List<CaseInsensitiveString>();
148 List<CaseInsensitiveString> WebHooks =
new List<CaseInsensitiveString>();
150 Response.StatusCode = 200;
151 Response.StatusMessage =
"OK";
155 foreach (
string Part
in NotificationAddresses.Split(
CommonTypes.
CRLF, StringSplitOptions.RemoveEmptyEntries))
157 string s = Part.Trim();
158 if (
string.IsNullOrEmpty(s))
164 MailAddress Addr =
new MailAddress(s);
168 foreach (
string Part
in NotificationUrls.Split(
CommonTypes.
CRLF, StringSplitOptions.RemoveEmptyEntries))
170 string s = Part.
Trim();
171 if (
string.IsNullOrEmpty(s))
174 Uri Uri =
new Uri(s);
175 WebHooks.Add(Uri.ToString());
179 this.urls = WebHooks.ToArray();
183 if (this.addresses.
Length > 0 ||
this.urls.Length > 0)
185 await
Gateway.
SendNotification(
"Test\r\n===========\r\n\r\nThis message was generated to test the notification feature of **" +
189 if (!
string.IsNullOrEmpty(TabID))
190 await Response.
Write(1);
194 if (!
string.IsNullOrEmpty(TabID))
195 await Response.
Write(0);
212 return Task.FromResult(
true);
231 bool ValuesSet =
false;
242 return Task.FromResult(
false);
246 this.addresses = Jids;
257 if (!Uri.TryCreate(Url, UriKind.Absolute, out
_))
260 return Task.FromResult(
false);
268 return Task.FromResult(ValuesSet);
Helps with parsing of commong data types.
static readonly char[] CRLF
Contains the CR LF character sequence.
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
Static class managing the runtime environment of the IoT Gateway.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static Task SendNotification(Graph Graph)
Sends a graph as a notification message to configured notification recipients.
static XmppClient XmppClient
XMPP Client connection of gateway.
static string ApplicationName
Application Name.
Notification Configuration
override Task< bool > SimplifiedConfiguration()
Simplified configuration by configuring simple default values.
override Task ConfigureSystem()
Is called during startup to configure the system.
NotificationConfiguration()
Notification Configuration
override Task InitSetup(HttpServer WebServer)
Initializes the setup object.
override string ConfigPrivilege
Minimum required privilege for a user to be allowed to change the configuration defined by the class.
CaseInsensitiveString[] Urls
Notification addresses.
override Task< bool > EnvironmentConfiguration()
Environment configuration by configuring values available in environment variables.
override int Priority
Priority of the setting. Configurations are sorted in ascending order.
override Task UnregisterSetup(HttpServer WebServer)
Unregisters the setup object.
static NotificationConfiguration Instance
Current instance of configuration.
const string GATEWAY_NOTIFICATION_JIDS
JIDs of operators of gateway.
const string GATEWAY_NOTIFICATION_URLS
Webhook URLs of operators of gateway.
override void SetStaticInstance(ISystemConfiguration Configuration)
Sets the static instance of the configuration.
override Task< string > Title(Language Language)
Gets a title for the system configuration.
CaseInsensitiveString[] Addresses
Notification addresses.
Abstract base class for system configurations.
void LogEnvironmentError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value contains an error.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
bool HasData
If the request has data.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Base class for all HTTP resources.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Write(byte[] Data)
Returns binary data in the response.
Implements an HTTP server.
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
static readonly Regex BareJidRegEx
Regular expression for Bare JIDs
Represents a case-insensitive string.
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
int Length
Gets the number of characters in the current CaseInsensitiveString object.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
CaseInsensitiveString Trim()
Removes all leading and trailing white-space characters from the current CaseInsensitiveString object...
CaseInsensitiveString[] Split(params char[] separator)
Returns a string array that contains the substrings in this instance that are delimited by elements o...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
Contains information about a language.
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Interface for system configurations. The gateway will scan all module for system configuration classe...