/// <summary> /// Creates the controller for the view. /// </summary> /// <param name="view">The name of the view in the Views section of the configuration file.</param> /// <param name="navigator">The navigator that the controller uses for navigation services.</param> /// <returns></returns> public static ControllerBase Create(string view, Navigator navigator) { ObjectTypeSettings typeSettings = UIPConfiguration.Config.GetControllerSettings(view); if (typeSettings == null) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionControllerNotFound, view)); } return((ControllerBase)GenericFactory.Create(typeSettings, new object[] { navigator })); }
/// <summary> /// Creates a layout manager for the view. /// </summary> /// <param name="view">The view whose configuration information contains the layout manager settings.</param> /// <returns>A layout manager.</returns> public static ILayoutManager Create(string view) { ILayoutManager layoutManager = null; ObjectTypeSettings typeSettings = UIPConfiguration.Config.GetLayoutManagerSettings(view); if (typeSettings != null) { layoutManager = (ILayoutManager)GenericFactory.Create(typeSettings); } return(layoutManager); }
/// <summary> /// Creates the default State object, loading it from the persistence provider. /// </summary> /// <returns>Default state instance of type specified in the configuration file.</returns> public static State Create() { IStatePersistence spp = StatePersistenceFactory.Create(); ObjectTypeSettings typeSettings = UIPConfiguration.Config.DefaultState; State state = Create(spp, typeSettings); if (UIPConfiguration.Config.IsStateCacheEnabled) { StateCache.PutStateInCache(state, true); } return(state); }
private void LoadViewManagementObjects(XmlNode configNode) { //Get the configured IViewManager object types ObjectTypeSettings typedObject; foreach (XmlNode objectTypeNode in configNode.SelectSingleNode(NodeObjectTypesXPath).ChildNodes) { switch (objectTypeNode.LocalName) { case NodeILayoutManagerXPath: typedObject = new ObjectTypeSettings(objectTypeNode); _iLayoutManagerCollection.Add(typedObject.Name, typedObject); break; case NodeIViewManagerXPath: typedObject = new ObjectTypeSettings(objectTypeNode); _iViewManagerCollection.Add(typedObject.Name, typedObject); if (IsDefault(objectTypeNode)) { _defaultViewManager = typedObject; } break; case NodeStateXPath: typedObject = new ObjectTypeSettings(objectTypeNode); _stateCollection.Add(typedObject.Name, typedObject); if (IsDefault(objectTypeNode)) { _defaultState = typedObject; } break; case NodeControllerXpath: typedObject = new ObjectTypeSettings(objectTypeNode); _controllerCollection.Add(typedObject.Name, typedObject); break; case NodePersistProviderXPath: typedObject = new StatePersistenceProviderSettings(objectTypeNode); _statePersistenceCollection.Add(typedObject.Name, typedObject); if (IsDefault(objectTypeNode)) { _defaultStatePersistence = (StatePersistenceProviderSettings)typedObject; } break; } } }
/// <summary> /// Creates a State object, loading it from persistence provider. /// </summary> /// <param name="navigatorName">Name of the navigator.</param> /// <returns>State instance of the type specified in the configuration file.</returns> public static State Create(string navigatorName) { // Create a State persistence provider to be used by the state object IStatePersistence spp = StatePersistenceFactory.Create(navigatorName); ObjectTypeSettings typeSettings = UIPConfiguration.Config.GetStateSettings(navigatorName); State state = Create(spp, typeSettings); //Check if the cache is enabled if (UIPConfiguration.Config.IsStateCacheEnabled) { StateCache.PutStateInCache(state, navigatorName, true); } return(state); }
/// <summary> /// Creates an IViewManager defined as DefaultViewManager. /// </summary> /// <returns>An instance of IViewManager.</returns> public static IViewManager Create() { ObjectTypeSettings ivmSettings = UIPConfiguration.Config.DefaultViewManager; IViewManager ivm = null; try { // activate an instance ivm = (IViewManager)GenericFactory.Create(ivmSettings); } catch (Exception e) { throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantCreateIViewManager, ivmSettings.Type), e); } return(ivm); }
/// <summary> /// Constructor. /// </summary> public UIPConfigSettings( ) { //Init the hashtables _iLayoutManagerCollection = new HybridDictionary(); _iViewManagerCollection = new HybridDictionary(); _stateCollection = new HybridDictionary(); _controllerCollection = new HybridDictionary(); _statePersistenceCollection = new HybridDictionary(); _viewByNameCollection = new Hashtable(); _navigatorCollection = new HybridDictionary(); _globalSharedTransitions = new HybridDictionary(); _hostedControlsCollection = new HybridDictionary(); _isStateCacheEnabled = true; _defaultViewManager = null; _defaultState = null; _defaultStatePersistence = null; _allowBackButton = true; }
/// <summary> /// Creates an object using the full name type contained in typeSettings. /// </summary> /// <param name="typeSettings">A typeSetting object with the needed type information to create a class instance.</param> /// <param name="args">Constructor arguments.</param> /// <returns>An instance of the specified type.</returns> public static object Create(ObjectTypeSettings typeSettings, object[] args) { Assembly assemblyInstance = null; Type typeInstance = null; try { // Use full assembly name to get assembly instance assemblyInstance = Assembly.Load(typeSettings.Assembly); } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantLoadAssembly, typeSettings.Assembly) + UIPException.GetFirstExceptionMessage(e), e); } // use type name to get type from assembly try { typeInstance = assemblyInstance.GetType(typeSettings.Type, true, false); } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantGetTypeFromAssembly, typeSettings.Type, typeSettings.Assembly) + UIPException.GetFirstExceptionMessage(e), e); } try { if (args != null) { return(Activator.CreateInstance(typeInstance, args)); } else { return(Activator.CreateInstance(typeInstance)); } } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantCreateInstanceUsingActivate, typeInstance) + UIPException.GetFirstExceptionMessage(e), e); } }
/// <summary> /// Creates a State object, loading it from persistence provider. /// </summary> /// <param name="spp">The state persistence provider.</param> /// <param name="typeSettings">The state settings.</param> /// <returns>A state instance of the type specified in the configuration file.</returns> internal static State Create(IStatePersistence spp, ObjectTypeSettings typeSettings) { State state = null; Guid taskId = Guid.Empty; if (typeSettings == null) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionStateConfigNotFound, "")); } // set the arguments used by the State object constructor object[] args = { spp }; try { // pass to Base class' reflection code // DON'T look for this State in Cache, "CREATE" semantics in this class // demand that we create it freshly... // UNLIKE other Factories, State is stateful and we don't recycle in Create; // instead if the consuming class wishes a Cached entry, they might get it // from Load() methods instead... state = (State)GenericFactory.Create(typeSettings, args); } catch (Exception e) { throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantCreateState, typeSettings.Type), e); } // create a new Task id taskId = Guid.NewGuid(); // store the task id into the state object state.TaskId = taskId; // return it return(state); }
/// <summary> /// Gets the settings of the layout manager used by the specified view. /// </summary> /// <param name="viewName">The name of the view to retrieve layout manager settings for.</param> public virtual ObjectTypeSettings GetLayoutManagerSettings(string viewName) { ObjectTypeSettings layoutManagerSettings = null; ViewSettings viewSettings = GetViewSettingsFromName(viewName); if (viewSettings == null) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionViewConfigNotFound, viewName)); } if (ViewExpectsLayoutManager(viewSettings)) { layoutManagerSettings = (ObjectTypeSettings)_iLayoutManagerCollection[viewSettings.LayoutManager]; if (layoutManagerSettings == null) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionLayoutManagerNotFound, viewSettings.LayoutManager)); } } return(layoutManagerSettings); }
/// <summary> /// Creates an IViewManager of a type specific to the named NavigationGraph. /// If possible, it returns a reference from the internal cache because these are presumed to be stateless. /// </summary> /// <param name="navigator">The name of a navigator.</param> /// <param name="args">The constructor parameter for ViewManager.</param> /// <returns>An instance of IViewManager. It gets this from the internal cache, if possible.</returns> public static IViewManager Create(string navigator, object[] args) { ObjectTypeSettings ivmSettings = null; // check if we have an instance of requested ivm in cache IViewManager ivm = (IViewManager)_viewManagerCache[navigator]; // not found in cache--create, store in cache, and return if (ivm == null) { // get the type info from config //Get the view manager according to the configured application type ivmSettings = UIPConfiguration.Config.GetIViewManagerSettingsFromNavigatorName(navigator); if (ivmSettings == null) { throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionIViewManagerNotFound, navigator)); } try { // activate an instance ivm = (IViewManager)GenericFactory.Create(ivmSettings, args); } catch (Exception e) { throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantCreateIViewManager, ivmSettings.Type), e); } // lock collection lock (_viewManagerCache.SyncRoot) _viewManagerCache[navigator] = ivm; // add this IViewManager to the cache } // return it return(ivm); }
/// <summary> /// Creates an object using the full name type contained in typeSettings. /// </summary> /// <param name="typeSettings">A typeSetting object with the needed type information to create a class instance.</param> /// <returns>An instance of the specified type.</returns> public static object Create(ObjectTypeSettings typeSettings) { return(Create(typeSettings, null)); }