/// <summary> /// Will register a subscriber. Event will be recognized by "eventId" and will be attached to /// obj /// </summary> /// <param name="eventId"></param> /// <param name="obj"></param> /// <param name="handler"></param> public void Subscribe(string eventId, IStateObject obj, Delegate handler, out string eventSubscriptionId, bool isDynamic = false) { var result = String.Empty; if (handler != null) { //get/created subscribed promises info eventId = eventId.ToUpper(); var handlerSubscriptionId = UniqueIDGenerator.GetEventRelativeUniqueID(obj, eventId); LazyBehaviours.AddDependent(obj, UniqueIDGenerator.EVENTPrefix + eventId); var promisesInfo = PromisesInfo.CreateInstance(handlerSubscriptionId); ////subscribe handler var eventMethodName = handler.Method.Name.ToUpper() + eventId; eventSubscriptionId = UniqueIDGenerator.GetEventRelativeUniqueID(obj, eventMethodName); LazyBehaviours.AddDependent(obj, UniqueIDGenerator.EVENTPrefix + eventMethodName); promisesInfo.Add(eventMethodName); if (isDynamic) { EventPromiseInfoForClient.CreateEventInstance(_stateManager, handler, obj, eventSubscriptionId, actionID: eventId); } else { EventPromiseInfo.CreateEventInstance(_stateManager, handler, obj, eventSubscriptionId); } #if DEBUG Debug.Assert(_stateManager.GetObject(eventSubscriptionId) != null, "Event Subscription Failed", "Event for {0} on Object {1} failed", eventId, obj.UniqueID); #endif result = eventSubscriptionId; } eventSubscriptionId = result; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { PromisesInfo target = null; if (reader.TokenType == JsonToken.Null) { return(null); } target = existingValue as PromisesInfo; target.EventsName = reader.Value.ToString(); return(target); }
public static PromisesInfo CreateInstance(string handlersUniqueId) { PromisesInfo instance = null; instance = StateManager.Current.GetObject(handlersUniqueId) as PromisesInfo; if (instance == null) { instance = new PromisesInfo { UniqueID = handlersUniqueId, EventsName = "" }; StateManager.Current.AddNewObject(instance); } return(instance); }