I am getting an error msg is not defined when trying to loop through different OBX segments. In my destination DB Writer I have the code var msg = channelMap.get('msg'); but how to store the msg in the transformer with channelMap.put('msg', msg)?
This is what I have currently in the transformer(javascript mapper):
var message = message.getRawData();
channelMap.put('msg', message);
In destination DB writer:
var msg = channelMap.get('msg');
Error:
TypeError: Cannot call method "getRawData" of undefined;
On the source connector filters and transformers, msg is a given variable, you can't (and should not) declare it (var msg) and is not on the channelMap to be able to get it (channelMap.get('msg')), you just use it: msg[...].
On the destination you can get the message without putting it on the channelMap.
Related
Is it possible to receive a payload when using the NOTIFY psql method?
right now Im using
using (var cmd = new NpgsqlCommand("NOTIFY test", conn)) {
cmd.ExecuteNonQuery();
}
but I would like to attach a message with the NOTIFY event
to clarify
using (var cmd = new NpgsqlCommand("NOTIFY test_channel, test_message", conn)) {
cmd.ExecuteNonQuery();
}
this throws an error
Exception has occurred: CLR/Npgsql.PostgresException
An exception of type 'Npgsql.PostgresException'
occurred in System.Private.CoreLib.dll
but was not handled in user code: 'External component has thrown an exception.'
As the PostgreSQL docs shows, you can include an arbitrary payload string:
NOTIFY test, payload
I'm starting to work with Nearby, and sending a file over the stream. I see on the sender's side that the file is sent, and on the receiver's side I see both the onPayloadReceived event and 2 onPayloadTransferUpdate events, the second with a status of 1. Once I get that event with status 1, I run the following code:
Payload payload = payloads.remove(id);
try {
Payload.File payloadFile = payload.asFile();
Reader reader;
File file = payloadFile.asJavaFile();
if (file==null)
reader = new FileReader(payloadFile.asParcelFileDescriptor().getFileDescriptor());
else
reader = new FileReader(file);
StringBuilder builder = new StringBuilder();
char[] buff = new char[1024];
do
{
int count = reader.read(buff);
if (count<=0)
break;
builder.append(buff, 0, count);
}while(true);
receivedData.setText(builder);
}
catch (Exception exn){Log.d(TAG, "Exception thrown while receiving",exn);}
The result is that file is null, and the read command throws an IOException with the message read failed: EBADF (Bad file number). How do I fix this?
Could you show the code that corresponds to you "sending a file over the stream"?
I ask because STREAM and FILE are 2 different Payload types, so if you send as a STREAM (regardless of whether the contents of the STREAM came from a file), you will receive as a STREAM.
I need to run a raw sql query, but I'm getting an error when I try to open the connection to the database. "The connection was not closed. The connection's current state is open."
_loginValidator and _contactService are passed into the controller through DI:
services.AddScoped<ILoginValidator, LoginValidator>();
services.AddScoped<IContactService, ContactService>();
The two lines below are in an action function of the controller. If I switch the two lines, the error goes away...:
var validationErrors = _loginValidator.Validate(id, "");
var user = _contactService.GetContact(id);
Here is _loginValidator.Validate. If I comment out the second line, the error goes away...:
public LoginValidationResult Validate(int userId, string encryptedPassword)
{
var vr = new LoginValidationResult();
var user = _context.Users.Include(u => u.LoginUserQuestionAnswers).FirstOrDefault(u => u.Id == userId);
//...
}
Here is _contactService.GetContact. This is where I get the error:
public ContactDto GetContact(int id)
{
var conn = _context.Database.GetDbConnection();
//ERROR HERE!!!
conn.Open();
//work on conn, for example: ExecuteReader
conn.Close();
}
Notes:
If I comment out the _context line in the Validate(...) function, I do not get the error.
If I switch the two lines I listed in the action function, I do not get the error.
I think the problem is that EntityCore is not closing the connection after I finish using it in _loginValidator.Validate(...)
Anyone know how I can deal with this problem?
DB Connection is an unmanaged resource and you need to close it yourself. The best practice is to use a using statement for your DB connections.
See these links:
http://stackoverflow.com/questions/35077000/entity-framework-7-get-database-time
https://msdn.microsoft.com/en-us/data/dn456849.aspx
The connection being left open after the FirstOrDefault query is a bug. I filed https://github.com/aspnet/EntityFramework/issues/6581 for it and we just triaged it for the 1.0.2 release.
To workaround the bug for now I think you can check if the connection is already open and, if so, don't try to open it again.
I want to use an asynchronous connection to a postgres database for inserting a realtime incomming data. I am using Twisted for the TCP communication and i am giving txpostgres a shot for the interaction with the database.I am stacked with a weird message when i try to add a callback for my asynchronous insert.Here my code:
try:
conn = txpostgres.ConnectionPool(50,params)
d = conn.start()
def save_conn(c):
self.list_cnx.append(c)
print str(c),"Connect OK"
def print_err(m):
print m
d.addCallbacks(lambda _: save_conn(conn),lambda __: print_err('Connect NO'))
except Exception as e:
print "Cannot connect to database!!"
I am adding the refrence of the connction pool in a list for future query.
def insert_data(self,dic):
try:
insArRq="""INSERT INTO test_pool(date_msg, msg) VALUES ('%s','%s')"""%(dic['date'],dic['msg'])
for c in self.list_cnx:
def insert_finich():
print "insert finich"
def insert_error():
print "insert error"
d = c.runOperation(insArRq) # return a deferred as mentioned in the documentation
print d # for debug
d.addCallBack(insert_finich) # error mesage
except Exception as ee:
print "Insert error : ",ee
When i try to add a callback for the deferred returned by the runOperation this error appear:
<Deferred at 0x8d9782c waiting on Deferred at 0x8d9786c>
Insert error : Deferred instance has no attribute 'addCallBack'
and sometimes:
<Deferred at 0x8d97a0c>
Insert error : Deferred instance has no attribute 'addCallBack'
Help me please, i'am new to defrred concepts so i think i'am missing something.Thanks
The method is named addCallback; case is important.
This is my method to send message to a private Q
using (MessageQueue msgQ = new MessageQueue(MessageQueueName))
{
using (System.Messaging.Message newMessage = new System.Messaging.Message(MessageBody,
new System.Messaging.ActiveXMessageFormatter()))
{
newMessage.Label = MessageLabel;
newMessage.Priority = Priority;
msgQ.Send(newMessage);
}
}
I have an order object which i serialize and send as message body. The serialized object is
<?xml version="1.0"?>
<OrderInfo>
<OrderID>11111</OrderID>
<OrderDetails>
<LineItem>
<ProductDetails>
<Name>qwqwqw</Name>
<Manufacturer>asasas</Manufacturer>
<UPC>12222222222</UPC>
<sku>2132</sku>
<Price>12.21</Price>
</ProductDetails>
<Quantity>1</Quantity>
</LineItem>
</OrderDetails>
</OrderInfo>
This is my method to receive that message in a windows service
void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs asyncResult)
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)sender;
// End the asynchronous Receive operation.
Message m = mq.EndReceive(asyncResult.AsyncResult);
m.Formatter = new System.Messaging.ActiveXMessageFormatter()
//Get Filedata from body
OrdrInfo qMessage = (OrdrInfo)XMLUtil.Deserialize(m.Body.ToString(), typeof(OrdrInfo));
}
when I try to look at m.Body in quickwatch this is what it states
m.Body.Message = Cannot find a formatter capable of reading this message.
m.Body.StackTrace = at System.Messaging.Message.get_Body()
Hopefully you're not still stuck on this, but as it came up top of my search when running into the same problem.
As no one had answered it, here is one answer that I've just found else where (thanks TechRepublic). This code assume that "MyType" is a typically basic message that can be read by XML Serialisation - this means it is marked as serializable and all data to be sent/reconstructed is in public get/set properties.
Code is:
MessageQueue msgQ = new MessageQueue(#".\private$\CreateNewEntity");
msgQ.Formatter = new XmlMessageFormatter(new []{typeof(MyType)});
var msg = msgQ.Receive();
msgQ.Close();
return msg.Body as MyType;