locked
Develop a service on health alert with WHS notifications RRS feed

  • Question

  • I try to make a new service on health alert with WHS notifications, but I cannot to see any notification on the end-user computer after I add an AddNotification() function.

    Does anybody have some code snip or sample code about how to alert end-user or other application on the WHS computer through the Windows Home Server notification infrastructure? Thanks a lot... : )

    Wednesday, June 13, 2007 9:54 AM

Answers

  • This adds a notification for me. Note the WHS_ERROR severity -- only warnings and errors show up in the console.

     

    Code Snippet

    using System;

    using Microsoft.HomeServer.SDK.Interop.v1;

     

    namespace HelloNotification

    {
        class Program
        {
            static void Main(string[] args)
            {

                WHSInfoClass whsSDK = new WHSInfoClass();

                whsSDK.AddNotification("hello",
                                        WHS_Notification_Severity.WHS_ERROR,
                                        "Hello",
                                        "Hello world!",
                                        null,
                                        null,
                                        null);

                Console.ReadKey();
            }
        }

    }

     

    Tuesday, June 19, 2007 6:07 PM

All replies

  • Did you register your app to recieve notifications? Something like this...

     

     

    Code Snippet

    Private notifications As New NotificationCallback

     

    Public Sub New()

       WHSInfo.Init(My.Application.Info.AssemblyName)

       WHSInfo.RegisterForNotifications(notifications)

    End Sub

     

    This is vb.net obviously.

     

    Note that NotificationCallback is a class that implements WHSInfoIF.INotificationCallback.

     

    Rob

     

    Wednesday, June 13, 2007 10:32 PM
  • Thanks, Rob

    I still have got a confusion about notification operation. My first target is alert a notification ("Hello World") to end-user computer and change the color of Home Network Health dialog into "red" color, but the result was always keep "silent". What's wrong with my way? The code as following:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using WHSInfoIF;

    namespace WindowsHomeServer
    {
        class Program
        {
            static void Main(string[] args)
            {
                WHSInfoClass pInfo = new WHSInfoClass();
                WHS_Notification_Severity wns = WHS_Notification_Severity.WHS_ERROR;
                Guid guid = Guid.NewGuid();
                pInfo.Init("MyWHSApp");
                pInfo.AddNotification("f29d271c-00da-83c4-3bfa-4c50d27d3ad2", wns, "Hello, World", "Hello World!");
            }
        }
    }

    The second target is to register my application to recieve notifications from Windows Home Server, but it still has a error display about NotificationChanged() and BackupStateChanged() that has not a implementation on the console. The code snip as following:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using WHSInfoIF;

    namespace WindowsHomeServer
    {
        class HealthAlert : WHSInfoIF.INotificationCallback
        {
            public void Disconnected()
            {
                Console.WriteLine("Disconnected...");
            }

            public void ReConnected()
            {
                Console.WriteLine("ReConnected...");
            }

            public void BackupStateChanged(WHSBackupState State)
            {
                Console.WriteLine("Backup State: " + State.ToString());
            }

            public void NotificationChanged(string UniqueID, WHS_Notification_Type Type, WHS_Notification_Severity Severity, string textHeader, string textDescription)
            {
                Console.WriteLine("Notification Type: " + Type.ToString());
            }

            public void PhysicalDiskChanged(string UniqueID, WHS_Notification_Severity Severity)
            {
                Console.WriteLine("Severity: " + Severity.ToString());
            }
    }
    }

    And the code about
    to register my application that as following:

        HealthAlert ha = new HealthAlert();
        WHSBackupState bs = WHSBackupState.WHS_IDLE;
        WHS_Notification_Type nt = WHS_Notification_Type.WHS_NOTIFICATION_ADD;
        WHS_Notification_Severity ns = WHS_Notification_Severity.WHS_ERROR;
        pInfo.Init("MyWHSApp");
        pInfo.RegisterForNotifications(ha);
        ha.BackupStateChanged(bs);
        ha.NotificationChanged(Guid.NewGuid().ToString(), nt, ns, "Hello World", "Hello World!");

    I really don't know how to process the content of related functions of
    NotificationCallback.

    Thursday, June 14, 2007 2:29 AM
  • The first part looks OK to me. I will have to test it at home to see why it's not working.

     

    For the second part, you need to specify your functions are implementing the INotificationCallback functions. In VB.net it's like this:

    Public Sub Disconnected() Implements INotificationCallback.Disconnected

     

    In C#, I guess it would be like this:

    public void INotificationCallback.Disconnected()

     

    The NotificationChanged sub will be fired whenever a notification has been sent, so you don't need to call it. When your app starts, you should receive all of the current notifications. Inside that function, you will need to process the notifications. In my app, I have a collection that I add/remove the notification messages to.

     

    Rob
    Thursday, June 14, 2007 4:21 PM
  • Try putting a delay - eg Console.ReadKey -- after you add the notification.

     

    The lifetime of SDK Notifications are tied to the process that creates them. When the process goes away, so does the notifications it created.

    Thursday, June 14, 2007 6:41 PM
  • Dear Ryan and Rob

    I have tried to add Console.ReadKey for extending the lift time of SDK notifications,
    but the result was still nothing. Then, I also try to build a collection to receive SDK notifications, but another issue is that (which call can or how) to receive these notifications.

    Otherwise, could you kindly release the sample implementation about RegisterForNotifications and AddNotification function for me?

    Thanks

    Andy
    Friday, June 15, 2007 4:54 AM
  • This adds a notification for me. Note the WHS_ERROR severity -- only warnings and errors show up in the console.

     

    Code Snippet

    using System;

    using Microsoft.HomeServer.SDK.Interop.v1;

     

    namespace HelloNotification

    {
        class Program
        {
            static void Main(string[] args)
            {

                WHSInfoClass whsSDK = new WHSInfoClass();

                whsSDK.AddNotification("hello",
                                        WHS_Notification_Severity.WHS_ERROR,
                                        "Hello",
                                        "Hello world!",
                                        null,
                                        null,
                                        null);

                Console.ReadKey();
            }
        }

    }

     

    Tuesday, June 19, 2007 6:07 PM
  • Dear Ryan,

    I am very thanks for your support. I am already done this job and also find out what's issue to let this app fail to run. This is tivial. I hope everyone don't go this debug way when you want to develop an application with WHS notifications based on Microsoft MSDN site http://msdn2.microsoft.com/en-us/library/bb425850.aspx

    You need to copy Interop.WHSInfoIF.dll, not HomeServer.dll, from Windows Home Server to your develop environment before you want to develop an app with WHS notifications.

    Andy

    Wednesday, June 20, 2007 2:42 AM
  •  

     

    Hi Ryan,

     

    The prototype of AddNotification in the Interop.WHSInfoIF is:

    void AddNotification(string UniqueID, WHSInfoIF.WHS_Notification_Severity State, string textHeader, string textDescription, string helpFilename, string helpSection, string helpLinkText)

      The sample code in msdn library http://msdn2.microsoft.com/en-us/library/bb425850.aspx is:

    pInfo.AddNotification("????????-92c0-43bb-b432-a519d120663a",
      WHS_Notification_Severity.WHS_INFO, "Hello, World", "Hello World!");

     

    The code you wrote in this article is:

    whsSDK.AddNotification("hello",
                                        WHS_Notification_Severity.WHS_ERROR,
                                        "Hello",
                                        "Hello world!",
                                        null,
                                        null,
                                        null);

     

    I can't understand the conflicts above for the parameter 1. What should I fill in indeed? Does the value relate with whsSDK.Init("WHSInfo")??

     

    Thanks a lot.

    Delphine

     

     

     

    Tuesday, July 3, 2007 6:28 AM
  • The UniqueID parameter should be a unique string. It doesn't have to be a GUID, though a GUID is fine.

    If you receive notifications, you'll get this parameter, and can filter notifications based on it.

    whsSDK.Init() takes your application name. It's unrelated to the notification id.
    Tuesday, July 3, 2007 4:30 PM
  •  

    understood. Thank you.

     

    delphine

     

    Wednesday, July 4, 2007 2:29 AM