コード例 #1
0
        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;
        }
コード例 #2
0
        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));
        }
コード例 #4
0
 public AggregateRoot Get(string id)
 {
     byte[] value = _redisClient.Get(id);
     if (value != null && value.Length > 0)
     {
         return(_binarySerializer.Deserialize(value) as AggregateRoot);
     }
     return(null);
 }
コード例 #5
0
 public AggregateRoot Get(string id)
 {
     byte[] value;
     if (_cacheDict.TryGetValue(id, out value))
     {
         return(_binarySerializer.Deserialize(value) as AggregateRoot);
     }
     return(null);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
 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);
 }
コード例 #9
0
 /// <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));
         }
     }
 }
コード例 #10
0
 /// <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);
 }
コード例 #11
0
ファイル: MessageService.cs プロジェクト: yonghu86/equeue
        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)));
            }
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        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));
        }
コード例 #14
0
ファイル: Transaction.cs プロジェクト: shargon/neo-sharp
        /// <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));
                }
            }
        }
コード例 #15
0
        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)));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: DefaultMemoryCache.cs プロジェクト: ted9/cqrs
        /// <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));
        }
コード例 #18
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            var request = _binarySerializer.Deserialize <CreateTopicRequest>(remotingRequest.Body);

            _queueStore.CreateTopic(request.Topic, request.InitialQueueCount);
            return(RemotingResponseFactory.CreateResponse(remotingRequest));
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        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)));
        }
コード例 #21
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            var addQueueRequest = _binarySerializer.Deserialize <AddQueueRequest>(remotingRequest.Body);

            _queueStore.AddQueue(addQueueRequest.Topic);
            return(RemotingResponseFactory.CreateResponse(remotingRequest));
        }
コード例 #22
0
        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));
        }
コード例 #23
0
 public static T Deserialize <T>(this IBinarySerializer serializer, byte[] serialized)
 {
     using (var reader = new MemoryStream(serialized))
     {
         return((T)serializer.Deserialize(typeof(T), reader));
     }
 }
コード例 #24
0
        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));
        }
コード例 #25
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            var request = _binarySerializer.Deserialize <BrokerRegistrationRequest>(remotingRequest.Body);

            _clusterManager.RegisterBroker(context.Connection, request);
            return(RemotingResponseFactory.CreateResponse(remotingRequest));
        }
コード例 #26
0
        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;
            }
        }
コード例 #27
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            var disableQueueRequest = _binarySerializer.Deserialize <DisableQueueRequest>(remotingRequest.Body);

            _queueService.DisableQueue(disableQueueRequest.Topic, disableQueueRequest.QueueId);
            return(RemotingResponseFactory.CreateResponse(remotingRequest));
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        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();
            }
        }
コード例 #30
0
        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));
        }