示例#1
0
        public void HandleSyneryEvent(Antlr4.Runtime.ParserRuleContext context, IValue eventValue)
        {
            if (eventValue.Value is ExecutionExceptionRecord)
            {
                // if it is an #.ExecutionException or a derived type
                // set the information about the context the exception has occurred
                ((ExecutionExceptionRecord)eventValue.Value).Line         = context.Start.Line;
                ((ExecutionExceptionRecord)eventValue.Value).CharPosition = context.Start.Column;
            }

            // try to get the event record from the given value
            IRecord eventRecord = TryToGetEventRecordFromValue(context, eventValue);

            // get the event record type from the given value
            IRecordType eventRecordType = eventRecord.RecordType;

            // check whether it is an exception
            bool isException = eventRecordType.IsType(ExceptionRecord.RECORD_TYPE_NAME);

            // search for a HANDLE-block that handles the emitted/thrown event
            IEnumerable <IHandleBlockData> listOfHandleBlocks = GetHandleBlocks(eventRecord, eventRecordType.FullName);

            if (isException == true && listOfHandleBlocks.Count() == 0)
            {
                // no handle block found for the given exception
                // throw a real exception

                string message = "Unhandled Exception. Data:";

                foreach (var field in eventRecord.Data)
                {
                    message += String.Format("{0}{0}{1}={2}", Environment.NewLine, field.Key, (field.Value.Value ?? "NULL"));
                }

                throw new InterfaceBoosterException(message);
            }
            else
            {
                bool isFirst = true;

                foreach (var handleBlock in listOfHandleBlocks)
                {
                    EventHelper.InterpretHandleBlock(this, handleBlock, eventValue);

                    // mark the event as handled after the first handle block is executed
                    if (isFirst)
                    {
                        isFirst = false;
                        eventRecord.SetFieldValue("IsHandled", new TypedValue(TypeHelper.BOOL_TYPE, true));
                    }
                }
            }
        }
        /// <summary>
        /// Checks whether the record type <paramref name="checkTypeName"/> is derived from or equals to the given
        /// <paramref name="baseTypeName"/> record type.
        /// </summary>
        /// <param name="memory">The current memory state. Is needed to access the list of record types.</param>
        /// <param name="checkTypeName">the full name of the type that should be checked</param>
        /// <param name="baseTypeName">the full name of the potential base type</param>
        /// <returns>true = type is derived from or equal to the base type</returns>
        public static bool IsDerivedType(ISyneryMemory memory, string checkTypeName, string baseTypeName)
        {
            if (checkTypeName == baseTypeName)
            {
                return(true);
            }

            IRecordType checkType = (from t in memory.RecordTypes.Values
                                     where t.Name == checkTypeName
                                     select t).FirstOrDefault();

            if (checkType == null)
            {
                throw new SyneryException(String.Format("Record type wiht name='{0}' not found", baseTypeName));
            }

            return(checkType.IsType(baseTypeName));
        }