Пример #1
0
        public SerializedObject(object data, ISerializer serializer)
        {
            if (data == null)
            {
                return;
            }
            var type = data.GetType();

            DataType = type.GetTypeName();
            if (data is byte[] bytes)
            {
                SerializerMimeType = null;
                Data = bytes;
            }
            else
            {
                SerializerMimeType = serializer.MimeTypes[0];
                if (serializer.Compressor != null)
                {
                    SerializerMimeType += ":" + serializer.Compressor.EncodingType;
                }
                Data = (byte[])serializer.Serialize(data, type);
            }
            SerializedObjects.TryAdd(Data, data);
        }
Пример #2
0
        public async Task <T> ReceiveAsync <T>(Guid correlationId, CancellationToken cancellationToken)
        {
            var rsMsg = await OnReceiveAsync(correlationId, cancellationToken).ConfigureAwait(false);

            if (rsMsg == null)
            {
                return(default(T));
            }

            rsMsg.Header.Response.ApplicationReceivedTime = Core.Now;
            Counters.IncrementMessagesReceived();
            Counters.IncrementReceivingTime(rsMsg.Header.Response.TotalTime);

            if (OnResponseReceived != null || MQueueClientEvents.OnResponseReceived != null)
            {
                var rrea = new ResponseReceivedEventArgs(Name, rsMsg);
                if (OnResponseReceived != null)
                {
                    await OnResponseReceived.InvokeAsync(this, rrea).ConfigureAwait(false);
                }
                if (MQueueClientEvents.OnResponseReceived != null)
                {
                    await MQueueClientEvents.OnResponseReceived.InvokeAsync(this, rrea).ConfigureAwait(false);
                }
            }

            if (rsMsg.Body == null)
            {
                return(default(T));
            }

            var res = default(T);

            try
            {
                res = (T)rsMsg.Body;
            }
            catch (Exception ex)
            {
                Core.Log.Write(ex);
            }
            if (res != null)
            {
                _receivedMessagesCache.TryAdd(res, rsMsg);
            }
            return(res);
        }
        public void TryAddTest()
        {
            var dictionary = new WeakDictionary <object, int, object>();

            var obj1 = new object();
            var obj2 = new object();
            var obj3 = new object();
            var obj4 = new object();

            Assert.IsTrue(dictionary.TryAdd(obj1, 10, obj2));
            Assert.IsTrue(dictionary.TryAdd(obj1, 11, obj3));
            Assert.IsTrue(dictionary.TryAdd(obj2, 10, obj4));
            Assert.IsFalse(dictionary.TryAdd(obj1, 10, obj2));
            Assert.IsFalse(dictionary.TryAdd(obj1, 11, obj3));
            Assert.IsFalse(dictionary.TryAdd(obj2, 10, obj4));

            Assert.AreEqual(obj2, dictionary[obj1, 10]);
            Assert.AreEqual(obj3, dictionary[obj1, 11]);
            Assert.AreEqual(obj4, dictionary[obj2, 10]);
        }
Пример #4
0
 public bool TryAdd(WeakDictionary <object, int, object> d, Tuple <object, int> k, object v)
 {
     return(d.TryAdd(k.Item1, k.Item2, v));
 }
Пример #5
0
 public bool TryAdd(WeakDictionary <int, object> d, int k, object v)
 {
     return(d.TryAdd(k, v));
 }