Exemple #1
0
        /// <summary>
        /// Check array parameter.
        /// </summary>
        /// <param name="param">Parameter.</param>
        /// <param name="checkForNull">Check for null.</param>
        /// <param name="checkIfEmpty">Check if empty.</param>
        /// <param name="checkForCommas">Check for commas.</param>
        /// <param name="maxSize">Max size.</param>
        /// <param name="paramName">Parameter name.</param>
        public static void CheckArrayParameter(ref string[] param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName)
        {
            if (param == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (param.Length < 1)
            {
                throw new ArgumentException(APResource.GetString(APResource.APDB_ParameterArrayEmpty, paramName));
            }

            Hashtable values = new Hashtable(param.Length);

            for (int i = param.Length - 1; i >= 0; i--)
            {
                CheckParameter(ref param[i], checkForNull, checkIfEmpty, checkForCommas, maxSize, paramName + "[ " + i.ToString() + " ]");
                if (values.Contains(param[i]))
                {
                    throw new ArgumentException(APResource.GetString(APResource.APDB_ParameterArrayDuplicateElement, paramName), paramName);
                }
                else
                {
                    values.Add(param[i], param[i]);
                }
            }
        }
Exemple #2
0
        public override void ReadGen(APGen gen, string streamName, XmlTextReader reader)
        {
            StreamName = streamName;
            GenHost    = gen.GenHost;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "type": TypeName = reader.Value; break;

                case "name": Name = reader.Value; break;

                default: ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, reader.Name), reader); break;
                }
            }

            if (Name == null || TypeName == null)
            {
                ThrowException(APResource.GetString(APResource.APGen_MissingRequiredAttribute, "section", "name or type"), reader);
            }

            reader.MoveToElement();
            reader.Skip();
        }
Exemple #3
0
        /// <summary>
        /// Check parameter.
        /// </summary>
        /// <param name="param">Parameter.</param>
        /// <param name="checkForNull">Check for null.</param>
        /// <param name="checkIfEmpty">Check if empty.</param>
        /// <param name="checkForCommas">Check for commas.</param>
        /// <param name="maxSize">Max size.</param>
        /// <param name="paramName">Parameter name.</param>
        public static void CheckParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName)
        {
            if (param == null)
            {
                if (checkForNull)
                {
                    throw new ArgumentNullException(paramName);
                }
                return;
            }

            param = param.Trim();
            if (checkIfEmpty && param.Length == 0)
            {
                throw new ArgumentException(APResource.GetString(APResource.APDB_ParameterEmpty, paramName), paramName);
            }
            if (maxSize > 0 && param.Length > maxSize)
            {
                throw new ArgumentException(APResource.GetString(APResource.APDB_ParameterTooLong, paramName, maxSize), paramName);
            }
            if (checkForCommas && param.Contains(","))
            {
                throw new ArgumentException(APResource.GetString(APResource.APDB_ParameterContainComma, paramName), paramName);
            }
        }
Exemple #4
0
 static void checkT()
 {
     if (!typeof(T).IsEnum)
     {
         throw new APDataException(APResource.GetString(APResource.APData_EnumAPColumnDefT, typeof(T).Name));
     }
 }
Exemple #5
0
 public override void ReadData(APGen gen, XmlTextReader reader)
 {
     if (gen.GetSectionXml(this) != null)
     {
         ThrowException(APResource.GetString(APResource.APGen_RedefinedSection, Name), reader);
     }
     gen.SetSectionXml(this, reader.ReadOuterXml());
 }
Exemple #6
0
        /// <summary>
        /// Gets the key for the APGenElement at the specified index location.
        /// </summary>
        /// <param name="index">The index location for the APGenElement.</param>
        /// <returns>The key for the specified APGenElement.</returns>
        protected internal object BaseGetKey(int index)
        {
            if (index < 0 || index >= _list.Count)
            {
                throw new APGenException(APResource.GetString(APResource.APGen_IndexOutOfRange, index));
            }

            return(GetElementKey((APGenElement)_list[index]).ToString());
        }
Exemple #7
0
        public virtual Type GetGenType(string typeName, bool throwOnError)
        {
            Type type = Type.GetType(typeName);

            if (type == null && throwOnError)
            {
                throw new APGenException(APResource.GetString(APResource.APGen_TypeNotFound, typeName));
            }
            return(type);
        }
Exemple #8
0
        /// <summary>
        /// Set next phrase.
        /// </summary>
        /// <param name="phrase">The next phrase.</param>
        /// <returns>The next phrase.</returns>
        public override IAPSqlPhrase SetNext(IAPSqlPhrase phrase)
        {
            if (phrase is APSqlOrderPhrase || phrase == null)
            {
                return(base.SetNext(phrase));
            }

            throw new APDataException(APResource.GetString(APResource.APData_PhraseNextError,
                                                           GetType().Name, phrase.GetType().Name, typeof(APSqlOrderPhrase).Name));
        }
Exemple #9
0
        private void ValidateValue(APGenProperty property, string value)
        {
            APValidatorBase validator;

            if (property == null || (validator = property.Validator) == null)
                return;

            if (!validator.CanValidate(property.Type))
                throw new APGenException(APResource.GetString(APResource.APGen_ValidatorNotSupportType, property.Type));
            validator.Validate(property.ConvertFromString(value));
        }
Exemple #10
0
 /// <summary>
 /// Set property value.
 /// </summary>
 /// <param name="prop">Property</param>
 /// <param name="value">Value</param>
 protected void SetPropertyValue(APGenProperty prop, object value)
 {
     try
     {
         prop.Validate(value);
     }
     catch (Exception e)
     {
         throw new APGenException(APResource.GetString(APResource.APGen_PropertyValueInvalid, prop.Name, e.Message), e);
     }
 }
Exemple #11
0
        internal void Initialize(APGen gen, SectionGroupInfo groupInfo)
        {
            if (_initialized)
            {
                throw new SystemException(APResource.GetString(APResource.APGen_SectionInitTwice, GetType()));
            }

            _initialized = true;
            _gen         = gen;
            _groupInfo   = groupInfo;
        }
Exemple #12
0
        /// <summary>
        /// Set next phrase.
        /// </summary>
        /// <param name="phrase">The next phrase.</param>
        /// <returns>The next phrase.</returns>
        public override IAPSqlPhrase SetNext(IAPSqlPhrase phrase)
        {
            if (phrase is APSqlWherePhrase || phrase == null)
            {
                return(base.SetNext(phrase));
            }

            //string typeName = phrase == null ? "null" : phrase.GetType().Name;
            string typeName = phrase.GetType().Name;

            throw new APDataException(APResource.GetString(APResource.APData_PhraseNextError,
                                                           GetType().Name, typeName, typeof(APSqlWherePhrase).Name));
        }
Exemple #13
0
        /// <summary>
        /// Set next phrase.
        /// </summary>
        /// <param name="phrase">The next phrase.</param>
        /// <returns>The next phrase.</returns>
        public override IAPSqlPhrase SetNext(IAPSqlPhrase phrase)
        {
            if (phrase is APSqlSelectPhrase)
            {
                return(base.SetNext(phrase));
            }
            else if (phrase == null)
            {
                return(base.SetNext(new APSqlSelectPhrase(APSqlNullExpr.Expr)));
            }

            throw new APDataException(APResource.GetString(APResource.APData_PhraseNextError,
                                                           GetType().Name, phrase.GetType().Name, typeof(APSqlSelectPhrase).Name));
        }
Exemple #14
0
        private void ReadGenFile(XmlTextReader reader, string fileName)
        {
            reader.MoveToContent();

            if (reader.NodeType != XmlNodeType.Element || reader.Name != "gen")
            {
                ThrowException(APResource.APGen_InvalidRootElement, reader);
            }

            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "namespace")
                    {
                        _rootNamespace = reader.Value;
                        continue;
                    }
                    else if (reader.LocalName == "xmlns")
                    {
                        continue;
                    }

                    ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttributeInElement, "gen", reader.LocalName), reader);
                }
            }

            reader.MoveToElement();

            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return;
            }

            reader.ReadStartElement();
            reader.MoveToContent();

            if (reader.LocalName == "genSections")
            {
                if (reader.HasAttributes)
                {
                    ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttributeInElement, "genSections", "..."), reader);
                }
                _rootGroupInfo.ReadGen(this, fileName, reader);
            }

            _rootGroupInfo.ReadRootData(reader, this);
        }
Exemple #15
0
        /// <summary>
        /// Creates a new instance of the ConfigurationProperty class.
        /// </summary>
        /// <param name="name">The name of the xml entity.</param>
        /// <param name="type">The type of the xml entity.</param>
        /// <param name="defaultValue">The default value of the xml entity.</param>
        /// <param name="converter">The type of the converter to apply.</param>
        /// <param name="validation">The validator to use.</param>
        /// <param name="flags">One of the APXmlPropertyOptions enumeration values.</param>
        /// <param name="description">The description of the xml entity.</param>
        public APXmlProperty(string name, Type type, object defaultValue,
                             TypeConverter converter, APValidatorBase validation, APXmlPropertyOptions flags, string description)
        {
            _name = name;

            _converter = converter != null ? converter : TypeDescriptor.GetConverter(type);

            if (defaultValue != null)
            {
                if (defaultValue == NoDefaultValue)
                {
                    switch (Type.GetTypeCode(type))
                    {
                    case TypeCode.Object:
                        defaultValue = null;
                        break;

                    case TypeCode.String:
                        defaultValue = String.Empty;
                        break;

                    default:
                        defaultValue = Activator.CreateInstance(type);
                        break;
                    }
                }
                else
                {
                    if (!type.IsAssignableFrom(defaultValue.GetType()))
                    {
                        if (!_converter.CanConvertFrom(defaultValue.GetType()))
                        {
                            throw new APXmlException(APResource.GetString(APResource.APXml_DefaultValueTypeError, name, type, defaultValue.GetType()));
                        }
                        defaultValue = _converter.ConvertFrom(defaultValue);
                    }
                }
            }

            _defaultValue = defaultValue;
            _flags        = flags;
            _type         = type;
            _validation   = validation != null ? validation : new DefaultAPValidator();
            _description  = description;
        }
Exemple #16
0
        internal void CreateSection(SectionGroupInfo groupInfo, string name, APGenSection section)
        {
            if (groupInfo.HasChild(name))
            {
                throw new APGenException(APResource.GetString(APResource.APGen_SectionAlreadyExists, name));
            }

            if (section.SectionInformation.Type == null)
            {
                section.SectionInformation.Type = GenHost.GetGenTypeName(section.GetType());
            }

            SectionInfo sectionInfo = new SectionInfo(name, section.SectionInformation);

            sectionInfo.StreamName = _streamName;
            sectionInfo.GenHost    = GenHost;
            groupInfo.AddChild(sectionInfo);
            _elementData[sectionInfo] = section;
        }
Exemple #17
0
        /// <summary>
        /// Get or set value by property name.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        /// <returns>Value</returns>
        protected internal object this[string propertyName]
        {
            get
            {
                APGenPropertyInformation property = ElementInformation.Properties[propertyName];
                if (property == null)
                    throw new InvalidOperationException(APResource.GetString(APResource.APGen_PropertyNotExist, propertyName));
                return property.Value;
            }
            set
            {
                APGenPropertyInformation property = ElementInformation.Properties[propertyName];
                if (property == null)
                    throw new InvalidOperationException(APResource.GetString(APResource.APGen_PropertyNotExist, propertyName));

                SetPropertyValue(property.Property, value);

                property.Value = value;
            }
        }
Exemple #18
0
        public void ReadContent(XmlTextReader reader, APGen gen, bool root)
        {
            while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Skip();
                    continue;
                }

                GenInfo data = GetGenInfo(reader, this);
                if (data != null)
                {
                    data.ReadData(gen, reader);
                }
                else
                {
                    ThrowException(APResource.GetString(APResource.APGen_UnrecognizedSection, reader.LocalName), reader);
                }
            }
        }
Exemple #19
0
        internal void CreateSectionGroup(SectionGroupInfo parentGroup, string name, APGenSectionGroup section)
        {
            if (parentGroup.HasChild(name))
            {
                throw new APGenException(APResource.GetString(APResource.APGen_SectionAlreadyExists, name));
            }

            if (section.Type == null)
            {
                section.Type = GenHost.GetGenTypeName(section.GetType());
            }
            section.SetName(name);

            SectionGroupInfo sectionInfo = new SectionGroupInfo(name, section.Type);

            sectionInfo.StreamName = _streamName;
            sectionInfo.GenHost    = GenHost;
            parentGroup.AddChild(sectionInfo);
            _elementData[sectionInfo] = section;

            section.Initialize(this, sectionInfo);
        }
Exemple #20
0
        /// <summary>
        /// Load config file.
        /// Defaults, you can use 'null' parameter, Web project maybe find web.config, winform project maybe find
        /// app.config.
        /// </summary>
        /// <param name="configurationManager">The configurationManager.</param>
        public static void LoadConfig(System.Configuration.Configuration configurationManager)
        {
            if (configurationManager == null)
            {
                //cfgSection = (APQuerySection)WebConfigurationManager.GetSection("APQuery");
                cfgSection = (APQuerySection)ConfigurationManager.GetSection("APQuery");
            }
            else
            {
                cfgSection = (APQuerySection)configurationManager.GetSection("APQuery");
            }
            if (cfgSection == null)
            {
                throw new ConfigurationErrorsException(APResource.GetString(APResource.APConfig_NotFindSection, "APQuery"));
            }

            providersCollection = new APDalProviderCollection();
            ProvidersHelper.InstantiateProviders(cfgSection.Providers, providersCollection, typeof(APDalProvider));
            defaultProvider = Providers[cfgSection.DefaultProvider];
            if (defaultProvider == null)
            {
                throw new ConfigurationErrorsException(APResource.GetString(APResource.APProvider_NotFound, cfgSection.DefaultProvider));
            }
        }
Exemple #21
0
        public override void ReadGen(APGen gen, string streamName, XmlTextReader reader)
        {
            StreamName = streamName;
            GenHost    = gen.GenHost;

            if (reader.LocalName != "genSections")
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.Name == "name")
                    {
                        Name = reader.Value;
                    }
                    else if (reader.Name == "type")
                    {
                        TypeName = reader.Value;
                        Type     = null;
                    }
                    else
                    {
                        ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, ""), reader);
                    }
                }

                if (Name == null)
                {
                    ThrowException(APResource.GetString(APResource.APGen_MissingRequiredAttribute, "sectionGroup", "name"), reader);
                }
            }

            if (TypeName == null)
            {
                TypeName = typeof(APGenSectionGroup).FullName;
            }

            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return;
            }

            reader.ReadStartElement();
            reader.MoveToContent();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Skip();
                    continue;
                }

                string  name = reader.LocalName;
                GenInfo info = null;

                if (name == "section")
                {
                    info = new SectionInfo();
                }
                else if (name == "sectionGroup")
                {
                    info = new SectionGroupInfo();
                }
                else
                {
                    ThrowException(APResource.GetString(APResource.APGen_UnrecognizedElement, reader.Name), reader);
                }


                info.ReadGen(gen, streamName, reader);
                GenInfo actInfo = Groups[info.Name];
                if (actInfo == null)
                {
                    actInfo = Sections[info.Name];
                }

                if (actInfo != null)
                {
                    if (actInfo.GetType() != info.GetType())
                    {
                        ThrowException(APResource.GetString(APResource.APGen_SectionNameAlreadyExists, info.Name), reader);
                    }

                    actInfo.StreamName = streamName;
                }
                else
                {
                    AddChild(info);
                }
            }

            reader.ReadEndElement();
        }
Exemple #22
0
 /// <summary>
 /// Gets a APRptFilterParseException by InvalidValue.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="toType">Type of converted.</param>
 /// <param name="innerException">Inner exception.</param>
 /// <returns>APRptFilterParseException.</returns>
 public static APRptFilterParseException InvalidValue(string value, Type toType, Exception innerException)
 {
     return(new APRptFilterParseException(APResource.GetString(APResource.APRptFilter_InvalidValue, value, toType), innerException));
 }
Exemple #23
0
        /// <summary>
        /// Build SQL 'WHERE' phrase.
        /// </summary>
        /// <returns>The APSqlWherePhrase.</returns>
        public virtual APSqlWherePhrase BuildCondition()
        {
            if (_filters.Count == 0)
            {
                return(null);
            }

            string rpnCode = _def.Rpn;


            // If RPN expression is empty, return 'AND' of all filter.
            if (rpnCode == "")
            {
                List <APSqlWherePhrase> list = new List <APSqlWherePhrase>();

                foreach (var filter in _filters.Values)
                {
                    list.Add(filter.ParseQueryWherePhrase());
                }

                return(new APSqlConditionAndPhrase(list));
            }

            // Has RPN expression, build.

            Stack <APSqlWherePhrase> stack = new Stack <APSqlWherePhrase>();
            APSqlWherePhrase         left, right;

            foreach (string token in rpnCode.Split(' '))
            {
                if (token == "&")
                {
                    right = stack.Pop();
                    left  = stack.Pop();
                    stack.Push(new APSqlConditionAndPhrase(left, right));
                }
                else if (token == "|")
                {
                    right = stack.Pop();
                    left  = stack.Pop();
                    stack.Push(new APSqlConditionOrPhrase(left, right));
                }
                else if (token == "!")
                {
                    right       = stack.Pop();
                    right.IsNot = !right.IsNot;
                    stack.Push(right);
                }
                else
                {
                    if (_filters.ContainsKey(token))
                    {
                        stack.Push(_filters[token].ParseQueryWherePhrase());
                    }
                    else
                    {
                        throw new APRptConditionParseException(APResource.GetString(APResource.APRptFilter_LogicSerialNotFound, token));
                    }
                }
            }

            return(stack.Pop());
        }
Exemple #24
0
 /// <summary>
 /// Throw an exception indicate connection string not found.
 /// </summary>
 /// <param name="connectionStringName">Connection string name.</param>
 protected virtual void ThrowConnectionStringNotFound(string connectionStringName)
 {
     throw new ProviderException(APResource.GetString(APResource.APProvider_ConnectionStringNotFound, connectionStringName));
 }
Exemple #25
0
 /// <summary>
 /// Throw an exception indicate parsed type not implemented.
 /// </summary>
 /// <param name="type">DbType.</param>
 protected virtual void ThrowColumnParsedTypeNotImplemented(DbType type)
 {
     throw new NotSupportedException(APResource.GetString(APResource.APDal_ColumnParsedTypeNotImplemented, type.ToString()));
 }
Exemple #26
0
 /// <summary>
 /// Throw an exception indicate unsupport.
 /// </summary>
 /// <param name="message">The message.</param>
 protected virtual void ThrowDBUnsupport(string message)
 {
     throw new NotSupportedException(APResource.GetString(APResource.APDal_DBUnsupport, message));
 }
Exemple #27
0
        public RptUnit Parser(bool needParens)
        {
            int     token;
            RptUnit rpnUnit = null, cur;
            bool    meedParens = false;


            while ((token = _lexer.GetToken()) != Token.EOF)
            {
                cur = null;

                if (token == Token.INTEGER)
                {
                    int number = (int)_lexer.CurrentValue;

                    if (_checkIdentifier != null && !_checkIdentifier(number))
                    {
                        throw new APRptConditionParseException(APResource.GetString(APResource.APRptFilter_LogicIdentifierInvalidate, number));
                    }

                    cur = new OperandRpnUnit(number.ToString());
                }
                else if (token == Token.IDENTIFIER)
                {
                    string identifier = (string)_lexer.CurrentValue;

                    if (_checkIdentifier != null && !_checkIdentifier(identifier))
                    {
                        throw new APRptConditionParseException(APResource.GetString(APResource.APRptFilter_LogicIdentifierInvalidate, identifier));
                    }

                    cur = new OperandRpnUnit(identifier);
                }
                else if (token == Token.BITWISE_AND || token == Token.BITWISE_OR)
                {
                    if (rpnUnit == null || IsUncompletedRpnUnit(rpnUnit))
                    {
                        throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
                    }

                    cur = new BinaryRpnUnit(rpnUnit, token == Token.BITWISE_AND ? RpnOperator.AND : RpnOperator.OR);

                    rpnUnit = null;
                }
                else if (token == Token.LOGIC_NOT)
                {
                    if (rpnUnit != null && !IsUncompletedRpnUnit(rpnUnit))
                    {
                        throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
                    }

                    cur = new UnaryNotRpnUnit();
                }
                else if (token == Token.OPEN_PARENS)
                {
                    cur = Parser(true);
                }
                else if (token == Token.CLOSE_PARENS)
                {
                    meedParens = true;

                    if (!needParens)
                    {
                        throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
                    }

                    break;
                }
                else
                {
                    throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
                }

                if (cur == null)
                {
                    throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
                }

                if (rpnUnit == null)
                {
                    rpnUnit = cur;
                }
                else if (IsUncompletedRpnUnit(rpnUnit))
                {
                    (rpnUnit as IRightRpnUnit).SetRight(cur);
                }
                else
                {
                    throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
                }
            }

            if (needParens && !meedParens)
            {
                throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
            }

            if (IsUncompletedRpnUnit(rpnUnit))
            {
                throw new APRptConditionParseException(APResource.APRptFilter_LogicExpressionInvalidate);
            }

            return(rpnUnit);
        }
Exemple #28
0
        /// <summary>
        /// Reads XML from the configuration file.
        /// </summary>
        /// <param name="reader">The XmlReader that reads from the configuration file.</param>
        /// <param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param>
        protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            Hashtable readProps = new Hashtable();

            reader.MoveToContent();

            while (reader.MoveToNextAttribute())
            {
                APGenPropertyInformation prop = ElementInformation.Properties[reader.LocalName];
                if (prop == null || (serializeCollectionKey && !prop.IsKey))
                {
                    if (reader.LocalName == "xmlns")
                    {
                        // Ignore
                    }
                    else
                    {
                        if (!OnDeserializeUnrecognizedAttribute(reader.LocalName, reader.Value))
                            throw new APGenException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, reader.LocalName), reader);
                    }

                    continue;
                }

                if (readProps.ContainsKey(prop))
                    throw new APGenException(APResource.GetString(APResource.APGen_DuplicateAttribute, prop.Name), reader);

                string value = null;
                try
                {
                    value = reader.Value;
                    ValidateValue(prop.Property, value);
                    prop.SetStringValue(value);
                }
                catch (APGenException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new APGenException(APResource.GetString(APResource.APGen_PropertyCannotBeParsed, prop.Name), ex, reader);
                }
                readProps[prop] = prop.Name;
            }

            reader.MoveToElement();

            if (reader.IsEmptyElement)
            {
                reader.Skip();
            }
            else
            {
                int depth = reader.Depth;

                reader.ReadStartElement();
                reader.MoveToContent();

                do
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        reader.Skip();
                        continue;
                    }

                    APGenPropertyInformation prop = ElementInformation.Properties[reader.LocalName];
                    if (prop == null || (serializeCollectionKey && !prop.IsKey))
                    {
                        if (!OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                        {
                            if (prop == null)
                            {
                                APGenElementCollection collection = GetDefaultCollection();
                                if (collection != null && collection.OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                                    continue;
                            }
                            throw new APGenException(APResource.GetString(APResource.APGen_UnrecognizedElement, reader.LocalName), reader);
                        }
                        continue;
                    }

                    if (!prop.IsElement)
                        throw new APGenException(APResource.GetString(APResource.APGen_NotElement, prop.Name), reader);

                    if (readProps.Contains(prop))
                        throw new APGenException(APResource.GetString(APResource.APGen_DuplicateElement, prop.Name), reader);

                    APGenElement val = prop.Value as APGenElement;
                    val.DeserializeElement(reader, serializeCollectionKey);
                    readProps[prop] = prop.Name;
                } while (depth < reader.Depth);

                if (reader.NodeType == XmlNodeType.EndElement)
                    reader.Read();
            }

            foreach (APGenPropertyInformation prop in ElementInformation.Properties)
            {
                if (!String.IsNullOrEmpty(prop.Name) && prop.IsRequired && !readProps.ContainsKey(prop))
                {
                    APGenPropertyInformation property = ElementInformation.Properties[prop.Name];
                    if (property == null)
                    {
                        object val = OnRequiredPropertyNotFound(prop.Name);
                        if (!object.Equals(val, prop.DefaultValue))
                            prop.Value = val;
                    }
                }
            }

            PostDeserialize();
        }
Exemple #29
0
 /// <summary>
 /// Throws an exception when a required property is not found.
 /// </summary>
 /// <param name="name">The name of the required attribute that was not found.</param>
 /// <returns>None.</returns>
 protected virtual object OnRequiredPropertyNotFound(string name)
 {
     throw new APGenException(APResource.GetString(APResource.APGen_RequiredAttribute, name));
 }
Exemple #30
0
 /// <summary>
 /// Generate code.
 /// </summary>
 /// <param name="gen">The specified APGen object.</param>
 public virtual void Generate(APGen gen)
 {
     gen.GetCodeNamespace(gen.DefaultNamespace)
     .Comments
     .Add(Comment(APResource.GetString(APResource.APGen_DefaultGenerated, GetType().FullName)));
 }