using System.Security ;
using System.Text ;
using System.Windows.Forms ;
using System.Collections.Generic ;

using log4net ;

// --------------------------------------------------------------------

public static partial class Program
{

    private class MyMessageFilter : IMessageFilter {
        public bool PreFilterMessage( ref Message msg ) {
            // check if we should filter this message
            if ( Program.mainForm.preFilterMessage( ref msg ) )
                return true ;
            return false ;
        }
    }

    public static void logStartupMsg( string key, string msg )
    {
        // log the startup message
        List<string> msgs ;
        if ( ! mStartupMsgs.TryGetValue( key, out msgs ) )
            mStartupMsgs[key] = msgs = new List<string>() ;
        msgs.Add( msg ) ;
    }

    public static string getStartupMsgs( string key, string caption )
    {
        // check if there were any startup messages of the specified type
        List<string> msgs ;
        if ( ! mStartupMsgs.TryGetValue( key, out msgs ) || msgs.Count == 0 )
            return "" ;

        // NOTE: WebBrowser isn't really available with Mono, so we just log startup messages normally.
        ILog logger = LogManager.GetLogger( "startup" ) ;

        // generate a report for the specified startup messages
        StringBuilder buf = new StringBuilder() ;
        if ( caption != "" ) {
            buf.Append( caption ) ;
            logger.Warn( caption ) ;
        }
        buf.Append( "<ul>" ) ;
        foreach ( string msg in msgs ) {
            buf.Append( "<li> " + SecurityElement.Escape(msg) ) ;
            logger.Warn( (caption != "") ? $"- {msg}" : msg ) ;
        }
        buf.Append( "</ul>" ) ;

        return buf.ToString() ;
    }

}
