Пример #1
0
        /// <summary>
        /// Determines whether this instance [can process payload].
        /// </summary>
        /// <param name="vmp">The payload.</param>
        /// <returns>
        ///   <c>true</c> if this instance [can process payload]; otherwise, <c>false</c>.
        /// </returns>
        protected virtual bool CanProcessPayload(RegionViewMappingPayload vmp)
        {
            if (vmp.RegionName.IsNullOrEmpty() || RegisteredRegions.Contains(vmp.RegionName))
            {
                return(false);
            }

            // if not registered as delayed region yet, ignore on unmap and on destroy actions
            if (!DelayedRegions.ContainsKey(vmp.RegionName))
            {
                switch (vmp.ViewMappingType)
                {
                case RegionViewMappingType.UnmapView:
                case RegionViewMappingType.DestroyRegion:
                    return(false);
                }
            }

            switch (vmp.ViewMappingType)
            {
            case RegionViewMappingType.MapView:
            case RegionViewMappingType.UnmapView:
            case RegionViewMappingType.DestroyRegion:
                return(true);
            }
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Before calling the mapping action.
 /// </summary>
 /// <param name="ownerType">Type of the owner.</param>
 /// <param name="method">The method.</param>
 /// <param name="mapping">The mapping.</param>
 /// <param name="payload">The payload.</param>
 protected internal virtual bool BeforeAction(
     Type ownerType, MethodInfo method,
     RegionMapping mapping, RegionViewMappingPayload payload)
 {
     // TODO
     return(true);
 }
Пример #3
0
        protected static void MapView(RegionMapping mapping, RegionViewMappingPayload vmp)
        {
            var vm = vmp.View != null?
                     mapping.MapView(vmp.View) :
                         mapping.MapView(vmp.PrefabName);

            vm.DataContext = vmp.DataContext;
        }
Пример #4
0
 protected static void ShowView(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
     if (vmp.View != null)
     {
         mapping.ShowView(mapping, vmp.View);
     }
     else
     {
         mapping.ShowView(mapping, vmp.PrefabName);
     }
 }
Пример #5
0
        /// <summary>
        /// Invokes the region view mapping action.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="mapping">The mapping.</param>
        /// <param name="payload">The payload.</param>
        protected static void InvokeRegionViewMappingAction(
            MethodInfo method, ViewMappingActionAttribute attribute,
            RegionMapping mapping, RegionViewMappingPayload payload)
        {
            var canProceed = attribute.BeforeAction(method.DeclaringType, method, mapping, payload);

            if (!canProceed)
            {
                return;
            }

            method.Invoke(mapping, new object[] { mapping, payload });

            attribute.AfterAction(method.DeclaringType, method, mapping, payload);
        }
Пример #6
0
        /// <summary>
        /// Called when [view mapping] payload received.
        /// </summary>
        /// <param name="vmp">The VMP.</param>
        public virtual void ProcessPayload(RegionViewMappingPayload vmp)
        {
            if (!RegionViewMappingActions.ContainsKey(vmp.ViewMappingType))
            {
                LogError("Cannot find action to perform \"{0}\".", vmp.ViewMappingType);
                return;
            }

            var act = RegionViewMappingActions[vmp.ViewMappingType];

            if (act == null)
            {
                LogError("The action for \"{0}\" is NULL.", vmp.ViewMappingType);
                return;
            }

            act(this, vmp);
        }
Пример #7
0
        /// <summary>
        /// Processes the payload.
        /// </summary>
        /// <param name="vmp">The payload.</param>
        protected virtual void ProcessPayload(RegionViewMappingPayload vmp)
        {
            if (RegisteredRegions.Contains(vmp.RegionName))
            {
                return;
            }

            IList <RegionViewMappingPayload> payloads;

            if (!DelayedRegions.ContainsKey(vmp.RegionName))
            {
                payloads = new List <RegionViewMappingPayload>();
                DelayedRegions.Add(vmp.RegionName, payloads);
            }
            else
            {
                payloads = DelayedRegions[vmp.RegionName];

                switch (vmp.ViewMappingType)
                {
                case RegionViewMappingType.UnmapView:
                    var mapped =
                        payloads.Where(
                            mapping => mapping.ViewMappingType == RegionViewMappingType.MapView &&
                            (mapping.View == vmp.View || mapping.PrefabName == vmp.PrefabName));
                    foreach (var mapping in mapped.ToArray())
                    {
                        payloads.Remove(mapping);
                    }
                    return;

                case RegionViewMappingType.DestroyRegion:
                    DelayedRegions.Remove(vmp.RegionName);
                    payloads.Clear();
                    return;
                }
            }
            if (payloads.Contains(vmp))
            {
                return;
            }

            payloads.Add(vmp);
        }
Пример #8
0
 /// <summary>
 /// Afters the action.
 /// </summary>
 /// <param name="ownerType">Type of the owner.</param>
 /// <param name="method">The method.</param>
 /// <param name="mapping">The mapping.</param>
 /// <param name="payload">The payload.</param>
 protected internal virtual void AfterAction(
     Type ownerType, MethodInfo method,
     RegionMapping mapping, RegionViewMappingPayload payload)
 {
     // TODO
 }
Пример #9
0
 protected static void UpdateDataContext(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
     mapping.UpdateDataContext(vmp.DataContext);
 }
Пример #10
0
 protected static void HideAllViews(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
     mapping.HideAllViews();
 }
Пример #11
0
 protected static void HideView(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
 }
Пример #12
0
 protected static void UnlockAllViews(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
     mapping.Unlock();
 }
Пример #13
0
 protected static void UnlockView(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
     // TODO pass specific view
     mapping.Unlock();
 }
Пример #14
0
 protected static void DestroyRegion(RegionMapping mapping, RegionViewMappingPayload vmp)
 {
     mapping.DestroyRegion();
 }