Пример #1
0
 private void About_Click( object sender, System.EventArgs e )
 {
     MetaBuilders.Irc.Messages.GenericMessage msg = new MetaBuilders.Irc.Messages.GenericMessage();
     if ( msg.CanParse( this.ChatEntry.Text ) )
     {
         msg.Parse( this.ChatEntry.Text );
         General.client.Send( msg );
     }
     else
     {
         MessageBox.Show( "Cannot Parse Your Command." );
     }
 }
        /// <summary>
        /// Determines and instantiates the correct subclass of <see cref="IrcMessage"/> for the given given string.
        /// </summary>
        private IrcMessage DetermineMessage( String unparsedMessage )
        {
            IrcMessage msg = null;

            if ( this.customs != null )
            {
                msg = GetMessage( unparsedMessage, this.customs );
                if ( msg != null )
                {
                    return msg;
                }
            }

            String command = MessageUtil.GetCommand( unparsedMessage );
            if ( Char.IsDigit( command[ 0 ] ) )
            {
                msg = GetMessage( unparsedMessage, numerics );
                if ( msg == null )
                {
                    Int32 numeric = Convert.ToInt32( command, CultureInfo.InvariantCulture );
                    if ( NumericMessage.IsError( numeric ) )
                    {
                        msg = new GenericErrorMessage();
                    }
                    else
                    {
                        msg = new GenericNumericMessage();
                    }
                }
            }
            else
            {
                if ( CtcpUtil.IsCtcpMessage( unparsedMessage ) )
                {
                    msg = GetMessage( unparsedMessage, ctcps );
                    if ( msg == null )
                    {
                        if ( CtcpUtil.IsRequestMessage( unparsedMessage ) )
                        {
                            msg = new GenericCtcpRequestMessage();
                        }
                        else
                        {
                            msg = new GenericCtcpReplyMessage();
                        }
                    }
                }
                else
                {
                    msg = GetMessage( unparsedMessage, commands );
                    if ( msg == null )
                    {
                        msg = new GenericMessage();
                    }
                }
            }
            return msg;
        }
        private void RouteData( string messageData )
        {
            IrcMessage msg = null;
            try
            {
                msg = MessageParserService.Service.Parse( messageData );
            }
            catch ( MetaBuilders.Irc.Messages.InvalidMessageException ex )
            {
                // Try one more time to load it as a generic message
                msg = new GenericMessage();
                if ( msg.CanParse( messageData ) )
                {
                    msg.Parse( messageData );
                }
                else
                {
                    msg = null;
                    System.Diagnostics.Trace.WriteLine( ex.Message + " { " + ex.ReceivedMessage + " } ", "Invalid Message" );
                }
            }

            if ( msg != null )
            {
                this.OnMessageParsed( new IrcMessageEventArgs<IrcMessage>( msg ) );

                msg.Notify( this.Messages );
            }
        }