public NetworkPacket Deserialize(MessageReader br) { var packetSize = br.ReadInt32(); var packet = new NetworkPacket(); packet.Id = br.ReadInt16(); var payload = br.ReadBytes(packetSize - HeaderSize);//dataSize if (packetLookup.TryGetValue(packet.Id, out var targetType)) { try { packet.Data = binarySerializer.Deserialize(payload, targetType); return(packet); } catch (Exception exc) { var hoverOverMe = GenerateDebugCode(payload, targetType); throw; } } throw new Exception($"Unable to deserialize packet. No type lookups registered for packet ID ({packet.Id})."); //packet.Data = payload; //return packet; }
public void deserialize_primitive_reference_type() { var data = binarySerializer.Serialize("primitive.type"); var obj = binarySerializer.Deserialize <string>(data); Assert.AreEqual(obj, "primitive.type"); }
public async Task <DownstreamAuthorizeResponse> GetDownstreamIdTokenResponseAsync(string id) { var key = OIDCPipleLineStoreUtils.GenerateDownstreamIdTokenResponseKey(id); var result = await _cache.GetAsync(key); return(_binarySerializer.Deserialize <DownstreamAuthorizeResponse>(result)); }
public AggregateRoot Get(string id) { byte[] value = _redisClient.Get(id); if (value != null && value.Length > 0) { return(_binarySerializer.Deserialize(value) as AggregateRoot); } return(null); }
public AggregateRoot Get(string id) { byte[] value; if (_cacheDict.TryGetValue(id, out value)) { return(_binarySerializer.Deserialize(value) as AggregateRoot); } return(null); }
protected override void DeserializeExclusiveData(IBinarySerializer deserializer, BinaryReader reader, BinarySerializerSettings settings = null) { AssetType = (AssetType)reader.ReadByte(); Name = reader.ReadVarString(1024); Amount = deserializer.Deserialize <Fixed8>(reader, settings); Precision = reader.ReadByte(); Owner = deserializer.Deserialize <ECPoint>(reader, settings); Admin = deserializer.Deserialize <UInt160>(reader, settings); }
/// <summary>Query event streams from event store. /// </summary> public IEnumerable <EventStream> Query(string aggregateRootId, Type aggregateRootType, long minStreamVersion, long maxStreamVersion) { var dataArray = _redisClient.HVals(aggregateRootId); var streams = new List <EventStream>(); foreach (var data in dataArray) { var stream = _binarySerializer.Deserialize(data, typeof(EventStream)) as EventStream; streams.Add(stream); } return(streams.Where(x => x.Version >= minStreamVersion && x.Version <= maxStreamVersion)); }
public T Undo(T current) { if (CanUndo()) { var bson = _serializer.Serialize(current); if (bson != null) { _redos.Push(bson); return(_serializer.Deserialize <T>(_undos.Pop())); } } return(null); }
/// <summary> /// 从字节数组反序列化一个对象。 /// </summary> public static T Deserialize <T>(this IBinarySerializer serializer, byte[] data, bool resolveType = false) { using (var stream = new MemoryStream(data)) { if (resolveType) { return((T)serializer.Deserialize(stream, typeof(T))); } else { return((T)serializer.Deserialize(stream)); } } }
/// <summary>Get an aggregate from memory cache. /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public AggregateRoot Get(object id, Type type) { if (id == null) { throw new ArgumentNullException("id"); } byte[] value; if (_cacheDict.TryGetValue(id.ToString(), out value)) { return(_binarySerializer.Deserialize(value, type) as AggregateRoot); } return(null); }
public BrokerStatisticInfo QueryBrokerStatisticInfo() { var remotingRequest = new RemotingRequest((int)RequestCode.QueryBrokerStatisticInfo, new byte[0]); var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000); if (remotingResponse.Code == (int)ResponseCode.Success) { return(_binarySerializer.Deserialize <BrokerStatisticInfo>(remotingResponse.Body)); } else { throw new Exception(string.Format("QueryBrokerStatisticInfo failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body))); } }
/// <summary>Get an aggregate from memory cache. /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public AggregateRoot Get(object id, Type type) { if (id == null) { throw new ArgumentNullException("id"); } var value = _redisClient.Get(id.ToString()); if (value != null && value.Length > 0) { return(_binarySerializer.Deserialize(value, type) as AggregateRoot); } return(null); }
private T Deserialize <T>(IsolatedStorageFile file, string fileName, IBinarySerializer bin) { using (var stream = file.OpenFile(fileName, FileMode.Open)) { var buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); var data = bin.Deserialize <LocalData>(buffer); if (data != null) { return(bin.Deserialize <T>(data.License)); } } return(default(T)); }
/// <summary> /// Deserialize logic /// </summary> /// <param name="deserializer">Deserializer</param> /// <param name="reader">Reader</param> /// <param name="settings">Settings</param> public void Deserialize(IBinarySerializer deserializer, BinaryReader reader, BinarySerializerSettings settings = null) { // Check type // Byte already readed // if ((byte)Type != reader.ReadByte()) // throw new FormatException(); // Read version Version = reader.ReadByte(); // Deserialize exclusive data DeserializeExclusiveData(deserializer, reader, settings); // Deserialize shared content Attributes = deserializer.Deserialize <TransactionAttribute[]>(reader, settings); if (Attributes.Length > ushort.MaxValue) { throw new FormatException(nameof(Attributes)); } Inputs = deserializer.Deserialize <CoinReference[]>(reader, settings); if (Inputs.Length > ushort.MaxValue) { throw new FormatException(nameof(Inputs)); } Outputs = deserializer.Deserialize <TransactionOutput[]>(reader, settings); if (Outputs.Length > ushort.MaxValue) { throw new FormatException(nameof(Outputs)); } // Deserialize signature if (settings?.Filter?.Invoke(nameof(Witness)) != false) { Witness = deserializer.Deserialize <Witness[]>(reader, settings); if (Witness.Length > ushort.MaxValue) { throw new FormatException(nameof(Witness)); } } }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { if (BrokerController.Instance.IsCleaning) { throw new BrokerCleanningException(); } var request = _binarySerializer.Deserialize <QueryTopicQueueInfoRequest>(remotingRequest.Body); var topicQueueInfoList = new List <TopicQueueInfo>(); var queues = _queueStore.QueryQueues(request.Topic).ToList().OrderBy(x => x.Topic).ThenBy(x => x.QueueId); foreach (var queue in queues) { var topicQueueInfo = new TopicQueueInfo(); topicQueueInfo.Topic = queue.Topic; topicQueueInfo.QueueId = queue.QueueId; topicQueueInfo.QueueCurrentOffset = queue.NextOffset - 1; topicQueueInfo.QueueMinOffset = queue.GetMinQueueOffset(); topicQueueInfo.QueueMinConsumedOffset = _offsetStore.GetMinConsumedOffset(queue.Topic, queue.QueueId); topicQueueInfo.ProducerVisible = queue.Setting.ProducerVisible; topicQueueInfo.ConsumerVisible = queue.Setting.ConsumerVisible; topicQueueInfoList.Add(topicQueueInfo); } return(RemotingResponseFactory.CreateResponse(remotingRequest, _binarySerializer.Serialize(topicQueueInfoList))); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var consumerData = _binarySerializer.Deserialize <ConsumerHeartbeatData>(remotingRequest.Body); _consumerManager.RegisterConsumer(consumerData.GroupName, consumerData.ConsumerId, consumerData.SubscriptionTopics, consumerData.ConsumingQueues, context.Connection); return(null); }
/// <summary> /// 从缓存中获取该类型的实例。 /// </summary> public object Get(Type type, object key) { if (!_enabled) { return(null); } Ensure.NotNull(type, "type"); Ensure.NotNull(key, "key"); string cacheRegion = GetCacheRegion(type); string cacheKey = BuildCacheKey(type, key); object data = null; lock (cacheKey) { data = Cache.Current.Get(cacheRegion, cacheKey); } if (data == null) { return(null); } return(_serializer.Deserialize((byte[])data)); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <CreateTopicRequest>(remotingRequest.Body); _queueStore.CreateTopic(request.Topic, request.InitialQueueCount); return(RemotingResponseFactory.CreateResponse(remotingRequest)); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <SetQueueProducerVisibleRequest>(remotingRequest.Body); _queueStore.SetProducerVisible(request.Topic, request.QueueId, request.Visible); return(RemotingResponseFactory.CreateResponse(remotingRequest)); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <QueryConsumerInfoRequest>(remotingRequest.Body); var consumerInfoList = new List <ConsumerInfo>(); if (!string.IsNullOrEmpty(request.GroupName)) { var consumerGroups = _consumerManager.QueryConsumerGroup(request.GroupName); foreach (var consumerGroup in consumerGroups) { foreach (var topicConsumeInfo in GetConsumerInfoForGroup(consumerGroup, request.Topic)) { consumerInfoList.Add(topicConsumeInfo); } } } else { var consumerGroups = _consumerManager.GetAllConsumerGroups(); foreach (var consumerGroup in consumerGroups) { foreach (var topicConsumeInfo in GetConsumerInfoForGroup(consumerGroup, request.Topic)) { consumerInfoList.Add(topicConsumeInfo); } } } return(RemotingResponseFactory.CreateResponse(remotingRequest, _binarySerializer.Serialize(consumerInfoList))); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var addQueueRequest = _binarySerializer.Deserialize <AddQueueRequest>(remotingRequest.Body); _queueStore.AddQueue(addQueueRequest.Topic); return(RemotingResponseFactory.CreateResponse(remotingRequest)); }
public SendResult Send(Message message, object arg) { var queueCount = GetTopicQueueCount(message.Topic); if (queueCount == 0) { throw new Exception(string.Format("No available queue for topic [{0}], producerId:{1}.", message.Topic, Id)); } var queueId = _queueSelector.SelectQueueId(queueCount, message, arg); var remotingRequest = BuildSendMessageRequest(message, queueId); var remotingResponse = _remotingClient.InvokeSync(remotingRequest, Setting.SendMessageTimeoutMilliseconds); var response = _binarySerializer.Deserialize <SendMessageResponse>(remotingResponse.Body); var sendStatus = SendStatus.Success; //TODO, figure from remotingResponse.Code; return(new SendResult(sendStatus, response.MessageOffset, response.MessageQueue, response.QueueOffset)); }
public static T Deserialize <T>(this IBinarySerializer serializer, byte[] serialized) { using (var reader = new MemoryStream(serialized)) { return((T)serializer.Deserialize(typeof(T), reader)); } }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <QueryConsumerInfoRequest>(remotingRequest.Body); var consumerInfoList = new List <ConsumerInfo>(); if (!string.IsNullOrEmpty(request.GroupName)) { var consumerGroups = _consumerManager.QueryConsumerGroup(request.GroupName); foreach (var consumerGroup in consumerGroups) { foreach (var topicConsumeInfo in GetConsumerInfoForGroup(consumerGroup, request.Topic)) { consumerInfoList.Add(topicConsumeInfo); } } } else { var consumerGroups = _consumerManager.GetAllConsumerGroups(); foreach (var consumerGroup in consumerGroups) { foreach (var topicConsumeInfo in GetConsumerInfoForGroup(consumerGroup, request.Topic)) { consumerInfoList.Add(topicConsumeInfo); } } } var data = _binarySerializer.Serialize(consumerInfoList); return(new RemotingResponse((int)ResponseCode.Success, remotingRequest.Sequence, data)); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <BrokerRegistrationRequest>(remotingRequest.Body); _clusterManager.RegisterBroker(context.Connection, request); return(RemotingResponseFactory.CreateResponse(remotingRequest)); }
protected override void DeserializeExclusiveData(IBinarySerializer deserializer, BinaryReader reader, BinarySerializerSettings settings = null) { if (Version > 1) { throw new InvalidTransactionException(nameof(Version)); } Script = reader.ReadVarBytes(65536); if (Script.Length == 0) { throw new FormatException(); } if (Version >= 1) { Gas = deserializer.Deserialize <Fixed8>(reader, settings); if (Gas < Fixed8.Zero) { throw new InvalidTransactionException(); } } else { Gas = Fixed8.Zero; } }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var disableQueueRequest = _binarySerializer.Deserialize <DisableQueueRequest>(remotingRequest.Body); _queueService.DisableQueue(disableQueueRequest.Topic, disableQueueRequest.QueueId); return(RemotingResponseFactory.CreateResponse(remotingRequest)); }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <RemoveQueueOffsetInfoRequest>(remotingRequest.Body); _offsetManager.DeleteQueueOffset(request.ConsumerGroup, request.Topic, request.QueueId); return(RemotingResponseFactory.CreateResponse(remotingRequest)); }
public async Task <T> GetOrCreateAsync <T>(string key, Func <Task <T> > generator, TimeSpan?timeSpan = null) { try { await Semaphore.WaitAsync(); var value = await _distributedCache.GetAsync(key); if (value != default && value.Length != 0) { return(_binarySerializer.Deserialize <T>(value)); } var valueToCache = await generator(); await _distributedCache.SetAsync(key, _binarySerializer.Serialize(valueToCache), new DistributedCacheEntryOptions()); return(valueToCache); } finally { Semaphore.Release(); } }
public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest) { var request = _binarySerializer.Deserialize <QueryTopicQueueInfoRequest>(remotingRequest.Body); var topicQueueInfoList = new List <TopicQueueInfo>(); var topicList = !string.IsNullOrEmpty(request.Topic) ? new List <string> { request.Topic } : _queueService.GetAllTopics().ToList(); foreach (var topic in topicList) { var queues = _queueService.QueryQueues(topic).ToList(); foreach (var queue in queues) { var topicQueueInfo = new TopicQueueInfo(); topicQueueInfo.Topic = queue.Topic; topicQueueInfo.QueueId = queue.QueueId; topicQueueInfo.QueueCurrentOffset = queue.CurrentOffset; topicQueueInfo.QueueMinOffset = queue.GetMinQueueOffset(); topicQueueInfo.QueueMessageCount = queue.GetMessageRealCount(); topicQueueInfo.QueueMaxConsumedOffset = _offsetManager.GetMinOffset(queue.Topic, queue.QueueId); topicQueueInfo.Status = queue.Status; topicQueueInfoList.Add(topicQueueInfo); } } var data = _binarySerializer.Serialize(topicQueueInfoList); return(new RemotingResponse((int)ResponseCode.Success, remotingRequest.Sequence, data)); }