Ejemplo n.º 1
0
 public object valueFromEncodedString(string source, ClassicEncodingSettings settings, bool validate)
 {
     return
         (source.Equals(settings.isUseVisibleSeparators() ? DataTableUtils.DATA_TABLE_VISIBLE_NULL : DataTableUtils.DATA_TABLE_NULL)
             ? (object)null
             : (this.valueFromString(this.isTransferEncode() ? DataTableUtils.transferDecode(source) : source, settings, validate)));
 }
Ejemplo n.º 2
0
        public TableFormat(string format, ClassicEncodingSettings settings, bool validate)
        {
            if (format == null)
            {
                return;
            }

            var els = StringUtils.elements(format, settings.isUseVisibleSeparators());

            foreach (var el in els)
            {
                if (el.getName() == null)
                {
                    fields.Add(FieldFormat.create(el.getValue(), settings, validate));
                    continue;
                }
                if (el.getName().Equals(ELEMENT_FLAGS))
                {
                    var flags = el.getValue();
                    setReorderable(flags.IndexOf(REORDERABLE_FLAG) != -1 ? true : false);
                    setBindingsEditable(flags.IndexOf(BINDINGS_EDITABLE_FLAG) != -1 ? true : false);
                    continue;
                }
                if (el.getName().Equals(ELEMENT_MIN_RECORDS))
                {
                    minRecords = Int32.Parse(el.getValue());
                    continue;
                }
                if (el.getName().Equals(ELEMENT_MAX_RECORDS))
                {
                    maxRecords = Int32.Parse(el.getValue());
                    continue;
                }
                if (el.getName().Equals(ELEMENT_TABLE_VALIDATORS))
                {
                    createTableValidators(el.getValue(), settings);
                    continue;
                }
                if (el.getName().Equals(ELEMENT_RECORD_VALIDATORS))
                {
                    createRecordValidators(el.getValue(), settings);
                    continue;
                }
                if (el.getName().Equals(ELEMENT_BINDINGS))
                {
                    continue;
                }
                if (el.getName().Equals(ELEMENT_NAMING))
                {
                    createNaming(el.getValue());
                    continue;
                }
            }
        }
Ejemplo n.º 3
0
        private void setData(string dataString, ClassicEncodingSettings settings, Boolean validate,
                             IList <string> fieldNamesInData)
        {
            var recs = StringUtils.elements(dataString, settings.isUseVisibleSeparators());

            var i = 0;

            foreach (var el in recs)
            {
                if (el.getName() != null)
                {
                    if (el.getName().Equals(ELEMENT_ID))
                    {
                        setId(el.getValue());
                    }
                    else
                    {
                        // This code exists for compatibility reason only
                        var ff = format.getFieldFormat(el.getName());
                        if (ff != null)
                        {
                            setValue(el.getName(), ff.valueFromEncodedString(el.getValue(), settings, validate),
                                     validate);
                        }
                    }
                }
                else
                {
                    if (fieldNamesInData != null && fieldNamesInData.Count > i)
                    {
                        var fieldName = fieldNamesInData[i];
                        if (getFormat().hasField(fieldName))
                        {
                            var value = format.getFieldFormat(fieldName).valueFromEncodedString(el.getValue(), settings, validate);
                            setValue(fieldName, value, validate);
                        }
                    }
                    else if (i < format.getFieldCount())
                    {
                        var value = format.getFieldFormat(i).valueFromEncodedString(el.getValue(), settings, validate);
                        setValue(i, value, validate);
                    }
                    i++;
                }
            }
        }
Ejemplo n.º 4
0
        public StringBuilder valueToEncodedString(object value, ClassicEncodingSettings settings, StringBuilder sb, int?encodeLevel)
        {
            string strVal = this.valueToString(value, settings);

            if (strVal == null)
            {
                return((settings == null || !settings.isUseVisibleSeparators()) ? sb.Append(DataTableUtils.DATA_TABLE_NULL) : sb.Append(DataTableUtils.DATA_TABLE_VISIBLE_NULL));
            }

            if (this.isTransferEncode())
            {
                TransferEncodingHelper.encode(strVal, sb, encodeLevel);
            }
            else
            {
                sb.Append(strVal);
            }

            return(sb);
        }
Ejemplo n.º 5
0
        private void createRecordValidators(string source, ClassicEncodingSettings settings)
        {
            if (string.IsNullOrEmpty(source))
            {
                return;
            }

            var validatorsData = StringUtils.elements(source, settings.isUseVisibleSeparators());

            foreach (var el in validatorsData)
            {
                var validatorType = el.getName()[0];

                switch (validatorType)
                {
                case RECORD_VALIDATOR_KEY_FIELDS:
                    addRecordValidator(new KeyFieldsValidator());
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        public DataTable(TableFormat format, string dataString, ClassicEncodingSettings settings)
        {
            if (dataString == null)
            {
                throw new NullReferenceException("Data string is null");
            }

            this.setFormat(format);

            List <string> fieldNames = null;
            bool          flag       = false;

            if (settings != null)
            {
                flag = settings.isUseVisibleSeparators();
            }

            var recs = StringUtils.elements(dataString, flag);

            foreach (var el in recs)
            {
                if (el.getName().Equals(ELEMENT_FIELD_NAME))
                {
                    if (fieldNames == null)
                    {
                        fieldNames = new List <string>();
                    }
                    fieldNames.Add(el.getValue());
                }
                else if (el.getName() != null && el.getName().Equals(ELEMENT_RECORD))
                {
                    this.addRecord(new DataRecord(this.getFormat(), el.getValue(), settings, true, fieldNames));
                }
                else
                {
                    this.decodeAdvancedElement(el);
                }
            }
        }
Ejemplo n.º 7
0
        protected void createSelectionValues(string source, ClassicEncodingSettings settings)
        {
            if (source.Length == 0)
            {
                return;
            }

            var values = new AgDictionary <NullableObject, string>();

            var els = StringUtils.elements(source, settings.isUseVisibleSeparators());

            foreach (var el in els)
            {
                var valueSource = el.getValue();

                NullableObject selectionValue = new NullableObject(this.valueFromEncodedString(valueSource, settings, true));
                var            desc           = el.getName() ?? selectionValue.ToString();
                values[selectionValue] = desc;
            }

            this.setSelectionValues(values.Count > 0 ? values : null);
        }
Ejemplo n.º 8
0
        private void createValidators(string source, ClassicEncodingSettings settings)
        {
            if (string.IsNullOrEmpty(source))
            {
                return;
            }

            var validatorsData = StringUtils.elements(source, settings.isUseVisibleSeparators());

            foreach (var el in validatorsData)
            {
                var validatorType   = el.getName()[0];
                var validatorParams = el.getValue();

                switch (validatorType)
                {
                case VALIDATOR_LIMITS:
                    this.addValidator(new LimitsValidator(this, validatorParams));
                    break;

                case VALIDATOR_REGEX:
                    this.addValidator(new RegexValidator(validatorParams));
                    break;

                    //case VALIDATOR_NON_NULL:
                    //    addValidator(new NonNullValidator(validatorParams));
                    //    break;
                    //
                    //case VALIDATOR_ID:
                    //    addValidator(new IdValidator());
                    //    break;
                    //
                    //case VALIDATOR_EXPRESSION:
                    //    addValidator(new ExpressionValidator(validatorParams));
                    //    break;
                }
            }
        }
Ejemplo n.º 9
0
        public DataTable(string data, ClassicEncodingSettings settings, bool validate)
        {
            if (data == null)
            {
                return;
            }

            var           found         = false;
            string        encodedFormat = null;
            List <string> fieldNames    = null;

            bool flag = false;

            if (settings != null)
            {
                flag = settings.isUseVisibleSeparators();
            }

            var recs = StringUtils.elements(data, flag);

            foreach (var el in recs)
            {
                if (el.getName() == null)
                {
                    continue;
                }

                if (el.getName().Equals(ELEMENT_FORMAT_ID))
                {
                    var formatId = int.Parse(el.getValue());

                    if (settings == null || settings.getFormatCache() == null)
                    {
                        throw new InvalidOperationException("Can't use format ID - format cache not found");
                    }

                    if (encodedFormat != null)
                    {
                        // If format was already found in the encoded data
                        var newFormat1 = new TableFormat(encodedFormat, settings, validate);
                        settings.getFormatCache().put(formatId, newFormat1);
                        continue;
                    }

                    var newFormat = settings.getFormatCache().get(formatId);

                    // encodedFormat = settings.getFormatCache().get(formatId);
                    if (newFormat == null)
                    {
                        throw new InvalidOperationException(
                                  "Format with specified ID not found in the cache: " + formatId);
                    }

                    this.setFormat(newFormat);
                    found = true;
                    continue;
                }

                if (el.getName().Equals(ELEMENT_FORMAT))
                {
                    encodedFormat = el.getValue();
                    setFormat(new TableFormat(encodedFormat, settings, validate));
                    found = true;
                    continue;
                }

                if (el.getName().Equals(ELEMENT_RECORD))
                {
                    // Using table's format if encodedFormat is not NULL (i.e. was found in the encoded data)
                    var fmt = found ? this.getFormat() : (settings != null ? settings.getFormat() : null);

                    if (fmt == null)
                    {
                        throw new InvalidOperationException(
                                  "Table format is neither found in encoded table nor provided by decoding environment");
                    }

                    addRecord(new DataRecord(fmt, el.getValue(), settings, validate, fieldNames));
                    continue;
                }

                if (el.getName().Equals(ELEMENT_FIELD_NAME))
                {
                    if (fieldNames == null)
                    {
                        fieldNames = new List <string>();
                    }
                    fieldNames.Add(el.getValue());
                    continue;
                }

                if (el.getName().Equals(ELEMENT_TIMESTAMP))
                {
                    var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    this.timestamp = epoch.AddSeconds(Convert.ToDouble(el.getValue()) / 1000).AddMilliseconds(Convert.ToDouble(el.getValue()) % 1000);
                    continue;
                }

                if (el.getName().Equals(ELEMENT_QUALITY))
                {
                    this.quality = Convert.ToInt32(el.getValue());
                    continue;
                }

                if (el.getName().Equals(ELEMENT_INVALIDATOR))
                {
                    this.invalidationMessage = el.getValue();
                }
            }
        }
Ejemplo n.º 10
0
        public static FieldFormat create(string format, ClassicEncodingSettings settings, bool validate)
        {
            var els = StringUtils.elements(format, settings.isUseVisibleSeparators());

            string name;
            char   type;

            try
            {
                name = els[0].getValue();
                type = els[1].getValue()[0];
            }
            catch (IndexOutOfRangeException ex1)
            {
                throw new ArgumentException(ex1.Message + ", format was '" + format + "'", ex1);
            }

            var ff = create(name, type);

            //if (validate)
            //{
            //    ff.validateName();
            //}

            var el = els.getElement(ELEMENT_FLAGS);

            if (el != null)
            {
                var flags = el.getValue();
                ff.setNullable(flags.IndexOf(NULLABLE_FLAG) != -1 ? true : false);
                ff.setOptional(flags.IndexOf(OPTIONAL_FLAG) != -1 ? true : false);
                ff.setExtendableSelectionValues(flags.IndexOf(EXTENDABLE_SELECTION_VALUES_FLAG) != -1 ? true : false);
                ff.setReadonly(flags.IndexOf(READ_ONLY_FLAG) != -1 ? true : false);
                ff.setNotReplicated(flags.IndexOf(NOT_REPLICATED_FLAG) != -1 ? true : false);
                ff.setHidden(flags.IndexOf(HIDDEN_FLAG) != -1 ? true : false);
                ff.setKeyField(flags.IndexOf(KEY_FIELD_FLAG) != -1 ? true : false);
                ff.setDefaultOverride(flags.IndexOf(DEFAULT_OVERRIDE) != -1 ? true : false);
                ff.setInlineData(flags.IndexOf(INLINE_DATA_FLAG) != -1 ? true : false);
            }

            el = els.getElement(ELEMENT_DEFAULT_VALUE);

            if (el != null)
            {
                ff.setDefaultFromString(el.getValue(), settings, validate);
            }

            el = els.getElement(ELEMENT_DESCRIPTION);

            if (el != null)
            {
                ff.setDescription(el.getValue());
            }

            el = els.getElement(ELEMENT_HELP);

            if (el != null)
            {
                ff.setHelp(el.getValue());
            }

            el = els.getElement(ELEMENT_SELECTION_VALUES);

            if (el != null)
            {
                ff.createSelectionValues(el.getValue(), settings);
            }

            el = els.getElement(ELEMENT_VALIDATORS);

            if (el != null)
            {
                ff.createValidators(el.getValue(), settings);
            }

            el = els.getElement(ELEMENT_EDITOR);

            if (el != null)
            {
                ff.setEditor(el.getValue());
            }

            el = els.getElement(ELEMENT_EDITOR_OPTIONS);

            if (el != null)
            {
                ff.setEditorOptions(el.getValue());
            }

            el = els.getElement(ELEMENT_ICON);

            if (el != null)
            {
                ff.setIcon(el.getValue());
            }

            return(ff);
        }