Exemple #1
0
        public Task <Message <TKey, TValue> > ProduceAsync(string topic, TKey key, TValue val, DateTime?timestamp = null, int?partition = null, bool blockIfQueueFull = true)
        {
            var handler = new TypedTaskDeliveryHandlerShim(key, val);

            producer.ProduceAsync(topic, KeySerializer?.Serialize(key), ValueSerializer?.Serialize(val), handler, timestamp, partition, blockIfQueueFull);
            return(handler.Task);
        }
 /// <summary>Converts an object into its XML representation.</summary>
 /// <param name="writer">
 ///     The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.
 /// </param>
 void IXmlSerializable.WriteXml(XmlWriter writer)
 {
     foreach (KeyValuePair <TKey, TVal> pair in this)
     {
         KeySerializer.Serialize(writer, pair.Key);
         ValueSerializer.Serialize(writer, pair.Value);
     }
 }
Exemple #3
0
        private void Produce(string topic, TKey key, TValue val, DateTime?timestamp, int partition, bool blockIfQueueFull, IDeliveryHandler <TKey, TValue> deliveryHandler)
        {
            var handler  = new TypedDeliveryHandlerShim(key, val, deliveryHandler);
            var keyBytes = KeySerializer?.Serialize(key);
            var valBytes = ValueSerializer?.Serialize(val);

            producer.Produce(topic, valBytes, 0, valBytes == null ? 0 : valBytes.Length, keyBytes, 0, keyBytes == null ? 0 : keyBytes.Length, timestamp, partition, blockIfQueueFull, handler);
        }
Exemple #4
0
        public void Serialize_should_return_bytes_from_guid()
        {
            var sut = new KeySerializer <Guid>();

            var expectedGuid = Guid.NewGuid();
            var result       = sut.Serialize(expectedGuid, default);

            result.Should().BeEquivalentTo(expectedGuid.ToByteArray());
        }
Exemple #5
0
        public virtual async Task <ISet <TItem> > GetValueOrEmptyAsync(TKey key)
        {
            var setMap = (ISetMap <TKey, TItem>)Map;
            var items  = await setMap.GetValueOrEmptyAsync(key);

            await Scope.AddKeyAsync(Identifier, KeySerializer.Serialize(key)).ConfigureAwait(false);

            return(_removeOnEmptySet ? new SetWrapper(key, items, _scope, Identifier, _keySerializer) : items);
        }
Exemple #6
0
 public SerializedKey Protect(RsaKeyContainer key)
 {
     ProtectWasCalled = true;
     return(new SerializedKey
     {
         Id = key.Id,
         KeyType = key.KeyType,
         Created = DateTime.UtcNow,
         Data = KeySerializer.Serialize(key),
     });
 }
Exemple #7
0
        public void Serialize_should_return_json_bytes_from_class()
        {
            var sut = new KeySerializer <DummyMessage>();

            var message      = DummyMessage.New();
            var jsonMessage  = JsonSerializer.Serialize(message);
            var expectedData = Encoding.UTF8.GetBytes(jsonMessage);

            var result = sut.Serialize(message, default);

            result.Should().BeEquivalentTo(expectedData);
        }
Exemple #8
0
 public SerializedKey Protect(KeyContainer key)
 {
     ProtectWasCalled = true;
     return(new SerializedKey
     {
         Id = key.Id,
         Algorithm = key.Algorithm,
         IsX509Certificate = key.HasX509Certificate,
         Created = DateTime.UtcNow,
         Data = KeySerializer.Serialize(key),
     });
 }
Exemple #9
0
 /// <summary>
 /// Gets or sets the <see cref="TValue"/> with the specified key.
 /// </summary>
 /// <value>
 /// The <see cref="TValue"/>.
 /// </value>
 /// <param name="key">The key.</param>
 /// <returns></returns>
 public TValue this[TKey key]
 {
     get
     {
         var redisValue = RedisDb.HashGet(RedisKey, KeySerializer.Serialize(key));
         return(redisValue.IsNull ? default(TValue) : ValueSerializer.Deserialize <TValue>(redisValue));
     }
     set
     {
         Add(key, value);
     }
 }
 void IXmlSerializable.WriteXml(XmlWriter writer)
 {
     foreach (var kvp in this)
     {
         writer.WriteStartElement(ItemNodeName);
         writer.WriteStartElement(KeyNodeName);
         KeySerializer.Serialize(writer, kvp.Key);
         writer.WriteEndElement();
         writer.WriteStartElement(ValueNodeName);
         ValueSerializer.Serialize(writer, kvp.Value);
         writer.WriteEndElement();
         writer.WriteEndElement();
     }
 }
 void System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
 {
     foreach (System.Collections.Generic.KeyValuePair <TKey, TVal> kvp in this)
     {
         writer.WriteStartElement(ItemNodeName);
         writer.WriteStartElement(KeyNodeName);
         KeySerializer.Serialize(writer, kvp.Key);
         writer.WriteEndElement();
         writer.WriteStartElement(ValueNodeName);
         ValueSerializer.Serialize(writer, kvp.Value);
         writer.WriteEndElement();
         writer.WriteEndElement();
     }
 }
    /// <summary>
    /// Persists new key in storage.
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public Task StoreKeyAsync(SerializedKey key)
    {
        if (!_directory.Exists)
        {
            _directory.Create();
        }

        var json = KeySerializer.Serialize(key);

        var path = Path.Combine(_directory.FullName, KeyFilePrefix + key.Id + KeyFileExtension);

        File.WriteAllText(path, json, Encoding.UTF8);

        return(Task.CompletedTask);
    }
Exemple #13
0
 void IXmlSerializable.WriteXml(XmlWriter i_Writer)
 {
     //writer.WriteStartElement(DictionaryNodeName);
     foreach (KeyValuePair <TKey, TVal> kvp in this)
     {
         i_Writer.WriteStartElement(k_ItemNodeName);
         i_Writer.WriteStartElement(k_KeyNodeName);
         KeySerializer.Serialize(i_Writer, kvp.Key);
         i_Writer.WriteEndElement();
         i_Writer.WriteStartElement(k_ValueNodeName);
         ValueSerializer.Serialize(i_Writer, kvp.Value);
         i_Writer.WriteEndElement();
         i_Writer.WriteEndElement();
     }
 }
 void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
 {
     //writer.WriteStartElement(DictionaryNodeName);
     foreach (KeyValuePair <TKey, TVal> kvp in this)
     {
         writer.WriteStartElement(ItemNodeName);
         writer.WriteStartElement(KeyNodeName);
         KeySerializer.Serialize(writer, kvp.Key);
         writer.WriteEndElement();
         writer.WriteStartElement(ValueNodeName);
         ValueSerializer.Serialize(writer, kvp.Value);
         writer.WriteEndElement();
         writer.WriteEndElement();
     }
     //writer.WriteEndElement();
 }
        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            // writer.WriteStartElement(DictionaryNodeName);
            foreach (var kvp in this)
            {
                writer.WriteStartElement(Map <TKey, TVal> .ItemNodeName);
                writer.WriteStartElement(Map <TKey, TVal> .KeyNodeName);
                KeySerializer.Serialize(writer, kvp.Key);
                writer.WriteEndElement();
                writer.WriteStartElement(Map <TKey, TVal> .ValueNodeName);
                ValueSerializer.Serialize(writer, kvp.Value);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }

            // writer.WriteEndElement();
        }
Exemple #16
0
        /// <summary>
        /// Converts an object into its XML representation.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            foreach (var key in Keys)
            {
                writer.WriteStartElement(keyItem);

                writer.WriteStartElement(keyKey);
                KeySerializer.Serialize(writer, key);
                writer.WriteEndElement();

                writer.WriteStartElement(keyValue);
                var value = this[key];
                ValueSerializer.Serialize(writer, value);
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
        }
Exemple #17
0
    void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
    {
        //writer.WriteStartElement(DictionaryNodeName);
        foreach (KeyValuePair <TKey, TVal> kvp in this)
        {
            writer.WriteStartElement(ItemNodeName);
            writer.WriteStartElement(KeyNodeName);
            KeySerializer.Serialize(writer, kvp.Key);
            writer.WriteEndElement();
            writer.WriteStartElement(ValueNodeName);
//			if ( kvp.Value is float )
//				ValueSerializer.Serialize (writer, string.Format (System.Globalization.CultureInfo.InvariantCulture.NumberFormat, "{0}", kvp.Value) );
//			else
            ValueSerializer.Serialize(writer, kvp.Value);
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
        //writer.WriteEndElement();
    }
    /// <inheritdoc/>
    public SerializedKey Protect(KeyContainer key)
    {
        var data = KeySerializer.Serialize(key);

        if (_options.DataProtectKeys)
        {
            data = _dataProtectionProvider.Protect(data);
        }

        return(new SerializedKey
        {
            Version = 1,
            Created = DateTime.UtcNow,
            Id = key.Id,
            Algorithm = key.Algorithm,
            IsX509Certificate = key.HasX509Certificate,
            Data = data,
            DataProtected = _options.DataProtectKeys,
        });
    }
Exemple #19
0
        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            //writer.WriteStartElement(DictionaryNodeName);
            foreach (var kvp in this)
            {
                writer.WriteStartElement(ItemNodeName);

                // Key attribute
                writer.WriteStartElement(KeyNodeName);
                KeySerializer.Serialize(writer, kvp.Key);
                writer.WriteEndElement();

                // Value text
                writer.WriteStartElement(ValueNodeName);
                ValueSerializer.Serialize(writer, kvp.Value);
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
            //writer.WriteEndElement();
        }
 /// <summary>
 /// Adds the multiple.
 /// </summary>
 /// <param name="items">The items.</param>
 public void AddMultiple(IEnumerable <KeyValuePair <TKey, TValue> > items)
 {
     RedisDb.HashSet(RedisKey, items.Select(i => new HashEntry(KeySerializer.Serialize(i.Key), ValueSerializer.Serialize(i.Value))).ToArray());
 }
Exemple #21
0
 /// <summary>
 /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1" /> contains a specific value.
 /// </summary>
 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
 /// <returns>
 /// true if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false.
 /// </returns>
 public bool Contains(KeyValuePair <TKey, TValue> item)
 {
     return(RedisDb.HashExists(RedisKey, KeySerializer.Serialize(item.Key)));
 }
Exemple #22
0
        public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, DateTime?timestamp = null, int?partition = null, bool blockIfQueueFull = true)
        {
            var handler = new TypedDeliveryHandlerShim(key, val, deliveryHandler);

            producer.ProduceAsync(topic, KeySerializer?.Serialize(key), ValueSerializer?.Serialize(val), handler, timestamp, partition, blockIfQueueFull);
        }