/// <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); }
/// <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); }
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; }
protected static void ShowView(RegionMapping mapping, RegionViewMappingPayload vmp) { if (vmp.View != null) { mapping.ShowView(mapping, vmp.View); } else { mapping.ShowView(mapping, vmp.PrefabName); } }
/// <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); }
/// <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); }
/// <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); }
/// <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 }
protected static void UpdateDataContext(RegionMapping mapping, RegionViewMappingPayload vmp) { mapping.UpdateDataContext(vmp.DataContext); }
protected static void HideAllViews(RegionMapping mapping, RegionViewMappingPayload vmp) { mapping.HideAllViews(); }
protected static void HideView(RegionMapping mapping, RegionViewMappingPayload vmp) { }
protected static void UnlockAllViews(RegionMapping mapping, RegionViewMappingPayload vmp) { mapping.Unlock(); }
protected static void UnlockView(RegionMapping mapping, RegionViewMappingPayload vmp) { // TODO pass specific view mapping.Unlock(); }
protected static void DestroyRegion(RegionMapping mapping, RegionViewMappingPayload vmp) { mapping.DestroyRegion(); }