public int addIfNotExists(TableFormat format) { var formatId = this.getId(format); if (formatId == null) { try { cacheLock.EnterWriteLock(); formatId = this.getId(format); if (formatId == null) { formatId = add(format); } } finally { cacheLock.ExitWriteLock(); } } return((int)formatId); }
public DataRecord(TableFormat tableFormat, params Object[] data) : this(tableFormat) { foreach (var param in data) { this.addValue(param); } }
public int add(TableFormat format) { cacheLock.EnterWriteLock(); try { if (format == null) { throw new ArgumentException("Format is NULL"); } int id = this.currentId++; this.addImpl(format, id); if (!format.isImmutable()) { Log.PROTOCOL_CACHING.warn("Cached mutable format as #" + id + ": " + format, new Exception()); } if (Log.PROTOCOL_CACHING.isDebugEnabled()) { Log.PROTOCOL_CACHING.debug("Cached format as #" + id + ": " + format); } return(id); } finally { cacheLock.ExitWriteLock(); } }
public TableFormat getCachedVersion(TableFormat format) { if (format == null) { return(null); } cacheLock.EnterReadLock(); try { int?id = getId(format); if (id == null) { return(format); } TableFormat result = this.cache.ContainsKey((int)id) ? cache[(int)id] : null; return(result); } finally { cacheLock.ExitReadLock(); } }
public static FieldFormat createTableField(string name, TableFormat format) { var ff = (DataTableFieldFormat)FieldFormat.create(name, FieldFormat.DATATABLE_FIELD); ff.setDefault(new DataTable(format, true)); return(ff); }
public DataTable(TableFormat format, int emptyRecords) : this(format) { for (var i = 0; i < emptyRecords; i++) { this.addRecord(); } }
public DataRecord(TableFormat tableFormat) { if (tableFormat != null) { tableFormat.makeImmutable(null); format = tableFormat; } }
// Note, that resulting checking is not checked for validity. Format of existing records may be incompartible with new format of table. public DataTable setFormat(TableFormat aTableFormat) { if (aTableFormat != null) { format.makeImmutable(this); this.format = aTableFormat; } return(this); }
public void cloneFormatFromTable() { if (table != null) { format = table.getFormat().Clone() as TableFormat; } else { throw new InvalidOperationException("Table not defined"); } }
private TableFormat addImpl(TableFormat format, int id) { // We consider all formats as immutable now. This can cause some bugs if we cache mutable formats if (this.useExternalIds && format.isImmutable()) { format.setId(id); } this.reverse[format] = id; this.cache[id] = format; return(format); }
public string conformMessage(TableFormat rf) { if (this.getRecordCount() < rf.getMinRecords()) { return("Number of records too small: need " + rf.getMinRecords() + " or more, found " + this.getRecordCount()); } if (this.getRecordCount() > rf.getMaxRecords()) { return("Number of records too big: need " + rf.getMaxRecords() + " or less, found " + this.getRecordCount()); } return(this.getFormat().extendMessage(rf)); }
protected void checkOrSetFormat(DataRecord record) { if (this.getFormat().getFieldCount() != 0) { var message = record.getFormat().extendMessage(this.format); if (message != null) { throw new ArgumentException( "Format of new record ('" + record.getFormat() + "') differs from format of data table ('" + this.getFormat() + "'): " + message); } } else { this.format = record.getFormat(); } }
public string extendMessage(TableFormat other) { if (!Util.equals(getNamingExpression(), other.getNamingExpression())) { return("Different naming expressions: need " + getNamingExpression() + ", found " + other.getNamingExpression()); } foreach (Binding otherBinding in other.getBindings()) { if (!getBindings().Contains(otherBinding)) { return("Different bindings: need " + getBindings() + ", found " + other.getBindings()); } } for (var i = 0; i < other.getFieldCount(); i++) { var otherFormat = other.getFieldFormat(i); var fieldName = other.getFieldName(i); var ownFormat = getFieldFormat(fieldName); if (ownFormat == null) { if (otherFormat.isOptional()) { continue; } return("Required field doesn't exist: " + fieldName); } var fieldExtendMessage = ownFormat.extendMessage(otherFormat); if (fieldExtendMessage != null) { return("Incorrect format of field '" + fieldName + "': " + fieldExtendMessage); } } return(null); }
public void put(int id, TableFormat format) { cacheLock.EnterWriteLock(); try { if (format == null) { throw new InvalidOperationException("Format is NULL"); } if (addImpl(format, id) == null && Log.PROTOCOL_CACHING.isDebugEnabled()) { Log.PROTOCOL_CACHING.debug("Cached format as #" + id + ": " + format); } } finally { cacheLock.ExitWriteLock(); } }
public Int32?getId(TableFormat format) { if (useExternalIds && format.getId() != null) { return(format.getId()); } cacheLock.EnterReadLock(); try { if (!this.reverse.ContainsKey(format)) { return(null); } return(reverse[format]); } finally { cacheLock.ExitReadLock(); } }
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); } } }
public DataRecord(TableFormat tableFormat, string dataString, ClassicEncodingSettings settings, bool validate, IList <string> fieldNamesInData) : this(tableFormat) { setData(dataString, settings, validate, fieldNamesInData); }
public DataTable(TableFormat format, bool createEmptyRecords) : this(format, createEmptyRecords ? format != null ? format.getMinRecords() : 0 : 0) { }
public TableFormat get(int id) { TableFormat result; var retry = 0; do { cacheLock.EnterReadLock(); try { result = this.cache.ContainsKey(id) ? cache[id] : null; } finally { cacheLock.ExitReadLock(); } if (result == null) { if (controller != null && controller.getContextManager() != null) { try { if (Log.PROTOCOL_CACHING.isDebugEnabled()) { Log.PROTOCOL_CACHING.debug("Requesting remote format #" + id); } var formatData = controller.getContextManager().get(ContextUtils.CTX_UTILS).callFunction( UtilsContextConstants.F_GET_FORMAT, id) .rec() .getString(UtilsContextConstants.FOF_GET_FORMAT_DATA); result = new TableFormat(formatData, new ClassicEncodingSettings(false)); if (Log.PROTOCOL_CACHING.isDebugEnabled()) { Log.PROTOCOL_CACHING.debug( "Received explicitely requested remote format #" + id + ": " + result); } cacheLock.EnterWriteLock(); try { cache.Add(id, result); } finally { cacheLock.ExitWriteLock(); } } catch (ContextException ex) { throw new InvalidOperationException( "Error obtaining format #" + id + ": " + ex.Message, ex); } } else { Log.PROTOCOL_CACHING.warn("Waiting for format #" + id); try { Monitor.Wait(this, TIMEOUT); } catch (ThreadInterruptedException ex) { ex.GetType(); Log.PROTOCOL_CACHING.warn( "Interrupted while waiting for format with ID: " + id); return(null); } } } retry++; } while (result == null && retry < RETRIES); if (result == null) { Log.PROTOCOL_CACHING.warn("Timeout while getting format #" + id + ", cache size: " + cache.Count); dump(); } return(result); }
public DataTable(TableFormat format) { this.setFormat(format); }
public bool conform(TableFormat rf) { return(this.conformMessage(rf) == null); }
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(); } } }
public DataTable(TableFormat format, params object[] firstRowData) : this(format) { this.addRecord(new DataRecord(format, firstRowData)); }
public bool extend(TableFormat other) { return(extendMessage(other) == null); }
public DataRecord(TableFormat tableFormat, string dataString) : this(tableFormat, dataString, new ClassicEncodingSettings(false), true, null) { }
public ClassicEncodingSettings(Boolean useVisibleSeparatorsBoolean, TableFormat format) : base(true, format) { useVisibleSeparators = useVisibleSeparatorsBoolean; }
public void setFormat(TableFormat aTableFormat) { format = aTableFormat; }
protected EncodingSettings(bool encodeFormat, TableFormat aTableFormat) { this.encodeFormat = encodeFormat; format = aTableFormat; }
public void setFormat(TableFormat aTableFormat) { format.makeImmutable(null); format = aTableFormat; }