Beispiel #1
0
        public Message(
			Guid id,
			string name,
			string description,
			Color backgroundColor,
			IEnumerable<IMessagePart> parts,
			EventHandlerCollection eventHandlerCollection = null)
        {
            name.ThrowIfNull("name");
            description.ThrowIfNull("description");
            parts.ThrowIfNull("parts");

            parts = parts.ToArray();

            IMessagePart question = parts.SingleOrDefault(arg => arg is MessageMananger);

            if (question != null && parts.Last() != question)
            {
                throw new ArgumentException("When a MessageQuestion is present, it must be the last part.", "parts");
            }

            _id = id;
            Name = name;
            Description = description;
            _backgroundColor = backgroundColor;
            _parts = parts;
            _eventHandlerCollection = eventHandlerCollection;
        }
Beispiel #2
0
 protected override void RegisterDomainEvents(EventHandlerCollection events)
 {
     events.Register<TaskCreated>(OnCreated);
     events.Register<TaskPostponed>(OnPostponed);
     events.Register<TaskCompleted>(OnCompleted);
     events.Register<TaskCancelled>(OnCancelled);
     events.Register<TaskPrioritised>(OnPrioritised);
 }
Beispiel #3
0
        public Timer(
			Guid id,
			string name,
			string description,
			TimeSpan interval,
			EventHandlerCollection eventHandlers = null)
            : this(id, name, description, interval, TimerState.Stopped, TimeSpan.Zero, eventHandlers)
        {
        }
Beispiel #4
0
        protected void Unsubscribe(Type eventHandlerInterfaceType, object eventHandler)
        {
            var eventType = eventHandlerInterfaceType.GetTypeInfo().GenericTypeArguments[0];
            EventHandlerCollection eventHandlerCollection = null;

            if (_eventHandlers.TryGetValue(eventType, out eventHandlerCollection))
            {
                eventHandlerCollection.Remove(eventHandler);
            }
        }
        public MessageBuilder(Guid id, Color backgroundColor, string name = "", string description = "", EventHandlerCollection eventHandlerCollection = null)
        {
            name.ThrowIfNull("name");
            description.ThrowIfNull("description");

            _id = id;
            _backgroundColor = backgroundColor;
            _name = name;
            _description = description;
            _eventHandlerCollection = eventHandlerCollection;
        }
Beispiel #6
0
        protected void Subscribe(Type eventHandlerInterfaceType, object eventHandler)
        {
            var eventType = eventHandlerInterfaceType.GetTypeInfo().GenericTypeArguments[0];
            EventHandlerCollection eventHandlerCollection = null;

            if (!_eventHandlers.TryGetValue(eventType, out eventHandlerCollection))
            {
                eventHandlerCollection = new EventHandlerCollection(eventHandlerInterfaceType);
                _eventHandlers.Add(eventType, eventHandlerCollection);
            }

            eventHandlerCollection.Add(eventHandler);
        }
        public MessageAnswer(
			Guid id,
			string text,
			IEnumerable<IMessagePart> parts,
			EventHandlerCollection eventHandlerCollection = null)
        {
            parts.ThrowIfNull("parts");
            text.ThrowIfNull("text");

            _id = id;
            _text = text;
            _parts = parts;
            _eventHandlerCollection = eventHandlerCollection;
        }
Beispiel #8
0
        /// <summary>
        /// 注册监听
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="eventHander"></param>
        public static void RegisterEvent(EventId eventId, EventHandler handler)
        {
            EventHandlerCollection handlers;

            if (!m_AllListenerMap.TryGetValue(eventId, out handlers))
            {
                handlers = new EventHandlerCollection();
                handlers.Add(handler);
                m_AllListenerMap.Add(eventId, handlers);
                return;
            }

            handlers.Add(handler);
        }
        public byte[] Serialize(EventHandlerCollection eventHandlerCollection)
        {
            var serializer = new CompactSerializer();
            int index = 0;

            if (eventHandlerCollection != null)
            {
                foreach (IEventHandler eventHandler in eventHandlerCollection.EventHandlers)
                {
                    serializer[index++] = Encoding.ASCII.GetBytes(eventHandler.EventHandlerTypeName);
                }
            }

            return serializer.Serialize();
        }
Beispiel #10
0
        public Player(
			Guid id,
			Guid boardId,
			Coordinate coordinate,
			Character character,
			EventHandlerCollection eventHandlerCollection = null)
        {
            character.ThrowIfNull("character");

            _id = id;
            BoardId = boardId;
            _character = character;
            _eventHandlerCollection = eventHandlerCollection;
            Coordinate = coordinate;
        }
Beispiel #11
0
        public Board(
			Guid id,
			string name,
			string description,
			Size size,
			SpriteLayer backgroundLayer,
			SpriteLayer foregroundLayer,
			ActorInstanceLayer actorInstanceLayer,
			IEnumerable<BoardExit> exits,
			IEnumerable<Timer> timers,
			EventHandlerCollection eventHandlerCollection = null)
        {
            name.ThrowIfNull("name");
            description.ThrowIfNull("description");
            backgroundLayer.ThrowIfNull("backgroundLayer");
            foregroundLayer.ThrowIfNull("foregroundLayer");
            actorInstanceLayer.ThrowIfNull("actorInstanceLayer");
            exits.ThrowIfNull("exits");
            timers.ThrowIfNull("timers");

            if (backgroundLayer.BoardId != id)
            {
                throw new ArgumentException("Background layer must belong to board.", "backgroundLayer");
            }
            if (foregroundLayer.BoardId != id)
            {
                throw new ArgumentException("Foreground layer must belong to board.", "backgroundLayer");
            }
            if (actorInstanceLayer.BoardId != id)
            {
                throw new ArgumentException("Actor instance layer must belong to board.", "backgroundLayer");
            }

            _id = id;
            Name = name;
            Description = description;
            _size = size;
            _backgroundLayer = backgroundLayer;
            _foregroundLayer = foregroundLayer;
            _actorInstanceLayer = actorInstanceLayer;
            _exits = exits;
            _timers = timers;
            _eventHandlerCollection = eventHandlerCollection;
        }
        public ActorInstance(
			Guid id,
			string name,
			string description,
			Guid actorId,
			Guid boardId,
			Coordinate coordinate,
			Character character,
			EventHandlerCollection eventHandlerCollection = null)
            : base(coordinate, character)
        {
            name.ThrowIfNull("name");
            description.ThrowIfNull("description");

            _id = id;
            Name = name;
            Description = description;
            _actorId = actorId;
            _boardId = boardId;
            _eventHandlerCollection = eventHandlerCollection;
        }
Beispiel #13
0
        public Timer(
			Guid id,
			string name,
			string description,
			TimeSpan interval,
			TimerState state,
			TimeSpan elapsedTime,
			EventHandlerCollection eventHandlerCollection = null)
        {
            name.ThrowIfNull("name");
            description.ThrowIfNull("description");
            if (interval < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("interval");
            }

            _id = id;
            Name = name;
            Description = description;
            _interval = interval;
            _eventHandlerCollection = eventHandlerCollection;
            State = state;
            ElapsedTime = elapsedTime;
        }
 public ActorInstance CreateActorInstance(Guid boardId, Coordinate coordinate, EventHandlerCollection eventHandlerCollection = null)
 {
     return new ActorInstance(Guid.NewGuid(), _name, _description, _id, boardId, coordinate, _character, eventHandlerCollection);
 }
 public ActorInstance CreateActorInstance(Guid id, string name, string description, Guid boardId, Coordinate coordinate, Character character, EventHandlerCollection eventHandlerCollection = null)
 {
     return new ActorInstance(id, name, description, _id, boardId, coordinate, character, eventHandlerCollection);
 }
 public IEnumerable<XElement> Serialize(EventHandlerCollection eventHandlerCollection, string elementName = "eventHandler")
 {
     return eventHandlerCollection != null
            	? eventHandlerCollection.EventHandlers.Select(arg => new XElement("eventHandler", new XAttribute("type", arg.EventHandlerTypeName)))
            	: Enumerable.Empty<XElement>();
 }
Beispiel #17
0
 public static MessageBuilder Build(Guid id, Color backgroundColor, EventHandlerCollection eventHandlerCollection = null)
 {
     return new MessageBuilder(id, backgroundColor, eventHandlerCollection:eventHandlerCollection);
 }
Beispiel #18
0
 public EventBinding(string name, EventHandlerCollection e, PyObject?target)
 {
     this.name   = name;
     this.target = target;
     this.e      = e;
 }
 public MessageBuilder(Color backgroundColor, string name = "", string description = "", EventHandlerCollection eventHandlerCollection = null)
     : this(Guid.NewGuid(), backgroundColor, name, description, eventHandlerCollection)
 {
     _backgroundColor = backgroundColor;
     _id = Guid.NewGuid();
 }
 public static MessageAnswerBuilder Build(Guid id, string text, EventHandlerCollection eventHandlerCollection = null)
 {
     return new MessageAnswerBuilder(id, text, eventHandlerCollection);
 }
 public MessageAnswerBuilder(Guid id, string text, EventHandlerCollection eventHandlerCollection = null)
 {
     _id = id;
     _text = text;
     _eventHandlerCollection = eventHandlerCollection;
 }
 public MessageAnswerBuilder(string text, EventHandlerCollection eventHandlerCollection = null)
     : this(Guid.NewGuid(), text, eventHandlerCollection)
 {
 }
Beispiel #23
0
 public EventObject(EventInfo info)
 {
     Debug.Assert(!info.AddMethod.IsStatic);
     this.name = info.Name;
     this.reg  = new EventHandlerCollection(info);
 }