Example #1
0
        ///// <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();
                }
            }
        }
Example #2
0
        /// <summary> Implements <see cref="IModelDefinitionManager.AddModelType"/> </summary>
        public void AddModelType(IModelType modelType)
        {
            if (modelType == null)
            {
                return;
            }

            if (ModelTypeByName.ContainsKey(modelType.Name.ToUpper()))
            {
                Logger.Instance.LogFormat(LogType.Warn, "The Model Type '{0}' is register more than once.", modelType.Name);
            }

            ModelTypeByName[modelType.Name.ToUpper()] = modelType;
        }
Example #3
0
        /// <summary> Implements <see cref="IModelDefinitionManager.GetModelType"/> </summary>
        public IModelType GetModelType(string name)
        {
            lock (syncObj)
            {
                if (string.IsNullOrEmpty(name))
                {
                    return(null);
                }

                IModelType ret = null;
                ModelTypeByName.TryGetValue(name.ToUpper(), out ret);
                return(ret);
            }
        }
Example #4
0
        /// <summary> Add a model type from a .Net Type</summary>
        public IModelType AddModelType(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            IModelType modelType = ModelType.CreateInstance(this, type);

            if (ModelTypeByName.ContainsKey(modelType.Name.ToUpper()))
            {
                Logger.Instance.LogFormat(LogType.Warn, "The Model Type '{0}' is declared more than once.", modelType.Name);
            }
            ModelTypeByName[modelType.Name.ToUpper()] = modelType;
            return(modelType);
        }