示例#1
0
        public string encode(ClassicEncodingSettings settings)
        {
            StringBuilder data = new StringBuilder();

            new Element(null, this.getName()).encode(data, settings);
            new Element(null, this.getType().ToString()).encode(data, settings);

            encAppend(data, ELEMENT_FLAGS, this.getEncodedFlags(), settings);

            if (settings.isEncodeDefaultValues())
            {
                new Element(ELEMENT_DEFAULT_VALUE, this.valueToEncodedString(this.getDefaultValue(), settings)).encode(data, settings);
            }

            encAppend(data, ELEMENT_DESCRIPTION, DataTableUtils.transferEncode(this.description), settings);
            encAppend(data, ELEMENT_HELP, DataTableUtils.transferEncode(this.help), settings);
            encAppend(data, ELEMENT_SELECTION_VALUES, this.getEncodedSelectionValues(settings), settings);
            encAppend(data, ELEMENT_VALIDATORS, this.getEncodedValidators(settings), settings);
            encAppend(data, ELEMENT_EDITOR, DataTableUtils.transferEncode(this.editor), settings);
            encAppend(data, ELEMENT_EDITOR_OPTIONS, DataTableUtils.transferEncode(this.editorOptions), settings, true);
            encAppend(data, ELEMENT_ICON, DataTableUtils.transferEncode(this.icon), settings);
            encAppend(data, ELEMENT_GROUP, DataTableUtils.transferEncode(this.group), settings);

            return(data.ToString());
        }
示例#2
0
        public StringBuilder getEncodedData(StringBuilder finalSB, ClassicEncodingSettings settings, Boolean isTransferEncode, int encodeLevel)
        {
            bool encodeFieldNames = (settings != null) ? settings.isEncodeFieldNames() : true;

            if (encodeFieldNames)
            {
                for (int i = 0; i < format.getFieldCount(); i++)
                {
                    new Element(ELEMENT_FIELD_NAME, format.getField(i).getName()).encode(finalSB, settings, isTransferEncode, encodeLevel);
                }
            }

            for (int i = 0; i < getRecordCount(); i++)
            {
                new Element(ELEMENT_RECORD, getRecord(i)).encode(finalSB, settings, isTransferEncode, encodeLevel);
            }


            if (quality != null)
            {
                new Element(ELEMENT_QUALITY, quality.ToString()).encode(finalSB, settings, isTransferEncode, encodeLevel);
            }

            if (timestamp != null)
            {
                new Element(ELEMENT_TIMESTAMP, ((DateTime)this.timestamp).ToString(DateFieldFormat.FORMAT)).encode(finalSB, settings, isTransferEncode, encodeLevel);
            }

            return(finalSB);
        }
示例#3
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)));
 }
示例#4
0
        public string encode(ClassicEncodingSettings settings, Boolean isTransferEncode, int encodeLevel)
        {
            StringBuilder formatString = new StringBuilder(getFieldCount() * 7);

            encode(formatString, settings, isTransferEncode, encodeLevel);

            return(formatString.ToString());
        }
示例#5
0
        public void setDefaultFromString(string value, ClassicEncodingSettings settings, bool validate)
        {
            if (value.Length == 0)
            {
                return;
            }

            // Overriding validate flag here, as default value may contain non-valid table
            this.setDefault(this.valueFromEncodedString(value, settings, false));
        }
示例#6
0
        private string getEncodedBindings(ClassicEncodingSettings settings)
        {
            StringBuilder enc = new StringBuilder();

            foreach (Binding bin in bindings)
            {
                enc.Append(new Element(bin.getTarget().getImage(), bin.getExpression().getText()).encode(settings));
            }

            return(enc.ToString());
        }
示例#7
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;
                }
            }
        }
示例#8
0
        private string getEncodedRecordValidators(ClassicEncodingSettings settings)
        {
            var enc = new StringBuilder();

            foreach (var rv in recordValidators)
            {
                if (rv.getType() != null)
                {
                    enc.Append(
                        new Element(rv.getType().ToString(), rv.encode()).encode(settings));
                }
            }

            return(enc.ToString());
        }
示例#9
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++;
                }
            }
        }
示例#10
0
        private string getEncodedSelectionValues(ClassicEncodingSettings settings)
        {
            if (this.selectionValues == null)
            {
                return(null);
            }

            var enc = new StringBuilder();

            foreach (var value in this.selectionValues)
            {
                var valueDesc = value.Value;
                enc.Append(new Element(valueDesc, this.valueToEncodedString(value.Key.Value, settings)).encode(settings));
            }

            return(enc.ToString());
        }
示例#11
0
        public StringBuilder encode(StringBuilder sb, ClassicEncodingSettings settings, Boolean isTransferEncode, int encodeLevel)
        {
            if (getId() != null)
            {
                new Element(ELEMENT_ID, getId()).encode(sb, settings, isTransferEncode, encodeLevel);
            }

            for (int i = 0; i < format.getFieldCount(); i++)
            {
                FieldFormat ff = format.getField(i);

                Object value = getValue(ff);

                new Element(null, ff, value).encode(sb, settings, isTransferEncode, encodeLevel);
            }

            return(sb);
        }
示例#12
0
        private string getEncodedValidators(ClassicEncodingSettings settings)
        {
            if (this.validators.Count == 0)
            {
                return(null);
            }

            var enc = new StringBuilder();

            foreach (var fv in this.validators)
            {
                if (fv.getType() != null)
                {
                    enc.Append(new Element(fv.getType().ToString(), fv.encode()).encode(settings));
                }
            }

            return(enc.ToString());
        }
示例#13
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);
        }
示例#14
0
        public StringBuilder encode(StringBuilder builder, ClassicEncodingSettings settings, Boolean isTransferEncode, int encodeLevel)
        {
            for (int i = 0; i < fields.Count; i++)
            {
                new Element(null, getField(i).encode(settings)).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            if (minRecords != DEFAULT_MIN_RECORDS)
            {
                new Element(ELEMENT_MIN_RECORDS, minRecords.ToString()).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            if (maxRecords != DEFAULT_MAX_RECORDS)
            {
                new Element(ELEMENT_MAX_RECORDS, maxRecords.ToString()).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            if (tableValidators.Count > 0)
            {
                new Element(ELEMENT_TABLE_VALIDATORS, getEncodedTableValidators(settings)).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            if (recordValidators.Count > 0)
            {
                new Element(ELEMENT_RECORD_VALIDATORS, getEncodedRecordValidators(settings)).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            if (bindings.Count > 0)
            {
                new Element(ELEMENT_BINDINGS, getEncodedBindings(settings)).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            if (namingExpression != null)
            {
                new Element(ELEMENT_NAMING, namingExpression == null ? "" : namingExpression.getText()).encode(builder, settings, isTransferEncode, encodeLevel);
            }

            encAppend(builder, ELEMENT_FLAGS, getEncodedFlags(), settings);

            return(builder);
        }
示例#15
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;
                }
            }
        }
示例#16
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);
                }
            }
        }
示例#17
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);
        }
示例#18
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;
                }
            }
        }
示例#19
0
 public string valueToEncodedString(object value, ClassicEncodingSettings settings)
 {
     return(this.valueToEncodedString(value, settings, new StringBuilder(), 1).ToString());
 }
示例#20
0
 public String getEncodedData(ClassicEncodingSettings settings)
 {
     return(this.getEncodedData(new StringBuilder(), settings, false, 0).ToString());
 }
示例#21
0
        public StringBuilder encode(StringBuilder finalSB, ClassicEncodingSettings settings, bool isTransferEncode, int encodeLevel)
        {
            if (finalSB.Length + this.getEstimateDataSize() > finalSB.Capacity)
            {
                finalSB.EnsureCapacity(finalSB.Capacity + getEstimateDataSize());
            }

            int?formatId = null;

            bool formatWasInserted = false;

            bool needToInsertFormat = settings != null && settings.isEncodeFormat();

            bool isKnown = false;

            KnownFormatCollector collector = settings != null?settings.getKnownFormatCollector() : null;


            if (needToInsertFormat)
            {
                if (this.getFormat().getFieldCount() > 0 && settings.getFormatCache() != null)
                {
                    formatId = settings.getFormatCache().addIfNotExists(this.getFormat());

                    if (collector != null)
                    {
                        needToInsertFormat = false;

                        if (collector.isKnown(formatId) && collector.isMarked(formatId))
                        {
                            // Format is known - inserting ID only
                            new Element(ELEMENT_FORMAT_ID, formatId.ToString()).encode(finalSB, settings, isTransferEncode, encodeLevel);

                            isKnown = true;
                        }
                        else
                        {
                            var oldEncodeFormat = settings.isEncodeFormat();
                            settings.setEncodeFormat(true);

                            try
                            {
                                // Format is not known - inserting both format and ID
                                new Element(ELEMENT_FORMAT, this.getFormat()).encode(finalSB, settings, isTransferEncode, encodeLevel);
                                new Element(ELEMENT_FORMAT_ID, formatId.ToString()).encode(finalSB, settings, isTransferEncode, encodeLevel);

                                formatWasInserted = true;
                            }
                            finally
                            {
                                settings.setEncodeFormat((bool)oldEncodeFormat);
                            }
                        }
                    }
                }

                if (needToInsertFormat)
                {
                    var oldEncodeFormat = settings.isEncodeFormat();
                    settings.setEncodeFormat(true);
                    try
                    {
                        new Element(ELEMENT_FORMAT, this.getFormat()).encode(finalSB, settings, isTransferEncode, encodeLevel);

                        formatWasInserted = true;
                    }
                    finally
                    {
                        settings.setEncodeFormat((bool)oldEncodeFormat);
                    }
                }
            }

            bool?oldEncodeFormat1 = null;

            if (settings != null)
            {
                oldEncodeFormat1 = settings.isEncodeFormat();
            }
            try
            {
                if (formatWasInserted)
                {
                    settings.setEncodeFormat(false);
                }

                this.getEncodedData(finalSB, settings, isTransferEncode, encodeLevel + 1);
            }
            finally
            {
                if (oldEncodeFormat1 != null)
                {
                    settings.setEncodeFormat((bool)oldEncodeFormat1);
                }
            }

            if (isInvalid())
            {
                new Element(ELEMENT_FORMAT, this.invalidationMessage).encode(finalSB, settings, isTransferEncode, encodeLevel);
            }


            if (!isKnown && formatId != null && collector != null)
            {
                // Marking format as known
                collector.makeKnown((int)formatId, true);
            }

            return(finalSB);
        }
示例#22
0
 public string encode(ClassicEncodingSettings settings)
 {
     return(encode(new StringBuilder(getEstimateDataSize()), settings, false, 0).ToString());
 }
示例#23
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();
                }
            }
        }
示例#24
0
 private static void encAppend(StringBuilder buffer, string name, string value, ClassicEncodingSettings settings)
 {
     encAppend(buffer, name, value, settings, false);
 }
示例#25
0
 public DataRecord(TableFormat tableFormat, string dataString, ClassicEncodingSettings settings, bool validate,
                   IList <string> fieldNamesInData) : this(tableFormat)
 {
     setData(dataString, settings, validate, fieldNamesInData);
 }
示例#26
0
 private static void encAppend(StringBuilder buffer, string name, string value, ClassicEncodingSettings settings, bool allowEmptyString)
 {
     if (value != null && (allowEmptyString || value.Length > 0))
     {
         new Element(name, value).encode(buffer, settings, false, 0);
     }
 }
示例#27
0
 public string encode(ClassicEncodingSettings settings)
 {
     return(encode(new StringBuilder(), settings, false, 0).ToString());
 }
示例#28
0
 public TableFormat(string format, ClassicEncodingSettings settings)
     : this(format, settings, true)
 {
 }
示例#29
0
 public string encode(ClassicEncodingSettings settings)
 {
     return(encode(settings, false, 0));
 }
示例#30
0
 private static void encAppend(StringBuilder buffer, string name, string value, ClassicEncodingSettings settings)
 {
     if (!string.IsNullOrEmpty(value))
     {
         buffer.Append(new Element(name, value).encode(settings));
     }
 }