예제 #1
0
        /// <summary>Appends a field to an existing Formular, with extensive type checking.</summary>
        /// <param name="field">The field to be added</param>
        /// <param name="isRequired">A bool indicating if the registry should skip informing interested parties about this change.</param>
        /// <exception cref="DuplicateFieldException">This exception is thrown if a syntax error prevents the config to be parsed.</exception>
        /// <returns>success</returns>
        public bool Append(FormularFieldDescriptor field, bool isRequired)
        {
            if (!fields.ContainsKey(field.Name))
            {
                fields[field.Name] = field;
                field.IsRequired   = isRequired;
                return(true);
            }
            else
            {
                if (!fields[field.Name].Equals(field))
                {
                    throw new DuplicateFieldException("Cannot add new Field \"" + field.ToString() + "\" to Formular [" + this.Name + "]. Field is already defined as \"" + fields[field.Name].ToString() + "\".", field, fields[field.Name]);
                }

                fields[field.Name].IsRequired |= isRequired;
                return(true);
            }
        }
예제 #2
0
        /// <summary>Constructor, that uses a given message</summary>
        /// <param name="formularName">The name of the new Formular.</param>
        /// <param name="config">Comma separated Configuration string defining the Formular</param>
        public MessageFormular(string formularName, string config) : this()
        {
            if (string.IsNullOrWhiteSpace(formularName))
            {
                formularName = DYNAMIC;
            }
            this.Name = formularName.Trim();

            if (string.IsNullOrWhiteSpace(config))
            {
                return;                                    // nothing to do here. hand back empty Formular
            }
            string[] configArray = config.Trim().Split(',');

            foreach (string binConfig in configArray)
            {
                var field = new FormularFieldDescriptor(binConfig, true);
                fields[field.Name] = field;
            }
        }
예제 #3
0
 /// <summary>Checks if a field can be appended to an existing Formular, with extensive type checking.</summary>
 /// <param name="field">The field to be added</param>
 /// <returns>true, if possible to append</returns>
 public bool CanAppend(FormularFieldDescriptor field)
 {
     return(!fields.ContainsKey(field.Name) || fields[field.Name].Equals(field));
 }
예제 #4
0
 public DuplicateFieldException(string text, FormularFieldDescriptor fresh, FormularFieldDescriptor old) : base(text)
 {
     this.Fresh = fresh;
     this.Old   = old;
 }