public SessionBase()
        {
            #region Data Properties
            foreach (var descriptor in DataPropertyDescriptor.GetDescriptors(GetType()))
            {
                DataPropertyStore dataProperty;
                _dataProperties.Add(descriptor, dataProperty = descriptor.CreateDataStore(descriptor.PropertyName));
                _dataPropertyLookup.Add(descriptor.PropertyName, dataProperty);
                dataProperty.AvailabilityNotifier.ChangeNotificationSent += AvailabilityConditionNotifier_AvailabilityConditionChanged;
                dataProperty.ValueNotifier.ChangeNotificationSent        += AvailabilityConditionNotifier_AvailabilityConditionChanged;
                _availabilities.Add(descriptor.PropertyName, dataProperty);
            }
            #endregion

            InitializeSession();

            #region Code from AutoHookingSample
            TypeIdentifier = SessionManager.GetIdentifier(GetType());
            ulong key = TypeIdentifier.sessionOnly;

            ////
            //// Create sessionTraitStores
            //// In real code, this will be done in a similar fashion as DataObjectTraitStores
            ////
            //PropertyInfo[] propertyInfos = GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            //foreach (var property in propertyInfos)
            //    if (typeof(SessionBase).IsAssignableFrom(property.PropertyType))
            //        sessionTraitStores.Add(property.Name, new sessionTraitStore(this, property.Name));

            //SessionManager.RegisterListener(this);
            #endregion
        }
        public static SessionPropertyDescriptor <TValue> Register(string name, Type sessionType)
        {
            SessionPropertyDescriptor <TValue> descriptor;

            DataPropertyDescriptor.RegisterPropertyDescriptor(sessionType, descriptor = new SessionPropertyDescriptor <TValue>(name, sessionType));
            return(descriptor);
        }
        public LinkedSessionValue(LinkToSession <TSession> linkToSession, DataPropertyDescriptor <TValue> descriptor)
        {
            this.LinkToSession      = linkToSession;
            this.PropertyDescriptor = descriptor;

            this.LinkToSession.SessionChanged += SessionChanged;
        }
Exemple #4
0
        protected SessionListener(SessionNotificationType notificationType, bool allowMultipleHooks, Type broadcastingType, Predicate <SessionBase> matchsession, DataPropertyDescriptor <TValue> descriptor)
            : base(notificationType, broadcastingType, matchsession)
        {
            this.dataPropertyDescriptor = descriptor;

            // We initialize without a listener because we are going to hook our listeners explicitly by overriding Hooksession.
            Initialize(null);
        }
        public DynamicBool CreateDynamicBoolean <TValue1, TValue2>(DataPropertyDescriptor <TValue1> descriptor, IPropertyStore <TValue2> propertyStore, bool valueWhenUnavailable, Func <TValue1, bool> valueWhenAvailable)
        {
            IPropertyStore <TValue1> localPropertyStore = GetStore <TValue1>(descriptor);
            var gatedCondition = valueWhenUnavailable
                ? new Func <bool>(() => !propertyStore.IsAvailable || !localPropertyStore.IsAvailable || valueWhenAvailable(localPropertyStore.Value))
                : new Func <bool>(() => propertyStore.IsAvailable && localPropertyStore.IsAvailable && valueWhenAvailable(localPropertyStore.Value));

            return(CreateDynamicBool <TValue1, TValue2>(gatedCondition, localPropertyStore, propertyStore));
        }
        public DynamicBool CreateDynamicBoolean <TValue>(DataPropertyDescriptor <TValue> descriptor, bool valueWhenUnavailable, Predicate <TValue> valueWhenAvailable)
        {
            IPropertyStore <TValue> propertyStore = GetStore <TValue>(descriptor);
            var gatedCondition = valueWhenUnavailable
                ? new Func <bool>(() => !propertyStore.IsAvailable || valueWhenAvailable(propertyStore.Value))
                : new Func <bool>(() => propertyStore.IsAvailable && valueWhenAvailable(propertyStore.Value));

            return(new DynamicBool(gatedCondition, propertyStore.AvailabilityNotifier, propertyStore.ValueNotifier));
        }
Exemple #7
0
        public static DataPropertyDescriptor <TValue> Register(string name, Type sessionType)
        {
            System.Diagnostics.Debug.Assert(!typeof(SessionBase).GetTypeInfo().IsAssignableFrom(typeof(TValue).GetTypeInfo()));

            DataPropertyDescriptor <TValue> descriptor;

            DataPropertyDescriptor.RegisterPropertyDescriptor(sessionType, descriptor = new DataPropertyDescriptor <TValue>(name, sessionType));
            return(descriptor);
        }
        public DynamicBool CreateDynamicBoolean <TValue1, TValue2>(DataPropertyDescriptor <TValue1> firstDescriptor, DataPropertyDescriptor <TValue2> secondDescriptor, bool valueWhenNotAvailable, Func <TValue1, TValue2, bool> condition)
        {
            IPropertyStore <TValue1> firstPropertyStore  = GetStore <TValue1>(firstDescriptor);
            IPropertyStore <TValue2> secondPropertyStore = GetStore <TValue2>(secondDescriptor);
            var gatedCondition = valueWhenNotAvailable
                ? new Func <bool>(() => !firstPropertyStore.IsAvailable || !secondPropertyStore.IsAvailable || condition(firstPropertyStore.Value, secondPropertyStore.Value))
                : new Func <bool>(() => firstPropertyStore.IsAvailable && secondPropertyStore.IsAvailable && condition(firstPropertyStore.Value, secondPropertyStore.Value));

            return(CreateDynamicBool <TValue1, TValue2>(gatedCondition, firstPropertyStore, secondPropertyStore));
        }
Exemple #9
0
        public SessionListener(SessionNotificationType notificationType, SessionBase rootsession, string broadcastingPath, DataPropertyDescriptor <TValue> descriptor)
            : base(notificationType, rootsession, broadcastingPath)
        {
            this.dataPropertyDescriptor = descriptor;

            // When specifying a path, there shall never be two sessions hooked.
            this.allowMultipleHooks = false;

            // We initialize without a listener because we are going to hook our listeners explicitly by overriding Hooksession.
            Initialize(null);
        }
Exemple #10
0
        internal static void RegisterPropertyDescriptor(Type sessionType, DataPropertyDescriptor descriptor)
        {
            List <DataPropertyDescriptor> descriptors;

            if (!propertyDescriptors.TryGetValue(sessionType, out descriptors))
            {
                descriptors = new List <DataPropertyDescriptor>();
                propertyDescriptors.Add(sessionType, descriptors);
            }
            descriptors.Add(descriptor);
        }
        protected LinkToSession <Tsession> Link <Tsession>(DataPropertyDescriptor <Tsession> descriptor)
            where Tsession : SessionBase
        {
            if (linkLookup.ContainsKey(descriptor))
            {
                return((LinkToSession <Tsession>)linkLookup[descriptor]);
            }

            // TODO: Turn this inside out and have CreateLink(string) call this method.
            var sessionLink = CreateLink <Tsession>("./" + descriptor.PropertyName);

            linkLookup.Add(descriptor, sessionLink);
            return(sessionLink);
        }
        protected void SetValue <TValue>(DataPropertyDescriptor <TValue> descriptor, TValue value)
        {
            Action setValue = () => {
                _dataProperties[descriptor].Value = value;
            };

            if (operationNames.Any())
            {
                setValue();
            }
            else
            {
                SetValueAsOperation(descriptor.PropertyName, setValue);
            }
        }
 public LinkTosessionBool(LinkToSession <Tsession> linkTosession, DataPropertyDescriptor <bool> descriptor, bool valueOnUnlinked)
     : base(linkTosession, descriptor)
 {
     this.valueOnUnlinked = valueOnUnlinked;
 }
 protected void SetAvailabilityCalculator(DataPropertyDescriptor property, DynamicBool condition)
 {
     _availabilities[property.PropertyName].SetAvailabilityCondition(condition);
 }
 public LinkedsessionStore(LinkToSession <Tsession> linkTosession, DataPropertyDescriptor <TValue> descriptor)
     : base(linkTosession, descriptor)
 {
     AvailabilityNotifier = new NonSessionNotifier(this);
 }
        public DynamicBool CreateDynamicBoolean(DataPropertyDescriptor <Boolean> descriptor, bool valueWhenUnavailable)
        {
            var propertyStore = GetStore <bool>(descriptor);

            return(propertyStore.ToDynamicBooleanValue(valueWhenUnavailable));
        }
Exemple #17
0
 public sessionBooleanListener(SessionNotificationType notificationType, SessionBase rootsession, string broadcastingPath, DataPropertyDescriptor <bool> descriptor)
     : base(notificationType, rootsession, broadcastingPath, descriptor)
 {
 }
Exemple #18
0
 public SessionListener(SessionNotificationType notificationType, Type broadcastingType, Predicate <SessionBase> matchsession, DataPropertyDescriptor <TValue> descriptor)
     : this(notificationType, false, broadcastingType, matchsession, descriptor)
 {
 }
 protected LinkToSession <TResultsession> Link <TPropertysession, TIntermediatesession, TResultsession>(DataPropertyDescriptor <TPropertysession> propertysession, DataPropertyDescriptor <TIntermediatesession> intermediatsession, DataPropertyDescriptor <TResultsession> destinationsession)
     where TPropertysession : SessionBase
     where TIntermediatesession : SessionBase
     where TResultsession : SessionBase
 {
     return(Link <TPropertysession>(propertysession).Link <TIntermediatesession>(intermediatsession).Link <TResultsession>(destinationsession));
 }
 protected TValue GetValue <TValue>(DataPropertyDescriptor <TValue> descriptor)
 {
     return((TValue)_dataProperties[descriptor].Value);
 }
 internal protected DataPropertyStore <TValue> GetStore <TValue>(DataPropertyDescriptor <TValue> descriptor)
 {
     return((DataPropertyStore <TValue>)_dataProperties[descriptor]);
 }
 protected BooleanPropertyStore GetBooleanStore(DataPropertyDescriptor <bool> descriptor)
 {
     return((BooleanPropertyStore)GetStore <bool>(descriptor));
 }