Beispiel #1
0
        /// <summary>
        /// mutates an item in the eviction condition store, and returns true if it's not flagged for eviction
        /// </summary>
        /// <param name="soId"></param>
        /// <returns></returns>
        protected bool TouchExpirable(StoredObjectId soId)
        {
            if (soId == null)
            {
                return(false);
            }

            bool isExpired = false;
            //get the item's condition from the condition store
            var record = this.ExpirableStore.Get <ContextualId <StoredObjectId, IExpirable> >(soId);

            //if the eviction condition is touchable, touch it
            if (record != null && record.Context != null)
            {
                isExpired = record.Context.IsExpired();

                //if the expirable is touchable, touch it
                if (record.Context is ITouchable)
                {
                    ITouchable touch = (ITouchable)record.Context;
                    touch.Touch();
                }
                else if (record.Context is IPolyfacing) //or if it's polyfacing with a touchable face
                {
                    IPolyfacing poly  = (IPolyfacing)record.Context;
                    var         touch = poly.RootFace.AsHasTouchable();
                    if (touch != null)
                    {
                        touch.Touch();
                    }
                }
            }
            return(!isExpired);
        }
Beispiel #2
0
        /// <summary>
        /// a new Polyface is created and injected.
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        public static Polyface NewRoot(this IPolyfacing face)
        {
            Condition.Requires(face).IsNotNull();
            var rv = Polyface.New();

            rv.Is(face.GetType(), face);

            return(rv);
        }
Beispiel #3
0
        /// <summary>
        /// Sets the behaviour for the provided face name
        /// </summary>
        /// <param name="type"></param>
        /// <param name="behaviour"></param>
        /// <returns></returns>
        public static Polyface Is(this IPolyfacing face, string faceName, object behaviour)
        {
            Condition.Requires(face).IsNotNull();
            Polyface rv = face.RootFace;

            if (rv == null)
            {
                rv            = Polyface.New();
                face.RootFace = rv;
            }
            return(rv.Is(faceName, behaviour));
        }
Beispiel #4
0
        /// <summary>
        /// Sets the behaviour for the provided face name
        /// </summary>
        /// <param name="type"></param>
        /// <param name="behaviour"></param>
        /// <returns></returns>
        public Polyface Is(string face, object behaviour)
        {
            Condition.Requires(face).IsNotNullOrEmpty();

            //registers the behaviour
            this.NamedFaces[face] = behaviour;

            //if the behaviour is polyface compliant it registers the root
            if (behaviour is IPolyfacing)
            {
                IPolyfacing has = (IPolyfacing)behaviour;
                has.RootFace = this;
            }
            return(this);
        }
Beispiel #5
0
        /// <summary>
        /// sets behaviour
        /// </summary>
        /// <param name="type"></param>
        /// <param name="behaviour"></param>
        /// <returns></returns>
        public Polyface Is(Type type, object behaviour)
        {
            Condition.Requires(type).IsNotNull();

            //registers the behaviour
            this.TypedFaces[type] = behaviour;

            //if the behaviour is polyface compliant it registers the root
            if (behaviour is IPolyfacing)
            {
                IPolyfacing has = (IPolyfacing)behaviour;
                has.RootFace = this;
            }
            return(this);
        }
Beispiel #6
0
 /// <summary>
 /// Gets the behaviour with the provided name
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="name"></param>
 /// <returns></returns>
 public static T As <T>(this IPolyfacing face, string name)
 {
     Condition.Requires(face).IsNotNull();
     Condition.Requires(face.RootFace).IsNotNull();
     return(face.RootFace.As <T>(name));
 }