コード例 #1
0
        internal void NavigateToView(ILogicWithViewModel <IViewModel> logic, StateManager stateManager, bool isModal = false)
        {
            IViewModel view = logic.ViewModel;

            view.Visible = true;
            if (!LoadedViews.Any(x => x.UniqueID == view.UniqueID))
            {
                _viewsDelta.AddNewView(view, isModal);

                if (isModal)
                {
                    ModalViews.Add(view.UniqueID);
                }

                LoadedViews.Add(new ViewInfo {
                    UniqueID = view.UniqueID, Visible = view.Visible, ZOrder = 0
                });
                // Added to support promises in the first request(SKS Demo Splash)
                // The view is created but is not sent to the client because it is not loaded by the first request
                // Therefore the navigateToView requires to send the view's viewmodel completely.
                stateManager.Tracker.DetachModel(view);
                stateManager.Tracker.MarkAllAsModified(view);
                stateManager.AddInCache(view.UniqueID, view, true);
                // Lets fire the load event
                //Load can have no parameters or some parameters
                InvokeLifeCycleStartup(logic);
            }
            else
            {
                var currentView = LoadedViews.FirstOrDefault(v => v.UniqueID == view.UniqueID);
                currentView.Visible = view.Visible;
                currentView.ZOrder  = 0;
            }
            stateManager.Tracker.MarkAsModified(this, "LoadedViews");
        }
コード例 #2
0
        /// <summary>
        /// Disposes the view bound to the given <c>ILogicView</c> object.
        /// </summary>
        /// <param name="logic">The <c>ILogicView</c> object bound to the view to dispose.</param>
        internal void DisposeView(ILogicWithViewModel <IViewModel> logic)
        {
            IViewModel view  = logic.ViewModel;
            int        count = LoadedViews.RemoveAll(x => x.UniqueID == view.UniqueID);

            _viewsDelta.RemoveView(view);
            var stateManager = StateManager.Current;

            stateManager.RemoveObject(view.UniqueID, true, isDispose: true, formBaseVM: view as UpgradeHelpers.Helpers.FormBaseViewModel);
            stateManager.Tracker.MarkAsModified(this, "LoadedViews");
            ModalViews.Remove(view.UniqueID);
            Debug.Assert(count <= 1, "Exactly one view must be removed");
        }
コード例 #3
0
        ///// <summary>
        ///// Invoke the parent forms load method first
        ///// </summary>
        ///// <param name="logic">instance object</param>
        ///// <param name="logicType">current type object</param>
        //[Obsolete("InvokeLoadMethod is deprecated, all the Load methods should be handled by the ILoadable elements.")]
        //private static void InvokeLoadMethod(ILogicWithViewModel<IViewModel> logic, Type logicType)
        //{
        //	var parent = logicType.BaseType;
        //	if (parent != null && parent.Implements(typeof(ILogicView<>)))
        //	{
        //		InvokeLoadMethod(logic, parent);
        //	}

        //	if (logicType.Implements(typeof(ILogicView<>)))
        //	{
        //		InvokeInnerLoadMethods(logic.ViewModel, new HashSet<object>(ComparerByReference.CommonInstance));

        //		MethodInfo method = logicType.Method("Load", new Type[0]);
        //		if (method != null)
        //		{
        //			method.Invoke(logic, new object[0]);
        //		}
        //		else
        //		{
        //			method = logic.GetType().Method("Load", new[] { typeof(object), typeof(EventArgs) });
        //			if (method != null)
        //			{
        //				method.Invoke(logic, new object[] { null, null });
        //			}
        //		}
        //	}
        //}

        /// <summary>
        /// Invokes LifeCycle startup method for parent form, the parent form
        /// should also handle the startup method for inner User Controls.
        /// </summary>
        /// <param name="logic">instance object</param>
        /// <param name="logicType">current type object</param>
        private static void InvokeLifeCycleStartup(ILogicWithViewModel <IViewModel> logic)
        {
            // The View being displayed must implement ILifeCycle interface
            //in order to execute any desided logic once the View is Built
            //and added to the LoadedViews collection
            var ilifeCycleOBj = logic as ILifeCycle;

            if (ilifeCycleOBj != null)
            {
                ilifeCycleOBj.LifeCycleStartup();
            }
            else
            {
                var iloadableOBj = logic as ILoadable;
                if (iloadableOBj != null)
                {
                    iloadableOBj.Load();
                }
                //else
                //TODO  kesanchez: The call to this method MUST be removed and the method as well.
                //InvokeLoadMethod(logic, logic.GetType());
            }
        }
コード例 #4
0
        public void AutoWireEvents(ILogic logic)
        {
            var logicType          = logic.GetType();
            var methodsForAutoWire = TypeCacheUtils.NeedsAutoWire(logicType);

            foreach (var methodEx in methodsForAutoWire)
            {
                var method = methodEx.method;
                var attr   = methodEx.HandlerAttribute;
                ILogicWithViewModel <IViewModel> logicWithViewModel = logic as ILogicWithViewModel <IViewModel>;
                string componentName;
                string eventId;
                //We have an attribute with no arguments like [Handler] void MethodName(...) { ... }
                if (attr.IsDefault)
                {
                    if (methodEx.MethodAndEventParts != null)
                    {
                        var methodNameParts = methodEx.MethodAndEventParts;
                        Debug.Assert(methodNameParts.Count() == 2);
                        componentName = methodNameParts[0];
                        eventId       = methodNameParts[1];
                    }
                    else
                    {
                        componentName = null;
                        eventId       = method.Name;
                    }
                }
                else
                {
                    componentName = attr.GetControl();
                    eventId       = attr.GetEvent();
                }
                TraceUtil.WriteLine(string.Format("AutoWire Event for {0} {1}", componentName, eventId));
                //Is this event on a Form?
                if (logicWithViewModel != null)
                {
                    if (logicWithViewModel.ViewModel == null)
                    {
                        Debug.Assert(false, "A Form does not have its corresponding ViewModel");
                    }
                    else
                    {
                        if (componentName != null)
                        {
                            var componentProp = logicWithViewModel.ViewModel.GetType().Property(componentName);
                            if (componentProp != null)
                            {
                                var component    = componentProp.GetValue(logicWithViewModel.ViewModel, null) as IStateObject;
                                var controlArray = component is IList;
                                if (component != null && !controlArray)
                                {
                                    RegisterMethodForEvent(logicWithViewModel, method, componentName, eventId, component);
                                }
                                else if (component == null && componentProp.PropertyType.IsArray)
                                {
                                    var array = logicWithViewModel.ViewModel.GetPropertyValue(componentName) as IList;
                                    if (array != null)
                                    {
                                        foreach (IStateObject element in array)
                                        {
                                            RegisterMethodForEvent(logicWithViewModel, method, componentName, eventId, element);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (logic is IStateObject)
                {
                    IStateObject stateObject = (IStateObject)logic;
                    //If this is not a form then it must something like an IModel or an IDependentViewModel
                    if (componentName != null)
                    {
                        var componentProp = logicType.Property(componentName);
                        if (componentProp != null)
                        {
                            var component = componentProp.GetValue(logic, null) as IStateObject;
                            if (component != null)
                            {
                                RegisterMethodForEvent(logic, method, componentName, eventId, component);
                            }
                            else
                            {
                                TraceUtil.TraceError("EventAggregator::AutoWriteEvents failed for method [" + method.Name + "] property not found for [" + componentName + "]");
                                continue;
                            }
                        }
                    }
                    else
                    {
                        RegisterMethodForEvent(logic, method, NONCOMPONENT_EVENT, eventId, stateObject);
                    }
                }
                else
                {
                    throw new NotSupportedException("Events can only be register on object instances implementing ILogicView<T> or (ILogic and IDependentViewModel) or IModel");
                }
            }
        }
コード例 #5
0
//		/// <summary>
//		/// Executes the "Load" method which is the WebMap equivalent of the Load Event on the usercontrols of a Form (recursively)
//		/// </summary>
//		/// <param name="parentControl"></param>
//		/// <param name="visited">This is passed to avoid graph cycles</param>

//		private static void InvokeInnerLoadMethods(IStateObject parentControl, HashSet<object> visited)
//		{
//			//Visited is to avoid cycles
//			if (visited.Contains(parentControl))
//			{
//				return;
//			}

//			visited.Add(parentControl);
//			Type logicType = parentControl.GetType();
//			//Gets Information from the cache
//			var cachedTypePropertiesInfo = TypeCacheUtils.GetPropertyInfoExFor(logicType);
//#if DEBUG
//			Debug.Assert(cachedTypePropertiesInfo != null, "Cached Type Properties info was not present");
//#endif
//			if (cachedTypePropertiesInfo == null) return;


//			///Transverse all properties to find children that might need their Load methods to be called
//			foreach (PropertyInfoEx propInfoEx in cachedTypePropertiesInfo)
//			{
//				IStateObject propertyValue = null;
//				if (propInfoEx.prop.PropertyType.IsInterface)
//				{
//					//TODO get value
//					//TODO get typeFromValue
//					//TODO get PropertyInfoEx for property
//				}
//				else
//				{
//					//Load method can only be inside DependantViewModels
//					if (propInfoEx.isAssignableFromIDependantViewModel)
//					{
//						if (propertyValue==null && propInfoEx.MemberGetter!=null)
//							propertyValue = (IStateObject)propInfoEx.MemberGetter(parentControl);
//						//Deep first call of load method on dependants
//						if (propertyValue != null)
//						{
//							//Recursive call
//							InvokeInnerLoadMethods(propertyValue, visited);
//							//Now call the property LoadEvent
//							if (propInfoEx.LoadEvent != null)
//							{
//								var method = propInfoEx.LoadEvent;
//								method.Invoke(propertyValue, new object[0]);
//							}
//						}
//					}
//				}
//			}
//		}


        internal void HideView(ILogicWithViewModel <IViewModel> logicObjectWithView)
        {
            IViewModel view = logicObjectWithView.ViewModel;

            view.Visible = false;
        }
コード例 #6
0
 public static void SetCursor <TVM>(this ILogicWithViewModel <TVM> instance, Cursor cursor) where TVM : IViewModel
 {
 }
コード例 #7
0
 public static Cursor GetCursor <TVM>(this ILogicWithViewModel <TVM> instance) where TVM : IViewModel
 {
     return(null);
 }
コード例 #8
0
 public static int GetControlIndex(this ILogicWithViewModel <IViewModel> logic)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public static void LoadControl <T>(this ILogicWithViewModel <IViewModel> logic, string name, int index)
 {
     //throw new NotImplementedException();
 }