public RowForm GetNewRowForLocal() { RowForm form = null; var db = _process.GetDatabase(DatabaseId); if (db.HasParticipant(db.Id)) { form = new RowForm(GetNewRow(), db.GetParticipant(db.Id)); } return(form); }
private void AddRowRemotely(RowForm form) { var info = JsonConvert.SerializeObject(form); var addNewRowMessage = new Message(form.Participant.Location, _process.GetLocation(), info, MessageDataAction.Row.Save_Row, MessageType.Data); _process.Network.SendMessage(addNewRowMessage); //Client.SaveRow(participant.Location, DatabaseId, row.TableId, row); _rows.Add(GetNewRowReference(form.Row, form.Participant.Location)); _process.EventManager.TriggerEvent(EventName.Row.Added_Remotely, CreateRowAddedEventArgs(form.Row)); }
private void AddRowLocally(RowForm form) { var row = form.Row; string debug = $"Adding row to process {_process.GetLocation().IpAddress} : {_process.GetLocation().PortNumber.ToString()}"; Debug.WriteLine(debug); _process.Log.Debug(debug); _store.AddRow(row); _rows.Add(GetNewRowReference(row)); _process.EventManager.TriggerEvent(EventName.Row.Added, CreateRowAddedEventArgs(row)); }
public RowForm GetNewRow(Guid?participantId) { RowForm form = null; var db = _process.GetDatabase(DatabaseId); if (db.HasParticipant(participantId)) { form = new RowForm(GetNewRow(), db.GetParticipant(participantId)); form.DatabaseName = db.Name; form.TableName = this.Name; } return(form); }
public void AddRow(RowForm form) { if (CheckInsertRules(form)) { form = HandleAutoNum(form); if (form.Participant.Location.IsLocal(_process) || form.Participant.IsDatabase(DatabaseId)) { AddRowLocally(form); } else { form.IsRemoteInsert = true; AddRowRemotely(form); } } _process.EventManager.TriggerEvent(EventName.Row.Added, CreateRowAddedEventArgs(form.Row)); }
private bool CheckInsertRules(RowForm form) { return(true); // TO DO: FIX THIS bool insertAllowed = false; bool isLocalInsert = form.Participant.Location.IsLocal(_process); if (isLocalInsert) { if (RowMatchesTableColumns(form.Row)) { if (DatabaseId != null && _contractValidator is null) { if (_process.HasDatabase(form.DatabaseName)) { _contractValidator = new ContractValidator(_process.GetDatabase(form.DatabaseName).Contract, DatabaseId); } if (_process.HasPartialDatabase(form.DatabaseName)) { _contractValidator = new ContractValidator(_process.GetPartialDatabase(form.DatabaseName).Contract, DatabaseId); } } // we make sure this action is okay with the defined contract if (_contractValidator.ActionIsValidForParticipant(TableAction.AddRow, form.Participant)) { // we make sure the participant accepts this action if they're remote if (form.Participant.AcceptsAction(TableAction.AddRow)) { insertAllowed = true; } } } } else { insertAllowed = true; } return(insertAllowed); }
public void UpdateRow(RowReference reference, List <RowValue> values) { // TO DO: we should be checking the rights on the contract if this is allowed. var row = reference.Get(_process); if (row != null) { foreach (var value in values) { var item = row.Values.Where(v => v.ColumnName == value.ColumnName && v.ColumnType == value.ColumnType).FirstOrDefault(); if (item != null) { item.Value = value.Value; } } if (reference.IsLocal(_process)) { // update the row locally and trigger update row event to re-save the database // do we need to do this? or just go ahead and re-save the database since we've modified the row? _store.RemoveRow(reference.RowId); _store.AddRow(row); _process.EventManager.TriggerEvent(EventName.Row.Modified, CreateNewRowModifiedEventArgs(row)); } else { // need to send a message to the remote participant to update the row var updateRemoteRowId = Guid.NewGuid(); RowForm rowInfo = new RowForm(row, reference.Participant, reference, values); var content = JsonConvert.SerializeObject(rowInfo); var updateRemoteRowMessage = _process.Network.BuildMessage(reference.Participant.Location, content, MessageDataAction.Row.Update_Row, MessageType.Data, updateRemoteRowId, MessageActionType.Table, rowInfo.GetType()); var response = _process.Network.SendMessage(updateRemoteRowMessage); if (response != null) { _process.EventManager.TriggerEvent(EventName.Row.Modified, CreateNewRowModifiedEventArgs(row)); } } } }
private RowForm HandleAutoNum(RowForm row) { if (_hasIdentity) { _identityId += _identityIncrement; if (row.RowValues.Any(v => v.ColumnName == _identityColumnName)) { var value = row.RowValues.Where(k => k.ColumnName == _identityColumnName).First(); if (value != null) { value.Value = _identityId; } } else { RowValue identity = new RowValue(_identityColumnId, _identityId, _identityColumnName, Type.GetType("System.Int64")); row.RowValues.Add(identity); } if (row.Row.Values.Any(a => a.ColumnName == _identityColumnName)) { var item = row.Row.Values.Where(b => b.ColumnName == _identityColumnName).First(); if (item != null) { item.Value = _identityId; } } else { row.Row.AddValue(_identityColumnId, _identityId, _identityColumnName, Type.GetType("System.Int64")); } } return(row); }
public void RemoveRow(RowForm form) { throw new NotImplementedException(); }