Notifications Manager API (MotD)

The Message of the Day (MotD) is a message displayed to all users when they log in to Relativity. MotD is most commonly used to inform users of planned system maintenance. For more information, see the .

The Services API supports asynchronous read and update operations on the MotD. Using these operations, you can enable and disable the MotD and change its text and formatting. You can perform the operations using the MOTDRef DTO. Note that asynchronous operations return a standard .NET System.Threading.Tasks.Task<TResult> object that can be used to monitor progress and interact with the process.

You can also interact with the MotD through the REST API. See Notifications Manager service (MotD).

Complete code samples of operations on the MotD are included in the APISamples.sln solution in the Relativity SDK. (kCura.Relativity.Client.SamplesLibrary.CS\ServiceHost\MOTD.cs). For information, see Relativity SDK samples.

This page contains the following information:

Read the MotD

The following code sample illustrates how to read the MotD using the ReadMOTDAsync() method of the INotificationsManager interface.

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
public async Task<bool> ReadAsync_MOTD(Client.SamplesLibrary.Helper.IHelper helper)
{
    bool success = false;
 
    using (INotificationsManager proxy = helper.GetServicesManager().CreateProxy<INotificationsManager>(ExecutionIdentity.System))
    {
        try
        {
            Services.Notifications.MOTDRef motd = await proxy.ReadMOTDAsync();
 
            string info = string.Format("{0} : {1}", motd.Enabled, motd.Message);
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Debug, new StackFrame(0).GetMethod().Name, info, this.GetType().Name);
 
            success = true;
        }
        catch (ServiceException exception)
        {
            //Exceptions are returned as an ServiceException
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Error, new StackFrame(0).GetMethod().Name,
            exception.Message, this.GetType().Name);
        }
    }
 
    return success;
}

Update the MotD

The following code sample illustrates how to enable and change the MotD using the UpdateMOTDAsync() method of the INotificationsManager interface. Note that in order to contain formatting, such as font family, size, and color, the message must be specified as HTML. If you specify plain text, default system formatting is applied.

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
public async Task<bool> UpdateAsync_MOTD(Client.SamplesLibrary.Helper.IHelper helper)
{
    bool success = false;
 
    using (INotificationsManager proxy = helper.GetServicesManager().CreateProxy<INotificationsManager>(ExecutionIdentity.System))
    {
        try
        {
            MOTDRef motd = new MOTDRef();
 
            //Message of the Day only has two variables,
            //what the message is and if it should be displayed on log in
            motd.Message = "\r\n<p><font face=\"trebuchet ms,verdana,arial,helvetica,sans-serif\" size=\"2\" color=\"#ff0000\">
                            <b>"Relativity will be going offline at 8:00 pm for scheduled maintenance."</b></font></p>\n";
            motd.Enabled = true;
 
            await proxy.UpdateMOTDAsync(motd);
            success = true;
        }
        catch (ServiceException exception)
        {
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Error, new StackFrame(0).GetMethod().Name, exception.Message, this.GetType().Name);
        }
    }
    return success;
}

Dismiss the MotD

The following code sample illustrates how to dismiss the MotD using the DismissMOTDAsync() method of the INotificationsManager interface.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public async Task<bool> DismissAsync_MOTD(Client.SamplesLibrary.Helper.IHelper helper)
{
    bool success = false;
 
    using (INotificationsManager proxy = helper.GetServicesManager().CreateProxy<INotificationsManager>(ExecutionIdentity.System))
    {
        try
        {
            int userId = 9;
            await proxy.DismissMOTDAsync(9);
            success = true;
        }
        catch (ServiceException exception)
        {
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Error, new StackFrame(0).GetMethod().Name, exception.Message, this.GetType().Name);
        }
    }
    return success;
}

Has Dismissed the MotD

The following code sample illustrates how to check if the MotD has been dismissed previously from a user using the HasDismissedMOTDAsync() method of the INotificationsManager interface.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public async Task<bool> HasDismissedAsync_MOTD(Client.SamplesLibrary.Helper.IHelper helper)
{
    bool success = false;
 
    using (INotificationsManager proxy = helper.GetServicesManager().CreateProxy<INotificationsManager>(ExecutionIdentity.System))
    {
        try
        {
            int userId = 9;
            bool hasDismissedMOTD = await proxy.HasDismissedMOTDAsync(userId);
 
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Debug, new StackFrame(0).GetMethod().Name, hasDismissedMOTD.ToString(), this.GetType().Name);
 
            success = true;
        }
        catch (ServiceException exception)
        {
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Error, new StackFrame(0).GetMethod().Name, exception.Message, this.GetType().Name);
        }
    }
 
    return success;
}

Display the MotD

The following code sample illustrates how to check if the MotD can display HTML or only text using the IsTextOnlyMOTDAsync() method of the INotificationsManager interface.

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
public async Task<bool> IsTextOnlyAsync_MOTD(Client.SamplesLibrary.Helper.IHelper helper)
{
    bool success = false;
 
    using (INotificationsManager proxy = helper.GetServicesManager().CreateProxy<INotificationsManager>(ExecutionIdentity.System))
    {
        //Set the ForContext for the method.
        kCura.Relativity.Client.SamplesLibrary.Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false);
 
        try
        {
            bool isTextOnly = await proxy.IsTextOnlyMOTDAsync();
 
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Debug, new StackFrame(0).GetMethod().Name, isTextOnly.ToString(), this.GetType().Name);
 
            success = true;
        }
        catch (ServiceException exception)
        {
            this.Logger.LogMessage(Client.SamplesLibrary.Logging.LogLevel.Error, new StackFrame(0).GetMethod().Name, exception.Message, this.GetType().Name);
        }
    }
 
    return success;
}