public IBytesMessage CreateBytesMessage(byte[] body) { BytesMessage answer = new BytesMessage(); answer.Content = body; return(ConfigureMessage(answer) as IBytesMessage); }
public void getTransactionFromTestNetTesst() { Wallet.WalletClient wallet = GetMainNetWalletClient; // wallet.tra byte[] hashTransaction = StringHelper.HexStringToByteArray("d2e635f7c2d85cbcd343721047447b122a3c19e86f30651d8ec6ee76f744d065"); BytesMessage bytesMessage = new BytesMessage(); bytesMessage.Value = ByteString.CopyFrom(hashTransaction); // Transaction transactionLoad = wallet.GetTransactionByIdAsync(bytesMessage).GetAwaiter().GetResult(); // Transaction transactionLoad = wallet.GetTransactionByIdAsync(bytesMessage).GetAwaiter().GetResult(); NodeList nodeList = wallet.ListNodes(GetEmptyMessage); Block result = wallet.GetNowBlockAsync(GetEmptyMessage).GetAwaiter().GetResult(); //TK4BAeF72P3gop24RsoqPJynWgBBDv9fXX var keyTriple = new KeyTriple("B7E85CA5910922C49DCCB92EE48DFEC13A60674845CB7152C86B88F31DA6DC67"); byte[] addressWallet = keyTriple.GetAddressWallet(TypeNet.Main); string encode = Base58.Encode(addressWallet); Account account = new Account(); account.Address = ByteString.CopyFrom(addressWallet); Account account1 = wallet.GetAccountAsync(account).GetAwaiter().GetResult(); // new WalletExtension byte[] hashTransaction1 = StringHelper.HexStringToByteArray("a7e974c6e69fb7741bf5e08de8a2d8f6617826c59422b440de22e0612b03c393"); BytesMessage bytesMessage1 = new BytesMessage(); bytesMessage1.Value = ByteString.CopyFrom(hashTransaction1); Transaction transactionLoad1 = wallet.GetTransactionByIdAsync(bytesMessage1).GetAwaiter().GetResult(); TransferContract transferContract = TransferContract.Parser.ParseFrom(transactionLoad1.RawData.Contract[0].Parameter.Value.ToByteArray()); }
public MessageDispatch(ConsumerId consumerId, Destination destination, BytesMessage message, Int32 redeliveryCounter) { ConsumerId = consumerId; Destination = destination; Message = message; RedeliveryCounter = redeliveryCounter; }
protected virtual ICommand ReadMessage(StompFrame frame) { frame.RemoveProperty(PropertyKeys.Transformation); var message = new BytesMessage { Content = frame.Content }; // Remove any receipt header we might have attached if the outbound command was // sent with response required set to true frame.RemoveProperty(PropertyKeys.Receipt); // Clear any attached content length headers as they aren't needed anymore and can // clutter the Message Properties. frame.RemoveProperty(PropertyKeys.ContentLength); message.Type = frame.RemoveProperty(PropertyKeys.Type); message.Destination = Destination.ConvertToDestination(frame.RemoveProperty(PropertyKeys.Destination), SkipDestinationNameFormatting); message.ReplyTo = Destination.ConvertToDestination(frame.RemoveProperty(PropertyKeys.ReplyTo), SkipDestinationNameFormatting); message.TargetConsumerId = new(frame.RemoveProperty(PropertyKeys.Subscription)); message.CorrelationId = frame.RemoveProperty(PropertyKeys.CorrelationId); message.MessageId = new(frame.RemoveProperty(PropertyKeys.MessageId)); message.Persistent = StompHelper.ToBool(frame.RemoveProperty(PropertyKeys.Persistent), false); // If it came from NMS.Stomp we added this header to ensure its reported on the // receiver side. if (frame.HasProperty(PropertyKeys.NmsxDeliveryMode)) { message.Persistent = StompHelper.ToBool(frame.RemoveProperty(PropertyKeys.NmsxDeliveryMode), false); } if (frame.HasProperty(PropertyKeys.Priority)) { message.Priority = Byte.Parse(frame.RemoveProperty(PropertyKeys.Priority)); } if (frame.HasProperty(PropertyKeys.TimeStamp)) { message.Timestamp = Int64.Parse(frame.RemoveProperty(PropertyKeys.TimeStamp)); } if (frame.HasProperty(PropertyKeys.Expires)) { message.Expiration = Int64.Parse(frame.RemoveProperty(PropertyKeys.Expires)); } if (frame.RemoveProperty(PropertyKeys.Redelivered) != null) { message.RedeliveryCounter = 1; } // now lets add the generic headers foreach (var key in frame.Properties.Keys) { var value = frame.Properties[key]; message.Headers[key] = value; } return(new MessageDispatch(message.TargetConsumerId, message.Destination, message, message.RedeliveryCounter)); }
public void ConvertToMqMessage_CorrectBytesMessage_CorrectResult() { var message = new BytesMessage { Body = new byte[] { 97, 98, 99 }, MessageId = "abc", CorrelationId = "def", LifeTime = TimeSpan.FromMinutes(10), ReplyQueue = "Reply", Properties = { { "Prop1", 12 }, { "Prop2", "def" } } }; var session = Given.Session.Please(); var result = message.ConvertToMqMessage(session); Assert.Multiple(() => { Assert.IsInstanceOf <IBytesMessage>(result); var bytesMessage = (IBytesMessage)result; Assert.AreEqual(message.Body.Length, bytesMessage.BodyLength); var bytes = new byte[message.Body.Length]; bytesMessage.ReadBytes(bytes); CollectionAssert.AreEqual(message.Body, bytes); Assert.AreEqual("abc", bytesMessage.JMSMessageID); Assert.AreEqual(10 * 60 * 1000, bytesMessage.JMSExpiration); Assert.AreEqual("def", bytesMessage.JMSCorrelationID); Assert.AreEqual(message.ReplyQueue, bytesMessage.JMSReplyTo.Name); CollectionAssert.AreEquivalent(message.Properties, bytesMessage.GetProperties()); }); }
/// <summary> Create a EMS BytesMessage for the given byte array.</summary> /// <param name="bytes">the byyte array to convert /// </param> /// <param name="session">current EMS session /// </param> /// <returns> the resulting message /// </returns> /// <throws> EMSException if thrown by EMS methods </throws> protected virtual BytesMessage CreateMessageForByteArray(byte[] bytes, ISession session) { BytesMessage message = session.CreateBytesMessage(); message.WriteBytes(bytes); return(message); }
public void ConvertToMqMessage_CorrectBytesMessage_CorrectResult() { var message = new BytesMessage { Body = new byte[] { 97, 98, 99 }, MessageId = "abc", CorrelationId = "def", LifeTime = TimeSpan.FromMinutes(10), ReplyQueue = "Reply", Properties = { { "Prop1", 12 }, { "Prop2", "def" } } }; var session = Given.Session.Please(); var result = message.ConvertToMqMessage(session); Assert.Multiple(() => { Assert.IsInstanceOf <IBytesMessage>(result, nameof(IBytesMessage)); var bytesMessage = (IBytesMessage)result; Assert.AreEqual(message.Body.Length, bytesMessage.BodyLength, nameof(bytesMessage.BodyLength)); var bytes = new byte[message.Body.Length]; bytesMessage.ReadBytes(bytes); CollectionAssert.AreEqual(message.Body, bytes, nameof(message.Body)); Assert.AreEqual("abc", bytesMessage.NMSMessageId, nameof(bytesMessage.NMSMessageId)); Assert.AreEqual(TimeSpan.FromMinutes(10), bytesMessage.NMSTimeToLive, nameof(bytesMessage.NMSTimeToLive)); Assert.AreEqual("def", bytesMessage.NMSCorrelationID, nameof(bytesMessage.NMSCorrelationID)); }); }
public void TestClearBody() { BytesMessage message = new BytesMessage(); message.ClearBody(); Assert.IsFalse(message.ReadOnlyBody); }
public void Main4Test() { Wallet.WalletClient wallet = GetMainNetWalletClient; var keyTriple = new KeyTriple("B7E85CA5910922C49DCCB92EE48DFEC13A60674845CB7152C86B88F31DA6DC67"); byte[] hashTransaction1 = StringHelper.HexStringToByteArray("a7e974c6e69fb7741bf5e08de8a2d8f6617826c59422b440de22e0612b03c393"); BytesMessage bytesMessage1 = new BytesMessage(); bytesMessage1.Value = ByteString.CopyFrom(hashTransaction1); Transaction transactionLoad1 = wallet.GetTransactionByIdAsync(bytesMessage1).GetAwaiter().GetResult(); Transaction.Types.Contract contract = transactionLoad1.RawData.Contract[0]; TransferContract transferContract = TransferContract.Parser.ParseFrom(contract.Parameter.Value.ToByteArray()); byte[] publicKeyOwner = transferContract.OwnerAddress.ToByteArray(); string encode = Base58.Encode(publicKeyOwner); byte[] transactionRaw = transactionLoad1.RawData.ToByteArray(); byte[] hash = Sha256.Hash(transactionRaw); string signBase64 = transactionLoad1.Signature[0].ToBase64(); byte[] byteArray = transactionLoad1.Signature[0].ToByteArray(); bool isSignatureValidFromBytes = new ECSigner().IsSignatureValidFromBytes(hash, byteArray, publicKeyOwner); }
public ITransactionSendResult txGetSendingResult(string txid) { Transaction transactionLoad = null; BytesMessage txidByteMessage = GetByteMessageFromString(txid); try { transactionLoad = _walletClient.GetTransactionByIdAsync(txidByteMessage).GetAwaiter().GetResult(); } catch (Exception exception) { return(new TransactionSendResult(TransactionStatus.Error, exception.Message, null)); } if (transactionLoad == null) { return(new TransactionSendResult(TransactionStatus.Error, "Транзакция по txid не найдена.", null)); } Block block = _walletClient.GetBlockByIdAsync(txidByteMessage).GetAwaiter().GetResult(); ByteString rawDataData = transactionLoad.RawData.Data; // var bigInteger = new BigInteger(rawDataData.ToByteArray()); // Info info = new Info(txid, transactionLoad.RawData.ToByteString().ToBase64(), DateTime.Now); return(new TransactionSendResult(TransactionStatus.Sent, null, null)); }
public void TestReset() { BytesMessage message = new BytesMessage(); try { message.WriteDouble(24.5); message.WriteInt64(311); } catch (MessageNotWriteableException) { Assert.Fail("should be writeable"); } message.Reset(); try { Assert.IsTrue(message.ReadOnlyBody); Assert.AreEqual(message.ReadDouble(), 24.5, 0); Assert.AreEqual(message.ReadInt64(), 311); } catch (MessageNotReadableException) { Assert.Fail("should be readable"); } try { message.WriteInt32(33); Assert.Fail("should throw exception"); } catch (MessageNotWriteableException) { } }
protected override IBytesMessage DoCreateBytesMessage() { BytesMessage message = new BytesMessage(); message.Connection = connection; return(message); }
public void TestWriteObject() { BytesMessage msg = new BytesMessage(); try { msg.WriteObject("fred"); msg.WriteObject((Boolean)true); msg.WriteObject((Char)'q'); msg.WriteObject((Byte)((byte)1)); msg.WriteObject((Int16)((short)3)); msg.WriteObject((Int32)3); msg.WriteObject((Int64)300L); msg.WriteObject((Single)3.3f); msg.WriteObject((Double)3.3); msg.WriteObject((Object) new byte[3]); } catch (MessageFormatException) { Assert.Fail("objectified primitives should be allowed"); } try { msg.WriteObject(new Object()); Assert.Fail("only objectified primitives are allowed"); } catch (MessageFormatException) { } }
private void DoIndividualAcknowledge(BytesMessage message) { MessageDispatch dispatch = null; lock (_dispatchedMessages) foreach (var originalDispatch in _dispatchedMessages.Where(originalDispatch => originalDispatch.Message.MessageId.Equals(message.MessageId))) { dispatch = originalDispatch; _dispatchedMessages.Remove(originalDispatch); break; } if (dispatch == null) { if (Tracer.IsWarnEnabled) { Tracer.Warn($"Attempt to Ack MessageId[{message.MessageId}] failed because the original dispatch is not in the Dispatch List"); } return; } var ack = new MessageAck { AckType = (Byte)AckType.IndividualAck, ConsumerId = ConsumerInfo.ConsumerId, Destination = dispatch.Destination, LastMessageId = dispatch.Message.MessageId, MessageCount = 1 }; _session.SendAck(ack); }
public void TestReadBoolean() { BytesMessage msg = new BytesMessage(); msg.WriteBoolean(true); msg.Reset(); Assert.IsTrue(msg.ReadBoolean()); }
public IBytesMessage CreateBytesMessage(Byte[] body) { var answer = new BytesMessage { Content = body }; return(ConfigureMessage(answer) as IBytesMessage); }
protected override IBytesMessage DoCreateBytesMessage() { var message = new BytesMessage { Connection = _connection }; return(message); }
public void TestReadShort() { BytesMessage msg = new BytesMessage(); msg.WriteInt16((short)3000); msg.Reset(); Assert.IsTrue(msg.ReadInt16() == 3000); }
public void TestReadByte() { BytesMessage msg = new BytesMessage(); msg.WriteByte((byte)2); msg.Reset(); Assert.IsTrue(msg.ReadByte() == 2); }
public void TestReadDouble() { BytesMessage msg = new BytesMessage(); msg.WriteDouble(3.3d); msg.Reset(); Assert.IsTrue(msg.ReadDouble() == 3.3d); }
public void TestReadFloat() { BytesMessage msg = new BytesMessage(); msg.WriteSingle(3.3f); msg.Reset(); Assert.IsTrue(msg.ReadSingle() == 3.3f); }
public void TestReadLong() { BytesMessage msg = new BytesMessage(); msg.WriteInt64(3000); msg.Reset(); Assert.IsTrue(msg.ReadInt64() == 3000); }
public void TestReadChar() { BytesMessage msg = new BytesMessage(); msg.WriteChar('a'); msg.Reset(); Assert.IsTrue(msg.ReadChar() == 'a'); }
public void TestReadString() { BytesMessage msg = new BytesMessage(); string str = "this is a test"; msg.WriteString(str); msg.Reset(); Assert.IsTrue(msg.ReadString() == str); }
public BytesMessage GetByteMessageFromString(string message) { byte[] txId = StringHelper.GetBytesAdressFromString(message); BytesMessage bytesMessage = new BytesMessage(); bytesMessage.Value = ByteString.CopyFrom(txId); return(bytesMessage); }
private BytesMessage ConfigureMessage(BytesMessage message) { message.Connection = Connection; if (IsTransacted) { message.Acknowledger += DoNothingAcknowledge; } return(message); }
public void ConvertToProperties_BytesMessage_TypeIsText() { var queueConfiguration = new RabbitMqQueueConfiguration { Id = QueueId, Lifetime = TimeSpan.Zero }; var message = new BytesMessage(); var properties = message.ConvertToProperties(queueConfiguration); Assert.That(properties.ContentType, Is.EqualTo(BytesContentType)); }
public void Deserialize_NotATextMessage_ThrowsInvalidCastException() { // arrange var message = new BytesMessage(); // act var serializer = new JsonMessageSerializer <TestBody>(); // assert Assert.Throws <InvalidCastException>(() => serializer.Deserialize(message)); }
public void GetMessageBodyAsBytes_BytesMessage_BodyReturned() { var body = Encoding.UTF8.GetBytes(_xml.ToString()); var message = new BytesMessage { Body = body }; var result = message.GetMessageBodyAsBytes(); Assert.That(result == body); }
public void Deserialize_BytesMessage_CastResult() { var serializer = new XmlMessageSerializer <TextMessage>(); var message = new BytesMessage { Body = Encoding.UTF8.GetBytes(MessageText) }; var result = serializer.Deserialize(message); Assert.That(result.Body == "testMessage"); }
public IBytesMessage CreateBytesMessage(byte[] body) { BytesMessage answer = new BytesMessage(); answer.Content = body; return answer; }