void IAnimalEventHandler.Apply(AnimalEvent e, IAnimalEventContext context)
 {
     if (e is TEvent)
     {
         Apply(e as TEvent, context);
     }
 }
        bool IAnimalEventHandler.Validate(AnimalEvent e, IAnimalEventContext context)
        {
            if (e is TEvent)
            {
                return(Validate(e as TEvent, context));
            }

            return(true);
        }
Ejemplo n.º 3
0
        private IAnimalEventHandler InstantiateEventHandler(AnimalEvent e)
        {
            if (!_handlerTypeByEventType.TryGetValue(e.GetType(), out Type handlerType))
            {
                return(null);
            }

            ConstructorInfo emptyConstructor = handlerType.GetConstructor(new Type[] { });

            return(emptyConstructor.Invoke(new object[] { }) as IAnimalEventHandler);
        }
Ejemplo n.º 4
0
        public async Task ProcessEvent(OperationContext operationContext, AnimalEvent e)
        {
            Animal animal = await _animals.ByIdAsync(operationContext.Transaction, e.OwnerUserId, e.AnimalId);

            bool isSuccess = await RunEventsAsync(operationContext.Transaction, animal, new[] { e });

            if (!isSuccess)
            {
                throw new Exception();
            }
        }
Ejemplo n.º 5
0
        private bool RunEvent(AnimalEvent e, AnimalBoxEventContext context)
        {
            IAnimalEventHandler handler = InstantiateEventHandler(e);

            if (!handler.Validate(e, context))
            {
                return(false);
            }
            handler.Apply(e, context);

            return(true);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jObj = JObject.Load(reader);

            bool isEventTypeProperty(JProperty p)
            => String.Equals(p.Name, nameof(AnimalEvent.EventType), StringComparison.InvariantCultureIgnoreCase);

            string      typeName = ((string)jObj.Children <JProperty>().First(isEventTypeProperty).Value).ToLower();
            AnimalEvent result   = InstantiateByTypeName(typeName);

            serializer.Populate(jObj.CreateReader(), result);
            return(result);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PushEvent([FromBody] AnimalEvent e)
        {
            // TODO: Validate the event.

            try
            {
                await _operationRunner.RunAsync((context) => ProcessEvent(context, e));

                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 8
0
    public void ShowEventCreated(GameObject obj)
    {
        string      id        = obj.name;
        AnimalEvent thisEvent = eventLst[int.Parse(id)];

        eventHere = thisEvent;

        modifEventName.text         = GetEventNameById(thisEvent.idEvent, eventTypeLst);
        modifEventDay.text          = thisEvent.date.ToString("dd");
        modifEventMonth.text        = thisEvent.date.ToString("MM");
        modifEventYear.text         = thisEvent.date.ToString("yyyy");
        modifEventInformations.text = thisEvent.informations.Replace("&n", "\n");

        if (thisEvent.idEvent != "")
        {
            modifEventFather.text = thisEvent.father;
            modifEventFather.gameObject.SetActive(true);
        }
        else
        {
            modifEventFather.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 9
0
 public void onEat(AnimalEvent animalEvent)
 {
     Console.WriteLine(Name + eatingStrategy.ReactToAnimalEating() + "when " + animalEvent.animalName + " is eating");
 }
Ejemplo n.º 10
0
 public void onEat(AnimalEvent animalEvent)
 {
     Console.WriteLine($"{animalEvent.animalName} has eaten, I'll have to refill");
 }
Ejemplo n.º 11
0
 public void onMove(AnimalEvent animalEvent)
 {
     Console.WriteLine($"I observed that {animalEvent.animalName} has moved");
 }
Ejemplo n.º 12
0
 public void onEat(AnimalEvent animalEvent)
 {
     return;
 }
Ejemplo n.º 13
0
 public void onMove(AnimalEvent animalEvent)
 {
     return;
 }
Ejemplo n.º 14
0
 public void onEat(AnimalEvent animalEvent)
 {
     Console.WriteLine($"Yaay! {animalEvent.animalName} eats!");
 }
Ejemplo n.º 15
0
 public void onMove(AnimalEvent animalEvent)
 {
     Console.WriteLine($"Yaay! {animalEvent.animalName} moves!");
 }