Esempio n. 1
0
 public RowForm(Row row, Participant participant, RowReference reference, List <RowValue> rowValues)
 {
     _row         = row;
     _participant = participant;
     Reference    = reference;
     RowValues    = rowValues;
 }
Esempio n. 2
0
 private RemoteRowInfo BuildRemoteRowInfo(RowReference reference)
 {
     return(new RemoteRowInfo
     {
         DatabaseId = this.DatabaseId,
         DatabaseName = _process.GetDatabase(this.DatabaseId).Name,
         TableId = this.Id,
         TableName = this.Name,
         RowId = reference.RowId
     });
 }
Esempio n. 3
0
        private async Task <bool> DeleteRemoteRow(RowReference reference)
        {
            /*
             *
             * var getRowMessage = _process.Network.BuildMessage(Participant.Location, content, MessageDataAction.Process.Get_Remote_Row, MessageType.Data, requestId);
             * _process.Network.SendMessageRequestId(getRowMessage, requestId);
             * bool gotData = await _process.Network.WaitForMessageTokenAsync(requestId);
             *
             * if (gotData)
             * {
             *  if (_process.Network.DataProcessor.HasMessageId(requestId))
             *  {
             *      Message rowMessage;
             *      _process.Network.DataProcessor.TryGetMessage(requestId, out rowMessage);
             *
             *      if (rowMessage != null)
             *      {
             *          row = rowMessage.GetContentAs<Row>();
             *      }
             *
             *  }
             * }
             */

            if (!reference.IsLocal(_process))
            {
                var requestId = Guid.NewGuid();

                var remoteRowInfo = BuildRemoteRowInfo(reference);
                var content       = JsonConvert.SerializeObject(remoteRowInfo);

                var message  = _process.Network.BuildMessage(reference.Participant.Location, content, MessageDataAction.Row.Delete_Row, MessageType.Data, requestId, MessageActionType.Table, remoteRowInfo.GetType());
                var response = _process.Network.SendMessage(message);

                if (response != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
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));
                    }
                }
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public Row GetRow(Guid?rowId)
        {
            var result = new Row();
            var row    = new RowReference();

            row    = _rows.Where(r => r.RowId == rowId).FirstOrDefault();
            result = _store.Rows.Where(r => r.Id == rowId).FirstOrDefault();

            if (row.IsLocal(_process))
            {
                foreach (var value in result.Values)
                {
                    // this can return null if we're on a remote host rather than the main host
                    var item = GetColumn(value.ColumnId);
                    if (item != null)
                    {
                        value.ColumnName = item.Name;
                    }
                }
            }

            return(result);
        }