///// <summary> Implements <see cref="IModelDefinitionManager.GetModelType"/> </summary> //public void ResolveModel() //{ // try // { // Logger.Instance.Log(LogType.Info, "Starting the model resolution..."); // bool onError = false; // if (modelTypeByName != null) // { // foreach (IModelType type in modelTypeByName.Values) // { // try // { // (type as ModelType).ResolveDependencies(); // } // catch // { onError = true; } // } // } // if (onError) // throw new EtkException("Error(s) found"); // } // catch (Exception ex) // { // throw new EtkException(string.Format("Model resolution failed: {0}. Please check the log.", ex.Message)); // } // finally // { // Logger.Instance.Log(LogType.Info, "Model resolution finished."); // } //} #endregion #region protected methods //protected abstract IModelAccessor CreateModelAccessors(XmlModelAccessor modelAccessorDefinition); protected void PopulateFromXmlModelConfiguration(XmlModelConfiguration xmlModelConfiguration) { lock (syncObj) { if (xmlModelConfiguration.ModelAccessorGroupDefinitions != null) { HasModels = true; foreach (XmlModelAccessorGroup xmlGroup in xmlModelConfiguration.ModelAccessorGroupDefinitions) { //IModelAccessor accessor = CreateModelAccessors(modelAccessorDefinition); IModelAccessorGroup group = ModelAccessorGroup.CreateInstance(this, xmlGroup); if (group != null) { if (ModelAccessorGroupByName.ContainsKey(group.Name)) { Logger.Instance.LogFormat(LogType.Warn, "The model accessor group '{0}' is declared more than once.", group.Name); } ModelAccessorGroupByName[group.Name] = group; } } } if (xmlModelConfiguration.TypeDefinitions != null) { foreach (XmlModelType typeDefinition in xmlModelConfiguration.TypeDefinitions) { ModelType modelType = ModelType.CreateInstance(this, typeDefinition); if (modelType != null) { if (ModelTypeByName.ContainsKey(modelType.Name.ToUpper())) { Logger.Instance.LogFormat(LogType.Warn, "The model UnderlyingType '{0}' is declared more than once.", modelType.Name); } ModelTypeByName[modelType.Name.ToUpper()] = modelType; } } } // Resolve model accessorsNames dependencies foreach (ModelAccessor modelAccessor in ModelAccessorByIdent.Values) { modelAccessor.ResolveDependencies(); } // Resolve model types dependencies foreach (ModelType modelType in ModelTypeByName.Values.ToList()) { modelType.ResolveDependencies(); } // Resolve views dependencies of the model types foreach (ModelType modelType in ModelTypeByName.Values.ToList()) { modelType.ResolveViewsDependencies(); } } }
/// <summary> Implements <see cref="IModelDefinitionManager.RegisterModelFromFile"/> </summary> public void RegisterModelFromFile(string configurationFilePath) { try { Logger.Instance.LogFormat(LogType.Info, "Model configuration file '{0}' integration starting ...", configurationFilePath.EmptyIfNull()); XmlModelConfiguration xmlModelConfiguration = XmlModelConfiguration.CreateInstanceFromFile(configurationFilePath); if (xmlModelConfiguration != null) { PopulateFromXmlModelConfiguration(xmlModelConfiguration); } } catch (Exception ex) { throw new EtkException($"Retrieve model configuration from file '{configurationFilePath.EmptyIfNull()}' failed: {ex.Message}", ex); } finally { Logger.Instance.LogFormat(LogType.Info, "Model configuration file '{0}' integration finished", configurationFilePath.EmptyIfNull()); } }
/// <summary> Implements <see cref="IModelDefinitionManager.RegisterModelFromXml"/> </summary> public void RegisterModelFromXml(string xmlString) { string configName = string.Empty; try { XmlModelConfiguration xmlModelConfiguration = XmlModelConfiguration.CreateInstanceFromXml(xmlString); if (xmlModelConfiguration != null) { configName = xmlModelConfiguration.Name ?? string.Empty; PopulateFromXmlModelConfiguration(xmlModelConfiguration); } } catch (Exception ex) { throw new EtkException($"Retrieve model configuration from xml '{configName}' failed: {ex.Message}", ex); } finally { Logger.Instance.LogFormat(LogType.Info, "Integration of model configuration xml '{0}' finished", configName); } }