/// <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 Exception(string.Format("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 ConfigurationErrorsException(string.Format("ExceptionCantCreateState: {0} - {1}.", typeSettings.Type, e.Message)); } // create a new Task id taskId = Guid.NewGuid(); // store the task id into the state object state.TaskId = taskId; // return it return state; }
/// <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) { Type typeInstance = CreateTypeInstance(typeSettings); return Create(typeInstance, args); }
/// <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); }
public static Type CreateTypeInstance(ObjectTypeSettings typeSettings) { 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 Exception(string.Format("ExceptionCantLoadAssembly: {0} - {1}.", typeSettings.Assembly, e.Message)); } // use type name to get type from assembly try { typeInstance = assemblyInstance.GetType(typeSettings.Type, true, false); } catch (Exception e) { throw new Exception(string.Format("ExceptionCantGetTypeFromAssembly: {0} - {1} - {2}.", typeSettings.Type, typeSettings.Assembly, e.Message)); } return typeInstance; }
/// <summary> /// Constructor. /// </summary> public UIPConfigSettings( ) { //Init the hashtables _iLayoutManagerCollection = new HybridDictionary(); _iViewManagerCollection = new HybridDictionary(); _stateCollection = new HybridDictionary(); _interceptorCollection = new HybridDictionary(); _statePersistenceCollection = new HybridDictionary(); _viewByNameCollection = new Hashtable(); _stateKeyByNameCollection = new Hashtable(); _controllerByNameCollection = new Hashtable(); _navigatorCollection = new HybridDictionary(); _globalSharedTransitions=new HybridDictionary(); _hostedControlsCollection = new HybridDictionary(); _isStateCacheEnabled = true; _defaultViewManager = null; _defaultState = null; _defaultStatePersistence = null; _allowBackButton = true; }
/*private void LoadWizards(XmlNode configNode, IFormatProvider formatProvider) { foreach (XmlNode wizardNode in configNode.SelectNodes( NodeWizardsXPath ) ) { WizardSettings wizard = new WizardSettings(_defaultStatePersistence.Name,_defaultState.Name,wizardNode); NavigationGraphSettings navigationGraph = new NavigationGraphSettings(wizard.GetNavGraphXmlNode(formatProvider)); _navigatorCollection.Add(navigationGraph.Name, navigationGraph); } }*/ private void LoadViewManagementObjects(XmlNode configNode) { if (configNode.SelectSingleNode(NodeObjectTypesXPath) == null) return; //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 NodeCallInterceptorXpath: typedObject = new ObjectTypeSettings(objectTypeNode); _interceptorCollection.Add(typedObject.Name, typedObject); break; case NodePersistProviderXPath: typedObject = new StatePersistenceProviderSettings( objectTypeNode ); _statePersistenceCollection.Add( typedObject.Name, typedObject ); if (IsDefault(objectTypeNode)) _defaultStatePersistence = (StatePersistenceProviderSettings)typedObject; break; } } }