Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="actionName"></param>
        /// <param name="statement"></param>
        /// <returns></returns>
        public static AVM1.AbstractAction Create(string actionName, string statement)
        {
            AbstractAction product = null;

            if ((null == actionName) || (null == statement))
            {
                ArgumentException e = new ArgumentException("actionName or statement is null");
                Log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, e);
                throw e;
            }

            product = (AbstractAction)MethodBase.GetCurrentMethod().DeclaringType.Assembly.CreateInstance("Recurity.Swf.AVM1." + actionName);

            if (null == product)
            {
                AVM1ExceptionSourceFormat e = new AVM1ExceptionSourceFormat(actionName + " is not a valid AVM1 action");
                Log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, e);
                throw e;
            }

            if (!product.ParseFrom(statement))
            {
                AVM1ExceptionSourceFormat e = new AVM1ExceptionSourceFormat("Illegal statement: " + statement);
                Log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, e);
                throw e;
            }

            return product;
        }
Esempio n. 2
0
        /// <summary>
        /// TODO : Documentation
        /// </summary>
        /// <param name="statement"></param>
        /// <param name="actionName"></param>
        /// <returns></returns>
        private string PrepareAndReplaceLabel( string statement, out string actionName )
        {
            actionName = null;

            char[] delims = { ' ', '\t' };
            string[] token = statement.Split( delims, StringSplitOptions.RemoveEmptyEntries );

            if ( 0 == token.Length )
                return null;

            actionName = token[ 0 ];

            for ( int i = 0; i < token.Length; i++ )
            {
                //
                // replace Label in statement (token ending in ':') with
                // index of instruction referenced. Index is resolved in Populate().
                //
                if ( token[ i ].EndsWith( ":" ) )
                {
                    //
                    // find label
                    //
                    for ( int j = 0; j < _InnerCode.Count; j++ )
                    {
                        if ( null != _InnerCode[ j ].Label )
                        {
                            if ( _InnerCode[ j ].Label.Equals( token[ i ], StringComparison.InvariantCulture ) )
                            {
                                token[ i ] = j.ToString( "d" );
                            }
                        }
                    }
                }

                //
                // replace variables
                //
                if ( token[ i ].Contains( "$" ) )
                {
                    Match m = Regex.Match( token[i], @"(\$[A-Z]+)" );
                    if ( m.Success )
                    {
                        string vName = m.Value;
                        bool replacementDone = false;

                        for ( int j = 0; j < _Variables.Count; j++ )
                        {
                            if ( vName.Equals( _Variables[ j ].Name, StringComparison.InvariantCulture ) )
                            {
                                token[ i ] = token[ i ].Replace( vName, _Variables[ j ].Value );
                                replacementDone = true;
                                break;
                            }
                        }

                        if ( !replacementDone )
                        {
                            AVM1ExceptionSourceFormat e = new AVM1ExceptionSourceFormat( "Variable " + vName + " not found" );
                            throw e;
                        }
                    }
                }
            }

            return String.Join( " ", token );
        }