Exemple #1
0
        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));
                    }
                }
            }
        }
Exemple #2
0
        public Row GetRow(RowReference reference)
        {
            var row = new Row();

            if (reference.Participant.Location.IsLocal(_process) ||
                reference.Participant.IsDatabase(DatabaseId))
            {
                row = _store.Rows.Where(r => r.Id == reference.RowId).First();
                row.LastAccessed = DateTime.Now;

                _process.EventManager.TriggerEvent(EventName.Row.Read,
                                                   CreateRowAccessedEventArgs(row));
            }
            else
            {
                row = reference.Get(_process);
            }

            return(row);
        }