public override string valueToString(object value, ClassicEncodingSettings settings) { var nf = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); nf.NumberDecimalSeparator = "."; return(string.Format(nf, "{0}", value)); }
public void TestFirstEncoding() { TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, 12345.67f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(true); ces.setFormatCache(new FormatCache()); ces.setKnownFormatCollector(new KnownFormatCollector()); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); String encodedTable = table.encode(ces); String actual = "<F=<<variable><S><A=>><<value><T><A=<F=>>><<user><S><F=N><A=<NULL>>>" + "<M=1><X=1>><D=0><R=<test>" + "<<F=<<value><F><A=0>>" + "<<quality><I><A=0>><M=1><X=1>><D=1>" + "<R=<12345.67><123>>><<NULL>>>"; Assert.AreEqual(encodedTable, actual); }
public override string valueToString(object value, ClassicEncodingSettings settings) { if (value == null) { return(null); } var correctValue = (DataTable)value; var oldEncodeFormat = settings != null ? (bool?)settings.isEncodeFormat() : null; try { if (settings != null && (getDefaultValue() == null || ((DataTable)getDefaultValue()).getFieldCount() == 0 || !Util.equals(((DataTable)getDefaultValue()).getFormat(), correctValue.getFormat()))) { settings.setEncodeFormat(true); } return(correctValue.encode(settings)); } finally { if (oldEncodeFormat != null) { settings.setEncodeFormat((bool)oldEncodeFormat); } } }
public void EventDatatableEncoding() { TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, 12345.67f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(false); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); string encodedTable = table.encode(ces); // .encode(this.createClassicEncodingSettings(true)); //string expected = "<F=<<variable><S><A=>><<value><T><A=<F=>>><<user><S><F=N><A=<NULL>>>" // + "<M=1><X=1>><R=<test>" // + "<<F=<<value><F><A=0>>" // + "<<quality><I><A=0>><M=1><X=1>>" // + "<R=<12345.67><123>>><<NULL>>>"; string expected = "\\u001c\\u0046\\u001e\\u001c\\u001c\\u0076\\u0061\\u0072\\u0069\\u0061\\u0062\\u006c\\u0065\\u001d\\u001c\\u0053\\u001d\\u001c\\u0041\\u001e\\u001d\\u001d\\u001c\\u001c\\u0076\\u0061\\u006c\\u0075\\u0065\\u001d\\u001c\\u0054\\u001d\\u001c\\u0041\\u001e\\u001c\\u0046\\u001e\\u001d\\u001d\\u001d\\u001c\\u001c\\u0075\\u0073\\u0065\\u0072\\u001d\\u001c\\u0053\\u001d\\u001c\\u0046\\u001e\\u004e\\u001d\\u001c\\u0041\\u001e\\u001a\\u001d\\u001d\\u001c\\u004d\\u001e\\u0031\\u001d\\u001c\\u0058\\u001e\\u0031\\u001d\\u001d\\u001c\\u0052\\u001e\\u001c\\u0074\\u0065\\u0073\\u0074\\u001d\\u001c\\u001c\\u0046\\u001e\\u001c\\u001c\\u0076\\u0061\\u006c\\u0075\\u0065\\u001d\\u001c\\u0046\\u001d\\u001c\\u0041\\u001e\\u0030\\u001d\\u001d\\u001c\\u001c\\u0071\\u0075\\u0061\\u006c\\u0069\\u0074\\u0079\\u001d\\u001c\\u0049\\u001d\\u001c\\u0041\\u001e\\u0030\\u001d\\u001d\\u001c\\u004d\\u001e\\u0031\\u001d\\u001c\\u0058\\u001e\\u0031\\u001d\\u001d\\u001c\\u0052\\u001e\\u001c\\u0031\\u0032\\u0033\\u0034\\u0035\\u002e\\u0036\\u0037\\u001d\\u001c\\u0031\\u0032\\u0033\\u001d\\u001d\\u001d\\u001c\\u001a\\u001d\\u001d"; StringBuilder sb = new StringBuilder(); foreach (char c in encodedTable) { sb.Append("\\u"); sb.Append(string.Format("{0:x4}", (int)c)); } Assert.AreEqual(expected, sb.ToString()); }
public override object valueFromString(String value, ClassicEncodingSettings settings, Boolean validate) { var nf = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); nf.NumberDecimalSeparator = "."; return(float.Parse(value, nf)); }
public override object valueFromString(string value, ClassicEncodingSettings settings, bool validate) { if (value.StartsWith("#") && value.Length == 7) { var red = int.Parse(value.Substring(1, 3), NumberStyles.AllowHexSpecifier); var green = int.Parse(value.Substring(3, 5), NumberStyles.AllowHexSpecifier); var blue = int.Parse(value.Substring(5, 7), NumberStyles.AllowHexSpecifier); return(Color.FromArgb(red, green, blue)); } return(Color.FromArgb(int.Parse(value))); }
public override object valueFromString(String value, ClassicEncodingSettings settings, Boolean validate) { try { return(DateTime.Parse(value, dateFormatter)); } catch (Exception ex) { throw new ArgumentException("Error parsing date from string '" + value + "': " + ex.Message, ex); } }
public override object valueFromString(string value, ClassicEncodingSettings settings, bool validate) { try { return(long.Parse(value)); } catch (FormatException) { return((long)float.Parse(value)); } }
public ClassicEncodingSettings createClassicEncodingSettings(Boolean forSending) { var es = new ClassicEncodingSettings(false); if (!forSending) { es.setFormatCache(formatCache); } es.setEncodeFormat(!avoidSendingFormats); return(es); }
public override object valueFromString(String value, ClassicEncodingSettings settings, Boolean validate) { try { DataTable defaultValue = (DataTable)getDefaultValue(); bool? tempEncodeFieldNames = null; TableFormat oldFormat = null; if (settings != null) { oldFormat = settings.getFormat(); if (defaultValue != null) { settings.setFormat(defaultValue.getFormat()); } tempEncodeFieldNames = settings.isEncodeFieldNames(); } else { settings = new ClassicEncodingSettings(false); tempEncodeFieldNames = false; } try { DataTable res = value != null ? new DataTable(value, settings, validate) : null; // TODO: add data replication and validation // if (defaultValue != null && defaultValue.getFieldCount() > 0 && !res.getFormat().extend(defaultValue.getFormat())) // { // DataTable newRes = (DataTable) defaultValue.Clone(); // DataTableReplication.copy(res, newRes, true, true, true); // } // if (res != null && validate) // { // res.validate(null, null, null); // } return(res); } finally { settings.setFormat(oldFormat); settings.setEncodeFieldNames((bool)tempEncodeFieldNames); } } catch (Exception ex) { throw new ArgumentException("Error constructing value of field '" + ToString() + "': " + ex.Message, ex); } }
protected override ClassicEncodingSettings createClassicEncodingSettings(Boolean useFormatCache) { ClassicEncodingSettings settings = base.createClassicEncodingSettings(useFormatCache); if (useFormatCache) { settings.setFormatCache(formatCache); settings.setKnownFormatCollector(knownFormatCollector); } settings.setEncodeFormat(!useFormatCache); return(settings); }
public override object valueFromString(string value, ClassicEncodingSettings settings, bool validate) { //var longValue = Int64.Parse(value); //var byteArray = BitConverter.GetBytes(longValue); //var stream = new MemoryStream(byteArray); //var reader = new BinaryReader(stream); //return reader.ReadDouble(); var nf = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); nf.NumberDecimalSeparator = "."; return(double.Parse(value, nf)); }
public override string valueToString(object value, ClassicEncodingSettings settings) { //Double doubleValue = Convert.ToDouble(value); //byte[] bytes = new byte[8]; //var stream = new MemoryStream(bytes); //new BinaryWriter(stream).Write(doubleValue); //Int64 longValue = BitConverter.ToInt64(bytes, 0); //var stringValue = longValue.ToString(); //return stringValue; var nf = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); nf.NumberDecimalSeparator = "."; return(value == null ? null : String.Format(nf, "{0}", value)); }
public override object valueFromString(string value, ClassicEncodingSettings settings, bool validate) { if (value.Length == 0) { return(0); } try { return(int.Parse(value)); } catch (FormatException ex) { //return Util.convertToNumber(value, validate, false).intValue(); return((int)float.Parse(value)); } }
public StringBuilder encode(StringBuilder sb, ClassicEncodingSettings settings, bool isTransferEncode, int encodeLevel) { if (sb.Length + (estimateDataSize() * BUFFER_MULTIPLIER) > sb.Capacity) { sb.EnsureCapacity((int)(sb.Capacity + (estimateDataSize() * BUFFER_MULTIPLIER))); } StringBuilder tempSB = new StringBuilder(); tempSB.Append(TRANSCODER_VERSION.ToString()); tempSB.Append(SEPARATOR); tempSB.Append(getId() != null ? getId().ToString() : DataTableUtils.DATA_TABLE_NULL); tempSB.Append(SEPARATOR); tempSB.Append(getName() != null ? getName() : DataTableUtils.DATA_TABLE_NULL); tempSB.Append(SEPARATOR); tempSB.Append(getPreview() != null ? getPreview().Length.ToString() : "-1"); tempSB.Append(SEPARATOR); tempSB.Append(getData() != null ? getData().Length.ToString() : "-1"); tempSB.Append(SEPARATOR); if (isTransferEncode) { sb.Append(DataTableUtils.transferEncode(tempSB.ToString())); } else { sb.Append(tempSB); } appendBytes(sb, getPreview(), isTransferEncode, encodeLevel); appendBytes(sb, getData(), isTransferEncode, encodeLevel); return(sb); }
public void processOperationSetVar(String id, Context con, String name, String encodedValue, OutgoingAggreGateCommand ans) { var vd = con.getVariableDefinition(name); if (vd == null) { ans.constructReply(id, AggreGateCommand.REPLY_CODE_DENIED, Cres.get().getString("conVarNotAvail") + name); return; } var settings = new ClassicEncodingSettings(false, vd.getFormat()); var value = new DataTable(encodedValue, settings, true); con.setVariable(name, callerController, value); ans.constructReply(id, AggreGateCommand.REPLY_CODE_OK); }
public void processOperationCallFunction(String id, Context con, String name, String encodedParameters, OutgoingAggreGateCommand ans) { Logger.getLogger(Log.CLIENTS).debug("Calling function '" + name + "' of context '" + con.getPath() + "'"); var fd = con.getFunctionDefinition(name); if (fd == null) { ans.constructReply(id, AggreGateCommand.REPLY_CODE_DENIED, Cres.get().getString("conFuncNotAvail") + name); return; } var settings = new ClassicEncodingSettings(false, fd.getInputFormat()); var parameters = new DataTable(encodedParameters, settings, true); var result = con.callFunction(name, callerController, parameters); ans.constructReply(id, AggreGateCommand.REPLY_CODE_OK); ans.addParam(result.encode(createClassicEncodingSettings(fd.getOutputFormat() != null))); }
public override object valueFromString(string value, ClassicEncodingSettings settings, Boolean validate) { try { var data = new Data(); var parts = StringUtils.split(value, SEPARATOR, 5); if (!parts[1].Equals(DataTableUtils.DATA_TABLE_NULL)) { data.setId(Int64.Parse(parts[1])); } if (!parts[2].Equals(DataTableUtils.DATA_TABLE_NULL)) { data.setName(parts[2]); } var previewLen = Int32.Parse(parts[3]); if (previewLen != -1) { data.setPreview(StringUtils.ASCII_CHARSET.GetBytes(parts[5].Substring(0, previewLen))); } var dataLen = Int32.Parse(parts[4]); if (dataLen != -1) { data.setData(StringUtils.ASCII_CHARSET.GetBytes(parts[5].Substring(previewLen <= 0 ? 0 : previewLen))); } return(data); } catch (Exception ex) { throw new ArgumentException("Invalid data block: " + ex.Message, ex); } }
public void TestCachedEncoding() { TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, 12345.67f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(true); ces.setFormatCache(new FormatCache()); ces.setKnownFormatCollector(new KnownFormatCollector()); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); table.encode(ces); String encodedTable = table.encode(ces); String actual = "<D=0><R=<test><<D=0><R=<12345.67><123>>><<NULL>>>"; Assert.AreEqual(encodedTable, actual); }
public override string valueToString(object value, ClassicEncodingSettings settings) { return(((DateTime)value).ToString(FORMAT)); }
public override string valueToString(object value, ClassicEncodingSettings settings) { Data correctValue = (Data)value; return(correctValue.encode()); }
public override string valueToString(object value, ClassicEncodingSettings settings) { return((string)value); }
public override object valueFromString(string value, ClassicEncodingSettings settings, bool validate) { return(value); }
public override string valueToString(object value, ClassicEncodingSettings settings) { return(value == null ? null : value.ToString()); }
public StringBuilder encode(StringBuilder sb, ClassicEncodingSettings settings, bool isTransferEncode, int encodeLevel) { bool useVisibleSeparators = false; if (settings != null) { useVisibleSeparators = settings.isUseVisibleSeparators(); } char elStart = useVisibleSeparators ? DataTableUtils.ELEMENT_VISIBLE_START : DataTableUtils.ELEMENT_START; char elEnd = useVisibleSeparators ? DataTableUtils.ELEMENT_VISIBLE_END : DataTableUtils.ELEMENT_END; char elNameValSep = useVisibleSeparators ? DataTableUtils.ELEMENT_VISIBLE_NAME_VALUE_SEPARATOR : DataTableUtils.ELEMENT_NAME_VALUE_SEPARATOR; if (isTransferEncode) { TransferEncodingHelper.encodeChar(elStart, sb); if (name != null) { TransferEncodingHelper.encode(name, sb, 0); TransferEncodingHelper.encodeChar(elNameValSep, sb); } } else { sb.Append(elStart); if (name != null) { sb.Append(name); sb.Append(elNameValSep); } } if (encodable != null) { encodable.encode(sb, settings, isTransferEncode, encodeLevel); } else if (fieldFormat != null) { fieldFormat.valueToEncodedString(fieldValue, settings, sb, encodeLevel); } else { if (isTransferEncode) { TransferEncodingHelper.encode(value, sb, encodeLevel); } else { sb.Append(value); } } if (isTransferEncode) { TransferEncodingHelper.encodeChar(elEnd, sb); } else { sb.Append(elEnd); } return(sb); }
public StringBuilder encode(StringBuilder sb, ClassicEncodingSettings settings, int encodeLevel) { return(this.encode(sb, settings, false, encodeLevel)); }
public StringBuilder encode(StringBuilder sb, ClassicEncodingSettings settings) { return(this.encode(sb, settings, false, 0)); }
public String encode(ClassicEncodingSettings settings) { return(this.encode(new StringBuilder(), settings, false, 0).ToString()); }
public override string valueToString(object value, ClassicEncodingSettings settings) { var correctValue = (Color?)value; return(StringUtils.colorToString(correctValue)); }
static void Main() { try { Log.start(); TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.DATE_FIELD, "date"); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, DateTime.Now, 12345.67890f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(false); ces.setFormatCache(new FormatCache()); //ces.setKnownFormatCollector(new KnownFormatCollector()); ces.setKnownFormatCollector(new KnownFormatCollector()); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); int tablesPerTask = 10000; // Encoding //System.Threading.WaitCallback etask = new System.Threading.WaitCallback() Action etask = () => { for (int i = 0; i < tablesPerTask; i++) { table.encode(ces); } }; execute(tablesPerTask, etask); // Decoding // table.encode(ces); // First time format will be encoded into table, and we'd like to test decoding tables without format // // final String encoded = table.encode(ces); // // Callable dtask = new Callable() // { // @Override // public Object call() throws Exception // { // try // { // for (int i = 0; i < tablesPerTask; i++) // { // new DataTable(encoded, ces, true); // } // } // catch (Exception ex) // { // ex.printStackTrace(); // } // return null; // } // }; // // execute(tablesPerTask, dtask); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }