Ejemplo n.º 1
0
        public async Task <Effect> Model(IEventData e)
        {
            EventConditionRule eventCondition = null;

            if (!TryGetCondition <ConditionRule.EventConditionRule>(e, out eventCondition))
            {
                throw new Exception($"Model does not have a parent");
            }

            var parent = await Storage.GetEvent(eventCondition.EventID);

            if (null == parent)
            {
                throw new Exception($"Event '{eventCondition.EventID}' does not exist");
            }

            if (parent.EventValue.ValueID != StaticEvent.Model && parent.EventValue.ValueID != StaticEvent.Event)
            {
                throw new Exception("Model base can only be another model");
            }

            var parentModel = await Storage.GetModel(parent.EventValue.ID);

            if (eventCondition.EventID != StaticEvent.Event && null == parentModel)
            {
                throw new Exception("Model " + eventCondition.EventID + " does not exist");
            }

            return(Effect.Pass);
        }
Ejemplo n.º 2
0
        public async Task <Effect> Individual(IEventData e)
        {
            var parentEvent = await Storage.GetEvent(e.BaseEventID);

            if (null == parentEvent)
            {
                throw new Exception($"Event '{e.BaseEventID}' does not exist");
            }


            EventConditionRule conditionEvent = null;

            if (!TryGetCondition <ConditionRule.EventConditionRule>(e, out conditionEvent))
            {
                throw new Exception("Individual does not have a model");
            }

            var model = await Storage.GetModel(conditionEvent.EventID);

            if (null == model)
            {
                throw new Exception("Model " + conditionEvent.EventID + " does not exist");
            }

            if (e.BaseEventID == StaticEvent.DataType)
            {
                var type = Storage.GetDataType(e.Value);
                if (null == type)
                {
                    throw new Exception($"Type '{e.Value}' does not exist");
                }
            }

            switch (e.BaseEventID)
            {
            case StaticEvent.Attribute:
            case StaticEvent.Actor:
            case StaticEvent.Role:
            case StaticEvent.DataType:
            case StaticEvent.Relation:
                break;

            default:
                switch (parentEvent.EventValue.BaseEventID)
                {
                case StaticEvent.Entity:
                    break;

                default:
                    throw new Exception($"Invalid individual base event");
                }
                break;
            }

            return(new MultipleEffect(
                       new TagSubEventEffect(e.BaseEventID, e.ID),
                       new TagContainerEffect(e.ID, model.ModelID)
                       ));
        }