Ejemplo n.º 1
0
 public AnyProto ToAnyProto <T>(T obj)
 {
     return(new AnyProto()
     {
         Data = ByteString.CopyFrom(_binarySerializer.Serialize(obj))
     });
 }
Ejemplo n.º 2
0
        private byte[] SerializeDict(Type dictType, object dictObj)
        {
            var genericArgs = dictType.GetGenericArguments();
            var keyType     = genericArgs[0];
            var valueType   = genericArgs[1];

            var myDict = new SerializableDictionary()
            {
                KeyTypeFullName   = keyType.FullName,
                ValueTypeFullName = valueType.FullName
            };

            var dict = (IDictionary)dictObj;

            foreach (DictionaryEntry item in dict)
            {
                var key   = item.Key;
                var value = item.Value;

                var dictItem = new SerializableKeyValuePair()
                {
                    Key   = Serialize(key),
                    Value = Serialize(value)
                };

                myDict.Items.Add(dictItem);
            }

            return(_binarySerializer.Serialize(myDict));
        }
Ejemplo n.º 3
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var req      = (ChaosInvocation)_binarySerializer.Deserialize(typeof(ChaosInvocation), e.RawData);
            var resp     = _chaosService.ProcessInvocation(req);
            var respData = _binarySerializer.Serialize(resp);

            Send(respData);
        }
Ejemplo n.º 4
0
        void MessageReceived(IWebSocketConnection webSocketConnection)
        {
            webSocketConnection.OnBinary = data =>
            {
                var req = (ChaosInvocation)_binarySerializer.Deserialize(typeof(ChaosInvocation), data);

                var resp = _chaosService.ProcessInvocation(req);

                var respData = _binarySerializer.Serialize(resp);

                webSocketConnection.Send(respData);
            };
        }
Ejemplo n.º 5
0
        public object Send(ChaosInvocation invocation)
        {
            var data = _binarySerializer.Serialize(invocation);

            object resp = null;

            lock (_lock)
            {
                _singal = new AutoResetEvent(false);
                _client.Send(data);

                if (!_singal.WaitOne(_config.Value.WaitTimeout))
                {
                    throw new TimeoutException();
                }

                resp = _chaosConverter.ToData(_reply);
            }

            return(resp);
        }