Add Sound to Infolog


I’ve been asked by a colleague if it is possible to let the Infolog make a noise depending on the log type, e.g. a *beep* for an info, a *pling* for a warning and an evil noise for an error. Fortunately we can use .NET in AX 2009. The System.Media.SystemSound class already provides access to the typical system sounds. I’ve modified the Info class in AX this way:
Exception add(
    Exception _exception,
    str _txt,
    str _helpUrl = ”,
    SysInfoAction _sysInfoAction = null,
    boolean buildprefix = true)
{

    int numOfLines,i;
    int actionClassId;
    container packedAction;
    xSession session;   
    System.Media.SystemSound sound;
    InteropPermission permission;

    ; 
// default infolog code here …
    permission = new InteropPermission(Interopkind::ClrInterop);
    permission.assert();
    
switch(_exception)
    {
        case(Exception::Info):
        sound = System.Media.SystemSounds::get_Asterisk();
        break;
        case(Exception::Warning):
        sound = System.Media.SystemSounds::get_Hand();
        break;
        case(Exception::Error):
        sound = System.Media.SystemSounds::get_Exclamation();
        break;
    }    
    if(sound!=null)
        sound.Play();
 
    CodeAccessPermission::revertAssert();
    return super(_exception, (buildprefix?getprefix():”)+_txt);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.