Exemple #1
0
        public static IModelAccessor CreateInstance(IModelAccessorGroup parent, XmlModelAccessor definition)
        {
            if (definition == null)
            {
                return(null);
            }

            ModelAccessor accessor = new ModelAccessor();

            try
            {
                accessor.Parent = parent;
                accessor.Name   = definition.Name.EmptyIfNull().Trim();
                accessor.Ident  = definition.Ident.EmptyIfNull().Trim();
                if (string.IsNullOrEmpty(accessor.Ident))
                {
                    accessor.Ident = accessor.Name;
                }

                accessor.Description = definition.Description.EmptyIfNull().Trim();
                accessor.modelType   = definition.ReturnModelType.EmptyIfNull().Trim();

                definition.InstanceName = definition.InstanceName.EmptyIfNull().Trim();
                definition.InstanceType = definition.InstanceType.EmptyIfNull().Trim();
                definition.Method       = definition.Method.EmptyIfNull().Trim();

                definition.Method = definition.Method.EmptyIfNull().Trim();

                if (string.IsNullOrEmpty(accessor.Name))
                {
                    throw new EtkException("'Name' is mandatory");
                }
                if (string.IsNullOrEmpty(definition.Method))
                {
                    throw new EtkException("'Method' is mandatory");
                }

                DataAccessorInstanceType dataAccessorInstanceType = ModelManagement.DataAccessors.DataAccessor.AccessorInstanceTypeFrom(definition.InstanceType);
                accessor.DataAccessor = ModelManagement.DataAccessors.DataAccessor.CreateInstance(definition.Method, dataAccessorInstanceType, definition.InstanceName);
            }
            catch (Exception ex)
            {
                throw new EtkException($"Cannot create 'ModelAccessor' '{definition.Name.EmptyIfNull()} {definition.Method.EmptyIfNull()}': {ex.Message}");
            }
            return(accessor);
        }
        public static IModelAccessorGroup CreateInstance(ModelDefinitionManager parent, XmlModelAccessorGroup definition)
        {
            if (definition == null)
            {
                return(null);
            }

            ModelAccessorGroup group = new ModelAccessorGroup();

            try
            {
                if (string.IsNullOrEmpty(definition.Name))
                {
                    throw new EtkException("'Name' is mandatory");
                }

                group.Parent      = parent;
                group.Name        = definition.Name.EmptyIfNull().Trim();
                group.Description = definition.Description.EmptyIfNull().Trim();

                if (definition.Accessors != null)
                {
                    foreach (XmlModelAccessor xmlAccessor in definition.Accessors)
                    {
                        //IModelAccessor accessor = CreateModelAccessors(modelAccessorDefinition);
                        IModelAccessor accessor = ModelAccessor.CreateInstance(group, xmlAccessor);
                        if (accessor != null)
                        {
                            group.accessors.Add(accessor);

                            if (parent.ModelAccessorByIdent.ContainsKey(accessor.Ident))
                            {
                                Logger.Instance.LogFormat(LogType.Warn, "The model accessor '{0}' is declared more than once.", accessor.Ident);
                            }
                            parent.ModelAccessorByIdent[accessor.Ident] = accessor;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new EtkException($"Cannot create 'Model Accessor Group' '{definition.Name.EmptyIfNull()}': {ex.Message}");
            }
            return(group);
        }