public override void validate(DataTable table, DataRecord record) { var keyFields = table.getFormat().getKeyFields(); if (keyFields.Count == 0) { return; } var query = new Query(); var key = new List <Object>(); foreach (var keyField in keyFields) { var value = record.getValue(keyField); key.Add(value); query.addCondition(new QueryCondition(keyField, value)); } var rec = table.select(query); if (rec != null && rec != record) { throw new ValidationException(String.Format(Cres.get().getString("dtKeyFieldViolation"), key)); } }
public void connect() { try { context.setSynchronized(false); Logger.getLogger(Log.PROTOCOL).debug("Connecting to remote " + Cres.get().getString("ls") + " (" + server + ")"); Logger.getLogger(Log.PROTOCOL).debug("Connection with remote LinkServer established"); contextManager.start(); //Note: Code smell --- controller and format cache should not be an ivar controller = new AgentImplementationController(ConstructStreamWrapper(), contextManager, formatCache); contextManager.getRoot().accept(new DelegatedContextVisitor <Context>(aContext => { foreach (var ed in aContext.getEventDefinitions()) { if (ed.getGroup() != null) { aContext.addEventListener(ed.getName(), controller.getDefaultEventListener()); } } })); } catch (Exception ex) { throw new RemoteDeviceErrorException( String.Format(Cres.get().getString("devErrConnecting"), server.getDescription() + " (" + server.getInfo() + ")") + ex.Message, ex); } }
public Boolean addEventListener(String name, ContextEventListener contextEventListener, Boolean sendRemoteCommand) { try { init(); var ed = getEventData(name); if (ed == null) { throw new ContextException(Cres.get().getString("conEventNotFound") + name); } if (sendRemoteCommand) { addRemoteListener(ed.getDefinition().getName(), contextEventListener); } return(base.addEventListener(name, contextEventListener)); } catch (Exception ex) { var msg = String.Format(Cres.get().getString("conErrAddingListener"), name, this.getPath()); throw new InvalidOperationException(msg + ": " + ex.Message, ex); } }
public override object validate(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value) { if (value == null) { return(value); } if (value is Data) { var data = value as Data; if (data.getData() != null) { IComparable size = data.getData().Length; this.compare(size, null, null); } } else if (value is string) { this.compare(value.ToString().Length, Cres.get().getString("dtValueTooShort"), Cres.get().getString("dtValueTooLong")); } else { if (!(value is IComparable)) { throw new ValidationException(Cres.get().getString("dtValueNotComparable")); } var cv = (IComparable)value; this.compare(cv, null, null); } return(value); }
public Boolean removeEventListener(String name, ContextEventListener contextEventListener, Boolean sendRemoteCommand) { try { init(); Log.CONTEXT_EVENTS.debug("Removing listener for event '" + name + "' from context '" + this.getPath() + "'"); var res = base.removeEventListener(name, contextEventListener); var ed = getEventData(name); if (sendRemoteCommand && ed != null && ed.getListeners().Count == 0) { var hashCode = contextEventListener.getListenerCode(); if (!notManageRemoteListenersBoolean) { this.controller.sendCommandAndCheckReplyCode(ClientCommandUtils.removeEventListenerOperation(this.getPath(), name, hashCode)); } } return(res); } catch (Exception ex) { var msg = String.Format(Cres.get().getString("conErrRemovingListener"), name, this.getPath()); throw new InvalidOperationException(msg + ": " + ex.Message, ex); } }
public override void handle(Event anEvent) { if (owner.shutDown) { throw new ObsoleteListenerException("Client constoller was stopped"); } try { OutgoingAggreGateCommand cmd = this.owner.constructEventCommand(anEvent, this.getListenerCode()); owner.sendCommand(cmd); } catch (SocketException ex) { owner.shutdown(); const string msg = "Socket exception while forwarding event to client: "; Logger.getLogger(Log.CLIENTS).info(msg + ex); Logger.getLogger(Log.CLIENTS).debug(msg + ex.Message, ex); } catch (Exception ex) { throw new EventHandlingException( String.Format(Cres.get().getString("clErrorHandlingEvent"), anEvent.getName()) + ex.Message, ex); } }
public object checkAndConvertValue(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value, bool validate) { if (!this.isNullable() && value == null) { throw new ValidationException("Nulls are not permitted in " + this); //throw new ValidationException(MessageFormat.format(Cres.get().getString("dtNullsNotPermitted"), this.toString())); } value = this.convertValue(value); if (value != null && !this.isExtendableSelectionValues() && this.hasSelectionValue(value)) { if (validate) { throw new ValidationException(Cres.get().getString("dtValueNotInSelVals") + value + " (" + value.GetType().Name + ")"); } else { value = this.getDefaultValue(); } } if (validate) { foreach (var fv in this.validators) { value = fv.validate(context, contextManager, caller, value); } } return(value); }
static AgentContext() { FOFT_LOGIN.addField("<" + FOF_LOGIN_OWNER + "><S>"); FOFT_LOGIN.addField("<" + FOF_LOGIN_NAME + "><S>"); FOFT_LOGIN.addField("<" + FOF_LOGIN_RESPONSE + "><S>"); FOFT_GET_HISTORY.addField("<" + FOF_GET_HISTORY_VARIABLE + "><S>"); FOFT_GET_HISTORY.addField("<" + FOF_GET_HISTORY_TIMESTAMP + "><D>"); FOFT_GET_HISTORY.addField("<" + FOF_GET_HISTORY_VALUE + "><T>"); FIFT_ACKNOWLEDGE_EVENT.addField("<" + FIF_ACKNOWLEDGE_EVENT_ID + "><L><F=N>"); FIFT_ACKNOWLEDGE_EVENT.addField("<" + FIF_ACKNOWLEDGE_EVENT_DATE + "><D>"); FIFT_ACKNOWLEDGE_EVENT.addField("<" + FIF_ACKNOWLEDGE_EVENT_AUTHOR + "><S><F=N>"); FIFT_ACKNOWLEDGE_EVENT.addField("<" + FIF_ACKNOWLEDGE_EVENT_ACKNOWLEDGEMENT + "><S>"); FIFT_ACKNOWLEDGE_EVENT.addField("<" + FIF_ACKNOWLEDGE_EVENT_EVENT_DATA + "><T>"); FOFT_ASSET.addField("<" + FIELD_ID + "><S><F=HRK>"); FOFT_ASSET.addField("<" + FIELD_DESCRIPTION + "><S><F=R><D=" + Cres.get().getString("description") + ">"); FOFT_ASSET.addField("<" + FIELD_ENABLED + "><B><A=1><D=" + Cres.get().getString("enabled") + ">"); FOFT_ASSET.addField(FieldFormat.create("<" + FIELD_CHILDREN + "><T><F=N><D=" + Cres.get().getString("devNestedAssets") + ">")); FOFT_ASSET.setNamingExpression(AGGREGATE + "({}, \"{env/previous} + ({" + FIELD_ENABLED + "} ? 1 : 0)\", 0) + '/' + {#" + RECORDS + "}"); String reff = FIELD_CHILDREN + "#" + PROPERTY_ENABLED; String exp = "{" + FIELD_ENABLED + "}"; FOFT_ASSET.addBinding(reff, exp); }
protected void processMessage(IncomingAggreGateCommand cmd, OutgoingAggreGateCommand ans) { var messageCode = cmd.getMessageCode(); if (messageCode.Length > 1) { throw new SyntaxErrorException(Cres.get().getString("clInvalidMsgCode") + messageCode); } var code = messageCode[0]; if ((code != AggreGateCommand.MESSAGE_CODE_START) && (!startMessageReceived)) { Logger.getLogger(Log.CLIENTS).debug("Can't process message: start message was not received yet"); ans.constructReply(cmd.getId(), AggreGateCommand.REPLY_CODE_DENIED); return; } switch (code) { case AggreGateCommand.MESSAGE_CODE_START: processMessageStart(cmd, ans); break; case AggreGateCommand.MESSAGE_CODE_OPERATION: processMessageOperation(cmd, ans); break; default: throw new SyntaxErrorException(Cres.get().getString("clUnknownMsgCode") + messageCode[0]); } }
public IncomingAggreGateCommand sendCommandAndCheckReplyCode(OutgoingAggreGateCommand cmd) { var ans = sendCommand(cmd); if (ans.getReplyCode().Equals(AggreGateCommand.REPLY_CODE_DENIED)) { throw new ContextSecurityException(String.Format(Cres.get().getString("devAccessDeniedReply"), ans.getReplyCode(), cmd)); } if (ans.getReplyCode().Equals(AggreGateCommand.REPLY_CODE_ERROR)) { var message = ans.getNumberOfParameters() > AggreGateCommand.INDEX_REPLY_MESSAGE ? ": " + DataTableUtils.transferDecode(ans.getParameter(AggreGateCommand.INDEX_REPLY_MESSAGE)) : ""; var details = ans.getNumberOfParameters() > AggreGateCommand.INDEX_REPLY_DETAILS ? DataTableUtils.transferDecode(ans.getParameter(AggreGateCommand.INDEX_REPLY_DETAILS)) : null; throw new RemoteDeviceErrorException(Cres.get().getString("devServerReturnedError") + message, details); } if (!ans.getReplyCode().Equals(AggreGateCommand.REPLY_CODE_OK)) { throw new RemoteDeviceErrorException(Cres.get().getString("devServerReturnedError") + ": " + ans + " (error code: '" + ans.getReplyCode() + "')"); } return(ans); }
private static String getErrorDetails(Exception error) { var buf = new StringBuilder(); buf.Append(Cres.get().getString("clServerTime") + ": " + new DateTime() + "\n"); buf.Append(error.StackTrace); return(buf.ToString()); }
private static HashSet <String> copyRecord(DataRecord source, DataRecord target, bool copyReadOnlyFields, bool copyNonReplicatableFields, ICollection <String> fields) { var errors = new HashSet <String>(); foreach (var tgtFf in target.getFormat()) { var fieldName = tgtFf.getName(); var srcFf = source.getFormat().getFieldFormat(fieldName); if (fields != null && !fields.Contains(tgtFf.getName())) { continue; } if (srcFf == null) { continue; } if (tgtFf.isReadonly() && !copyReadOnlyFields) { continue; } if (!copyNonReplicatableFields) { if (tgtFf.isNotReplicated() || srcFf.isNotReplicated()) { continue; } } try { if (srcFf.getFieldWrappedClass().Equals(tgtFf.getFieldWrappedClass())) { target.setValue(fieldName, CloneUtils.genericClone(source.getValue(fieldName))); } else { target.setValue(fieldName, tgtFf.valueFromString(srcFf.valueToString(source.getValue(fieldName)))); } } catch (Exception ex2) { var msg = String.Format(Cres.get().getString("dtErrCopyingField"), fieldName); Logger.getLogger(Log.DATATABLE).debug(msg, ex2); errors.Add(msg + ": " + ex2.Message); continue; } } return(errors); }
static EventUtils() { IntFieldFormat ff = (IntFieldFormat)FieldFormat.create("<" + FIELD_SEVERITY_STATS_LEVEL + "><I><D=" + Cres.get().getString(FIELD_SEVERITY_STATS_LEVEL) + ">"); ff.setSelectionValues(EventLevel.getSelectionValues()); SEVERITY_STATS_FORMAT.addField(ff); SEVERITY_STATS_FORMAT.addField( FieldFormat.create("<" + FIELD_SEVERITY_STATS_NUMBER + "><I><D=" + Cres.get().getString("efEventCount") + ">")); SEVERITY_STATS_FORMAT.addField(FieldFormat.create("<" + FIELD_SEVERITY_STATS_COLOR + "><C><F=H>")); }
private I waitReplyMonitor(ReplyMonitor <O, I> mon) { if (mon.getReply() == null) { mon.waitReply(timeout); } sentCommandsQueue.Remove(mon); if (mon.getReply() != null) { return(mon.getReply()); } throw new IOException(String.Format(Cres.get().getString("cmdTimeout"), mon.getCommand())); }
protected virtual Boolean connectImpl() { processor = new AsyncDeviceCommandProcessor(this, device, commandTimeout); processor.start(); var ans = sendCommand(ClientCommandUtils.startMessage()); if (!ans.getReplyCode().Equals(AggreGateCommand.REPLY_CODE_OK)) { throw new RemoteDeviceErrorException(Cres.get().getString("devUncompatibleVersion")); } return(true); }
private void compare(IComparable cv, string smallMessage, string bigMessage) { if (this.min != null) { if (cv.CompareTo(this.min) < 0) { throw new ValidationException(string.Format(smallMessage ?? Cres.get().getString("dtValueTooSmall"), cv, min)); } } if (cv.CompareTo(max) > 0) { throw new ValidationException(string.Format(bigMessage ?? Cres.get().getString("dtValueTooBig"), cv, max)); } }
private int findIndex(string name) { int index = 0; for (var iter = format.getFields().GetEnumerator(); iter.MoveNext();) { var ff = iter.Current; if (ff.getName().Equals(name)) { return(index); } index++; } throw new ArgumentException(string.Format(Cres.get().getString("dtFieldNotFound"), name)); }
protected override Boolean connectImpl() { try { Logger.getLogger(Log.PROTOCOL).debug("Connecting to remote " + Cres.get().getString("ls") + " (" + getDevice() + ")"); var client = new TcpClient(getDeviceAsRemoteLinkServer().getAddress(), getDeviceAsRemoteLinkServer().getPort()); SslStream ssl = new SslStream( client.GetStream(), false, (sender, certificate, chain, sslpolicyerrors) => true //, (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => { return null; } ); //ssl.CipherAlgorithm = ; ssl.AuthenticateAsClient(""); streamWrapper = new StreamWrapper(ssl, 0); setCommandBuffer(new CommandBuffer(streamWrapper, Command.START_CHAR, Command.END_CHAR)); Logger.getLogger(Log.PROTOCOL).debug("Connection with remote LinkServer established"); } catch (Exception ex) { throw new RemoteDeviceErrorException( String.Format(Cres.get().getString("devErrConnecting"), getDevice().getDescription() + " (" + getDevice().getInfo() + ")") + ex.Message, ex); } base.connectImpl(); getContextManager().setRoot(new RemoteDeviceContextProxy <RemoteLinkServer>(ContextUtils.CTX_ROOT, this)); getContextManager().restart(); try { var version = this.getContextManager().getRoot().getVariable(RootContextConstants.V_VERSION).get().ToString(); } catch (Exception ex) { Logger.getLogger(Log.PROTOCOL).error("Server version check failure", ex); } return(true); }
private void sendRemoveListener(String context, String eventString, ContextEventListener listener) { try { getController().sendCommandAndCheckReplyCode(ClientCommandUtils.removeEventListenerOperation(context, eventString, listener. getListenerCode ())); } catch (Exception ex) { var msg = String.Format(Cres.get().getString("conErrRemovingListener"), eventString, context); throw new InvalidOperationException(msg + ": " + ex.Message, ex); } }
public FieldFormat setEditor(string editorString) { if (immutable) { throw new ArgumentException("Immutable"); } if (editorString != null && !this.getSuitableEditors().Contains(editorString)) { Logger.getLogger(Log.DATATABLE).warn(Cres.get().getString("dtEditorNotSuitable") + editorString + " (" + this.ToString() + ")"); } this.editor = editorString; return(this); }
static EventLevel() { LEVELS.Add(NOTICE, Cres.get().getString("conElNotice")); LEVELS.Add(INFO, Cres.get().getString("conElInfo")); LEVELS.Add(WARNING, Cres.get().getString("conElWarning")); LEVELS.Add(ERROR, Cres.get().getString("conElError")); LEVELS.Add(FATAL, Cres.get().getString("conElFatal")); LEVELS.Add(NONE, Cres.get().getString("conElNotDefined")); SELECTION_VALUES.Add(new NullableObject(0), Cres.get().getString("none")); for (int i = 1; i <= NUM_LEVELS; i++) { SELECTION_VALUES.Add(new NullableObject(i), getName(i)); } }
public void processOperationGetVar(String id, Context con, String name, OutgoingAggreGateCommand ans) { var vd = con.getVariableDefinition(name); if (vd == null) { ans.constructReply(id, AggreGateCommand.REPLY_CODE_DENIED, Cres.get().getString("conVarNotAvail") + name); return; } var result = con.getVariable(name, callerController); ans.constructReply(id, AggreGateCommand.REPLY_CODE_OK); ans.addParam(result.encode(createClassicEncodingSettings(vd.getFormat() != null))); }
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 override object validate(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value) { Regex reg; try { reg = new Regex(regex); } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex); } if (value != null && !reg.IsMatch(value.ToString())) { throw new ValidationException(this.message ?? string.Format(Cres.get().getString("dtValueDoesNotMatchPattern"), value, this.regex)); } return(value); }
public override void setupMyself() { base.setupMyself(); var def = new FunctionDefinition(F_LOGIN, FIFT_LOGIN, FOFT_LOGIN, Cres.get().getString("login")); def.setImplementation(loginImpl); addFunctionDefinition(def); def = new FunctionDefinition(F_REGISTER, TableFormat.EMPTY_FORMAT, FOFT_REGISTER, Cres.get().getString("register")); def.setImplementation(registerImpl); addFunctionDefinition(def); def = new FunctionDefinition(F_SYNCHRONIZED, TableFormat.EMPTY_FORMAT, TableFormat.EMPTY_FORMAT); def.setImplementation(synchronizedImpl); addFunctionDefinition(def); var fd = new FunctionDefinition(F_CONFIRM_EVENT, FIFT_CONFIRM_EVENT, TableFormat.EMPTY_FORMAT); fd.setImplementation(confirmEventImpl); addFunctionDefinition(fd); fd = new FunctionDefinition(F_ACKNOWLEDGE_EVENT, FIFT_ACKNOWLEDGE_EVENT, TableFormat.EMPTY_FORMAT); fd.setImplementation(acknowledgeEventImpl); addFunctionDefinition(fd); fd = new FunctionDefinition(F_GET_HISTORY, TableFormat.EMPTY_FORMAT, FOFT_GET_HISTORY); fd.setImplementation(getHistoryImpl); addFunctionDefinition(fd); if (eventConfirmation) { EventDefinition edCon = new EventDefinition(E_EVENT_CONFIRMED, EFT_EVENT_CONFIRMED); addEventDefinition(edCon); } EventDefinition edAck = new EventDefinition(E_EVENT_ACKNOWLEDGED, FIFT_ACKNOWLEDGE_EVENT); addEventDefinition(edAck); }
static TimeHelper() { SELECTION_VALUES.Add(MILLISECOND, Cres.get().getString("tuMillisecond")); SELECTION_VALUES.Add(SECOND, Cres.get().getString("tuSecond")); SELECTION_VALUES.Add(MINUTE, Cres.get().getString("tuMinute")); SELECTION_VALUES.Add(HOUR, Cres.get().getString("tuHour")); SELECTION_VALUES.Add(DAY, Cres.get().getString("tuDay")); SELECTION_VALUES.Add(WEEK, Cres.get().getString("tuWeek")); SELECTION_VALUES.Add(MONTH, Cres.get().getString("tuMonth")); SELECTION_VALUES.Add(QUARTER, Cres.get().getString("tuQuarter")); SELECTION_VALUES.Add(YEAR, Cres.get().getString("tuYear")); UNITS.Add(MILLISECOND_UNIT); UNITS.Add(SECOND_UNIT); UNITS.Add(MINUTE_UNIT); UNITS.Add(HOUR_UNIT); UNITS.Add(DAY_UNIT); UNITS.Add(WEEK_UNIT); UNITS.Add(MONTH_UNIT); UNITS.Add(QUARTER_UNIT); UNITS.Add(YEAR_UNIT); }
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 ReplyMonitor <O, I> sendCommand(O cmd) { if (!thread.IsAlive) { lock (sentCommandsQueue) { foreach (var cur in sentCommandsQueue) { cur.setReply(null); } } lock (unsentCommandsQueue) { foreach (var cur in unsentCommandsQueue) { cur.setReply(null); } } throw new DisconnectionException(Cres.get().getString("cmdDisconnected")); } var mon = new ReplyMonitor <O, I>(cmd); if (sendImmediately) { addSentCommand(mon); doSend(cmd); } else { unsentCommandsQueue.enqueue(mon); } return(mon); }
static FieldFormat() { TYPES.Add(INTEGER_FIELD, typeof(IntFieldFormat)); TYPES.Add(STRING_FIELD, typeof(StringFieldFormat)); TYPES.Add(BOOLEAN_FIELD, typeof(BooleanFieldFormat)); TYPES.Add(LONG_FIELD, typeof(LongFieldFormat)); TYPES.Add(FLOAT_FIELD, typeof(FloatFieldFormat)); TYPES.Add(DOUBLE_FIELD, typeof(DoubleFieldFormat)); TYPES.Add(DATE_FIELD, typeof(DateFieldFormat)); TYPES.Add(DATATABLE_FIELD, typeof(DataTableFieldFormat)); TYPES.Add(COLOR_FIELD, typeof(ColorFieldFormat)); TYPES.Add(DATA_FIELD, typeof(DataFieldFormat)); CLASS_TO_TYPE.Add(typeof(Int32), INTEGER_FIELD); CLASS_TO_TYPE.Add(typeof(string), STRING_FIELD); CLASS_TO_TYPE.Add(typeof(Boolean), BOOLEAN_FIELD); CLASS_TO_TYPE.Add(typeof(Int64), LONG_FIELD); CLASS_TO_TYPE.Add(typeof(float), FLOAT_FIELD); CLASS_TO_TYPE.Add(typeof(double), DOUBLE_FIELD); CLASS_TO_TYPE.Add(typeof(DateTime), DATE_FIELD); CLASS_TO_TYPE.Add(typeof(DataTable), DATATABLE_FIELD); CLASS_TO_TYPE.Add(typeof(Object), OBJECT_FIELD); CLASS_TO_TYPE.Add(typeof(Color), COLOR_FIELD); CLASS_TO_TYPE.Add(typeof(Data), DATA_FIELD); TYPE_SELECTION_VALUES.Add(INTEGER_FIELD.ToString(), Cres.get().getString("dtInteger")); TYPE_SELECTION_VALUES.Add(STRING_FIELD.ToString(), Cres.get().getString("dtString")); TYPE_SELECTION_VALUES.Add(BOOLEAN_FIELD.ToString(), Cres.get().getString("dtBoolean")); TYPE_SELECTION_VALUES.Add(LONG_FIELD.ToString(), Cres.get().getString("dtLong")); TYPE_SELECTION_VALUES.Add(FLOAT_FIELD.ToString(), Cres.get().getString("dtFloat")); TYPE_SELECTION_VALUES.Add(DOUBLE_FIELD.ToString(), Cres.get().getString("dtDouble")); TYPE_SELECTION_VALUES.Add(DATE_FIELD.ToString(), Cres.get().getString("date")); TYPE_SELECTION_VALUES.Add(DATATABLE_FIELD.ToString(), Cres.get().getString("dtDataTable")); TYPE_SELECTION_VALUES.Add(OBJECT_FIELD.ToString(), Cres.get().getString("dtObject")); TYPE_SELECTION_VALUES.Add(COLOR_FIELD.ToString(), Cres.get().getString("color")); TYPE_SELECTION_VALUES.Add(DATA_FIELD.ToString(), Cres.get().getString("dtDataBlock")); }
private DataRecord setValue(int index, Object value, Boolean validate) { FieldFormat ff = getFormat().getFieldFormat(index); try { ff.checkAndConvertValue(value, validate); } catch (ValidationException ex) { throw new ArgumentException( string.Format(Cres.get().getString("dtIllegalFieldValue"), value, ff) + ex.Message, ex); } Object oldValue = null; if (data.ContainsKey(ff.getName())) { oldValue = data[ff.getName()]; } try { data[ff.getName()] = value; if (table != null) { table.validateRecord(this); } } catch (ValidationException ex1) { data.Add(ff.getName(), oldValue); throw new ArgumentException(ex1.Message, ex1); } return(this); }